public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _knobs.ForEach(x => { x.MoveTo(1.0f, 1.0f); }); _gauges.ForEach(x => { x.SetState(1.0f); }); _lightbulb.Toggle(false); _lever.MoveTo(1.0f, 0.0f); } else if (state == BreakableState.FUNCTIONAL) { _lightbulb.Toggle(true); for (int i = 0; i < _gauges.Count; i++) { _gauges[i].SetState(UnityEngine.Random.Range(0.0f, 0.4f)); _knobs[i].MoveTo(1.0f, UnityEngine.Random.Range(0.4f, 0.6f)); } } }
public virtual void SetState(BreakableState state) { if (_state != state && state == BreakableState.BROKEN) { GameManager.Instance?.InstantiateSparks(transform.position, transform.rotation); _sparksTimeNext = Time.time + Random.Range(4f, 7f); } _state = state; if (_state == BreakableState.BROKEN) { _timeBroken = 0.0f; if (_breakSound != null) { _breakSound.clip = _breakClips[UnityEngine.Random.Range(0, _breakClips.Count)]; _breakSound.Play(); } } if (_state == BreakableState.DEAD) { _deadSound?.Play(); } }
/// <summary> /// Set the state of the breakable entity /// </summary> /// <param name="state"></param> public void SetState(BreakableState state) { if (lastState == BreakableState.DEAD) { return; } switch (state) { case BreakableState.NORMAL: // Normal state this.sprite.TexturePath = this.NormalTexture; this.childParticleSystem.Emit = false; break; case BreakableState.DAMAGED: // Damaged state this.sprite.TexturePath = this.BrokenTexture; this.childParticleSystem.Emit = false; break; case BreakableState.DEAD: // dead state, starts the particle system this.childParticleSystem.Emit = true; this.score.Points += this.scene.BlockDestroyPoints; break; default: break; } this.lastState = this.state; this.state = state; }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { int number = UnityEngine.Random.Range(1, 16); _code = number.ToString(); string bitpattern = Convert.ToString(number, 2).PadLeft(4, '0'); for (int i = 0; i < 4; i++) { if ((int)Char.GetNumericValue(bitpattern[i]) == 1) { _LEDs[i].SetEmissiveColor(ColorPalette.BAD); } else { _LEDs[i].GetComponent <TheToggler>().Toggle(false); } } } else if (state == BreakableState.FUNCTIONAL) { _LEDs.ForEach(x => { x.GetComponent <TheToggler>().Toggle(true); x.SetEmissiveColor(ColorPalette.OK); }); _code = string.Empty; } }
public BreakableObject(string id, bool isEnabled, int hideDuration, int resetDuration) { Id = id; IsEnabled = isEnabled; State = BreakableState.Spawn; HideDuration = hideDuration; ResetDuration = resetDuration; }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { GenerateCode(); } else if (state == BreakableState.FUNCTIONAL) { Reset(); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _toggler.Toggle(false); } else if (state == BreakableState.FUNCTIONAL) { _toggler.Toggle(true); } }
public Task BreakObject(FieldManager field) { return(Task.Run(async() => { State = BreakableState.Break; field.BroadcastPacket(BreakablePacket.Interact(this)); await Task.Delay(HideDuration); State = BreakableState.Despawn; field.BroadcastPacket(BreakablePacket.Interact(this)); await Task.Delay(ResetDuration); State = BreakableState.Spawn; field.BroadcastPacket(BreakablePacket.Interact(this)); })); }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { List <int> indices = new List <int>(); while (indices.Count == 0) { for (int i = 0; i < _LEDs.Count; i++) { if (indices.Contains(i)) { continue; } if (UnityEngine.Random.Range(0.0f, 1.0f) <= 0.5f) { indices.Add(i); } } } foreach (int i in indices) { _wireInputs[i].Disconnect(); } for (int i = 0; i < 2; i++) { if (!_wireInputs[i].Connected) { _LEDs[i].SetEmissiveColor(ColorPalette.BAD); } else { _LEDs[i].SetEmissiveColor(ColorPalette.WARNING); } } } else if (state == BreakableState.FUNCTIONAL) { for (int i = 0; i < 2; i++) { _LEDs[i].SetEmissiveColor(ColorPalette.OK); } } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _input.Disconnect(); _gauge.SetState(1.0f); _LED.SetEmissiveColor(ColorPalette.BAD); } else if (state == BreakableState.FUNCTIONAL) { _LED.SetEmissiveColor(ColorPalette.OK); _gauge.SetState(UnityEngine.Random.Range(0.0f, 0.4f)); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _sequence = string.Empty; _currentSequenceIndex = 0; for (int i = 0; i < 5; i++) { int random = UnityEngine.Random.Range(0, 4); if (_sequence.Length > 0) { while ((int)Char.GetNumericValue(_sequence[i - 1]) == random) { random = UnityEngine.Random.Range(0, 4); } } _sequence += random.ToString(); } for (int i = 0; i < _LEDs.Count; i++) { if (i == (int)Char.GetNumericValue(_sequence[_currentSequenceIndex])) { _LEDs[i].GetComponent <TheToggler>().Toggle(true); } else { _LEDs[i].GetComponent <TheToggler>().Toggle(false); } _LEDs[i].SetEmissiveColor(ColorPalette.BAD); } } else if (state == BreakableState.FUNCTIONAL) { _LEDs.ForEach(x => { x.GetComponent <TheToggler>().Toggle(true); x.SetEmissiveColor(ColorPalette.OK); }); _sequence = string.Empty; _currentSequenceIndex = 0; } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { int codeLength = UnityEngine.Random.Range(3, 7); for (int i = 0; i < codeLength; i++) { int number = UnityEngine.Random.Range(0, 10); if (_code.Length > 0) { while (number == (int)Char.GetNumericValue(_code[_code.Length - 1])) { number = UnityEngine.Random.Range(0, 10); } } _code += number.ToString(); } List <ColorControl> shuffled = _LEDs.Shuffle(); for (int i = 0; i < shuffled.Count; i++) { if (i < (int)Char.GetNumericValue(_code[_currentIndex])) { shuffled[i].GetComponent <TheToggler>().Toggle(true); shuffled[i].SetEmissiveColor(ColorPalette.BAD); } else { shuffled[i].GetComponent <TheToggler>().Toggle(false); } } } else if (state == BreakableState.FUNCTIONAL) { _code = string.Empty; _currentIndex = 0; _LEDs.ForEach(x => { x.GetComponent <TheToggler>().Toggle(true); x.SetEmissiveColor(ColorPalette.OK); }); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _bulbs.ForEach(x => { x.Toggle(false); }); } else if (state == BreakableState.FUNCTIONAL) { _bulbs.ForEach(x => { x.Toggle(true); }); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _currentError = UnityEngine.Random.Range(0, _errorCodes.Count); _currentCode = string.Empty; string errorCode = _errorCodes[_currentError]; Vector3 color = new Vector3((int)Char.GetNumericValue(errorCode[0]), (int)Char.GetNumericValue(errorCode[1]), (int)Char.GetNumericValue(errorCode[2])); _colorControl.SetEmissiveColor(color); } else if (state == BreakableState.FUNCTIONAL) { _colorControl.SetEmissiveColor(ColorPalette.OK); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { if (_gauge.State < 0.9f) { _gauge.SetState(1.0f); } _LED.SetEmissiveColor(ColorPalette.BAD); } else if (state == BreakableState.FUNCTIONAL) { _gauge.SetState(0.0f); _LED.SetEmissiveColor(ColorPalette.OK); } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _inputs.ForEach(x => { x.Disconnect(); }); _lightbulbs.ForEach(x => { x.Toggle(false); }); } else if (state == BreakableState.FUNCTIONAL) { } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { _targets.Clear(); for (int i = 0; i < 3; i++) { float newVal = Random.Range(0.0f, 1.0f); while(Mathf.Abs(_knobs[i].State - newVal) < 0.2f) { newVal = Random.Range(0.0f, 1.0f); } _targets.Add((newVal)); _LEDs[i].SetEmissiveColor(ColorPalette.BAD); } } }
public override void SetState(BreakableState state) { base.SetState(state); if (state == BreakableState.BROKEN) { bool broken = false; while (!broken) { for (int i = 0; i < 3; i++) { if (UnityEngine.Random.Range(0.0f, 1.0f) <= 0.6f) { broken = true; _levers[i].MoveTo(0.5f, 0.0f); _lightbulbs[i].Toggle(false); } } } } }
/// <summary> /// Update method /// </summary> /// <param name="gameTime"></param> protected override void Update(TimeSpan gameTime) { if (!this.firstUpdated) { this.collider.TexturePath = this.sprite.TexturePath; this.firstUpdated = true; } // if entity is in Dead state will stop the particle system after a defined time and remove the entity. if (this.state == BreakableState.DEAD) { // update counters this.timeToEmit -= gameTime; this.timeToRemove -= gameTime; // only an update loop if (this.lastState != this.state) { this.rigidBody.IsActive = false; this.Owner.RemoveComponent(this.rigidBody); this.spriteRenderer.IsVisible = false; this.lastState = this.state; } if (this.timeToEmit <= TimeSpan.Zero) { this.childParticleSystem.Emit = false; } if (this.timeToRemove <= TimeSpan.Zero) { if (this.Owner.Parent != null) { this.Owner.Parent.RemoveChild(this.Owner.Name); } } } }