[Serializable] public class Game_event { public char key; // public float time; // [NonSerialized]public float finish_time; //, public bool isFinish(){ //, return false; } public void Create(){ // //, (Main.sound_time - time) } public void Destroy(){ // } public Game_event (float time, char key){ this.time = time; this.key = key; } }
public static float sound_time=0; // , public static List<Game_event> game_event = new List<Game_event>(); // void Update () { sound_time = sound.time; //sound - AudioSource, foreach (Game_event e in game_event) { if (sound_time>=e._time && sound_time<e.finish_time && !e.active) { e.active = true; e.finish_time = float.MaxValue; current_event =e; e.Create(); } if (e.active) if (e.isFinish()) // isFinish , , { e.active=false; e.finish_time = sound_time; e.Destroy(); } } }
public static char[] keys_s = { 'Q','W','E','R','T', 'A','S','D','F','G', 'Z','X','C','V','B'}; // void Update () { … Event c_e = Event.current; if (c_e.isKey && c_e.type == EventType.KeyDown) { if (Array.Exists(Main.keys_s, c=>c==c_e.keyCode.ToString()[0])) // , { game_event.Add (new Game_event (sound_time,c_e.keyCode.ToString()[0])); } } }
float[] samples = new float[sound.clip.samples * sound.clip.channels]; sound.clip.GetData(samples, 0); // int frequency = sound.clip.frequency; // int scale = 10; // 1 SoundTex = new Texture2D ((int)(sound.clip.length*sound.clip.channels*scale), 200); int height = (int)(SoundTex.height / 2); for (int i=0; i<SoundTex.width; i++) { int c_hi = 0; int c_low = 0; float s_hi = 0; float s_low = 0; // 1px for (int k=0; k<(int)(frequency/scale); k++) { if (samples[k+i*(int)(frequency/scale)]>=0) { c_hi++; s_hi+=samples[k+i*(int)(frequency/scale)]; } else { c_low++; s_low+=samples[k+i*(int)(frequency/scale)]; } } // // , for (int j=0; j<(int)(SoundTex.height); j++) { if (j<(int)((s_hi/c_hi)*height*0.6f+height) && j>(int)((s_low/c_low)*height*0.6f+height)) SoundTex.SetPixel(i,j,new Color(0.7f,1,0.7f)); else if (j<=(int)((s_hi/c_hi)*height+height) && j>=(int)((s_low/c_low)*height+height)) SoundTex.SetPixel(i,j,new Color(0,1,0)); else SoundTex.SetPixel(i,j,new Color(0,0,0,0)); } } SoundTex.Apply (); // //
Source: https://habr.com/ru/post/242631/
All Articles