public static GenericMenu ExecutableContextMenu(ExecutableNode executable, Node node) { GenericMenu menu = new GenericMenu(); if (executable == null) { return(menu); } menu.AddItem(new GUIContent("Enable"), executable.IsEnabled, delegate() { executable.IsEnabled = !executable.IsEnabled; }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Find Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); }); menu.AddItem(new GUIContent("Edit Script"), false, delegate() { MonoScript[] monoScriptArray = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); Selection.activeObject = monoScriptArray.ToList().Find(x => x.GetClass() == executable.GetType()); AssetDatabase.OpenAsset(Selection.activeObject); }); menu.AddSeparator(""); bool moveDown = false; int currentIndex = -1; if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; currentIndex = Array.IndexOf(state.Actions, executable); moveDown = currentIndex + 1 < state.Actions.Length; } else { currentIndex = Array.IndexOf(FsmEditor.SelectedTransition.Conditions, executable); moveDown = currentIndex + 1 < FsmEditor.SelectedTransition.Conditions.Length; } if (currentIndex - 1 >= 0) { menu.AddItem(new GUIContent("Move Up"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex - 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex - 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Up")); } if (moveDown) { menu.AddItem(new GUIContent("Move Down"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.MoveItem(state.Actions, currentIndex, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.MoveItem(FsmEditor.SelectedTransition.Conditions, currentIndex, currentIndex + 1); } NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Move Down")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Copy"), false, delegate() { executableCopy = executable; }); if (executableCopy != null) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex + 1); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex + 1); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); menu.AddItem(new GUIContent("Replace"), false, delegate() { ExecutableNode dest = FsmUtility.Copy(executableCopy); if (dest.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; FsmEditorUtility.DestroyImmediate(state.Actions[currentIndex]); state.Actions = ArrayUtility.RemoveAt <StateAction>(state.Actions, currentIndex); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, currentIndex); } else { FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition.Conditions[currentIndex]); FsmEditor.SelectedTransition.Conditions = ArrayUtility.RemoveAt <Condition>(FsmEditor.SelectedTransition.Conditions, currentIndex); FsmEditor.SelectedTransition.Conditions = ArrayUtility.Insert <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)dest, currentIndex); } FsmEditorUtility.ParentChilds(node); NodeInspector.Dirty(); }); } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Remove"), false, delegate() { if (executable.GetType().IsSubclassOf(typeof(StateAction))) { State state = node as State; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, (StateAction)executable); } else { FsmEditor.SelectedTransition.Conditions = ArrayUtility.Remove <Condition>(FsmEditor.SelectedTransition.Conditions, (Condition)executable); } FsmEditorUtility.DestroyImmediate(executable); //NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); }); return(menu); }
public F64CeilNode(ExecutableNode expr) : base(expr) { }
public static bool NodeTitlebar(ExecutableNode executable, Node node) { int controlID = EditorGUIUtility.GetControlID(FocusType.Passive); GUIContent content = new GUIContent(executable.name.Replace("/", "."), executable.GetType().GetTooltip()); Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle); Rect rect = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f); Rect rect1 = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f); Rect rect4 = rect1; rect4.x = rect4.x - 18f; Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height) { xMax = rect4.xMin - 2f }; Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f); executable.IsEnabled = GUI.Toggle(rect3, executable.IsEnabled, GUIContent.none); string url = executable.GetType().GetHelpUrl(); if (ErrorChecker.HasErrors(executable)) { Rect rect5 = rect4; rect5.y += 1.0f; if (!string.IsNullOrEmpty(url)) { rect5.x = rect5.x - 18f; rect2.xMax = rect5.x; } GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText); } if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText)) { ExecutableContextMenu(executable, node).ShowAsContext(); } if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText)) { Application.OpenURL(url); } EventType eventType = Event.current.type; if (eventType != EventType.MouseDown) { if (eventType == EventType.Repaint) { FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, executable.IsOpen); FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, executable.IsOpen); } } position.width = 15; bool flag = DoToggleForward(position, controlID, executable.IsOpen, GUIContent.none, GUIStyle.none); if (flag != executable.IsOpen) { executable.IsOpen = flag; } return(flag); }
protected ExecutableNode GetNode(int nodeID) { ExecutableNode node = ExecutableNodeFactory.GetNode(_fleet, _nodes, nodeID); return(node); }
private void OnGUI() { GUILayout.BeginHorizontal(); DoSearch(); DoSettings(); GUILayout.EndHorizontal(); GUILayout.Space(2.0f); scroll = GUILayout.BeginScrollView(scroll); foreach (KeyValuePair <string, List <Type> > kvp in sortedTypes) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); if (string.IsNullOrEmpty(searchString)) { if (GUILayout.Button(kvp.Key, (foldout?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton))) { foldout = !foldout; EditorPrefs.SetBool(kvp.Key, foldout); } } else { foldout = true; } if (foldout) { foreach (Type actionType in kvp.Value) { if (!string.IsNullOrEmpty(searchString) && !actionType.Name.ToLower().StartsWith(searchString.ToLower())) { continue; } Color color = GUI.contentColor; GUI.contentColor = (active != null && actionType == active.GetType() ? EditorStyles.foldout.focused.textColor : color); if (GUILayout.Button(string.IsNullOrEmpty(searchString)?actionType.Name:actionType.GetCategory() + "." + actionType.Name, "label", GUILayout.ExpandWidth(true))) { DestroyActive(); ExecutableNode node = (ExecutableNode)ScriptableObject.CreateInstance(actionType); node.hideFlags = HideFlags.HideAndDontSave; node.name = actionType.Name; active = node; if ((EditorApplication.timeSinceStartup - clickTime) < doubleClickTime) { if (FsmEditor.Active != null) { int selectedStatesCount = FsmEditor.SelectionCount; if (selectedStatesCount == 0) { EditorUtility.DisplayDialog("Could not add node " + active.GetType().Name + "!", "Select a state before adding nodes.", "Cancel"); } else if (selectedStatesCount == 1) { Node selectedNode = FsmEditor.SelectedNodes[0]; OnAddNode(selectedNode, active.GetType()); NodeInspector.Dirty(); } else { EditorUtility.DisplayDialog("Could not add node " + active.GetType().Name + "!", "Select only one state. Adding nodes to multiple states is not supported.", "Cancel"); } } } clickTime = EditorApplication.timeSinceStartup; } GUI.contentColor = color; } } } GUILayout.EndScrollView(); if (active != null) { OnPreviewGUI(active); } }
public I64ShrUNode(ExecutableNode left, ExecutableNode right) : base(left, right) { }
public F32MulNode(ExecutableNode left, ExecutableNode right) : base(left, right) { }
public I64ClzNode(ExecutableNode expr) : base(expr) { }
private void AddBlock(List <Instruction> instructions, ExecutableNode node, HashSet <Node> visitedNodes) { //var block = new InstructionBlock() //{ // Instructions = instructions, // MergeLabel = mergePoint, // AlreadyAdded = new HashSet<Node>() //}; while (node != null) { switch (node.OpCode) { case Op.OpBranch: AddInstructionToBlock(instructions, node, visitedNodes); var branch = ((Branch)node); if (visitedNodes.Contains(branch.TargetLabel)) { return; } node = branch.TargetLabel; break; case Op.OpBranchConditional: var branchConditional = (BranchConditional)node; AddInstructionToBlock(instructions, node, visitedNodes); if (!visitedNodes.Contains(branchConditional.TrueLabel)) { AddBlock(instructions, branchConditional.TrueLabel, visitedNodes); } if (!visitedNodes.Contains(branchConditional.FalseLabel)) { AddBlock(instructions, branchConditional.FalseLabel, visitedNodes); } return; case Op.OpLabel: visitedNodes.Add(node); AddInstructionToBlock(instructions, node, visitedNodes); node = node.GetNext(); break; case Op.OpLoopMerge: var loopMerge = (LoopMerge)node; AddInstructionToBlock(instructions, loopMerge, visitedNodes); visitedNodes.Add(loopMerge.GetNext()); visitedNodes.Add(loopMerge.ContinueTarget); visitedNodes.Add(loopMerge.MergeBlock); //Add body AddBlock(instructions, loopMerge.GetNext(), visitedNodes); AddBlock(instructions, (Label)loopMerge.ContinueTarget, visitedNodes); node = loopMerge.MergeBlock; break; case Op.OpSwitch: var switchNode = (Switch)node; AddInstructionToBlock(instructions, node, visitedNodes); foreach (var target in switchNode.Target) { if (!visitedNodes.Contains(target.Node)) { AddBlock(instructions, (ExecutableNode)target.Node, visitedNodes); } } if (!visitedNodes.Contains(switchNode.Default)) { AddBlock(instructions, (ExecutableNode)switchNode.Default, visitedNodes); } return; case Op.OpSelectionMerge: var selectionMerge = (SelectionMerge)node; visitedNodes.Add(selectionMerge.MergeBlock); EnsureInputs(instructions, node.GetNext(), visitedNodes); AddInstructionToBlock(instructions, node, visitedNodes); AddBlock(instructions, node.GetNext(), visitedNodes); node = selectionMerge.MergeBlock; break; case Op.OpFunctionCall: visitedNodes.Add(node); AddInstructionToBlock(instructions, node, visitedNodes); node = node.GetNext(); break; default: AddInstructionToBlock(instructions, node, visitedNodes); node = node.GetNext(); break; } } }
public F64AbsNode(ExecutableNode expr) : base(expr) { }
public F64CopySignNode(ExecutableNode left, ExecutableNode right) : base(left, right) { }
public I32PopCntNode(ExecutableNode expr) : base(expr) { }
public F64FloorNode(ExecutableNode expr) : base(expr) { }
public F32TruncNode(ExecutableNode expr) : base(expr) { }
public F64SubNode(ExecutableNode left, ExecutableNode right) : base(left, right) { }
private void ResetActionList() { this.actions = this.state.Actions; this.actionList = new ReorderableList(this.actions, "Action", true, true) { drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.OnActionElement), onReorderCallback = new ReorderableList.ReorderCallbackDelegate(this.OnReorderList), onAddCallback = new ReorderableList.AddCallbackDelegate(delegate(){ FsmGUIUtility.SubclassMenu <StateAction> (CreateAction); }), onContextClick = new ReorderableList.ContextCallbackDelegate(delegate(int index){ FsmGUIUtility.ExecutableContextMenu(actions[index], state).ShowAsContext(); }), onHeaderClick = new ReorderableList.OnHeaderClick(delegate(){ GenericMenu menu = new GenericMenu(); if (actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); NodeInspector.Dirty(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }), }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
private void ResetActionList() { SerializedObject obj = new SerializedObject(state); SerializedProperty elements = obj.FindProperty("actions"); actionList = new ReorderableObjectList(obj, elements); actionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Actions"); }; actionList.onAddCallback = delegate(ReorderableObjectList list) { FsmGUIUtility.SubclassMenu <StateAction> (delegate(Type type){ StateAction action = (StateAction)ScriptableObject.CreateInstance(type); action.name = type.GetCategory() + "." + type.Name; action.hideFlags = HideFlags.HideInHierarchy; state.Actions = ArrayUtility.Add <StateAction> (state.Actions, action); if (EditorUtility.IsPersistent(state)) { AssetDatabase.AddObjectToAsset(action, state); AssetDatabase.SaveAssets(); } list.index = list.count; EditorUtility.SetDirty(state); }); }; actionList.drawElementCallback = delegate(int index, bool selected) { StateAction action = state.Actions [index]; bool enabled = action.IsEnabled; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state)); if (selected) { GUILayout.EndVertical(); } action.IsEnabled = enabled; if (action.IsOpen) { GUIDrawer.OnGUI(action); } }; actionList.onRemoveCallback = delegate(ReorderableObjectList list) { StateAction action = state.Actions[list.index]; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, action); FsmEditorUtility.DestroyImmediate(action); list.index = list.index - 1; ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(state); }; actionList.onContextClick = delegate(int index) { FsmGUIUtility.ExecutableContextMenu(state.Actions [index], state).ShowAsContext(); }; actionList.onHeaderContextClick = delegate() { GenericMenu menu = new GenericMenu(); if (state.Actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(state.Actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }
public F32NearestNode(ExecutableNode expr) : base(expr) { }
public I32LtsNode(ExecutableNode left, ExecutableNode right) : base(left, right) { }
public static void CheckForErrors(UnityEngine.Object targetObject) { if (targetObject == null) { return; } if (targetObject.GetType() == typeof(StateMachine)) { checkingStateMachine = targetObject as StateMachine; } else if (targetObject.GetType() == typeof(State)) { checkingState = targetObject as State; } else if (targetObject.GetType().IsSubclassOf(typeof(ExecutableNode))) { checkingExecutableNode = targetObject as ExecutableNode; } string obsoleteMessage = targetObject.GetObsoleteMessage(); if (!string.IsNullOrEmpty(obsoleteMessage)) { FsmError error = new FsmError(FsmError.ErrorType.Obsolete, checkingStateMachine, checkingState, checkingExecutableNode, null, null); if (!ContainsError(error)) { errorList.Add(error); } } FieldInfo[] fields = targetObject.GetType().GetAllFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < fields.Length; i++) { FieldInfo field = fields[i]; if (field.HasAttribute(typeof(ReferenceAttribute)) || !field.IsSerialized()) { continue; } object value = field.GetValue(targetObject); if (field.FieldType.IsSubclassOf(typeof(FsmVariable))) { if (!field.HasAttribute(typeof(NotRequiredAttribute)) && (value == null || CheckForVariableError(value as FsmVariable, field))) { FsmError error = new FsmError(FsmError.ErrorType.RequiredField, checkingStateMachine, checkingState, checkingExecutableNode, value as FsmVariable, field); if (!ContainsError(error)) { errorList.Add(error); } } } else if (field.FieldType.IsSubclassOf(typeof(UnityEngine.Object))) { CheckForErrors(value as UnityEngine.Object); } else if (field.FieldType.IsArray) { var array = value as Array; Type elementType = field.FieldType.GetElementType(); if (elementType.IsSubclassOf(typeof(UnityEngine.Object))) { foreach (UnityEngine.Object element in array) { CheckForErrors(element); } } } } checkForErrors = false; }
public T Then <T>(T node) where T : ExecutableNode { Next = node; return(node); }
public F64SqrtNode(ExecutableNode expr) : base(expr) { }