private void Unload() { ChromaSDKAnimation1D animation = GetAnimation(); if (animation.IsLoaded()) { animation.Unload(); } }
private void OnClickPlayButton() { ChromaSDKAnimation1D animation = GetAnimation(); EditorUtility.SetDirty(animation); if (!animation.IsLoaded()) { animation.Load(); } animation.Play(); }
public override void OnInspectorGUI() { if (!EditorApplication.isCompiling) { base.OnInspectorGUI(); // backup original color Color oldBackgroundColor = GUI.backgroundColor; ChromaSDKAnimation1D animation = GetAnimation(); if (_mLastTarget != animation) { _mLastTarget = animation; _mDevice = animation.Device; } var frames = animation.Frames; //copy if (frames.Count == 0) { OnClickAddButton(); } // Device GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); GUILayout.Label("Device:"); _mDevice = (ChromaDevice1DEnum)EditorGUILayout.EnumPopup(_mDevice, GUILayout.Width(150)); if (GUILayout.Button("Set", GUILayout.Width(100))) { OnClickSetDevice(); } GUILayout.FlexibleSpace(); GUILayout.Label(ChromaUtils.VERSION); GUILayout.EndHorizontal(); bool connected = ChromaConnectionManager.Instance.Connected; GUI.enabled = connected; GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Play")) { OnClickPlayButton(); } if (GUILayout.Button("Stop")) { OnClickStopButton(); } GUI.enabled = connected && !animation.IsLoaded(); if (GUILayout.Button("Load")) { OnClickLoadButton(); } GUI.enabled = connected && animation.IsLoaded(); if (GUILayout.Button("Unload")) { OnClickUnloadButton(); } GUI.enabled = true; if (GUILayout.Button("Preview")) { OnClickPreviewButton(); } GUILayout.EndHorizontal(); // Import GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); GUILayout.FlexibleSpace(); if (GUILayout.Button("Import")) { OnClickImportButton(); } if (GUILayout.Button("Export")) { OnClickExportButton(); } if (GUILayout.Button("Import Image")) { OnClickImportImageButton(); } if (GUILayout.Button("Import Animation")) { OnClickImportAnimationButton(); } if (GUILayout.Button("Reverse Animation")) { OnClickReverseAnimationButton(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Apply GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Clear")) { OnClickClearButton(); } if (GUILayout.Button("Fill")) { OnClickFillButton(); } if (GUILayout.Button("Random")) { OnClickRandomButton(); } if (GUILayout.Button("Copy")) { OnClickCopyButton(); } if (GUILayout.Button("Paste")) { OnClickPasteButton(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Contrast")) { OnClickContrastButton(); } if (GUILayout.Button("Saturate")) { OnClickSaturateButton(); } if (GUILayout.Button("Desaturate")) { OnClickDesaturateButton(); } if (GUILayout.Button("Darken")) { OnClickDarkenButton(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Shift Left")) { OnClickShiftButton(-1); } if (GUILayout.Button("Shift Right")) { OnClickShiftButton(1); } GUILayout.EndHorizontal(); int maxLeds = ChromaUtils.GetMaxLeds(animation.Device); GUILayout.Label(string.Format("1 x {0}", maxLeds)); // Preview Texture2D oldTexture = GUI.skin.button.normal.background; SetupBlankTexture(); if (_mCurrentFrame < frames.Count) { GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); EffectArray1dInput frame = frames[_mCurrentFrame]; for (int i = 0; i < frame.Count; ++i) { int color = (int)frame[i]; GUI.backgroundColor = ChromaUtils.ToRGB(color); // use a box instead of button so it looks better GUILayout.Box("", GUILayout.Width(12)); Rect rect = GUILayoutUtility.GetLastRect(); // use the box location to use a button to catch the click event GUI.skin.button.normal.background = _sTextureClear; if (GUI.Button(rect, "")) { OnClickColor(i); } GUI.skin.button.normal.background = oldTexture; } GUILayout.EndHorizontal(); } GUI.SetNextControlName(""); // restore original color GUI.backgroundColor = oldBackgroundColor; // show separator EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); // preset colors GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); const float k = 0.5f; Color[] palette = { Color.red, Color.red *k, ORANGE, ORANGE *k, Color.yellow, Color.yellow *k, Color.green, Color.green *k, Color.blue, Color.blue *k, Color.cyan, Color.cyan *k, PURPLE, PURPLE *k, Color.white, Color.gray, Color.black, }; foreach (Color color in palette) { Color newColor = color; newColor.a = 1f; GUI.backgroundColor = newColor; // use a box instead of button so it looks better GUILayout.Box("", GUILayout.Width(12)); Rect rect = GUILayoutUtility.GetLastRect(); // use the box location to use a button to catch the click event GUI.skin.button.normal.background = _sTextureClear; if (GUI.Button(rect, "")) { _mColor = newColor; } GUI.skin.button.normal.background = oldTexture; } GUILayout.EndHorizontal(); // restore original color GUI.backgroundColor = oldBackgroundColor; // Set the color _mColor = EditorGUILayout.ColorField("Brush color", _mColor); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); GUI.SetNextControlName(CONTROL_OVERRIDE); GUILayout.Label("Override Time (ALL frames)"); _mOverrideFrameTime = EditorGUILayout.FloatField(_mOverrideFrameTime, GUILayout.Width(100)); GUI.SetNextControlName(string.Empty); if (GUILayout.Button("Override", GUILayout.Width(100))) { OnClickOverrideButton(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Frame:", string.Format("{0} of {1}", _mCurrentFrame + 1, null == frames ? 0 : frames.Count)); float duration = 0.0f; if (_mCurrentFrame < frames.Count && _mCurrentFrame < animation.Curve.keys.Length) { if (_mCurrentFrame == 0) { duration = animation.Curve.keys[_mCurrentFrame].time; } else { duration = animation.Curve.keys[_mCurrentFrame].time - animation.Curve.keys[_mCurrentFrame - 1].time; } } GUI.SetNextControlName(CONTROL_DURATION); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); float newDuration = EditorGUILayout.FloatField("Duration:", duration); if (duration != newDuration && newDuration > 0f) { if (_mCurrentFrame < frames.Count && _mCurrentFrame < animation.Curve.keys.Length) { float time; if (_mCurrentFrame == 0) { time = newDuration; } else { time = animation.Curve.keys[_mCurrentFrame - 1].time + newDuration; } animation.Curve.RemoveKey(_mCurrentFrame); animation.Curve.AddKey(time, 0f); } } GUILayout.Label("seconds(s)"); GUILayout.EndHorizontal(); GUI.SetNextControlName(string.Empty); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("First")) { OnClickFirstButton(); } if (GUILayout.Button("Previous")) { OnClickPreviousButton(); } if (GUILayout.Button("Next")) { OnClickNextButton(); } if (GUILayout.Button("Last")) { OnClickLastButton(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Add")) { OnClickAddButton(); } if (GUILayout.Button("Insert")) { OnClickInsertButton(); } if (GUILayout.Button("Delete")) { OnClickDeleteButton(); } if (GUILayout.Button("Reset")) { OnClickResetButton(); } GUILayout.EndHorizontal(); // Custom Curve animation.Curve = EditorGUILayout.CurveField("Edit Curve:", animation.Curve); //Debug.Log(GUI.GetNameOfFocusedControl()); if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) { Event e = Event.current; if (e.type == EventType.keyUp) { if (e.keyCode == KeyCode.Delete) { OnClickClearButton(); Repaint(); } else if (e.keyCode == KeyCode.C && e.modifiers == EventModifiers.Control) { OnClickCopyButton(); } else if (e.keyCode == KeyCode.V && e.modifiers == EventModifiers.Control) { OnClickPasteButton(); Repaint(); } else if (e.keyCode == KeyCode.P) { OnClickPlayButton(); } else if (e.keyCode == KeyCode.LeftArrow) { OnClickPreviousButton(); Repaint(); } else if (e.keyCode == KeyCode.RightArrow) { OnClickNextButton(); Repaint(); } else if (e.keyCode == KeyCode.Plus || e.keyCode == KeyCode.KeypadPlus) { OnClickAddButton(); Repaint(); } else if (e.keyCode == KeyCode.Minus || e.keyCode == KeyCode.KeypadMinus) { OnClickDeleteButton(); Repaint(); } } } } Repaint(); }