主頁 > 前端設計 > unity 音樂小游戲

unity 音樂小游戲

2020-09-18 23:08:48 前端設計

目錄

  • 設計思路
  • 簡易特效
  • 游戲視頻
  • 源代碼
    • GetSpectrumData決議

設計思路

<style>#mermaid-svg-EeytOrTJIlUOdT70 .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-EeytOrTJIlUOdT70 .label text{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .node rect,#mermaid-svg-EeytOrTJIlUOdT70 .node circle,#mermaid-svg-EeytOrTJIlUOdT70 .node ellipse,#mermaid-svg-EeytOrTJIlUOdT70 .node polygon,#mermaid-svg-EeytOrTJIlUOdT70 .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-EeytOrTJIlUOdT70 .node .label{text-align:center;fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .node.clickable{cursor:pointer}#mermaid-svg-EeytOrTJIlUOdT70 .arrowheadPath{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-EeytOrTJIlUOdT70 .flowchart-link{stroke:#333;fill:none}#mermaid-svg-EeytOrTJIlUOdT70 .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-EeytOrTJIlUOdT70 .edgeLabel rect{opacity:0.9}#mermaid-svg-EeytOrTJIlUOdT70 .edgeLabel span{color:#333}#mermaid-svg-EeytOrTJIlUOdT70 .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-EeytOrTJIlUOdT70 .cluster text{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-EeytOrTJIlUOdT70 .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-EeytOrTJIlUOdT70 text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-EeytOrTJIlUOdT70 .actor-line{stroke:grey}#mermaid-svg-EeytOrTJIlUOdT70 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-EeytOrTJIlUOdT70 .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-EeytOrTJIlUOdT70 #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-EeytOrTJIlUOdT70 .sequenceNumber{fill:#fff}#mermaid-svg-EeytOrTJIlUOdT70 #sequencenumber{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 #crosshead path{fill:#333;stroke:#333}#mermaid-svg-EeytOrTJIlUOdT70 .messageText{fill:#333;stroke:#333}#mermaid-svg-EeytOrTJIlUOdT70 .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-EeytOrTJIlUOdT70 .labelText,#mermaid-svg-EeytOrTJIlUOdT70 .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-EeytOrTJIlUOdT70 .loopText,#mermaid-svg-EeytOrTJIlUOdT70 .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-EeytOrTJIlUOdT70 .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-EeytOrTJIlUOdT70 .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-EeytOrTJIlUOdT70 .noteText,#mermaid-svg-EeytOrTJIlUOdT70 .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-EeytOrTJIlUOdT70 .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-EeytOrTJIlUOdT70 .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-EeytOrTJIlUOdT70 .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-EeytOrTJIlUOdT70 .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .section{stroke:none;opacity:0.2}#mermaid-svg-EeytOrTJIlUOdT70 .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-EeytOrTJIlUOdT70 .section2{fill:#fff400}#mermaid-svg-EeytOrTJIlUOdT70 .section1,#mermaid-svg-EeytOrTJIlUOdT70 .section3{fill:#fff;opacity:0.2}#mermaid-svg-EeytOrTJIlUOdT70 .sectionTitle0{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .sectionTitle1{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .sectionTitle2{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .sectionTitle3{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-EeytOrTJIlUOdT70 .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .grid path{stroke-width:0}#mermaid-svg-EeytOrTJIlUOdT70 .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-EeytOrTJIlUOdT70 .task{stroke-width:2}#mermaid-svg-EeytOrTJIlUOdT70 .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .taskText:not([font-size]){font-size:11px}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-EeytOrTJIlUOdT70 .task.clickable{cursor:pointer}#mermaid-svg-EeytOrTJIlUOdT70 .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-EeytOrTJIlUOdT70 .taskText0,#mermaid-svg-EeytOrTJIlUOdT70 .taskText1,#mermaid-svg-EeytOrTJIlUOdT70 .taskText2,#mermaid-svg-EeytOrTJIlUOdT70 .taskText3{fill:#fff}#mermaid-svg-EeytOrTJIlUOdT70 .task0,#mermaid-svg-EeytOrTJIlUOdT70 .task1,#mermaid-svg-EeytOrTJIlUOdT70 .task2,#mermaid-svg-EeytOrTJIlUOdT70 .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutside0,#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutside2{fill:#000}#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutside1,#mermaid-svg-EeytOrTJIlUOdT70 .taskTextOutside3{fill:#000}#mermaid-svg-EeytOrTJIlUOdT70 .active0,#mermaid-svg-EeytOrTJIlUOdT70 .active1,#mermaid-svg-EeytOrTJIlUOdT70 .active2,#mermaid-svg-EeytOrTJIlUOdT70 .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-EeytOrTJIlUOdT70 .activeText0,#mermaid-svg-EeytOrTJIlUOdT70 .activeText1,#mermaid-svg-EeytOrTJIlUOdT70 .activeText2,#mermaid-svg-EeytOrTJIlUOdT70 .activeText3{fill:#000 !important}#mermaid-svg-EeytOrTJIlUOdT70 .done0,#mermaid-svg-EeytOrTJIlUOdT70 .done1,#mermaid-svg-EeytOrTJIlUOdT70 .done2,#mermaid-svg-EeytOrTJIlUOdT70 .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-EeytOrTJIlUOdT70 .doneText0,#mermaid-svg-EeytOrTJIlUOdT70 .doneText1,#mermaid-svg-EeytOrTJIlUOdT70 .doneText2,#mermaid-svg-EeytOrTJIlUOdT70 .doneText3{fill:#000 !important}#mermaid-svg-EeytOrTJIlUOdT70 .crit0,#mermaid-svg-EeytOrTJIlUOdT70 .crit1,#mermaid-svg-EeytOrTJIlUOdT70 .crit2,#mermaid-svg-EeytOrTJIlUOdT70 .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-EeytOrTJIlUOdT70 .activeCrit0,#mermaid-svg-EeytOrTJIlUOdT70 .activeCrit1,#mermaid-svg-EeytOrTJIlUOdT70 .activeCrit2,#mermaid-svg-EeytOrTJIlUOdT70 .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-EeytOrTJIlUOdT70 .doneCrit0,#mermaid-svg-EeytOrTJIlUOdT70 .doneCrit1,#mermaid-svg-EeytOrTJIlUOdT70 .doneCrit2,#mermaid-svg-EeytOrTJIlUOdT70 .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-EeytOrTJIlUOdT70 .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-EeytOrTJIlUOdT70 .milestoneText{font-style:italic}#mermaid-svg-EeytOrTJIlUOdT70 .doneCritText0,#mermaid-svg-EeytOrTJIlUOdT70 .doneCritText1,#mermaid-svg-EeytOrTJIlUOdT70 .doneCritText2,#mermaid-svg-EeytOrTJIlUOdT70 .doneCritText3{fill:#000 !important}#mermaid-svg-EeytOrTJIlUOdT70 .activeCritText0,#mermaid-svg-EeytOrTJIlUOdT70 .activeCritText1,#mermaid-svg-EeytOrTJIlUOdT70 .activeCritText2,#mermaid-svg-EeytOrTJIlUOdT70 .activeCritText3{fill:#000 !important}#mermaid-svg-EeytOrTJIlUOdT70 .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-EeytOrTJIlUOdT70 g.classGroup text .title{font-weight:bolder}#mermaid-svg-EeytOrTJIlUOdT70 g.clickable{cursor:pointer}#mermaid-svg-EeytOrTJIlUOdT70 g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-EeytOrTJIlUOdT70 g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-EeytOrTJIlUOdT70 .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-EeytOrTJIlUOdT70 .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-EeytOrTJIlUOdT70 .dashed-line{stroke-dasharray:3}#mermaid-svg-EeytOrTJIlUOdT70 #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 .commit-id,#mermaid-svg-EeytOrTJIlUOdT70 .commit-msg,#mermaid-svg-EeytOrTJIlUOdT70 .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-EeytOrTJIlUOdT70 g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-EeytOrTJIlUOdT70 g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-EeytOrTJIlUOdT70 g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-EeytOrTJIlUOdT70 .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-EeytOrTJIlUOdT70 .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-EeytOrTJIlUOdT70 .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-EeytOrTJIlUOdT70 .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-EeytOrTJIlUOdT70 .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-EeytOrTJIlUOdT70 .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-EeytOrTJIlUOdT70 .edgeLabel text{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-EeytOrTJIlUOdT70 .node circle.state-start{fill:black;stroke:black}#mermaid-svg-EeytOrTJIlUOdT70 .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-EeytOrTJIlUOdT70 #statediagram-barbEnd{fill:#9370db}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-state .divider{stroke:#9370db}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-EeytOrTJIlUOdT70 .note-edge{stroke-dasharray:5}#mermaid-svg-EeytOrTJIlUOdT70 .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-EeytOrTJIlUOdT70 .error-icon{fill:#522}#mermaid-svg-EeytOrTJIlUOdT70 .error-text{fill:#522;stroke:#522}#mermaid-svg-EeytOrTJIlUOdT70 .edge-thickness-normal{stroke-width:2px}#mermaid-svg-EeytOrTJIlUOdT70 .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-EeytOrTJIlUOdT70 .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-EeytOrTJIlUOdT70 .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-EeytOrTJIlUOdT70 .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-EeytOrTJIlUOdT70 .marker{fill:#333}#mermaid-svg-EeytOrTJIlUOdT70 .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style> <style>#mermaid-svg-EeytOrTJIlUOdT70 { color: rgba(0, 0, 0, 0.75); font: ; }</style>
方案一
方案二
音樂游戲
頻率
頻率峰值
改良
頻率密度
<style>#mermaid-svg-rO6IK5PgS6NuVDZu .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .label text{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .node rect,#mermaid-svg-rO6IK5PgS6NuVDZu .node circle,#mermaid-svg-rO6IK5PgS6NuVDZu .node ellipse,#mermaid-svg-rO6IK5PgS6NuVDZu .node polygon,#mermaid-svg-rO6IK5PgS6NuVDZu .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-rO6IK5PgS6NuVDZu .node .label{text-align:center;fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .node.clickable{cursor:pointer}#mermaid-svg-rO6IK5PgS6NuVDZu .arrowheadPath{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-rO6IK5PgS6NuVDZu .flowchart-link{stroke:#333;fill:none}#mermaid-svg-rO6IK5PgS6NuVDZu .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-rO6IK5PgS6NuVDZu .edgeLabel rect{opacity:0.9}#mermaid-svg-rO6IK5PgS6NuVDZu .edgeLabel span{color:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-rO6IK5PgS6NuVDZu .cluster text{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-rO6IK5PgS6NuVDZu .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-rO6IK5PgS6NuVDZu text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-rO6IK5PgS6NuVDZu .actor-line{stroke:grey}#mermaid-svg-rO6IK5PgS6NuVDZu .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-rO6IK5PgS6NuVDZu #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .sequenceNumber{fill:#fff}#mermaid-svg-rO6IK5PgS6NuVDZu #sequencenumber{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu #crosshead path{fill:#333;stroke:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .messageText{fill:#333;stroke:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-rO6IK5PgS6NuVDZu .labelText,#mermaid-svg-rO6IK5PgS6NuVDZu .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-rO6IK5PgS6NuVDZu .loopText,#mermaid-svg-rO6IK5PgS6NuVDZu .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-rO6IK5PgS6NuVDZu .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-rO6IK5PgS6NuVDZu .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-rO6IK5PgS6NuVDZu .noteText,#mermaid-svg-rO6IK5PgS6NuVDZu .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-rO6IK5PgS6NuVDZu .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-rO6IK5PgS6NuVDZu .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-rO6IK5PgS6NuVDZu .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-rO6IK5PgS6NuVDZu .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .section{stroke:none;opacity:0.2}#mermaid-svg-rO6IK5PgS6NuVDZu .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-rO6IK5PgS6NuVDZu .section2{fill:#fff400}#mermaid-svg-rO6IK5PgS6NuVDZu .section1,#mermaid-svg-rO6IK5PgS6NuVDZu .section3{fill:#fff;opacity:0.2}#mermaid-svg-rO6IK5PgS6NuVDZu .sectionTitle0{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .sectionTitle1{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .sectionTitle2{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .sectionTitle3{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-rO6IK5PgS6NuVDZu .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .grid path{stroke-width:0}#mermaid-svg-rO6IK5PgS6NuVDZu .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-rO6IK5PgS6NuVDZu .task{stroke-width:2}#mermaid-svg-rO6IK5PgS6NuVDZu .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .taskText:not([font-size]){font-size:11px}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-rO6IK5PgS6NuVDZu .task.clickable{cursor:pointer}#mermaid-svg-rO6IK5PgS6NuVDZu .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-rO6IK5PgS6NuVDZu .taskText0,#mermaid-svg-rO6IK5PgS6NuVDZu .taskText1,#mermaid-svg-rO6IK5PgS6NuVDZu .taskText2,#mermaid-svg-rO6IK5PgS6NuVDZu .taskText3{fill:#fff}#mermaid-svg-rO6IK5PgS6NuVDZu .task0,#mermaid-svg-rO6IK5PgS6NuVDZu .task1,#mermaid-svg-rO6IK5PgS6NuVDZu .task2,#mermaid-svg-rO6IK5PgS6NuVDZu .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutside0,#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutside2{fill:#000}#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutside1,#mermaid-svg-rO6IK5PgS6NuVDZu .taskTextOutside3{fill:#000}#mermaid-svg-rO6IK5PgS6NuVDZu .active0,#mermaid-svg-rO6IK5PgS6NuVDZu .active1,#mermaid-svg-rO6IK5PgS6NuVDZu .active2,#mermaid-svg-rO6IK5PgS6NuVDZu .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-rO6IK5PgS6NuVDZu .activeText0,#mermaid-svg-rO6IK5PgS6NuVDZu .activeText1,#mermaid-svg-rO6IK5PgS6NuVDZu .activeText2,#mermaid-svg-rO6IK5PgS6NuVDZu .activeText3{fill:#000 !important}#mermaid-svg-rO6IK5PgS6NuVDZu .done0,#mermaid-svg-rO6IK5PgS6NuVDZu .done1,#mermaid-svg-rO6IK5PgS6NuVDZu .done2,#mermaid-svg-rO6IK5PgS6NuVDZu .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-rO6IK5PgS6NuVDZu .doneText0,#mermaid-svg-rO6IK5PgS6NuVDZu .doneText1,#mermaid-svg-rO6IK5PgS6NuVDZu .doneText2,#mermaid-svg-rO6IK5PgS6NuVDZu .doneText3{fill:#000 !important}#mermaid-svg-rO6IK5PgS6NuVDZu .crit0,#mermaid-svg-rO6IK5PgS6NuVDZu .crit1,#mermaid-svg-rO6IK5PgS6NuVDZu .crit2,#mermaid-svg-rO6IK5PgS6NuVDZu .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-rO6IK5PgS6NuVDZu .activeCrit0,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCrit1,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCrit2,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-rO6IK5PgS6NuVDZu .doneCrit0,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCrit1,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCrit2,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-rO6IK5PgS6NuVDZu .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-rO6IK5PgS6NuVDZu .milestoneText{font-style:italic}#mermaid-svg-rO6IK5PgS6NuVDZu .doneCritText0,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCritText1,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCritText2,#mermaid-svg-rO6IK5PgS6NuVDZu .doneCritText3{fill:#000 !important}#mermaid-svg-rO6IK5PgS6NuVDZu .activeCritText0,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCritText1,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCritText2,#mermaid-svg-rO6IK5PgS6NuVDZu .activeCritText3{fill:#000 !important}#mermaid-svg-rO6IK5PgS6NuVDZu .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-rO6IK5PgS6NuVDZu g.classGroup text .title{font-weight:bolder}#mermaid-svg-rO6IK5PgS6NuVDZu g.clickable{cursor:pointer}#mermaid-svg-rO6IK5PgS6NuVDZu g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-rO6IK5PgS6NuVDZu g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-rO6IK5PgS6NuVDZu .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-rO6IK5PgS6NuVDZu .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-rO6IK5PgS6NuVDZu .dashed-line{stroke-dasharray:3}#mermaid-svg-rO6IK5PgS6NuVDZu #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu .commit-id,#mermaid-svg-rO6IK5PgS6NuVDZu .commit-msg,#mermaid-svg-rO6IK5PgS6NuVDZu .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-rO6IK5PgS6NuVDZu g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-rO6IK5PgS6NuVDZu g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-rO6IK5PgS6NuVDZu g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-rO6IK5PgS6NuVDZu .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-rO6IK5PgS6NuVDZu .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-rO6IK5PgS6NuVDZu .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-rO6IK5PgS6NuVDZu .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-rO6IK5PgS6NuVDZu .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-rO6IK5PgS6NuVDZu .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-rO6IK5PgS6NuVDZu .edgeLabel text{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-rO6IK5PgS6NuVDZu .node circle.state-start{fill:black;stroke:black}#mermaid-svg-rO6IK5PgS6NuVDZu .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-rO6IK5PgS6NuVDZu #statediagram-barbEnd{fill:#9370db}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-state .divider{stroke:#9370db}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-rO6IK5PgS6NuVDZu .note-edge{stroke-dasharray:5}#mermaid-svg-rO6IK5PgS6NuVDZu .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-rO6IK5PgS6NuVDZu .error-icon{fill:#522}#mermaid-svg-rO6IK5PgS6NuVDZu .error-text{fill:#522;stroke:#522}#mermaid-svg-rO6IK5PgS6NuVDZu .edge-thickness-normal{stroke-width:2px}#mermaid-svg-rO6IK5PgS6NuVDZu .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-rO6IK5PgS6NuVDZu .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-rO6IK5PgS6NuVDZu .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-rO6IK5PgS6NuVDZu .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-rO6IK5PgS6NuVDZu .marker{fill:#333}#mermaid-svg-rO6IK5PgS6NuVDZu .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style> <style>#mermaid-svg-rO6IK5PgS6NuVDZu { color: rgba(0, 0, 0, 0.75); font: ; }</style>
頻率密度
顏色
不同時機使用不同的顏色

具體玩法:音頻的高度不同,顏色不同,根據提示點擊相同顏色的音頻,點擊范圍有對應顏色加分,沒有對應顏色時,減分或者斷Combo,連續點對加分翻倍,要求顏色會隨機變化,
效果圖:在這里插入圖片描述

在這里插入圖片描述

簡易特效

新建一個粒子系統,將Mode變為Sprites,
添加自己的UI圖片(本體白色,背景透明),因為看不見所以我這里用的黑底,在這里插入圖片描述

在這里插入圖片描述
修改粒子的引數達到想要的效果,start color會使發出的星星隨機獲得顏色,
在這里插入圖片描述
由于前面的全是由UI做的,粒子效果為3D的,兩個無法同時顯示,
需要Ugui demo中的方法,就是利用相機,創建Render Texture,實作混排,
1:首先在你的project視圖中右鍵點擊create Render Texture
2:然后在新建一個攝像機,對準,新攝像機需要洗掉Audio Listener,
3:給攝像機target texuure賦予Render Texture,
4:在你的canvas 畫布下面新建一個Raw Image,調整好大小,再將render texture拖入到texture中,
在這里插入圖片描述
如果顯示出現背景,需要隱藏背景,解決方法:更改相機引數ClearFlags為Soild Color,
在這里插入圖片描述

游戲視頻

鏈接: 游戲視頻.

源代碼

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;


public class AudioDate : MonoBehaviour
{

    private AudioSource _audio;//聲源
    private float[] samples = new float[512];//存放頻譜資料的陣列長度(64-8192)
    public Transform sc;
    public float late;
    private float time;
                            // Use this for initialization
    private void Start()
    {
        time = 0;
        _audio = GetComponent<AudioSource>();//獲取聲源組件
        _audio.clip = SceneLink.Instance.audioClip;
        _audio.Play();
    }
    private void Update()
    {
        if (!_audio.isPlaying)
        {
            SceneLink.Instance.scores = GameRule.Instance.GetScores();
            SceneManager.LoadScene(0, LoadSceneMode.Single);
        }
        time += Time.deltaTime;
        if (time >= late)
        {
            //獲取頻譜
            _audio.GetSpectrumData(samples, 0, FFTWindow.BlackmanHarris);
            /* 因為子物體排列規律為0,1,-1,2,-2,所以,需要在賦予頻率密度時也需要重新排 */
            int mapIndex;         //映射對應的頻率塊,
            if ((sc.childCount-1) % 2 == 0)   
                mapIndex = sc.childCount - 1;
            else
                mapIndex = sc.childCount - 2;
            
            for (int i = 0; i < sc.childCount ; i++)
            {

                HeightChange hg = sc.GetChild(mapIndex).GetComponent<HeightChange>();
                hg.SetHeigth(samples[i]);
                hg.SetIndex(i);
                /*賦予規律為 6,4,2,0,1,3,5, */
                if (mapIndex % 2 == 0 && mapIndex != 0)
                    mapIndex -= 2;
                else if (mapIndex == 0)
                    mapIndex ++;
                else if (mapIndex % 2 != 0)
                    mapIndex += 2;

            };
            time = 0;
        }
    }
}

引數Late決定重繪速度
在這里插入圖片描述

GetSpectrumData決議

其中GetSpectrumData為關鍵API
以下為官方解釋
FFTWindow
enumerationLeave feedback
Description
Spectrum analysis windowing types.

Use this to reduce leakage of signals across frequency bands.

Properties
Rectangular W[n] = 1.0.
Triangle W[n] = TRI(2n/N).
Hamming W[n] = 0.54 - (0.46 * COS(n/N) ).
Hanning W[n] = 0.5 * (1.0 - COS(n/N) ).
Blackman W[n] = 0.42 - (0.5 * COS(n/N) ) + (0.08 * COS(2.0 * n/N) ).
BlackmanHarris W[n] = 0.35875 - (0.48829 * COS(1.0 * n/N)) + (0.14128 * COS(2.0 * n/N)) - (0.01168 * COS(3.0 * n/N)).

public void GetSpectrumData(float[] samples, int channel, FFTWindow window);
Parameters
samples The array to populate with audio samples. Its length must be a power of 2.
channel The channel to sample from.
window The FFTWindow type to use when sampling.
Description
Provides a block of the currently playing audio source’s spectrum data.

The array given in the samples parameter will be filled with the requested data.

Number of values (the length of the samples array provided) must be a power of 2. (ie 128/256/512 etc). Min = 64. Max = 8192. Use window to reduce leakage between frequency bins/bands. Note, the more complex window type, the better the quality, but reduced speed.

This function will use the sampling rate specified in AudioSettings.outputSampleRate, and NOT the sampling rate specified for the audio clip.

See Also: AudioSource.GetOutputData, AudioListener.GetSpectrumData, AudioListener.GetOutputData.

對于GetSpectrumData的引數:

Channel 0在這里是一個安全的選擇,因為如果我們有立體聲音頻,我們需要單獨處理2個通道的樣本資料, Channel 0包含立體聲樣本的平均值,將每2個立體聲樣本組合成1個單聲道樣本, 這使我們能夠更簡單地決定音頻中發生的事情,我們可以從眾多FFT視窗中選擇視窗并縮放我們的光譜資料, 我發現BlackmanHarris非常出色地向我們展示了每個頻率箱的不同動作,而箱之間沒有太多泄漏,

我們提供的陣列將填充到我們提供的陣列的長度,以及最近播放的音頻樣本的頻譜資料, 這意味著我們不必在GetSpectrumData之前呼叫GetOutputData, 陣列長度必須是2的冪,FFT分析對于2的冪的樣本大小最有效,Unity使用GetSpectrumData強制執行該建議,

我發現1024的頻譜陣列大小給了我們很好的粒度, 同樣,這意味著Unity引擎將采集2048個音頻樣本, 如果我們知道音頻采樣率,我們可以找到支持的頻譜資料頻率范圍,然后,使用我們的陣列大小,我們可以快速找出陣列的每個索引所代表的頻率范圍,

快速傅里葉變換(FFT)以將時域上的幅度轉換到頻域,僅回傳從FFT回傳的復數資料的相對幅度部分,雖然FFT通常在從0Hz到采樣率的整個頻率范圍內執行(在本例中讓我們使用48kHz),0Hz - 采樣率的一半(24kHz)是范圍后半部分的鏡像(24kHz-48kHz) ,該中點稱為奈奎斯特頻率(Nyquist frequency),因此,GetSpectrumData和其他一些基于FFT的助手僅回傳分析前半部分的相對幅度,這意味著執行FFT所需的音頻樣本數量是GetSpectrumData回傳的頻率倉數量的兩倍,因此,要分析的頻率粒度越高,生成該粒度所需的時間范圍就越大,如果你想要1024個頻率箱(frequency bins),每箱的粒度為23.43Hz,則需要2048個音頻樣本,

float[] samples:float型別的陣列來存放取到的頻譜資料,此陣列長度必須是2的n次方,最小64,最大8192,

int channel:采樣的聲道,一般用0,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AutoClose : MonoBehaviour
{
    public float closeTime;
    private float time;
    void Start()
    {
        time = 0;
    }

    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;
        if(time>=closeTime)
        {
            time = 0;
            this.gameObject.SetActive(false);
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class ButtonTriggers : MonoBehaviour
{
    public string key;
    public int index;
    public ParticleSystem start;

    private Button button;


    private void Start()
    {
        button = this.GetComponent<Button>();
        button.onClick.AddListener(OnClick);
        index = this.transform.GetSiblingIndex();

    }

    public void OnClick()
    {
        if ( ColorDivider.CheckColor(GameRule.Instance.currentColor, index))
        {
            GameRule.Instance.Add(1*ScoresRatio());
            GameRule.Instance.AddCombo();
            ParticleSystem ps=Instantiate(this.start, Input.mousePosition, new Quaternion());
            ps.transform.localPosition = PositionMap(Input.mousePosition);
            ps.Play();
            Destroy(ps.gameObject,0.5f);
        }
        else
        {
            GameRule.Instance.ClearCombo();
            if(GameRule.Instance.mode==GameMode.hand)
                GameRule.Instance.Add(-1);
        }
        int ScoresRatio()
        {
            if (GameRule.Instance.Get() >= 2 && GameRule.Instance.Get() < 4 )
            {
                GameRule.Instance.SetRatio(2);
                return 2;
            }
            if (GameRule.Instance.Get() >= 4 && GameRule.Instance.Get() < 8)
            {
                GameRule.Instance.SetRatio(4);
                return 4;
            }
            if (GameRule.Instance.Get() >= 8)
            {
                GameRule.Instance.SetRatio(8);
                return 8;
            }
            GameRule.Instance.SetRatio(0);
            return 1;
        }
    }

    private Vector3 PositionMap(Vector3 vector3)
    {
        return new Vector3((vector3.x - 540f) * 10.3f / 540f, (vector3.y - 303.75f) * 5.8f / 303.75f + 0.95f, 0);
    }

    private void Update()
    {
        ColorBlock cb = button.colors;
        cb.pressedColor = UnityEngine.Color.HSVToRGB((float)GameRule.Instance.currentColor / 360, 1f, 1f);
        button.colors = cb;
        if (Input.GetKeyDown( (KeyCode)Enum.Parse(typeof(KeyCode), key)))
        {
            button.onClick.Invoke();
            cb.normalColor = UnityEngine.Color.HSVToRGB((float)GameRule.Instance.currentColor / 360, 1f, 1f);
            button.colors = cb;
        }
        if(Input.GetKeyUp((KeyCode)Enum.Parse(typeof(KeyCode), key)))
        {
            ColorBlock cb2 = button.colors;
            cb2.normalColor = new Color32(255, 255, 255, 55);
            button.colors = cb2;
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum Color : int
{ 
    red=360,     //紅色0-20,312-360
    purple=295,  //紫色271-311
    blue=195,    //藍色156-270
    green=118,   //綠色70-154
    yellow=58,   //黃色52-69
    other=28
}

public class ColorDivider : MonoBehaviour
{
    public static ColorDivider Instance;
    public float[] colors;
    public CreateSlice createSlice;
    private static int length;
    void Start()
    {
        Instance = this;
        colors = new float[createSlice.sliceCount];
        length = createSlice.sliceCount / 8;
    }
    public static bool CheckColor(Color color,int index)
    {
        for(int i=index*length;i<length*(index+1);i++)
        {
            float colorValue= Instance.colors[i];
            switch (color)
            {
                case Color.red:if (colorValue > 312 && colorValue <= 360) return true; else break;
                case Color.purple: if (colorValue > 270 && colorValue <= 312) return true; else break;
                case Color.blue: if (colorValue > 156 && colorValue <= 270) return true; else break;
                case Color.green: if (colorValue > 70 && colorValue <= 156) return true; else break;
                case Color.yellow: if (colorValue > 52 && colorValue <= 70) return true; else break;
                default:break;
            }
        }
        return false;
    }
}

using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;

[RequireComponent(typeof(CreateSlice))]
public class CreateButtons : MonoBehaviour
{
    public Transform buttons;
    private CreateSlice createSlice;
    private float length;
    private float num;
    private void Start()
    {
        createSlice = this.GetComponent<CreateSlice>();
        num = createSlice.sliceCount / 8;
        length = 28 * num * 0.8f;

        for (int i= 0;i<buttons.childCount;i++)
        {
            buttons.GetChild(i).GetComponent<RectTransform>().sizeDelta = new Vector2(length,612.9f);
            buttons.GetChild(i).transform.localPosition = new Vector3((i-num/2)*length-56.3f,0,0);
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateSlice : MonoBehaviour
{
    public GameObject slice;
    public int sliceCount;
    void Start()
    {
        int x=0;
        for (int i = 0; i < sliceCount; i++)
        {
            /* 子物體排列規律為0,1,-1,2,-2  */
            GameObject gameObject = Instantiate(slice, this.transform.parent.Find("SliceCenter"));
            gameObject.transform.localPosition = new Vector3(x*28,0,0);
            if (i == 0 || i % 2 == 0)
            {
                x *= -1;
                x++;
            }
            else
                x *= -1;
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public enum GameMode:int
{
    easy,
    medium,
    hand
}

public class GameRule : MonoBehaviour
{
    public Color currentColor;
    public Text color;
    public Transform scores;
    [Space]
    public GameMode mode;
    public float changeTime;
    [Space]
    public Transform colorChange;
    public Text Combo;
    private int combo;

    public static GameRule Instance;

    private int score;
    private Dictionary<int, Action> dic;
    private IEnumerator conroutine;

    private void Start()
    {
        mode = SceneLink.Instance.gameMode;
        conroutine = AutoChangeColor();
        currentColor = Color.blue;
        dic = new Dictionary<int, Action>()
        {
            {(int)GameMode.easy,()=>StopAllCoroutines()},
            {(int)GameMode.medium,()=>StartCoroutine(conroutine)},
            {(int)GameMode.hand,()=>StartCoroutine(conroutine)},
         };
        if (dic.TryGetValue((int)mode, out Action action))
            action.Invoke();
        Instance = this;
        score = 0;
        time = 0;
        combo = 0;
    }
    private float time;
    private IEnumerator AutoChangeColor()
    {
        while (true)
        {
            time += Time.deltaTime;
            if(changeTime<=time)
            {
                ColorSet(RandomColor());
                time = 0;
            }
            yield return null;
        }
        Color RandomColor()
        {
            int max = 5;
            int min = 1;
            switch (UnityEngine.Random.Range(min, max))
            {
                case 1:return Color.red;
                case 2: return Color.purple;
                case 3: return Color.blue;
                case 4: return Color.green;
                case 5: return Color.yellow;
            }
            return Color.other;
        }
    }

    public void Add(int score)
    {
        this.score += score;
        scores.GetComponent<Text>().text=string.Format("scores:{0}",this.score);
    }
    public void ColorSet(Color color)
    {
        currentColor = color;
        this.color.text = string.Format("color:{0}", currentColor.ToString());
        this.color.GetComponent<Outline>().effectColor = UnityEngine.Color.HSVToRGB((float)color/360, 1f, 1f);
        colorChange.gameObject.SetActive(true);
        colorChange.GetComponent<Text>().color = UnityEngine.Color.HSVToRGB((float)color / 360, 0.47f, 1f);
        colorChange.GetComponent<Outline>().effectColor = UnityEngine.Color.HSVToRGB((float)color / 360, 1f, 1f);
    }


    #region Combo
    public void AddCombo()
    {
        if(combo==1)
            this.Combo.text = string.Format("Combo:{0}", combo);
        this.combo++;
    }
    public void ClearCombo()
    {
        combo = 0;
    }
    public int Get()
    {
        return combo;
    }
    public void SetRatio(int num)
    {
        if (num <= 0)
            this.Combo.text = string.Empty;
        else
            this.Combo.text = string.Format("Combo:{1}\nx{0}", num, combo);
    }
    public int GetScores()
    {
        return score;
    }
    #endregion
}

using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using UnityEngine;
using UnityEngine.UI;

public class HeightChange : MonoBehaviour
{
    //public float lateTime;
    public float speed;
    public float range;
    public float O_height;

    private int index;
    private float t;
    private float height;

    private Rect rect;
    private RectTransform rectTransform;
    private void Start()
    {
        rectTransform = this.GetComponent<RectTransform>();
        height= O_height;
        t = 0f;
        index = -1;
    }
    public void SetHeigth(float height)
    {
        this.height = height;
        t = 0f;
    }
    public void SetIndex(int i)
    {
        if(index<0)
        this.index = i;
    }
    private void Update()
    {
        if (index < 0)
            return;
        rect = this.GetComponent<RectTransform>().rect;
        if (t <= 1f)
        {
            t += speed* (1+t)/2 * Time.deltaTime;    //變速 初始速度為0.5v,最大速度為1v
        }
        else
            t = 1f;
        if(rect.height> height * range)
            Move(Mathf.Lerp(height * range, rect.height, t));
        else
            Move(Mathf.Lerp(rect.height, height * range, t));//換向
    }
    private void Move(float L)
    {
        rectTransform.sizeDelta = new Vector2(rect.width, L + O_height);
        this.transform.localPosition = new Vector3(this.transform.localPosition.x, L / 2, this.transform.localPosition.z);
        float color;
        if (L > 100)
            color = 1f;
        else
            color = L / 100;
        this.GetComponent<Image>().color = UnityEngine.Color.HSVToRGB(color, 1f, 1f);
        ColorDivider.Instance.colors[index] = color * 360;
    }
}

speed小方塊移動速度
range頻率密度放大倍數
O_height最低(原始)高度
在這里插入圖片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SceneLink : MonoBehaviour
{
    public static SceneLink Instance;
    public GameMode gameMode;
    public AudioClip audioClip;
    public int scores;
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else if (Instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
    }

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Begin : MonoBehaviour
{
    
    void Start()
    {
        this.transform.GetComponent<Button>().onClick.AddListener(OnClick);
    }
    private void  OnClick()
    {
        SceneLink.Instance.gameMode = Mode.Instance.mode;
        SceneLink.Instance.audioClip = Music.Instance.clips[Music.GetIndex()];
        SceneManager.LoadScene(1, LoadSceneMode.Single);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Mode : MonoBehaviour
{
    public static Mode Instance;
    public Text text;
    public GameMode mode;
    void Start()
    {
        Instance = this;
        text.text = mode.ToString();
    }
    private void R()
    {
        if (mode == GameMode.hand)
        {
            mode = GameMode.easy;
        }
        else
        {
            mode++;
        }
        Show();
    }
    private void L()
    {
        if (mode == GameMode.easy)
        {
            mode = GameMode.hand;
        }
        else
        {
            mode--;
        }
        Show();
    }
    private void Show()
    {
        text.text = mode.ToString();
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Music : MonoBehaviour
{
    public static Music Instance;
    public Text text;
    public List<AudioClip> clips;
    [SerializeField]
    private int index;
    void Start()
    {
        index = 0;
        text.text = clips[0].name;
        Instance = this;
    }
    public static int  GetIndex()
    {
        return Instance.index;
    }
    private void R()
    {
        if (index==clips.Count-1)
        {
            index = 0;
        }
        else
        {
            index ++;
        }
        text.text = clips[index].name;
    }
    private void L()
    {
        if (index == 0)
        {
            index = clips.Count - 1;
        }
        else
        {
            index--;
        }
        text.text = clips[index].name;
    }

}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/77118.html

標籤:其他

上一篇:“堆箱子”小游戲

下一篇:LintCode 395. 硬幣排成線 II JavaScript演算法

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • vue移動端上拉加載

    可能做得過于簡單或者比較low,請各位大佬留情,一起探討技術 ......

    uj5u.com 2020-09-10 04:38:07 more
  • 優美網站首頁,頂部多層導航

    一個個人用的瀏覽器首頁,可以把一下常用的網站放在這里,平常打開會比較方便。 第一步,HTML代碼 <script src=https://www.cnblogs.com/szharf/p/"js/jquery-3.4.1.min.js"></script> <div id="navigate"> <ul> <li class="labels labels_1"> ......

    uj5u.com 2020-09-10 04:38:47 more
  • 頁面為要加<!DOCTYPE html>

    最近因為寫一個js函式,需要用到$(window).height(); 由于手寫demo的時候,過于自信,其實對前端方面的認識也不夠體系,用文本檔案直接敲出來的html代碼,第一行沒有加上<!DOCTYPE html> 導致了$(window).height();的結果直接是整個document的高 ......

    uj5u.com 2020-09-10 04:38:52 more
  • WordPress網站程式手動升級要做好資料備份

    WordPress博客網站程式在進行升級前,必須要做好網站資料的備份,這個問題良家佐言是遇見過的;在剛開始接觸WordPress博客程式的時候,因為升級問題和博客網站的修改的一些嘗試,良家佐言是吃盡了苦頭。因為購買的是西部數碼的空間和域名,每當佐言把自己的WordPress博客網站搞到一塌糊涂的時候 ......

    uj5u.com 2020-09-10 04:39:30 more
  • WordPress程式不能升級為5.4.2版本的原因

    WordPress是一款個人博客系統,受到英文博客愛好者和中文博客愛好者的追捧,并逐步演化成一款內容管理系統軟體;它是使用PHP語言和MySQL資料庫開發的,用戶可以在支持PHP和MySQL資料庫的服務器上使用自己的博客。每一次WordPress程式的更新,就會牽動無數WordPress愛好者的心, ......

    uj5u.com 2020-09-10 04:39:49 more
  • 使用CSS3的偽元素進行首字母下沉和首行改變樣式

    網頁中常見的一種效果,首字改變樣式或者首行改變樣式,效果如下圖。 代碼: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, ......

    uj5u.com 2020-09-10 04:40:09 more
  • 關于a標簽的講解

    什么是a標簽? <a> 標簽定義超鏈接,用于從一個頁面鏈接到另一個頁面。 <a> 元素最重要的屬性是 href 屬性,它指定鏈接的目標。 a標簽的語法格式:<a href=https://www.cnblogs.com/summerxbc/p/"指定要跳轉的目標界面的鏈接">需要展示給用戶看見的內容</a> a標簽 在所有瀏覽器中,鏈接的默認外觀如下: 未被訪問的鏈接帶 ......

    uj5u.com 2020-09-10 04:40:11 more
  • 前端輪播圖

    在需要輪播的頁面是引入swiper.min.js和swiper.min.css swiper.min.js地址: 鏈接:https://pan.baidu.com/s/15Uh516YHa4CV3X-RyjEIWw 提取碼:4aks swiper.min.css地址 鏈接:https://pan.b ......

    uj5u.com 2020-09-10 04:40:13 more
  • 如何設定html中的背景圖片(全屏顯示,且不拉伸)

    1 <style>2 body{background-image:url(https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture); 3 background-size:cover;background ......

    uj5u.com 2020-09-10 04:40:16 more
  • Java學習——HTML詳解(上)

    HTML詳解 初識HTML Hyper Text Markup Language(超文本標記語言) 1 <!--DOCTYPE:告訴瀏覽器我們要使用什么規范--> 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <!--meta 描述性的標簽,描述一些 ......

    uj5u.com 2020-09-10 04:40:33 more
最新发布
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 07:59:23 more
  • 生產事故-走近科學之消失的JWT

    入職多年,面對生產環境,盡管都是小心翼翼,慎之又慎,還是難免捅出簍子。輕則滿頭大汗,面紅耳赤。重則系統停擺,損失資金。每一個生產事故的背后,都是寶貴的經驗和教訓,都是專案成員的血淚史。為了更好地防范和遏制今后的各類事故,特開此專題,長期更新和記錄大大小小的各類事故。有些是親身經歷,有些是經人耳傳口授 ......

    uj5u.com 2023-04-18 07:55:04 more
  • 記錄--Canvas實作打飛字游戲

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 打開游戲界面,看到一個畫面簡潔、卻又富有挑戰性的游戲。螢屏上,有一個白色的矩形框,里面不斷下落著各種單詞,而我需要迅速地輸入這些單詞。如果我輸入的單詞與螢屏上的單詞匹配,那么我就可以獲得得分;如果我輸入的單詞錯誤或者時間過長,那么我就會輸 ......

    uj5u.com 2023-04-04 08:35:30 more
  • 了解 HTTP 看這一篇就夠

    在學習網路之前,了解它的歷史能夠幫助我們明白為何它會發展為如今這個樣子,引發探究網路的興趣。下面的這張圖片就展示了“互聯網”誕生至今的發展歷程。 ......

    uj5u.com 2023-03-16 11:00:15 more
  • 藍牙-低功耗中心設備

    //11.開啟藍牙配接器 openBluetoothAdapter //21.開始搜索藍牙設備 startBluetoothDevicesDiscovery //31.開啟監聽搜索藍牙設備 onBluetoothDeviceFound //30.停止監聽搜索藍牙設備 offBluetoothDevi ......

    uj5u.com 2023-03-15 09:06:45 more
  • canvas畫板(滑鼠和觸摸)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>canves</title> <style> #canvas { cursor:url(../images/pen.png),crosshair; } #canvasdiv{ bo ......

    uj5u.com 2023-02-15 08:56:31 more
  • 手機端H5 實作自定義拍照界面

    手機端 H5 實作自定義拍照界面也可以使用 MediaDevices API 和 <video> 標簽來實作,和在桌面端做法基本一致。 首先,使用 MediaDevices.getUserMedia() 方法獲取攝像頭媒體流,并將其傳遞給 <video> 標簽進行渲染。 接著,使用 HTML 的 < ......

    uj5u.com 2023-01-12 07:58:22 more
  • 記錄--短視頻滑動播放在 H5 下的實作

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 短視頻已經無數不在了,但是主體還是使用 app 來承載的。本文講述 H5 如何實作 app 的視頻滑動體驗。 無聲勝有聲,一圖頂百辯,且看下圖: 網址鏈接(需在微信或者手Q中瀏覽) 從上圖可以看到,我們主要實作的功能也是本文要講解的有: ......

    uj5u.com 2023-01-04 07:29:05 more
  • 一文讀懂 HTTP/1 HTTP/2 HTTP/3

    從 1989 年萬維網(www)誕生,HTTP(HyperText Transfer Protocol)經歷了眾多版本迭代,WebSocket 也在期間萌芽。1991 年 HTTP0.9 被發明。1996 年出現了 HTTP1.0。2015 年 HTTP2 正式發布。2020 年 HTTP3 或能正... ......

    uj5u.com 2022-12-24 06:56:02 more
  • 【HTML基礎篇002】HTML之form表單超詳解

    ??一、form表單是什么

    ??二、form表單的屬性

    ??三、input中的各種Type屬性值

    ??四、標簽 ......

    uj5u.com 2022-12-18 07:17:06 more