public void Draw(Rect rect) { TimeLineRect = rect; GUI.color = Color.white; //GUI.Box(TimeLineRect, "", EditorStyles.toolbarTextField); Rect DragLimit = new Rect(0, 0, Screen.width, Screen.height); if (!Init) { UpdateSelection(); } refresh = false; for (int index = 0; index < KeyframeSet.Count; index++) { TLkeyframe _keyframe = (TLkeyframe)KeyframeSet[index]; _keyframe.TimeLineRect = TimeLineRect; //_keyframe.TimeLineRect.y = TimeLineRect.y + 20; _keyframe.IconRect.y = TimeLineRect.y - 18; _keyframe.TotalValue = totalValue; if (enabled) { if (SelectedValue == _keyframe.Value && !isDragging) { SelectedIndex = index; _keyframe.state = KeyframeState.selected; } //SELECT SLIDER if ((Event.current.type == EventType.mouseDown) && (!isDragging) && (SelectedIndex != index) && (_keyframe.IconRect.Contains(Event.current.mousePosition))) { for (int index2 = 0; index2 < KeyframeSet.Count; index2++) { TLkeyframe temp_keyframe = (TLkeyframe)KeyframeSet[index2]; if (index2 != index) { temp_keyframe.state = KeyframeState.normal; } } _keyframe.state = KeyframeState.selected; SelectedValue = _keyframe.Value; SelectedIndex = index; refresh = true; } //START DRAG if (!isDragging && Event.current.type == EventType.mouseDrag && SelectedIndex == index && _keyframe.IconRect.Contains(Event.current.mousePosition)) { isDragging = true; if (Event.current.shift) { Debug.Log("duplicar"); } } //UPDATE DRAG if (isDragging && SelectedIndex == index) { //if (EventType.mouseDown()) SelectedIndex = index; SelectedValue = _keyframe.Value; _keyframe.state = KeyframeState.drag; refresh = true; } if (SelectedIndex == index) { GUI.color = GUI.contentColor; _keyframe.Value = SelectedValue; //_keyframe.Value = EditorGUI.Slider(new Rect(TimeLineRect.xMax + 5, TimeLineRect.y, 50, 16), _keyframe.Value, 0f, TotalValue); } //ROLLOVER if (SelectedIndex != index && !isDragging && _keyframe.state != KeyframeState.drag) { if (_keyframe.IconRect.Contains(Event.current.mousePosition)) { //Refresh = true; _keyframe.state = KeyframeState.over; } else { _keyframe.state = KeyframeState.normal; } } //STOP DRAG if (Event.current.type == EventType.mouseUp || !DragLimit.Contains(Event.current.mousePosition) && isDragging) { if (SelectedValue == _keyframe.Value) { _keyframe.state = KeyframeState.selected; isDragging = false; KeyframeSet.Sort(new ordenador()); } } } else { _keyframe.state = KeyframeState.normal; SelectedIndex = -1; //SelectedValue = 0; } //DRAW SLIDER _keyframe.draw(); } TLkeyframe _keyframe_0 = (TLkeyframe)KeyframeSet[0]; TLkeyframe _keyframe_1 = (TLkeyframe)KeyframeSet[1]; if (_keyframe_0.Value < _keyframe_1.Value) { GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x - 1, TimeLineRect.y - 14, _keyframe_0.IconRect.width, _keyframe_0.IconRect.height), icoA); GUI.DrawTexture(new Rect(_keyframe_1.IconRect.x - 1, TimeLineRect.y - 14, _keyframe_1.IconRect.width, _keyframe_1.IconRect.height), icoB); } else { GUI.DrawTexture(new Rect(_keyframe_1.IconRect.x - 1, TimeLineRect.y - 14, _keyframe_1.IconRect.width, _keyframe_1.IconRect.height), icoA); GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x - 1, TimeLineRect.y - 14, _keyframe_0.IconRect.width, _keyframe_0.IconRect.height), icoB); } if (_keyframe_0.Value + _keyframe_1.Value != totalValue) { active = true; /* * GUI.color = new Color(250f / 255f, 100f / 255f, 40f / 255f, 0.5f); * GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x + 6, TimeLineRect.y + 1, (_keyframe_1.IconRect.x - _keyframe_0.IconRect.x), 39), EditorGUIUtility.whiteTexture); * GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x + 6, TimeLineRect.y + 43, (_keyframe_1.IconRect.x - _keyframe_0.IconRect.x), 7), EditorGUIUtility.whiteTexture); */ GUI.color = new Color(0, 0, 0, 0.6f); GUI.DrawTexture(new Rect(TimeLineRect.xMin, TimeLineRect.y + 1, (_keyframe_0.IconRect.x - TimeLineRect.xMin) + 6, 39), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(_keyframe_1.IconRect.x + 6, TimeLineRect.y + 1, (TimeLineRect.xMax - _keyframe_1.IconRect.x) - 6, 39), EditorGUIUtility.whiteTexture); GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.2f); GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x + 6, TimeLineRect.y + 43, (_keyframe_1.IconRect.x - _keyframe_0.IconRect.x), 11), EditorGUIUtility.whiteTexture); GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 1f); GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x + 6, TimeLineRect.y + 41, (_keyframe_1.IconRect.x - _keyframe_0.IconRect.x), 2), EditorGUIUtility.whiteTexture); } else { active = false; } GUI.color = Color.white; //GUI.DrawTexture(new Rect(_keyframe_0.IconRect.x + 3, _keyframe_0.IconRect.y + 5, 2, 5), EditorGUIUtility.whiteTexture); //GUI.DrawTexture(new Rect(_keyframe_1.IconRect.x + 3, _keyframe_0.IconRect.y + 5, 2, 5), EditorGUIUtility.whiteTexture); //if (Refresh) GetWindow(typeof(TagarelaEditor)).Repaint(); }
public void Draw(Rect rect) { rect = new Rect(rect.x, rect.y, Mathf.Max(imgTimeline.width, rect.width), Mathf.Max(imgTimeline.height, rect.height)); timeLineRect = rect; GUI.color = Color.white; GUI.Box(timeLineRect, "", styleTimeline); Rect dragLimit = new Rect(0, 0, Screen.width, Screen.height); if (!init) { UpdateSelection(); } refresh = false; for (int index = 0; index < keyframeSet.Count; index++) { TLkeyframe _keyframe = (TLkeyframe)keyframeSet[index]; _keyframe.timeLineRect = new Rect(timeLineRect.x + styleTimeline.border.left, timeLineRect.y + styleTimeline.border.top, timeLineRect.width - styleTimeline.border.horizontal, timeLineRect.height); _keyframe.iconRect.y = timeLineRect.y + 2; //top position of the icons _keyframe.totalValue = totalValue; if (enabled) { if (selectedValue == _keyframe.value && !isDragging) { selectedIndex = index; morphSliders = _keyframe.morphSliders; _keyframe.state = KeyframeState.selected; } //SELECT SLIDER if ((Event.current.type == EventType.mouseDown) && (!isDragging) && (selectedIndex != index) && (_keyframe.iconRect.Contains(Event.current.mousePosition))) { for (int index2 = 0; index2 < keyframeSet.Count; index2++) { TLkeyframe temp_keyframe = (TLkeyframe)keyframeSet[index2]; if (index2 != index) { temp_keyframe.state = KeyframeState.normal; } } _keyframe.state = KeyframeState.selected; selectedValue = _keyframe.value; selectedIndex = index; morphSliders = _keyframe.morphSliders; refresh = true; } //START DRAG if (!isDragging && Event.current.type == EventType.mouseDrag && selectedIndex == index && _keyframe.iconRect.Contains(Event.current.mousePosition)) { isDragging = true; //DRAG TO CLONE if (Event.current.shift) { TagarelaMorphTarget morphInstance = new TagarelaMorphTarget(); morphInstance.id = _keyframe.morphSliders.id.GetRange(0, _keyframe.morphSliders.id.ToArray().Length); morphInstance.sliderValue = _keyframe.morphSliders.sliderValue.GetRange(0, _keyframe.morphSliders.sliderValue.ToArray().Length); AddKeyframe(selectedValue + 0.0001f, morphInstance); isKeyframeSetChanged = true; } } //UPDATE DRAG if (isDragging && selectedIndex == index) { //if (EventType.mouseDown()) selectedIndex = index; selectedValue = _keyframe.value; morphSliders = _keyframe.morphSliders; _keyframe.state = KeyframeState.drag; refresh = true; } if (selectedIndex == index) { GUI.color = GUI.contentColor; //_keyframe.Value = EditorGUI.Slider(new Rect(TimeLineRect.xMax + 5, TimeLineRect.y, 50, 16), _keyframe.Value, 0f, totalValue); //_keyframe.Value = SelectedValue; } //ROLLOVER if (selectedIndex != index && !isDragging && _keyframe.state != KeyframeState.drag) { if (_keyframe.iconRect.Contains(Event.current.mousePosition)) { //Refresh = true; _keyframe.state = KeyframeState.over; } else { _keyframe.state = KeyframeState.normal; } } //STOP DRAG if (Event.current.type == EventType.mouseUp || !dragLimit.Contains(Event.current.mousePosition) && isDragging) { if (selectedValue == _keyframe.value) { _keyframe.state = KeyframeState.selected; isDragging = false; keyframeSet.Sort(new ordenador()); } } } else { _keyframe.state = KeyframeState.normal; //SelectedIndex = -1; //SelectedValue = -1; } //DRAW SLIDER _keyframe.draw(); } //if (Refresh) GetWindow(typeof(TagarelaEditor)).Repaint(); }