設計思路
<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;
}
}