private void On_Transaction_Handler(Blockchain_Listener.Transaction transaction) { lock (this.transactions) { this.transactions.Enqueue(transaction); } }
protected virtual void Update() { lock (this.transactions) { while (this.transactions.Count > 0) { Blockchain_Listener.Transaction transaction = this.transactions.Dequeue(); this.Process_Transaction(transaction); } } }
protected override void Process_Transaction(Blockchain_Listener.Transaction transaction) { Vector3 spawn_position = UnityEngine.Random.onUnitSphere * this.radius; spawn_position.y = 0f; spawn_position += this.transform.position; float size = Mathf.Max(this.min_size, transaction.Amount * this.size_per_btc); Transform spawned = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; spawned.position = spawn_position; spawned.localScale = Vector3.one * size; }
protected abstract void Process_Transaction(Blockchain_Listener.Transaction transaction);
private IEnumerator Process_Transaction_Coroutine(Blockchain_Listener.Transaction transaction) { // Wait a small amount of time, helps with many transactions arriving in clusters yield return(new WaitForSeconds(Random.value)); // Instantiate and position particle system Vector3 spawn_position = new Vector3(this.min_spawn_x + ((this.max_spawn_x - this.min_spawn_x) * Random.value), this.spawn_y, this.spawn_z); GameObject particle_system_gameobject = Object.Instantiate(this.particle_system_prefab) as GameObject; particle_system_gameobject.transform.position = spawn_position; // Randomly select a colour (note only activate 2 of the 3 components so we don't // end up with washed out pastel colours) Color start_colour = new Color(0f, 0f, 0f, 1f); float rand_value = Random.value; if (rand_value < 0.33333333333333333f) { start_colour.r = 1f; if (Random.value < 0.5f) { start_colour.g = Random.value; } else { start_colour.b = Random.value; } } else if (rand_value < 0.66666666666666667f) { start_colour.g = 1f; if (Random.value < 0.5f) { start_colour.r = Random.value; } else { start_colour.b = Random.value; } } else { start_colour.b = 1f; if (Random.value < 0.5f) { start_colour.r = Random.value; } else { start_colour.g = Random.value; } } ParticleSystem[] particle_systems = particle_system_gameobject.GetComponentsInChildren <ParticleSystem>(); foreach (ParticleSystem particle_system in particle_systems) { particle_system.startColor = start_colour; } // Deal with particle system customisations float t = Mathf.InverseLerp(this.min_amount, this.max_amount, transaction.Amount); foreach (Particle_System_Customisation customisation in this.particle_system_customisations) { ParticleSystem particle_system; if (customisation.path == "") { particle_system = particle_system_gameobject.GetComponent <ParticleSystem>(); } else { Transform child = particle_system_gameobject.transform.Find(customisation.path); if (child == null) { Debug.LogWarning("Couldn't find child '" + customisation.path + "' on Transform " + particle_system_gameobject.transform); continue; } particle_system = child.GetComponent <ParticleSystem>(); } if (particle_system == null) { Debug.LogWarning("Particle System not found for '" + customisation.path + "'"); continue; } if (customisation.override_emission_rate) { particle_system.emissionRate = this.LerpIntRounded(customisation.min_emission_rate, customisation.max_emission_rate, t); } if (customisation.override_start_speed) { particle_system.startSpeed = Mathf.Lerp(customisation.min_start_speed, customisation.max_start_speed, t); } } // Audio AudioClip audio_clip = null; float pitch = 1f; if (this.bang_sounds != null && this.bang_sounds.Length > 0) { int index = 0; while (index < (this.bang_sounds.Length - 1) && this.bang_sounds[index + 1].amount <= transaction.Amount) { ++index; } audio_clip = this.bang_sounds[index].audio_clip; pitch = Random.Range(this.bang_sounds[index].min_pitch_shift, this.bang_sounds[index].max_pitch_shift); } ParticleSystem root_particle_system = particle_system_gameobject.GetComponent <ParticleSystem>(); this.StartCoroutine(this.Do_Text_And_Audio(root_particle_system, transaction.Amount, Mathf.Lerp(this.min_text_size, this.max_text_size, t), audio_clip, pitch)); this.StartCoroutine(this.Destroy_Particle_System_When_Done(root_particle_system)); }
protected override void Process_Transaction(Blockchain_Listener.Transaction transaction) { this.StartCoroutine(this.Process_Transaction_Coroutine(transaction)); }