/// <summary> /// Stops playing effect. /// </summary> public void Stop(EffectUpdateEventArgs e) { if(cachedInstance == null) return; if(!playing) return; playing = false; cachedInstance.SetActive(false); }
/// <summary> /// When binding exits active state all effects are stopped. /// </summary> public void Exit(EffectUpdateEventArgs e) { //Debug.Log("AnimatorStateBindig.Exit: " + stateName); if(!string.IsNullOrEmpty(exitMessage)) e.controller.gameObject.SendMessage(exitMessage, e, SendMessageOptions.RequireReceiver); System.Array.ForEach(effects, effect => effect.Stop(e)); }
/// <summary> /// Updates the active binding state. /// </summary> public void Update(EffectUpdateEventArgs e) { //Debug.Log("AnimatorStateBindig.Update: " + stateName); if(!string.IsNullOrEmpty(updateMessage)) e.controller.gameObject.SendMessage(updateMessage, e, SendMessageOptions.RequireReceiver); if(string.IsNullOrEmpty(timerMessage)) return; if(timerTreshold == .0f) return; if(timerNotificationSent && e.controller.layerState[e.layerIndex].stateSeconds <= timerTreshold) { timerNotificationSent = false; } else if(!timerNotificationSent && e.controller.layerState[e.layerIndex].stateSeconds > timerTreshold) { e.controller.gameObject.SendMessage(timerMessage, e, SendMessageOptions.RequireReceiver); timerNotificationSent = true; } }
/// <summary> /// Plays the effect if additional conditions are met. /// </summary> public void Play(EffectUpdateEventArgs e) { if(prefab == null) return; if(playing) return; playing = true; playingSubject = this.subject == null ? e.controller.gameObject : this.subject; if(cachedInstance == null) { var position = playingSubject.transform.position; var rotation = playingSubject.transform.rotation; cachedInstance = GameObject.Instantiate(prefab, position, rotation) as GameObject; cachedInstance.transform.parent = playingSubject.transform; } else { cachedInstance.SetActive(true); cachedInstance.transform.parent = playingSubject.transform; if(resetOnReplay) cachedInstance.SendMessage("Reset", SendMessageOptions.RequireReceiver); } }