public override void OnInspectorGUI() { bool doPreview = false; if (_sGoToFirstFrame) { _sGoToFirstFrame = false; _mCurrentFrame = 0; } else if (_sGoToLastFrame) { _sGoToLastFrame = false; if (GetFrameCount() > 0) { _mCurrentFrame = GetFrameCount() - 1; } doPreview = true; } if (doPreview) { ChromaSDKBaseAnimation animation = GetBaseAnimation(); if (animation) { animation.RefreshCurve(); } OnClickPreviewButton(); } // Add the target to a list of targets that will be updated IUpdate targetUpdater = (IUpdate)target; int i = 0; bool found = false; while (i < _sTargets.Count) { IUpdate updater = _sTargets[i]; if (null != updater) { if (updater == targetUpdater) { found = true; break; } ++i; } else { _sTargets.RemoveAt(i); } } if (!found) { _sTargets.Add(targetUpdater); } }
private void OnEnable() { _mAnimation = (ChromaSDKBaseAnimation)LoadPath(KEY_ANIMATION, typeof(ChromaSDKBaseAnimation)); Object obj = LoadPath(KEY_CAMERA, typeof(Camera)); if (obj && obj is Camera) { _mRenderCamera = (Camera)obj; } obj = LoadPath(KEY_PARTICLE, typeof(ParticleSystem)); if (obj && obj is ParticleSystem) { _mParticleSystem = (ParticleSystem)obj; } }
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> /// 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!"); } } } }
private void OnGUI() { if (_mCapturing) { if (_mTimerCapture < DateTime.Now) { _mTimerCapture = DateTime.Now + TimeSpan.FromSeconds(_mInterval); CaptureFrame(); } } GameObject activeGameObject = Selection.activeGameObject; Object activeObject = Selection.activeObject; if (activeGameObject) { ParticleSystem particleSystem = activeGameObject.GetComponent <ParticleSystem>(); if (particleSystem) { _mParticleSystem = particleSystem; } } #if SHOW_TEMP_TEXTURE _mTempTexture = (Texture2D)EditorGUILayout.ObjectField("TempTexture", _mTempTexture, typeof(Texture2D), true); #endif _mAnimation = (ChromaSDKBaseAnimation)EditorGUILayout.ObjectField("Animation", _mAnimation, typeof(ChromaSDKBaseAnimation), true); _mRenderCamera = (Camera)EditorGUILayout.ObjectField("RenderCamera", _mRenderCamera, typeof(Camera), true); GUILayout.BeginHorizontal(GUILayout.Width(position.width)); GUILayout.Label("Select:"); GUI.enabled = null != _mAnimation; if (GUILayout.Button("Animation")) { Selection.activeGameObject = null; Selection.activeObject = _mAnimation; } GUI.enabled = null != _mRenderCamera; if (GUILayout.Button("Camera")) { Selection.activeObject = null; Selection.activeGameObject = _mRenderCamera.gameObject; } GUI.enabled = null != _mParticleSystem; if (GUILayout.Button("ParticleSystem")) { Selection.activeGameObject = null; Selection.activeObject = _mParticleSystem; } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(position.width)); GUILayout.Label("Camera:"); GUI.enabled = null != _mRenderCamera; if (GUILayout.Button("Align With View")) { Selection.activeGameObject = _mRenderCamera.gameObject; EditorApplication.ExecuteMenuItem("GameObject/Align With View"); Selection.activeObject = activeObject; Selection.activeGameObject = activeGameObject; } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(position.width)); GUILayout.Label("Animation:"); if (_mAnimation) { GUI.enabled = ChromaConnectionManager.Instance.Connected; if (GUILayout.Button("Play")) { _mAnimation.Play(); } GUI.enabled = IsAnimationSelected() && !_mAnimation.IsPlaying(); if (GUILayout.Button("First")) { ChromaSDKAnimationBaseEditor.GoToFirstFrame(); } if (GUILayout.Button("Last")) { ChromaSDKAnimationBaseEditor.GoToLastFrame(); } if (GUILayout.Button("Delete")) { DeleteFrame(); } GUI.enabled = !_mAnimation.IsPlaying(); if (GUILayout.Button("Reset")) { ResetAnimation(); } GUI.enabled = true; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(position.width)); float interval = EditorGUILayout.FloatField("Capture Interval", _mInterval); if (interval >= 0.1f) { _mInterval = interval; } int frameCount = 0; if (_mAnimation) { frameCount = _mAnimation.GetFrameCount(); } GUILayout.Label(string.Format("{0} frames", frameCount)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(position.width)); GUILayout.Label("Capture:"); GUI.enabled = null != _mRenderCamera && null != _mAnimation && !_mAnimation.IsPlaying(); if (GUILayout.Button("1 Frame")) { CaptureFrame(); } if (GUILayout.Button(_mCapturing ? "Stop" : "Start")) { _mCapturing = !_mCapturing; if (!_mCapturing) { AutoOverrideTime(); } } GUI.enabled = true; GUILayout.EndHorizontal(); Rect rect = GUILayoutUtility.GetLastRect(); if (_mRenderCamera) { if (null == _mRenderTexture) { _mRenderTexture = new RenderTexture(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, 24, RenderTextureFormat.ARGB32); _mRenderCamera.targetTexture = _mRenderTexture; } _mRenderCamera.Render(); rect.y += 30; DisplayRenderTexture((int)rect.y, RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE); if (_mAnimation) { rect.y += 300; const int padding = 8; if (_mAnimation is ChromaSDKAnimation1D) { int maxLeds = ChromaUtils.GetMaxLeds((_mAnimation as ChromaSDKAnimation1D).Device); for (int k = 1; (k * maxLeds) < position.width && (rect.y + rect.height) <= position.height; k *= 2) { DisplayRenderTexture((int)rect.y, maxLeds * k, k); rect.y += k + padding; } } else if (_mAnimation is ChromaSDKAnimation2D) { int maxRow = ChromaUtils.GetMaxRow((_mAnimation as ChromaSDKAnimation2D).Device); int maxColumn = ChromaUtils.GetMaxColumn((_mAnimation as ChromaSDKAnimation2D).Device); DisplayRenderTexture((int)rect.y, maxColumn, maxRow); for (int k = 1; (k * maxColumn) < position.width && (rect.y + rect.height) <= position.height; k *= 2) { DisplayRenderTexture((int)rect.y, maxColumn * k, maxRow * k); rect.y += maxRow * k + padding; } } } } Repaint(); }