private void DoVariable(FsmVariable variable){ SerializedObject serializedObject = new SerializedObject (variable); SerializedProperty nameProperty = serializedObject.FindProperty ("name"); SerializedProperty valueProperty = serializedObject.FindProperty ("value"); GUILayout.BeginHorizontal (); serializedObject.Update (); EditorGUILayout.PropertyField(nameProperty,GUIContent.none); if (valueProperty != null) { if (valueProperty.propertyType == SerializedPropertyType.Boolean) { EditorGUILayout.PropertyField (valueProperty, GUIContent.none, GUILayout.Width (17)); } else { EditorGUILayout.PropertyField (valueProperty, GUIContent.none); } } serializedObject.ApplyModifiedProperties (); GUILayout.FlexibleSpace (); if (GUILayout.Button (FsmEditorStyles.toolbarMinus,FsmEditorStyles.label)) { FsmEditor.Root.Variables=ArrayUtility.Remove<FsmVariable>(FsmEditor.Root.Variables,variable); UnityEngine.Object.DestroyImmediate(variable,true); AssetDatabase.SaveAssets(); } GUILayout.EndHorizontal (); }
public int GetVariablesOfType(FsmVariable variable, out string[] names) { if (FsmEditor.Root == null) { names = new string[0]; return(0); } FsmVariable[] variables = FsmEditor.Root.Variables; variables = ArrayUtility.AddRange <FsmVariable> (variables, GlobalVariables.GetVariables()); int count = 0; List <string> strs = new List <string> () { "None" }; for (int i = 0; i < variables.Length; i++) { Type propertyType = variables[i].GetType().GetProperty("Value").PropertyType; if (variable == null || propertyType.Equals(variable.GetType().GetProperty("Value").PropertyType)) { strs.Add(variables[i].Name); if (variable != null && variables[i].Name.Equals(variable.Name)) { count = strs.Count - 1; } } } names = strs.ToArray(); return(count); }
private void DoSet() { if (fsm == null) { return; } FsmVariable icodeVariable = this.Root.GetVariable(variableName.Value); HutongGames.PlayMaker.FsmObject fsmVar = fsm.FsmVariables.FindFsmObject(variableName.Value); if (direction == SetDirection.ToPlayMaker) { if (fsmVar != null && icodeVariable != null && icodeVariable is FsmObject) { fsmVar.Value = (Object)icodeVariable.GetValue(); } } else { if (fsmVar != null && icodeVariable != null && icodeVariable is FsmObject) { icodeVariable.SetValue(fsmVar.Value); } } }
public int GetVariablesOfType(FsmVariable variable,out string[] names){ if (FsmEditor.Root == null) { names= new string[0]; return 0; } FsmVariable[] variables = FsmEditor.Root.Variables; variables = ArrayUtility.AddRange<FsmVariable> (variables, GlobalVariables.GetVariables ()); int count = 0; List<string> strs = new List<string> (){ "None" }; for (int i = 0; i < variables.Length; i++) { Type propertyType = variables[i].GetType().GetProperty("Value").PropertyType; if (variable == null || propertyType.Equals(variable.GetType().GetProperty("Value").PropertyType)) { strs.Add(variables[i].Name); if (variable != null && variables[i].Name.Equals(variable.Name)) { count = strs.Count - 1; } } } names = strs.ToArray(); return count; }
public void DoGUI(Rect position) { GUILayout.BeginArea(position, EditorStyles.inspectorDefaultMargins); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); if (DoHeader()) { scrollPosition = GUILayout.BeginScrollView(scrollPosition); GUILayout.BeginVertical(FsmEditorStyles.elementBackground); if (FsmEditor.Root != null && FsmEditor.Root.VisibleVariables.Length > 0) { for (int i = 0; i < FsmEditor.Root.VisibleVariables.Length; i++) { FsmVariable variable = FsmEditor.Root.VisibleVariables[i]; DoVariable(variable); } } else { GUILayout.Label("List is Empty"); } GUILayout.EndVertical(); GUILayout.EndScrollView(); } GUILayout.EndVertical(); GUILayout.EndArea(); }
public virtual void CreateVariable(SerializedProperty property) { FsmVariable variable = ScriptableObject.CreateInstance(fieldInfo.FieldType) as FsmVariable; variable.hideFlags = HideFlags.HideInHierarchy; DefaultValueAttribute defaultAttribute = fieldInfo.GetAttribute <DefaultValueAttribute>(); if (defaultAttribute != null) { variable.SetValue(defaultAttribute.DefaultValue); } SharedPersistentAttribute sharedPersistantAttribute = fieldInfo.GetAttribute <SharedPersistentAttribute> (); if (sharedPersistantAttribute != null && variable.GetType() == typeof(FsmGameObject)) { variable.Name = "Owner"; } if (EditorUtility.IsPersistent(property.serializedObject.targetObject)) { AssetDatabase.AddObjectToAsset(variable, property.serializedObject.targetObject); AssetDatabase.SaveAssets(); } variable.IsShared = fieldInfo.HasAttribute(typeof(SharedAttribute)) || EditorUtility.IsPersistent(variable) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || fieldInfo.FieldType == typeof(FsmArray); property.objectReferenceValue = variable; property.serializedObject.ApplyModifiedProperties(); ErrorChecker.CheckForErrors(); }
public FsmError(FsmError.ErrorType type,StateMachine stateMachine,State state,ExecutableNode executableNode,FsmVariable variable ,FieldInfo fieldInfo){ this.type = type; this.variable = variable; this.fieldInfo = fieldInfo; this.stateMachine = stateMachine; this.state = state; this.executableNode = executableNode; }
public FsmError(FsmError.ErrorType type, StateMachine stateMachine, State state, ExecutableNode executableNode, FsmVariable variable, FieldInfo fieldInfo) { this.type = type; this.variable = variable; this.fieldInfo = fieldInfo; this.stateMachine = stateMachine; this.state = state; this.executableNode = executableNode; }
private static bool CheckForVariableError(FsmVariable variable, FieldInfo field){ if (variable.IsShared) { return variable.Name == "None" || string.IsNullOrEmpty(variable.Name); } else { if(variable is FsmString){ return CheckForStringError(((FsmString)variable).Value,field); } } return false; }
public override void OnEnter () { ICodeBehaviour behaviour = gameObject.Value.GetBehaviour (group.Value); if (behaviour != null) { mVaraible=behaviour.stateMachine.GetVariable(variable.Value); if(mVaraible != null){ mVaraible.onVariableChange.AddListener(DoSync); } } Finish (); }
private void CreateVariable() { FsmVariable variable = (FsmVariable)ScriptableObject.CreateInstance(variableType); variable.Name = variableName; variable.Group = variableGroup; variable.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(variable, globalVariables); AssetDatabase.SaveAssets(); globalVariables.Variables = ArrayUtility.Add(globalVariables.Variables, variable); EditorUtility.SetDirty(globalVariables); }
public override void OnEnter() { ICodeBehaviour behaviour = gameObject.Value.GetBehaviour(group.Value); if (behaviour != null) { mVaraible = behaviour.stateMachine.GetVariable(variable.Value); if (mVaraible != null) { mVaraible.SetValue(_value.GetValue()); } } Finish(); }
private void DoSync() { FsmVariable variable = this.Root.GetVariable(variableName.Value); SharedVariable sharedVariable = behaviorTree.GetVariable(variableName.Value); if (direction == Direction.FromBehaviourTree) { variable.SetValue(sharedVariable.GetValue()); } else { sharedVariable.SetValue(variable.GetValue()); } }
public override void OnGUI(SerializedProperty property, GUIContent label) { SerializedProperty componentProperty = property.serializedObject.FindProperty("component"); SerializedProperty propProperty = property.serializedObject.FindProperty("property"); SerializedProperty parameterProperty = property.serializedObject.FindProperty("parameter"); GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(componentProperty); ComponentHint(componentProperty, propProperty); GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(componentProperty.stringValue)) { Type componentType = TypeUtility.GetType(componentProperty.stringValue); if (componentType != null) { GUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(propProperty); PropertyHint(propProperty, componentType); GUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(propProperty.stringValue)) { Type variableType = FsmUtility.GetVariableType(TypeUtility.GetMemberType(componentType, propProperty.stringValue)); Debug.Log(variableType); if (variableType != null) { fieldInfo = property.serializedObject.targetObject.GetType().GetField("parameter"); if (parameterProperty.objectReferenceValue == null || parameterProperty.objectReferenceValue.GetType() != variableType) { FsmEditorUtility.DestroyImmediate(parameterProperty.objectReferenceValue as FsmVariable); FsmVariable variable = ScriptableObject.CreateInstance(variableType) as FsmVariable; variable.hideFlags = HideFlags.HideInHierarchy; if (EditorUtility.IsPersistent(parameterProperty.serializedObject.targetObject)) { AssetDatabase.AddObjectToAsset(variable, property.serializedObject.targetObject); AssetDatabase.SaveAssets(); } variable.IsShared = fieldInfo.HasAttribute(typeof(SharedAttribute)) || EditorUtility.IsPersistent(variable) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || variable is FsmArray; parameterProperty.serializedObject.Update(); parameterProperty.objectReferenceValue = variable; parameterProperty.serializedObject.ApplyModifiedProperties(); } base.OnGUI(parameterProperty, new GUIContent("Parameter")); } } } } }
private void DoGlobalVariablesGUI() { EditorGUILayout.HelpBox(Strings.Hint_GlobalsInspector_Shows_DEFAULT_Values, MessageType.Info); GUILayout.Label(Strings.Command_Global_Variables, EditorStyles.boldLabel); if (variableList.Count > 0) { FsmVariable.DoVariableListGUI(variableList); } else { GUILayout.Label(Strings.Label_None_In_Table); } }
private static bool CheckForVariableError(FsmVariable variable, FieldInfo field) { if (variable.IsShared) { return(variable.Name == "None" || string.IsNullOrEmpty(variable.Name)); } else { if (variable is FsmString) { return(CheckForStringError(((FsmString)variable).Value, field)); } } return(false); }
public override void OnEnter() { ICodeBehaviour behaviour = gameObject.Value.GetBehaviour(group.Value); if (behaviour != null) { mVaraible = behaviour.stateMachine.GetVariable(variable.Value); if (mVaraible != null) { mVaraible.onVariableChange.AddListener(DoSync); } } Finish(); }
private void DoVariable(FsmVariable variable) { SerializedObject serializedObject = new SerializedObject(variable); SerializedProperty nameProperty = serializedObject.FindProperty("name"); SerializedProperty valueProperty = serializedObject.FindProperty("value"); GUILayout.BeginHorizontal(); if (FsmEditor.Root.VisibleVariables.ToList().FindAll(x => x.Name == variable.Name).ToList().Count > 1) { GUILayout.Label(FsmEditorStyles.errorIcon); } serializedObject.Update(); string before = nameProperty.stringValue; EditorGUILayout.PropertyField(nameProperty, GUIContent.none); if (before != nameProperty.stringValue) { List <FsmVariable> variables = GetReferencedVariables(FsmEditor.Root, before); for (int i = 0; i < variables.Count; i++) { SerializedObject obj = new SerializedObject(variables[i]); obj.Update(); obj.FindProperty("name").stringValue = nameProperty.stringValue; obj.ApplyModifiedProperties(); } } if (valueProperty != null) { if (valueProperty.propertyType == SerializedPropertyType.Boolean) { EditorGUILayout.PropertyField(valueProperty, GUIContent.none, GUILayout.Width(17)); } else { EditorGUILayout.PropertyField(valueProperty, GUIContent.none); } } serializedObject.ApplyModifiedProperties(); GUILayout.FlexibleSpace(); if (GUILayout.Button(FsmEditorStyles.toolbarMinus, FsmEditorStyles.label)) { FsmEditor.Root.Variables = ArrayUtility.Remove <FsmVariable>(FsmEditor.Root.Variables, variable); UnityEngine.Object.DestroyImmediate(variable, true); AssetDatabase.SaveAssets(); } GUILayout.EndHorizontal(); }
private void DoGlobalVariablesGUI() { DoSectionTitle(Strings.Command_Global_Variables); //EditorGUILayout.HelpBox(Strings.Hint_GlobalsInspector_Shows_DEFAULT_Values, MessageType.None); EditorGUILayout.HelpBox("NOTE: This inspector shows the default values of variables. " + "\nTo see current values while playing use the PlayMaker Editor: " + "\nGlobals Variables Window, State Inspector Debug etc.", MessageType.None); if (variables.Count > 0) { var listSerializedObject = variables[0].SerializedObject; listSerializedObject.Update(); EditorGUI.BeginChangeCheck(); FsmVariable.DoVariableListGUI(variables); if (EditorGUI.EndChangeCheck()) { listSerializedObject.ApplyModifiedProperties(); } } GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh")) { Init(); } if (GUILayout.Button("Open Globals Window", GUILayout.Width(EditButtonWidth))) { if (FsmEditor.Instance == null) { FsmEditor.Open(); } FsmEditor.OpenGlobalVariablesWindow(); } GUILayout.EndHorizontal(); }
private void CreateVariable(Type type) { if (FsmEditor.Root != null) { FsmVariable variable = (FsmVariable)ScriptableObject.CreateInstance(type); variable.Name = "New " + type.Name.Replace("Fsm", ""); variable.IsShared = true; variable.hideFlags = HideFlags.HideInHierarchy; FsmEditor.Root.Variables = ArrayUtility.Add <FsmVariable> (FsmEditor.Root.Variables, variable); scrollPosition.y = Mathf.Infinity; if (EditorUtility.IsPersistent(FsmEditor.Root)) { AssetDatabase.AddObjectToAsset(variable, FsmEditor.Root); AssetDatabase.SaveAssets(); } } }
private void Init() { //Debug.Log("PlayMakerGlobalsInspector.Init"); FsmEditorSettings.LoadSettings(); if (globals != null) { variables = FsmVariable.GetFsmVariableList(globals); foreach (var fsmVariable in variables) { fsmVariable.NamedVar.Init(); } } Repaint(); }
private FsmVariable CreateVariable(Type type, string name) { if (FsmEditor.Root != null) { FsmVariable variable = (FsmVariable)ScriptableObject.CreateInstance(type); variable.Name = name; variable.IsShared = true; variable.hideFlags = HideFlags.HideInHierarchy; FsmEditor.Root.Variables = ArrayUtility.Add <FsmVariable> (FsmEditor.Root.Variables, variable); if (EditorUtility.IsPersistent(FsmEditor.Root)) { AssetDatabase.AddObjectToAsset(variable, FsmEditor.Root); AssetDatabase.SaveAssets(); } EditorUtility.SetDirty(FsmEditor.Root); return(variable); } return(null); }
// Use this for initialization // Spine.TrackEntry void Start() { //mSkeletonAnimation = gameObject.GetComponent<SkeletonAnimation> (); //mSkeletonAnimation.AnimationName = walkName; mAnimationState = mSkeletonAnimation.state; mAnimationState.SetAnimation(0, blinkName, true); cb = gameObject.GetBehaviour(0); Debug.Log("cb is " + cb); // cb.stateMachine. FsmVariable move = cb.stateMachine.GetVariable("state"); move.onVariableChange.AddListener(onFsmStateChange); moveTartget = new Vector3(direction == 1 ? pointRight.position.x : pointLeft.position.x, transform.position.y, transform.position.z); meshRender = GetComponent <MeshRenderer> (); }
public override void CreateVariable(SerializedProperty property) { FsmVariable variable = property.objectReferenceValue as FsmVariable; if (parameterTypeNames == null) { parameterTypeNames = TypeUtility.GetSubTypeNames(typeof(FsmVariable)); parameterTypeNames = ArrayUtility.Insert <string> (parameterTypeNames, "None", 0); } int index = parameterTypeNames.ToList().FindIndex(x => x == (variable != null?variable.GetType().ToString().Split('.').Last():"")); index = Mathf.Clamp(index, 0, int.MaxValue); index = EditorGUILayout.Popup("Parameter Type", index, parameterTypeNames); string typeName = parameterTypeNames [index]; string variableTypeName = (variable == null ? "None" : variable.GetType().Name); if (typeName != variableTypeName) { FsmEditorUtility.DestroyImmediate(property.objectReferenceValue as FsmVariable); if (typeName != "None") { variable = ScriptableObject.CreateInstance(TypeUtility.GetTypeByName(typeName)[0]) as FsmVariable; variable.hideFlags = HideFlags.HideInHierarchy; if (EditorUtility.IsPersistent(property.serializedObject.targetObject)) { AssetDatabase.AddObjectToAsset(variable, property.serializedObject.targetObject); AssetDatabase.SaveAssets(); } variable.IsShared = fieldInfo.HasAttribute(typeof(SharedAttribute)) || EditorUtility.IsPersistent(variable) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || variable is FsmArray || !variable.GetType().GetProperty("Value").PropertyType.IsSerializable; property.serializedObject.Update(); property.objectReferenceValue = variable; property.serializedObject.ApplyModifiedProperties(); } ErrorChecker.CheckForErrors(); } }
private List <FsmVariable> GetReferencedVariables(StateMachine fsm, string name) { List <FsmVariable> variables = new List <FsmVariable> (); ExecutableNode[] nodes = fsm.ExecutableNodesRecursive; for (int i = 0; i < nodes.Length; i++) { ExecutableNode mNode = nodes[i]; FieldInfo[] fields = mNode.GetType().GetPublicFields(); for (int k = 0; k < fields.Length; k++) { FieldInfo fieldInfo = fields[k]; if (typeof(FsmVariable).IsAssignableFrom(fieldInfo.FieldType)) { FsmVariable variable = (FsmVariable)fieldInfo.GetValue(mNode); if (variable != null && variable.IsShared && variable.Name == name) { variables.Add(variable); } } } } return(variables); }
private void DrawVariables() { scroll = GUILayout.BeginScrollView(scroll); Dictionary <string, List <FsmVariable> > groupParameters = GetGroupVariables(); EditorGUIUtility.labelWidth = 110; foreach (var kvp in groupParameters) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); bool state = EditorGUILayout.Foldout(foldout, kvp.Key); if (state != foldout) { EditorPrefs.SetBool(kvp.Key, state); } if (foldout) { for (int i = 0; i < groupParameters[kvp.Key].Count; i++) { FsmVariable parameter = groupParameters[kvp.Key][i]; if (parameter != null) { SerializedObject paramObject = new SerializedObject(parameter); SerializedProperty prop = paramObject.FindProperty("value"); GUILayout.BeginHorizontal(); GUILayout.Space(16f); string name = paramObject.FindProperty("name").stringValue; if (parameter is FsmGameObject) { GUI.changed = false; FsmGameObject mParam = parameter as FsmGameObject; if (string.IsNullOrEmpty(mParam.ScenePath)) { mParam.Value = (GameObject)EditorGUILayout.ObjectField(name, mParam.Value, typeof(UnityEngine.GameObject), true); } else { GUILayout.Label(name, GUILayout.Width(106)); GUILayout.Label(mParam.ScenePath, FsmEditorStyles.wrappedLabelLeft); GUILayout.FlexibleSpace(); } if (GUI.changed) { if (!EditorUtility.IsPersistent(mParam.Value) && mParam.Value is GameObject) { string currentOpenScene = string.Empty; #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 currentOpenScene = EditorApplication.currentScene; #else currentOpenScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; #endif if (string.IsNullOrEmpty(currentOpenScene)) { EditorUtility.DisplayDialog("Save Scene!", "You need to save the scene before setting the GameObject.", "Ok"); mParam.Value = null; } else { #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 mParam.ScenePath = mParam.Value.name + "(" + EditorApplication.currentScene + ")"; #else mParam.ScenePath = mParam.Value.name + "(" + UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().path + ")"; #endif SetGlobalGameObject mSet = mParam.Value.GetComponent <SetGlobalGameObject>(); if (mSet == null) { mSet = mParam.Value.AddComponent <SetGlobalGameObject>(); } mSet.variableName = mParam.Name; } } EditorUtility.SetDirty(mParam); } } else { paramObject.Update(); if (prop != null) { EditorGUILayout.PropertyField(prop, new GUIContent(name), true); } paramObject.ApplyModifiedProperties(); } if (GUILayout.Button("down", EditorStyles.toolbarButton, GUILayout.Width(35))) { if (i < groupParameters[kvp.Key].Count) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 0); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button("up", EditorStyles.toolbarButton, GUILayout.Width(20))) { if (i > 0) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 1); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button(parameter.Group, EditorStyles.toolbarDropDown, GUILayout.Width(54))) { GenericMenu menu = new GenericMenu(); foreach (FsmVariable p in globalVariables.Variables) { string group = p.Group; FsmVariable mParam = parameter; menu.AddItem(new GUIContent(group), mParam.Group == group, delegate() { mParam.Group = group; }); } menu.ShowAsContext(); } if (GUILayout.Button(EditorGUIUtility.FindTexture("Toolbar Minus"), "label", GUILayout.Width(20))) { if (parameter is FsmGameObject) { string scenePath = (parameter as FsmGameObject).ScenePath; scenePath = scenePath.Substring(scenePath.IndexOf("(") + 1); scenePath = scenePath.Substring(0, scenePath.IndexOf(")")); #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 if (EditorApplication.currentScene != scenePath.Split('/').Last()) { EditorApplication.SaveScene(); EditorApplication.OpenScene(scenePath); } #else UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); UnityEngine.SceneManagement.Scene scene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene(scenePath); UnityEditor.SceneManagement.EditorSceneManager.SetActiveScene(scene); #endif List <SetGlobalGameObject> gos = FindObjectsOfType <SetGlobalGameObject>().ToList(); SetGlobalGameObject go = gos.Find(x => x.variableName == parameter.Name); if (go != null) { DestroyImmediate(go); } } globalVariables.Variables = ArrayUtility.Remove(globalVariables.Variables, parameter); FsmEditorUtility.DestroyImmediate(parameter);; EditorUtility.SetDirty(globalVariables); #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 EditorApplication.SaveScene(); #else UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); #endif } GUILayout.EndHorizontal(); } } } } GUILayout.EndScrollView(); }
/// <summary> /// The fsmVariables list contains easily editable references to FSM variables /// (Similar in concept to SerializedProperty) /// </summary> void BuildFsmVariableList() { fsmVariables = FsmVariable.GetFsmVariableList(fsmComponent.Fsm.Variables, target); fsmVariables.Sort(); }
public static void Paste(Vector2 position, StateMachine stateMachine) { List <Node> copiedNodes = new List <Node> (); Vector2 center = GetCenter(nodes); for (int i = 0; i < nodes.Count; i++) { Node origNode = nodes[i]; List <FsmVariable> sharedVariables = new List <FsmVariable>(); GetSharedVariables(origNode, ref sharedVariables); if (sharedVariables.Count > 0) { string variableNames = string.Empty; sharedVariables.Select(x => x.Name).ToList().ForEach(y => variableNames = (variableNames + (string.IsNullOrEmpty(variableNames)?"":",") + y)); if (EditorUtility.DisplayDialog("Paste Variables", "Copied states have reference to shared variables, do you want to paste those variables? (" + variableNames + ")", "Yes", "No")) { for (int j = 0; j < sharedVariables.Count; j++) { FsmVariable variable = sharedVariables[j]; stateMachine.SetVariable(variable.Name, variable.GetValue()); } } } Node mNode = (Node)FsmUtility.Copy(origNode); mNode.Parent = stateMachine; mNode.hideFlags = HideFlags.HideInHierarchy; if (mNode.IsStartNode && stateMachine.GetStartNode() != null) { mNode.IsStartNode = false; } //mNode.Name = FsmEditorUtility.GenerateUniqueNodeName(mNode.GetType(),stateMachine); stateMachine.Nodes = ArrayUtility.Add <Node> (stateMachine.Nodes, mNode); mNode.position = new Rect(-(center.x - origNode.position.x) + position.x, -(center.y - origNode.position.y) + position.y, FsmEditorStyles.StateWidth, FsmEditorStyles.StateHeight); if (mNode.GetType() == typeof(StateMachine)) { mNode.position.width = FsmEditorStyles.StateMachineWidth; mNode.position.height = FsmEditorStyles.StateMachineHeight; } FsmEditorUtility.UpdateNodeColor(mNode); copiedNodes.Add(mNode); } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = copiedNodes [i]; if (mNode is AnyState) { bool mOverride = EditorUtility.DisplayDialog("Override AnyState", "AnyState can only exist once per state machine. Do you want to override it?", "Yes", "No"); AnyState anyState = stateMachine.Nodes.ToList().Find(x => x.GetType() == typeof(AnyState) && (mOverride && x != mNode || !mOverride && x == mNode)) as AnyState; stateMachine.Nodes = ArrayUtility.Remove(stateMachine.Nodes, anyState); FsmEditorUtility.DestroyImmediate(anyState); FsmEditor.SelectedNodes.Clear(); } } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = copiedNodes[i]; foreach (Transition transition in mNode.Transitions) { Node toNode = copiedNodes.Find(x => x.Name == transition.ToNode.Name) ?? stateMachine.Nodes.ToList().Find(x => x.Name == transition.ToNode.Name); if (toNode != null) { transition.ToNode = toNode; } else { FsmEditorUtility.DestroyImmediate(transition); mNode.Transitions = ArrayUtility.Remove(mNode.Transitions, transition); } } } for (int i = 0; i < copiedNodes.Count; i++) { Node mNode = stateMachine.Nodes.ToList().Find(x => x.Name == copiedNodes[i].Name && x != copiedNodes[i]); if (mNode != null) { copiedNodes[i].Name = FsmEditorUtility.GenerateUniqueNodeName(copiedNodes[i].GetType(), stateMachine); } } FsmEditorUtility.ParentChilds(stateMachine); nodes.Clear(); EditorUtility.SetDirty(stateMachine); ErrorChecker.CheckForErrors(); }
private static void DoVariablesToICodeSync(IVariableSource variableSource, FsmVariable[] iCodeVariables) { if (variableSource == null) { return; } SharedVariable behaviorDesignerVariable = null; FsmVariable iCodeVariable = null; for (int i = 0; i < iCodeVariables.Length; ++i) { iCodeVariable = iCodeVariables[i]; if ((behaviorDesignerVariable = variableSource.GetVariable(iCodeVariable.Name)) != null) { // FsmInt if (iCodeVariable is FsmInt) { if (behaviorDesignerVariable is SharedInt) { (iCodeVariable as FsmInt).Value = (int)behaviorDesignerVariable.GetValue(); } continue; } // FsmFloat if (iCodeVariable is FsmFloat) { if (behaviorDesignerVariable is SharedFloat) { (iCodeVariable as FsmFloat).Value = (float)behaviorDesignerVariable.GetValue(); } continue; } // FsmBool if (iCodeVariable is FsmBool) { if (behaviorDesignerVariable is SharedBool) { (iCodeVariable as FsmBool).Value = (bool)behaviorDesignerVariable.GetValue(); } continue; } // FsmString if (iCodeVariable is FsmString) { if (behaviorDesignerVariable is SharedString) { (iCodeVariable as FsmString).Value = (string)behaviorDesignerVariable.GetValue(); } continue; } // FsmColor if (iCodeVariable is FsmColor) { if (behaviorDesignerVariable is SharedColor) { (iCodeVariable as FsmColor).Value = (Color)behaviorDesignerVariable.GetValue(); } continue; } // FsmVector2 if (iCodeVariable is FsmVector2) { if (behaviorDesignerVariable is SharedVector2) { (iCodeVariable as FsmVector2).Value = (Vector2)behaviorDesignerVariable.GetValue(); } continue; } // FsmVector3 if (iCodeVariable is FsmVector3) { if (behaviorDesignerVariable is SharedVector3) { (iCodeVariable as FsmVector3).Value = (Vector3)behaviorDesignerVariable.GetValue(); } continue; } // FsmObject if (iCodeVariable is FsmObject) { if (behaviorDesignerVariable is SharedGameObject) { (iCodeVariable as FsmObject).Value = (GameObject)behaviorDesignerVariable.GetValue(); } else if (behaviorDesignerVariable is SharedObject) { (iCodeVariable as FsmObject).Value = (Object)behaviorDesignerVariable.GetValue(); } continue; } } } }
private void BuildVariableList() { variableList = FsmVariable.GetFsmVariableList(globals); }
void BuildVariableList() { variableList = FsmVariable.GetFsmVariableList(globals.Variables, globals); }
private void DrawVariables() { scroll = GUILayout.BeginScrollView(scroll); Dictionary <string, List <FsmVariable> > groupParameters = GetGroupVariables(); EditorGUIUtility.labelWidth = 110; foreach (var kvp in groupParameters) { bool foldout = EditorPrefs.GetBool(kvp.Key, false); bool state = EditorGUILayout.Foldout(foldout, kvp.Key); if (state != foldout) { EditorPrefs.SetBool(kvp.Key, state); } if (foldout) { for (int i = 0; i < groupParameters[kvp.Key].Count; i++) { FsmVariable parameter = groupParameters[kvp.Key][i]; if (parameter != null) { SerializedObject paramObject = new SerializedObject(parameter); SerializedProperty prop = paramObject.FindProperty("value"); GUILayout.BeginHorizontal(); GUILayout.Space(16f); string name = paramObject.FindProperty("name").stringValue; if (parameter is FsmGameObject) { GUI.changed = false; FsmGameObject mParam = parameter as FsmGameObject; if (string.IsNullOrEmpty(mParam.ScenePath)) { mParam.Value = (GameObject)EditorGUILayout.ObjectField(name, mParam.Value, typeof(UnityEngine.GameObject), true); } else { GUILayout.Label(name, GUILayout.Width(106)); GUILayout.Label(mParam.ScenePath, FsmEditorStyles.wrappedLabelLeft); GUILayout.FlexibleSpace(); } if (GUI.changed) { if (!EditorUtility.IsPersistent(mParam.Value) && mParam.Value is GameObject) { mParam.ScenePath = mParam.Value.name + "(" + EditorApplication.currentScene + ")"; SetGlobalGameObject mSet = mParam.Value.GetComponent <SetGlobalGameObject>(); if (mSet == null) { mSet = mParam.Value.AddComponent <SetGlobalGameObject>(); } mSet.variableName = mParam.Name; } EditorUtility.SetDirty(mParam); } } else { paramObject.Update(); if (prop != null) { EditorGUILayout.PropertyField(prop, new GUIContent(name), true); } paramObject.ApplyModifiedProperties(); } if (GUILayout.Button("down", EditorStyles.toolbarButton, GUILayout.Width(35))) { if (i < groupParameters[kvp.Key].Count) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 0); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button("up", EditorStyles.toolbarButton, GUILayout.Width(20))) { if (i > 0) { int indexToMove = Array.FindIndex(globalVariables.Variables, x => x.Name == parameter.Name); globalVariables.Variables.Move(indexToMove, 1); EditorUtility.SetDirty(globalVariables); } } if (GUILayout.Button(parameter.Group, EditorStyles.toolbarDropDown, GUILayout.Width(54))) { GenericMenu menu = new GenericMenu(); foreach (FsmVariable p in globalVariables.Variables) { string group = p.Group; FsmVariable mParam = parameter; menu.AddItem(new GUIContent(group), mParam.Group == group, delegate() { mParam.Group = group; }); } menu.ShowAsContext(); } if (GUILayout.Button(EditorGUIUtility.FindTexture("Toolbar Minus"), "label", GUILayout.Width(20))) { globalVariables.Variables = ArrayUtility.Remove(globalVariables.Variables, parameter); FsmEditorUtility.DestroyImmediate(parameter);; EditorUtility.SetDirty(globalVariables); } GUILayout.EndHorizontal(); } } } } GUILayout.EndScrollView(); }
/// <summary> /// The fsmVariables list contains easily editable references to FSM variables /// (Similar in concept to SerializedProperty) /// </summary> private void BuildFsmVariableList() { fsmVariables = FsmVariable.GetFsmVariableList(target); fsmVariables = fsmVariables.Where(x => x.ShowInInspector).ToList(); }