private void ChangeEditMode(EditMode editMode, bool deselect = true) { if (deselect) { smc.DeselectState(selectedState); selectedState = null; smc.DeselectTransition(selectedTransition); selectedTransition = null; } if (editMode != EditMode.Test && this.editMode == EditMode.Test) { NextButtonText.SetText("Test"); fileNameText.SetText(smc.stateMachineData.meta_name); smc.TestClear(); } switch (editMode) { case EditMode.Edit: this.editMode = EditMode.Edit; animator.SetTrigger("Cancle"); tooltip.SetText("Tap to select a state or transition."); break; case EditMode.AddState: this.editMode = EditMode.AddState; animator.SetTrigger("AddState"); tooltip.SetText("Tap to add a new state."); break; case EditMode.AddTransition: this.editMode = EditMode.AddTransition; animator.SetTrigger("AddTransition"); tooltip.SetText("Tap to add a new transition."); break; case EditMode.SelectState: this.editMode = EditMode.SelectState; animator.SetTrigger("SelectState"); tooltip.SetText("Drag the selected state to move."); break; case EditMode.SelectTransition: this.editMode = EditMode.SelectTransition; animator.SetTrigger("SelectTransition"); tooltip.SetText(""); break; case EditMode.Test: this.editMode = EditMode.Test; animator.SetTrigger("Test"); tooltip.SetText(""); NextButtonText.SetText("Run"); fileNameText.SetText(smc.stateMachineData.meta_name + testTopPanelText); break; default: break; } }
public void DrawTransitions() { // Remove old drawnTransitions.ForEach(x => Destroy(x.gameObject)); drawnTransitions.Clear(); // Copy of all transitions to draw List <StateMachineData.Transition> transitions = new List <StateMachineData.Transition>(stateMachineData.transitions); while (transitions.Count > 0) { // Stack same transition with other transitions List <StateMachineData.Transition> sameTransition = transitions.FindAll(x => x.from == transitions[0].from && x.to == transitions[0].to); transitions.RemoveAll(x => sameTransition.Contains(x)); // Draw GameObject o = Instantiate(transitionPrefab); o.transform.position = Vector3.zero; // Pos Vector2 startPos = stateMachineData.states.Find(x => x.id == sameTransition[0].from).pos; Vector2 endPos = stateMachineData.states.Find(x => x.id == sameTransition[0].to).pos; // Set & Add Text TransitionPrefab t = o.GetComponent <TransitionPrefab>(); t.Set(startPos, endPos, stateMachineData.InputToString(sameTransition[0].input), sameTransition[0]); sameTransition.RemoveAt(0); foreach (StateMachineData.Transition item in sameTransition) { t.AddText(stateMachineData.InputToString(item.input), item); } drawnTransitions.Add(t); } }
public void TransitionEditOKButton() { // Check Diff Then Update foreach (StateMachineData.Transition item in editedTransition) { // Add new Transitions if (!smc.stateMachineData.transitions.Exists(x => x.from == item.from && x.to == item.to && x.input == item.input)) { smc.stateMachineData.CreateTransition(item.from, item.to, item.input); } } // Remove deleted Transitions List <StateMachineData.Transition> deleteThis = new List <StateMachineData.Transition>(); foreach (StateMachineData.Transition item in smc.stateMachineData.transitions) { if (selectedTransition.transitions[0].from == item.from && selectedTransition.transitions[0].to == item.to && !editedTransition.Exists(x => x.input == item.input)) { deleteThis.Add(item); } } deleteThis.ForEach(x => smc.stateMachineData.RemoveTransition(x)); // Empty Transition? if (editedTransition.Count == 0) { ChangeEditMode(EditMode.Edit); smc.DrawTransitions(); } else { smc.DrawTransitions(); selectedTransition = smc.SelectTransition(selectedTransition.transitions[0].from, selectedTransition.transitions[0].to); } PopupMode = false; }
private void ClickAddTransition(Vector2 pos) { if (!IsInCanvas(pos)) { return; } Vector2 wp = Camera.main.ScreenToWorldPoint(pos); if (selectedState == null) { selectedState = smc.SelectState(wp); } else { StateMachineData.State otherState = smc.SelectState(wp); if (otherState != null) { StateMachineData.Transition t = smc.stateMachineData.transitions.Find(x => x.from == selectedState.id && x.to == otherState.id); if (t != null) { smc.DeselectState(otherState); ChangeEditMode(EditMode.SelectTransition); selectedTransition = smc.SelectTransition(t.from, t.to); } else { CreateTransition(selectedState.id, otherState.id, 0); smc.DeselectState(otherState); ChangeEditMode(EditMode.Edit); } } } }
public void DeselectTransition(TransitionPrefab t) { if (t == null) { return; } t.SetColor(Color.black); t.lineRenderer.sortingOrder = -10; }
public TransitionPrefab SelectTransition(int from, int to) { TransitionPrefab t = drawnTransitions.Find(x => x.transitions.Exists(y => y.from == from && y.to == to)); if (t == null) { return(null); } t.SetColor(Appdata.highlightColor); t.lineRenderer.sortingOrder = -9; return(t); }
public TransitionPrefab SelectTransition(Vector2 pos) { TransitionPrefab t = drawnTransitions.Find(x => x.coll.OverlapPoint(pos)); if (t == null) { return(null); } t.SetColor(Appdata.highlightColor); t.lineRenderer.sortingOrder = -9; return(t); }
private bool SelectThing(Vector2 pos) { if (!IsInCanvas(pos)) { return(false); } smc.DeselectState(selectedState); smc.DeselectTransition(selectedTransition); selectedState = null; Vector2 wp = Camera.main.ScreenToWorldPoint(pos); selectedState = smc.SelectState(wp); if (selectedState == null) { selectedTransition = smc.SelectTransition(wp); } return(true); }
private void RemoveTransition(TransitionPrefab t) { smc.stateMachineData.transitions.FindAll(x => x.from == t.transitions[0].from && x.to == t.transitions[0].to).ForEach(x => smc.stateMachineData.RemoveTransition(x)); smc.DrawTransitions(); }