/// <summary> /// Only called when first constructed. /// </summary> /// <param name="behaviourAI"></param> /// <param name="newJsonFilepath"></param> public void Initialize(OhBehaveAI behaviourAI, string jsonFilepath) { if (!AssetDatabase.IsValidFolder(blueprintsPath)) { string guid = AssetDatabase.CreateFolder( Path.GetDirectoryName(blueprintsPath), Path.GetFileName(blueprintsPath)); blueprintsPath = AssetDatabase.GUIDToAssetPath(guid); } AssetDatabase.CreateAsset(this, blueprintsPath + "/" + blueprintsPrefix + Path.GetFileNameWithoutExtension(jsonFilepath) + GetInstanceID() + ".asset"); string blueprintGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(this)); ohBehaveAI = behaviourAI; behaviourSource = ohBehaveAI.GetComponent <OhBehaveActions>(); savedNodes = new List <NodeEditorObject>(); jsonTreeData = new JsonBehaviourTree(); jsonTreeData.name = Path.GetFileNameWithoutExtension(jsonFilepath); jsonTreeData.blueprintGUID = blueprintGUID; string jsonString = JsonUtility.ToJson(jsonTreeData, true); StreamWriter writer = new StreamWriter(jsonFilepath); writer.WriteLine(jsonString); writer.Close(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); string relativePath = jsonFilepath.Replace("Assets/StreamingAssets", ""); ohBehaveAI.jsonFilepath = relativePath; jsonGUID = AssetDatabase.AssetPathToGUID(jsonFilepath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.SetDirty(this); }
public override void OnInspectorGUI() { serializedObject.Update(); GUI.enabled = false; EditorGUILayout.ObjectField("Script", target, typeof(OhBehaveAI), false); if (string.IsNullOrEmpty(instance.jsonFilepath)) { EditorGUILayout.DelayedTextField("Tree file", "!NO FILE SELECTED!"); } else { EditorGUILayout.DelayedTextField("Tree file", Path.GetFileName(instance.jsonFilepath)); } GUI.enabled = true; if (GUILayout.Button("Change json file")) { // If FileChooser is opened here, will get EditorLayout Error. // make sure the right target is in focus? (might not be necessary) EditorWindow.GetWindow <OhBehaveEditorWindow>().OpenFileChooser(instance); } // do something here to verify tree is well-formed. If not, display angry button. if (GUILayout.Button("Open in AIOhBehaveEditor")) { EditorWindow.GetWindow <OhBehaveEditorWindow>().Open(instance); } if (GUILayout.Button("Create New AI Tree")) { CreateNewJson(); } var actionSource = instance.GetComponent <OhBehaveActions>(); //if (instance.sharedMethods != null && instance.sharedMethods.Count > 0) { // Create the dropdown in the inspector for the found methods EditorGUILayout.Popup("Action List", 0, instance.GetMethodNames()); } serializedObject.ApplyModifiedProperties(); }
public void GetFunctions() { if (behaviourSource == null) { if (ohBehaveAI != null) { behaviourSource = ohBehaveAI.GetComponent <OhBehaveActions>(); } else { sharedMethods = null; privateMethods = null; sharedMethodNames = null; privateMethodNames = null; return; } } sharedMethods = new List <MethodInfo>(); privateMethods = new List <MethodInfo>(); sharedMethodNames = new List <string>(); privateMethodNames = new List <string>(); foreach (MethodInfo element in behaviourSource.GetType().GetMethods(flags)) { foreach (var param in element.GetParameters()) { if (param.ParameterType == typeof(LeafNode)) { // at least one of the params must be a LeafNode privateMethods.Add(element); privateMethodNames.Add(element.Name); break; } } } sharedMethods.Add(null); sharedMethods.AddRange(privateMethods); sharedMethodNames.Add("No action selected"); sharedMethodNames.AddRange(privateMethodNames); }