private void DoSlider(IGUIState guiState) { Vector3 newPosition; var changed = guiState.Slider(ID, m_SliderData, out newPosition); if (changed) { m_SliderData.position = newPosition; if (m_Start) { m_Start = false; if (onSliderBegin != null) { onSliderBegin(guiState, hoveredControl, newPosition); } } if (onSliderChanged != null) { onSliderChanged(guiState, hoveredControl, newPosition); } } }
private bool EnableCreatePointRepaint(IGUIState guiState, Control pointControl, Control leftTangentControl, Control rightTangentControl) { return(guiState.nearestControl != pointControl.ID && guiState.hotControl == 0 && (guiState.nearestControl != leftTangentControl.ID) && (guiState.nearestControl != rightTangentControl.ID)); }
protected override void OnTrigger(IGUIState guiState) { if (onCommand != null) { onCommand(); } }
protected override void OnRepaint(IGUIState guiState, int index) { if (onRepaint != null) { onRepaint(guiState, this, index); } }
protected override void OnEndLayout(IGUIState guiState) { if (onEndLayout != null) { onEndLayout(guiState); } }
public void Layout(IGUIState guiState) { Debug.Assert(guiState.eventType == EventType.Layout); for (var i = 0; i < GetCount(); ++i) { if (guiState.hotControl == actionID && hotLayoutData.index == i) { continue; } var layoutData = new LayoutData() { index = i, position = GetPosition(guiState, i), distance = GetDistance(guiState, i), forward = GetForward(guiState, i), up = GetUp(guiState, i), right = GetRight(guiState, i), userData = GetUserData(guiState, i) }; m_LayoutData = LayoutData.Nearest(m_LayoutData, layoutData); } }
public void GoToState(GUIState state) { if (_lockTransitions) { throw new InvalidOperationException("Попытка изменения UI-состояния в момент открытия-закрытия другого состояния."); } _lockTransitions = true; try { if (_currentState != null) { if (_currentState.Key == state) { return; } _currentState.OnExitState(); } _currentState = _guiStates[state]; _currentState.OnEnterState(); } finally { _lockTransitions = false; } }
public void Repaint(IGUIState guiState) { for (var i = 0; i < GetCount(); ++i) { OnRepaint(guiState, i); } }
private void DrawEdge(IGUIState guiState, Control control, int index) { if (GetShapeType() == ShapeType.Polygon) { var nextIndex = NextIndex(index); var color = Color.white; if (guiState.nearestControl == control.ID && control.layoutData.index == index && guiState.hotControl == 0) { color = Color.yellow; } m_Drawer.DrawLine(GetPoint(index).position, GetPoint(nextIndex).position, 5f, color); } else if (GetShapeType() == ShapeType.Spline) { var nextIndex = NextIndex(index); var color = Color.white; if (guiState.nearestControl == control.ID && control.layoutData.index == index && guiState.hotControl == 0) { color = Color.yellow; } m_Drawer.DrawBezier( GetPoint(index).position, GetRightTangent(index), GetLeftTangent(nextIndex), GetPoint(nextIndex).position, 5f, color); } }
private bool EnableCreatePointRepaint(IGUIState guiState, GUIAction action) { return(guiState.nearestControl != m_PointControl.ID && guiState.hotControl == 0 && (guiState.nearestControl != m_LeftTangentControl.ID) && (guiState.nearestControl != m_RightTangentControl.ID)); }
private Vector3 ClosestPointInEdge(IGUIState guiState, Vector2 mousePosition, int index) { if (GetShapeType() == ShapeType.Polygon) { var p0 = GetPoint(index).position; var p1 = NextControlPoint(index).position; var mouseWorldPosition = GUIToWorld(guiState, mousePosition); var dir1 = (mouseWorldPosition - p0); var dir2 = (p1 - p0); return(Mathf.Clamp01(Vector3.Dot(dir1, dir2.normalized) / dir2.magnitude) * dir2 + p0); } else if (GetShapeType() == ShapeType.Spline) { var nextIndex = NextIndex(index); float t; return(BezierUtility.ClosestPointOnCurve( GUIToWorld(guiState, mousePosition), GetPoint(index).position, GetPoint(nextIndex).position, GetRightTangent(index), GetLeftTangent(nextIndex), out t)); } return(Vector3.zero); }
/// <summary> /// Calls the methods in its invocation list when Unity draws this GUIAction's GUI. /// </summary> /// <param name="guiState">The current state of the custom editor.</param> public void OnGUI(IGUIState guiState) { m_ID = guiState.GetControlID(GetType().GetHashCode(), FocusType.Passive); if (guiState.hotControl == 0 && IsEnabled(guiState) && CanTrigger(guiState) && GetTriggerContidtion(guiState)) { guiState.hotControl = ID; OnTrigger(guiState); } if (guiState.hotControl == ID) { if (GetFinishContidtion(guiState)) { OnFinish(guiState); guiState.hotControl = 0; } else { OnPerform(guiState); } } if (guiState.eventType == EventType.Repaint && IsRepaintEnabled(guiState)) { Repaint(guiState); } }
protected override void OnFinish(IGUIState guiState) { if (onCommand != null) { onCommand(guiState); } }
/// <summary> /// Calls the methods in its invocation list when repainting the GUI. /// </summary> /// <param name="guiState">The current state of the custom editor.</param> private void Repaint(IGUIState guiState) { Debug.Assert(guiState.eventType == EventType.Repaint); if (onRepaint != null) { onRepaint(guiState, this); } }
private Vector3 GetMousePositionWorld(IGUIState guiState) { if (guiToWorld != null) { return(guiToWorld(guiState, guiState.mousePosition)); } return(guiState.GUIToWorld(guiState.mousePosition, hoveredControl.layoutData.forward, hoveredControl.layoutData.position)); }
/// <summary> /// Checks whether the GUIAction is enabled. /// </summary> /// <param name="guiState">The current state of the custom editor.</param> /// <returns>Returns `true` if the GUIAction is enabled in the custom editor. Otherwise, returns `false`.</returns> public bool IsEnabled(IGUIState guiState) { if (enable != null) { return(enable(guiState, this)); } return(true); }
protected override Vector3 GetRight(IGUIState guiState, int index) { if (right != null) { return(right(index)); } return(base.GetRight(guiState, index)); }
/// <summary> /// Preprocessing that occurs before the GUI repaints. /// </summary> /// <param name="guiState">The current state of the custom editor.</param> public void PreRepaint(IGUIState guiState) { Debug.Assert(guiState.eventType == EventType.Repaint); if (IsEnabled(guiState) && onPreRepaint != null) { onPreRepaint(guiState, this); } }
protected override Vector3 GetForward(IGUIState guiState, int index) { if (forward != null) { return(forward(index)); } return(base.GetForward(guiState, index)); }
protected override Vector3 GetUp(IGUIState guiState, int index) { if (up != null) { return(up(index)); } return(base.GetUp(guiState, index)); }
protected override Vector3 GetPosition(IGUIState guiState, int index) { if (position != null) { return(position(index)); } return(base.GetPosition(guiState, index)); }
protected override float GetDistance(IGUIState guiState, int index) { if (distance != null) { return(distance(guiState, index)); } return(base.GetDistance(guiState, index)); }
protected override object GetUserData(IGUIState guiState, int index) { if (userData != null) { return(userData(index)); } return(base.GetUserData(guiState, index)); }
protected override LayoutData OnBeginLayout(LayoutData data, IGUIState guiState) { if (onBeginLayout != null) { return(onBeginLayout(guiState)); } return(data); }
protected override void OnTrigger(IGUIState guiState) { base.OnTrigger(guiState); m_SliderData.position = hoveredControl.hotLayoutData.position; m_SliderData.forward = hoveredControl.hotLayoutData.forward; m_SliderData.right = hoveredControl.hotLayoutData.right; m_SliderData.up = hoveredControl.hotLayoutData.up; m_Start = true; }
protected override void OnPerform(IGUIState guiState) { if (GetTriggerContidtion(guiState)) { guiState.hotControl = 0; guiState.nearestControl = ID; } DoSlider(guiState); }
protected override void OnFinish(IGUIState guiState) { if (onSliderEnd != null) { onSliderEnd(guiState, hoveredControl, m_SliderData.position); } guiState.UseCurrentEvent(); guiState.Repaint(); }
protected override bool GetTriggerContidtion(IGUIState guiState) { if (guiState.eventType == EventType.ValidateCommand && guiState.commandName == m_CommandName) { guiState.UseCurrentEvent(); return(true); } return(false); }
private Vector3 GUIToWorld(IGUIState guiState, Vector2 guiPosition) { var forward = Vector3.forward; if (guiState.HasCurrentCamera()) { forward = Camera.current.transform.forward; } return(guiState.GUIToWorld(guiPosition, forward, Vector3.zero)); }
protected override bool GetFinishContidtion(IGUIState guiState) { if (guiState.eventType == EventType.ExecuteCommand && guiState.commandName == m_CommandName) { guiState.UseEvent(); return(true); } return(false); }