private void OnClickFillRow(int row) { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); var rows = frames[_mCurrentFrame]; if (row < rows.Count && row < maxRow) { var colors = rows[row]; for (int j = 0; j < maxColumn; ++j) { colors[j] = ChromaUtils.ToBGR(_mColor); } } frames[_mCurrentFrame] = rows; } animation.Frames = frames; }
private void OnClickDarkenButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); var frame = frames[_mCurrentFrame]; for (int i = 0; i < maxRow; ++i) { var row = frame[i]; for (int j = 0; j < maxColumn; ++j) { Color color = ChromaUtils.ToRGB(row[j]); color.r *= 0.75f; color.g *= 0.75f; color.b *= 0.75f; row[j] = ChromaUtils.ToBGR(color); } } } animation.Frames = frames; }
private void OnClickShiftButton(int y, int x) { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); int offsetX = maxColumn - x; int offsetY = maxRow - y; var oldFrame = frames[_mCurrentFrame]; var newFrame = ChromaUtils.CreateColors2D(device); for (int i = 0; i < maxRow; ++i) { var oldRow = oldFrame[(i + offsetY) % maxRow]; var newRow = newFrame[i]; for (int j = 0; j < maxColumn; ++j) { int color = oldRow[(j + offsetX) % maxColumn]; newRow[j] = color; } } frames[_mCurrentFrame] = newFrame; } animation.Frames = frames; }
private void OnClickFillColumn(int column) { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); var rows = frames[_mCurrentFrame]; for (int i = 0; i < maxRow; ++i) { var row = rows[i]; if (column < row.Count && column < maxColumn) { row[column] = ChromaUtils.ToBGR(_mColor); } } frames[_mCurrentFrame] = rows; } animation.Frames = frames; }
private void OnClickSaturateButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); var frame = frames[_mCurrentFrame]; for (int i = 0; i < maxRow; ++i) { var row = frame[i]; for (int j = 0; j < maxColumn; ++j) { Color color = ChromaUtils.ToRGB(row[j]); float max = Mathf.Max(Mathf.Max(color.r, color.g), color.b); color = Color.Lerp(Color.black, _mColor, max); row[j] = ChromaUtils.ToBGR(color); } } } animation.Frames = frames; }
private void OnClickPasteButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); if (null != _mColors && _mColors.Count == maxRow && null != _mColors[0] && _mColors[0].Count == maxColumn) { var frame = ChromaUtils.CreateColors2D(device); for (int i = 0; i < maxRow; ++i) { for (int j = 0; j < maxColumn; ++j) { frame[i][j] = _mColors[i][j]; } } frames[_mCurrentFrame] = frame; } } animation.Frames = frames; }
public static EffectResponseId CreateEffectCustom2D(ChromaDevice2DEnum device, EffectArray2dInput input) { if (ChromaConnectionManager.Instance.Connected) { ChromaApi apiChromaInstance = ChromaConnectionManager.Instance.ApiChromaInstance; return(ChromaUtils.CreateEffectCustom2D(apiChromaInstance, device, input)); } return(null); }
private void OnClickAddButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame < 0 || _mCurrentFrame >= frames.Count) { _mCurrentFrame = 0; } EffectArray2dInput oldFrame; if (frames.Count > 0) { oldFrame = frames[_mCurrentFrame]; } else { oldFrame = ChromaUtils.CreateColors2D(animation.Device); } EffectArray2dInput frame = ChromaUtils.CreateColors2D(animation.Device); if (_mCurrentFrame == frames.Count || (_mCurrentFrame + 1) == frames.Count) { frames.Add(frame); _mCurrentFrame = frames.Count - 1; } else { ++_mCurrentFrame; frames.Insert(_mCurrentFrame, frame); } // copy colors if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); for (int i = 0; i < maxRow; ++i) { var row = frame[i]; for (int j = 0; j < maxColumn; ++j) { row[j] = oldFrame[i][j]; } } } animation.Frames = frames; animation.RefreshCurve(); }
private void LoadImage(string path) { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); Unload(); if (!string.IsNullOrEmpty(path)) { ImageManager.LoadImage(path); int frameCount = ImageManager.PluginGetFrameCount(); if (frameCount == 0) { Debug.LogError("Failed to read frames from image! Please try again!"); } ChromaDevice2DEnum device = animation.Device; var colors = ChromaUtils.CreateColors2D(device); for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { if (frameIndex > 0) { OnClickAddButton(); } var frames = animation.Frames; //copy if (_mCurrentFrame >= 0 && _mCurrentFrame < animation.Frames.Count) { //Debug.Log(string.Format("Frame count: {0}", frameCount)); int height = ImageManager.PluginGetHeight(); int width = ImageManager.PluginGetWidth(); for (int y = 0; y < colors.Count && y < height; y++) { var row = colors[y]; for (int x = 0; x < row.Count && x < width; x++) { int color = ImageManager.PluginGetPixel(frameIndex, x, y); row[x] = color; } } frames[_mCurrentFrame] = colors; } animation.Frames = frames; } } }
/// <summary> /// Get the max row given the device /// </summary> /// <param name="device"></param> /// <returns></returns> public static int GetMaxRow(ChromaDevice2DEnum device) { switch (device) { case ChromaDevice2DEnum.Keyboard: return(Keyboard.MAX_ROW); case ChromaDevice2DEnum.Keypad: return(Keypad.MAX_ROW); case ChromaDevice2DEnum.Mouse: return(Mouse.MAX_ROW); } return(0); }
public static EffectArray2dInput CreateColors2D(ChromaDevice2DEnum device) { int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); EffectArray2dInput effectArray2dInput = new EffectArray2dInput(); for (int i = 0; i < maxRow; i++) { List <int> list = new List <int>(); for (int j = 0; j < maxColumn; j++) { list.Add(0); } effectArray2dInput.Add(list); } return(effectArray2dInput); }
public static EffectArray2dInput CreateRandomColors2D(ChromaDevice2DEnum device) { int maxRow = GetMaxRow(device); int maxColumn = GetMaxColumn(device); var rows = new EffectArray2dInput(); for (int i = 0; i < maxRow; ++i) { var row = new List <int>(); for (int j = 0; j < maxColumn; ++j) { row.Add(_sRandom.Next(16777215)); } rows.Add(row); } return(rows); }
public static int GetMaxColumn(ChromaDevice2DEnum device) { switch (device) { case ChromaDevice2DEnum.Keyboard: return(22); case ChromaDevice2DEnum.Keypad: return(5); case ChromaDevice2DEnum.Mouse: return(7); default: return(0); } }
public static int GetMaxRow(ChromaDevice2DEnum device) { switch (device) { case ChromaDevice2DEnum.Keyboard: return(6); case ChromaDevice2DEnum.Keypad: return(4); case ChromaDevice2DEnum.Mouse: return(9); default: return(0); } }
private void OnClickClearButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < animation.Frames.Count) { ChromaDevice2DEnum device = animation.Device; frames[_mCurrentFrame] = ChromaUtils.CreateColors2D(device); } animation.Frames = frames; }
private static EffectResponseId CreateEffectCustom2D(ChromaApi api, ChromaDevice2DEnum device, EffectArray2dInput input) { if (null == api) { Debug.LogError("CreateEffectCustom2D: Parameter api is null!"); return(null); } if (null == input) { Debug.LogError("CreateEffectCustom2D: Parameter input is null!"); return(null); } int maxRow = GetMaxRow(device); int maxColumn = GetMaxColumn(device); if (maxRow != input.Count || (input.Count > 0 && maxColumn != input[0].Count)) { Debug.LogError(string.Format("CreateEffectCustom2D Array size mismatch row: %d==%d column: %d==%d!", maxRow, input.Count, maxColumn, input.Count > 0 ? input[0].Count : 0)); } try { switch (device) { case ChromaDevice2DEnum.Keyboard: return(api.PostKeyboardCustom(input)); case ChromaDevice2DEnum.Keypad: return(api.PostKeypadCustom(input)); case ChromaDevice2DEnum.Mouse: return(api.PostMouseCustom(input)); } } catch (Exception) { } return(null); }
private void OnClickContrastButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; int maxRow = ChromaUtils.GetMaxRow(device); int maxColumn = ChromaUtils.GetMaxColumn(device); var frame = frames[_mCurrentFrame]; for (int i = 0; i < maxRow; ++i) { var row = frame[i]; for (int j = 0; j < maxColumn; ++j) { Color color = ChromaUtils.ToRGB(row[j]); float avg = (color.r + color.g + color.b) / 3f; if (avg < 0.5f) { color.r *= 0.75f; color.g *= 0.75f; color.b *= 0.75f; } else if (avg > 0.5f) { color.r = Mathf.Min(1f, color.r * 1.25f); color.g = Mathf.Min(1f, color.g * 1.25f); color.b = Mathf.Min(1f, color.b * 1.25f); } row[j] = ChromaUtils.ToBGR(color); } } } animation.Frames = frames; }
protected override void OnClickPreviewButton() { ChromaSDKAnimation2D animation = GetAnimation(); EditorUtility.SetDirty(animation); var frames = animation.Frames; //copy Unload(); if (_mCurrentFrame >= 0 && _mCurrentFrame < frames.Count) { ChromaDevice2DEnum device = animation.Device; EffectArray2dInput colors = frames[_mCurrentFrame]; EffectResponseId effect = ChromaUtils.CreateEffectCustom2D(device, colors); if (null != effect && effect.Result == 0) { ChromaUtils.SetEffect(effect.Id); ChromaUtils.RemoveEffect(effect.Id); } } }
public override void OnInspectorGUI() { if (!EditorApplication.isCompiling) { base.OnInspectorGUI(); // backup original color Color oldBackgroundColor = GUI.backgroundColor; ChromaSDKAnimation2D 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 = (ChromaDevice2DEnum)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") || Event.current.shift) { 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 Down")) { OnClickShiftButton(1, 0); } if (GUILayout.Button("Shift Left")) { OnClickShiftButton(0, -1); } if (GUILayout.Button("Shift Right")) { OnClickShiftButton(0, 1); } if (GUILayout.Button("Shift Up")) { OnClickShiftButton(-1, 0); } GUILayout.EndHorizontal(); // grid info int maxRow = ChromaUtils.GetMaxRow(animation.Device); int maxColumn = ChromaUtils.GetMaxColumn(animation.Device); GUILayout.Label(string.Format("{0} x {1}", maxRow, maxColumn)); if (_mDevice == ChromaDevice2DEnum.Keyboard) { GUILayout.BeginHorizontal(GUILayout.Width(Screen.width)); _sToggleLabels = EditorGUILayout.Toggle("Labels:", _sToggleLabels); _sLabelColor = EditorGUILayout.ColorField("Label Color:", _sLabelColor); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } // Preview // the grid panel GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); GUILayout.FlexibleSpace(); // the left-part GUILayout.BeginVertical(); if (GUILayout.Button(" ", GUILayout.Height(20))) { OnClickFillButton(); } for (int i = 0; i < maxRow; ++i) { if (GUILayout.Button(" ", GUILayout.Height(20))) { OnClickFillRow(i); } } GUILayout.EndVertical(); // the right-part GUILayout.BeginVertical(); int boxWidth = Screen.width / (maxColumn + 1) - 5; // the top-buttons GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); for (int j = 0; j < maxColumn; ++j) { if (GUILayout.Button(" ", GUILayout.Width(boxWidth))) { OnClickFillColumn(j); } } GUILayout.EndHorizontal(); // the main-grid string tooltip = null; Rect tooltipRect = new Rect(0, 0, 0, 0); Texture2D oldTexture = GUI.skin.button.normal.background; SetupBlankTexture(); if (_mCurrentFrame < frames.Count) { EffectArray2dInput frame = frames[_mCurrentFrame]; for (int i = 0; i < maxRow && i < frame.Count; ++i) { List <int> row = frame[i]; GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); for (int j = 0; j < maxColumn && j < row.Count; ++j) { int color = row[j]; GUI.backgroundColor = ChromaUtils.ToRGB(color); // use a box instead of button so it looks better GUILayout.Box("", GUILayout.Width(boxWidth)); Rect rect = GUILayoutUtility.GetLastRect(); // check for hovering box if (Event.current.alt && rect.Contains(Event.current.mousePosition)) { _mColor = ChromaUtils.ToRGB(color); } if (_mDevice == ChromaDevice2DEnum.Keyboard && !_sToggleLabels && rect.Contains(Event.current.mousePosition)) { tooltip = ChromaUtils.GetKeyString(i, j); tooltipRect = rect; } // 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, j); } GUI.skin.button.normal.background = oldTexture; if (_mDevice == ChromaDevice2DEnum.Keyboard && _sToggleLabels) { string keyString = ChromaUtils.GetKeyString(i, j); Color oldColor = GUI.skin.label.normal.textColor; GUI.skin.label.normal.textColor = _sLabelColor; GUI.Label(rect, keyString); GUI.skin.label.normal.textColor = oldColor; } } GUILayout.EndHorizontal(); } } GUI.SetNextControlName(""); if (!string.IsNullOrEmpty(tooltip)) { var labelStyle = GUI.skin.GetStyle("Label"); Vector2 size = labelStyle.CalcSize(new GUIContent(tooltip)); tooltipRect.y -= 20; tooltipRect.width = size.x + 10; tooltipRect.height = size.y + 10; GUI.skin.box.normal.background = _sTextureClear; GUI.Box(tooltipRect, " "); labelStyle.alignment = TextAnchor.MiddleCenter; GUI.Label(tooltipRect, tooltip); } // end of right-part GUILayout.EndVertical(); GUILayout.FlexibleSpace(); // end of grid panel GUILayout.EndHorizontal(); // restore original color GUI.backgroundColor = oldBackgroundColor; // show separator EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); // Key if (animation.Device == ChromaDevice2DEnum.Keyboard) { GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); _mKey = (Keyboard.RZKEY)EditorGUILayout.EnumPopup("Select a key", _mKey); if (GUILayout.Button("Set key", GUILayout.Width(100))) { OnClickColor( ChromaUtils.GetHighByte((int)_mKey), ChromaUtils.GetLowByte((int)_mKey)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); if (GUILayout.Button("Set RZLED_LOGO")) { OnClickColor( ChromaUtils.GetHighByte((int)Keyboard.RZLED.RZLED_LOGO), ChromaUtils.GetLowByte((int)Keyboard.RZLED.RZLED_LOGO)); } GUILayout.EndHorizontal(); } // Led if (animation.Device == ChromaDevice2DEnum.Mouse) { GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); _mLed = (Mouse.RZLED2)EditorGUILayout.EnumPopup("Select an LED", _mLed); if (GUILayout.Button("Set LED", GUILayout.Width(100))) { OnClickColor( ChromaUtils.GetHighByte((int)_mLed), ChromaUtils.GetLowByte((int)_mLed)); } GUILayout.EndHorizontal(); } // 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 GUILayout.BeginHorizontal(GUILayout.Width(Screen.width - LAYOUT_PADDING)); _mColor = EditorGUILayout.ColorField(_mColor, GUILayout.Width(40)); _mColor = EditorGUILayout.ColorField("Brush color", _mColor); GUILayout.EndHorizontal(); 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(); } else if (e.keyCode == KeyCode.Space) { OnClickPlayButton(); Repaint(); } } } } Repaint(); }