public void ProcessEvents(StateMachineNode fighterState) { Event ev = Event.current; Rect rect = new Rect(Vector2.zero, fighterState.nodeRect.size); switch (ev.type) { case EventType.MouseDown: if (ev.button == 0 && rect.Contains(ev.mousePosition)) { if (ev.clickCount > 1) { int index = machine.states.FindIndex((s) => s == fighterState); treePath.Add(index); if (OnNodeSelected != null) { OnNodeSelected.Invoke(index); } ev.Use(); return; } fighterState.isDragged = true; selectedType = SELECTED_TYPE.STATE; if (!ev.shift) { selectedStates.Clear(); } selectedTransitions.Clear(); selectedStates.Add(fighterState); hasSelected = true; ev.Use(); LZFighterEditor.RepaintWindow(); GUI.FocusControl("Node"); } if (ev.button == 1) { BeginTransition(fighterState); ev.Use(); } break; case EventType.MouseUp: if (state == STATE.MAKING_TRANSITION) { Debug.Log("Making transition between " + transitionStart.name + " and " + fighterState.name); EndTransition(fighterState); ev.Use(); } break; } }
private void EndTransition(StateMachineNode end) { state = STATE.IDLE; LZFighterStateTransition newTransition = new LZFighterStateTransition(); newTransition.source = machine.states.FindIndex((s) => s == transitionStart); newTransition.target = machine.states.FindIndex((s) => s == end); if (newTransition.source != newTransition.target && machine.transitions.Find((t) => t.source == newTransition.source && t.target == newTransition.target) == null) { machine.transitions.Add(newTransition); } LZFighterEditor.RepaintWindow(); }
private void EndTransition() { state = STATE.IDLE; LZFighterEditor.RepaintWindow(); }
public void ProcessEvents() { Event ev = Event.current; switch (ev.type) { case EventType.MouseDown: if (ev.button == 0) { //Select Transition foreach (LZFighterStateTransition t in GetCurrentTransitions()) { Vector2 A = machine[t.source].nodeRect.center; Vector2 B = machine[t.target].nodeRect.center; Vector2 dirMod = (B - A).normalized.Rotated(90); A += dirMod * 7; B += dirMod * 7; if (GUITools.SegmentPointDistance(A, B, ev.mousePosition) < 7) { selectedType = SELECTED_TYPE.TRANSITION; if (!ev.shift) { selectedTransitions.Clear(); } selectedTransitions.Add(t); selectedStates.Clear(); hasSelected = true; ev.Use(); return; } } foreach (StateMachineNode state in GetCurrentStates()) { state.isDragged = true; } selectedTransitions.Clear(); selectedStates.Clear(); hasSelected = false; dragging = true; LZFighterEditor.RepaintWindow(); } if (ev.button == 1) { ProcessContextMenu(ev.mousePosition, fighter); } break; case EventType.MouseUp: foreach (StateMachineNode state in GetCurrentStates()) { state.isDragged = false; } EndTransition(); dragging = false; break; case EventType.MouseDrag: foreach (StateMachineNode state in GetCurrentStates()) { if (state.isDragged) { state.nodeRect.position += ev.delta; } } if (dragging) { graphOffset += ev.delta; } ev.Use(); break; case EventType.KeyDown: switch (ev.keyCode) { case KeyCode.Delete: if (selectedType == SELECTED_TYPE.TRANSITION) { foreach (var t in selectedTransitions) { machine.transitions.Remove(t); } } else { foreach (var s in selectedStates) { machine.RemoveState(s); } } ev.Use(); break; case KeyCode.S: if (selectedType == SELECTED_TYPE.TRANSITION) { } else { if (treePath.Count > 0) { machine.states[treePath[treePath.Count - 1]].startState = machine.states.FindIndex((s) => s == selectedStates[0]); } else { machine.startState = machine.states.FindIndex((s) => s == selectedStates[0]); } } ev.Use(); break; } break; } }