主頁 >  其他 > unity 音樂小游戲

unity 音樂小游戲

2020-09-18 17:05:59 其他

目錄

  • 設計思路
  • 簡易特效
  • 游戲視頻
  • 源代碼
    • 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/qita/75224.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)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more