public override void Update() { base.Update(); if (_mTime == DateTime.MinValue) { return; } float time = (float)(DateTime.Now - _mTime).TotalSeconds; float nextTime = GetTime(_mCurrentFrame); if (nextTime < time) { ++_mCurrentFrame; if (_mCurrentFrame < _mEffects.Count) { if (!_mIsPaused && ChromaConnectionManager.Instance.Connected) { //Debug.Log("SetEffect."); EffectResponseId effect = _mEffects[_mCurrentFrame]; if (null != effect) { ChromaUtils.SetEffect(effect.Id); } /* * //Silently fail * if (null != effect) * { * EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id); * if (null == result || * result.Result != 0) * { * Debug.LogError("Failed to set effect!"); * } * } * else * { * Debug.LogError("Failed to set effect!"); * } */ } } else { //UE_LOG(LogTemp, Log, TEXT("UChromaSDKPluginAnimation2DObject::Tick Animation Complete.")); _mIsPlaying = false; _mTime = DateTime.MinValue; //reset _mCurrentFrame = 0; // execute the complete event if set if (null != _mOnComplete) { _mOnComplete.Invoke(this); } } } }
protected override void OnClickPreviewButton() { ChromaSDKAnimation1D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (ChromaConnectionManager.Instance.Connected) { if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice1DEnum device = animation.Device; EffectArray1dInput colors = frames[_mCurrentFrame]; EffectResponseId effect = ChromaUtils.CreateEffectCustom1D(device, colors); if (null != effect && effect.Result == 0) { ChromaUtils.SetEffect(effect.Id); ChromaUtils.RemoveEffect(effect.Id); } } } }
/// <summary> /// Load the effects before playing /// </summary> public void Load() { //Debug.Log("Load:"); if (_mIsLoaded) { //Debug.LogError("Animation has already been loaded!"); return; } if (ChromaConnectionManager.Instance.Connected) { //Debug.Log(string.Format("Create {0} Frames.", Frames.Count)); for (int i = 0; i < Frames.Count; ++i) { EffectArray2dInput frame = Frames[i]; //Debug.Log("Create Effect."); EffectResponseId effect = ChromaUtils.CreateEffectCustom2D(Device, frame); /* * // app can check the effect list for null or non-zero result * if (null == effect || * effect.Result != 0) * { * Debug.LogError("Failed to create effect!"); * } */ _mEffects.Add(effect); } _mIsLoaded = true; } }
/// <summary> /// Play the animation and fire the OnComplete event /// </summary> /// <param name="onComplete"></param> public void PlayWithOnComplete(ChomaOnComplete2D onComplete) { //Debug.Log("PlayWithOnComplete"); if (!_mIsLoaded) { // auto load if not loaded Load(); //Debug.LogError("Animation has not been loaded!"); //return; } _mOnComplete = onComplete; _mTime = DateTime.Now; //Time when animation started _mIsPlaying = true; _mCurrentFrame = 0; if (_mCurrentFrame < _mEffects.Count) { if (!_mIsPaused && ChromaConnectionManager.Instance.Connected) { //Debug.Log("SetEffect."); EffectResponseId effect = _mEffects[_mCurrentFrame]; if (null != effect) { ChromaUtils.SetEffect(effect.Id); } /* * //Silently fail * if (null != effect) * { * EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id); * if (null == result || * result.Result != 0) * { * Debug.LogError("Failed to set effect!"); * } * } * else * { * Debug.LogError("Failed to set effect!"); * } */ } } }
/// <summary> /// Play the animation /// </summary> public override void Play() { //Debug.Log("Play"); if (!_mIsLoaded) { Load(); //Debug.LogError("Play Animation has not been loaded!"); //return; } // clear on play to avoid unsetting on a loop _mOnComplete = null; _mTime = DateTime.Now; //Time when animation started _mIsPlaying = true; _mCurrentFrame = 0; if (_mCurrentFrame < _mEffects.Count) { if (!_mIsPaused && ChromaConnectionManager.Instance.Connected) { //Debug.Log("SetEffect."); EffectResponseId effect = _mEffects[_mCurrentFrame]; if (null != effect) { ChromaUtils.SetEffect(effect.Id); } /* * //Silently fail * if (null != effect) * { * EffectIdentifierResponse result = ChromaUtils.SetEffect(effect.Id); * if (null == result || * result.Result != 0) * { * Debug.LogError("Failed to set effect!"); * } * } * else * { * Debug.LogError("Failed to set effect!"); * } */ } } }
public void Unload() { if (!this._mIsLoaded) { Debug.LogError("Animation has already been unloaded!"); return; } for (int i = 0; i < this._mEffects.Count; i++) { EffectResponseId effectResponseId = this._mEffects[i]; if (effectResponseId != null) { ChromaUtils.RemoveEffect(effectResponseId.Id); } } this._mEffects.Clear(); this._mIsLoaded = false; }
public void Load() { if (this._mIsLoaded) { Debug.LogError("Animation has already been loaded!"); return; } if (ChromaConnectionManager.Instance.Connected) { for (int i = 0; i < this.Frames.Count; i++) { EffectArray2dInput input = this.Frames[i]; EffectResponseId item = ChromaUtils.CreateEffectCustom2D(this.Device, input); this._mEffects.Add(item); } this._mIsLoaded = true; } }
public void Play() { if (!this._mIsLoaded) { Debug.LogError("Play Animation has not been loaded!"); return; } this._mOnComplete = null; this._mTime = DateTime.Now; this._mIsPlaying = true; this._mCurrentFrame = 0; if (this._mCurrentFrame < this._mEffects.Count && !this._mIsPaused && ChromaConnectionManager.Instance.Connected) { EffectResponseId effectResponseId = this._mEffects[this._mCurrentFrame]; if (effectResponseId != null) { ChromaUtils.SetEffect(effectResponseId.Id); } } }
private void ValidateAnimation(ChromaSDKBaseAnimation animation) { List <EffectResponseId> effects = animation.GetEffects(); if (effects == null || effects.Count == 0) { Debug.LogError("Animation failed to create effects!"); } else { for (int i = 0; i < effects.Count; i++) { EffectResponseId effectResponseId = effects[i]; if (effectResponseId == null || effectResponseId.Result != 0) { Debug.LogError("Failed to create effect!"); } } } }
/// <summary> /// Unload the effects /// </summary> public override void Unload() { //Debug.Log("Unload:"); if (!_mIsLoaded) { //Debug.LogError("Animation has already been unloaded!"); return; } for (int i = 0; i < _mEffects.Count; ++i) { EffectResponseId effect = _mEffects[i]; if (null != effect) { ChromaUtils.RemoveEffect(effect.Id); } /* * //Silently fail * if (null != effect) * { * //Debug.Log("RemoveEffect."); * EffectIdentifierResponse result = ChromaUtils.RemoveEffect(effect.Id); * if (null == result || * result.Result != 0) * { * Debug.LogError("Failed to delete effect!"); * } * } * else * { * Debug.LogError("Failed to delete effect!"); * } */ } _mEffects.Clear(); _mIsLoaded = false; }
/// <summary> /// Verify the animation loaded, /// failure indicates the device was not connected /// </summary> /// <param name="animation"></param> void ValidateAnimation(ChromaSDKBaseAnimation animation) { // validate animation loaded List <EffectResponseId> effects = animation.GetEffects(); if (null == effects || effects.Count == 0) { Debug.LogError("Animation failed to create effects!"); } else { for (int i = 0; i < effects.Count; ++i) { EffectResponseId effect = effects[i]; if (null == effect || effect.Result != 0) { Debug.LogError("Failed to create effect!"); } } } }
public override void Update() { base.Update(); if (this._mTime == DateTime.MinValue) { return; } float num = (float)(DateTime.Now - this._mTime).TotalSeconds; float time = this.GetTime(this._mCurrentFrame); if (time < num) { this._mCurrentFrame++; if (this._mCurrentFrame < this._mEffects.Count) { if (!this._mIsPaused && ChromaConnectionManager.Instance.Connected) { EffectResponseId effectResponseId = this._mEffects[this._mCurrentFrame]; if (effectResponseId != null) { ChromaUtils.SetEffect(effectResponseId.Id); } } } else { this._mIsPlaying = false; this._mTime = DateTime.MinValue; this._mCurrentFrame = 0; if (this._mOnComplete != null) { this._mOnComplete(this); } } } }