Exemplo n.º 1
0
        static void CreateNewBehaviorTree(MenuCommand menuCommand)
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (path == "")
            {
                path = "Assets";
            }
            else if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
            }

            string fullPath = AssetDatabase.GenerateUniqueAssetPath(path + "/New Behavior Tree.asset");

            BehaviorTree bt   = ScriptableObject.CreateInstance <BehaviorTree>();
            Root         root = ScriptableObject.CreateInstance <Root>();

            root.editorPosition = new Vector2(0, 0);
            bt.SetRoot(root);
            BTAsset btAsset = ScriptableObject.CreateInstance <BTAsset>();

            btAsset.Serialize(bt);

            AssetDatabase.CreateAsset(btAsset, fullPath);
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = btAsset;
        }
Exemplo n.º 2
0
        public void SelectNode(Node node)
        {
            // Valid selection, but BTAsset is not selected in the project view, queue selection
            if (node != null && Selection.activeObject != btAsset)
            {
                QueuedSelectionFor     = btAsset;
                QueuedSelectionGUID    = node.GUID;
                Selection.activeObject = btAsset;
                return;
            }

            selectedNode = node;

            // Node is null, deselecting
            if (node == null && btInspector != null)
            {
                nodeInspector = null;
                btInspector.Repaint();
                return;
            }

            // Node selected
            Editor newInspector = Editor.CreateEditor(node);

            if (newInspector != null)
            {
                nodeInspector = newInspector;
                nodeInspector.Repaint();
                return;
            }
        }
Exemplo n.º 3
0
        static void CreateNewBehaviorTree(MenuCommand menuCommand)
        {
//			string path = AssetDatabase.GetAssetPath(Selection.activeObject);
//			if (path == "")
//				path = "Assets";
//			else if (Path.GetExtension(path) != "")
//				path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");


            string basePath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/xRes/carbonEvent/").e();
            string fullPath = EditorUtility.SaveFilePanel("Save Carbon Event", basePath, "New Behavior Tree", "asset");

            if (string.IsNullOrEmpty(fullPath))
            {
                return;
            }
//			fullPath = AssetDatabase.GenerateUniqueAssetPath (fullPath);
            fullPath = fullPath.Substring(fullPath.IndexOf("/Assets/") + 1);
            BehaviorTree bt   = ScriptableObject.CreateInstance <BehaviorTree> ();
            Root         root = ScriptableObject.CreateInstance <Root> ();

            root.editorPosition = new Vector2(0, 0);
            bt.SetRoot(root);
            BTAsset btAsset = ScriptableObject.CreateInstance <BTAsset> ();

            btAsset.Serialize(bt);

            AssetDatabase.CreateAsset(btAsset, fullPath);
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = btAsset;
        }
Exemplo n.º 4
0
        public void OnEnable()
        {
            BTAsset      btAsset = (BTAsset)serializedObject.targetObject;
            BehaviorTree bt      = btAsset.Deserialize();

            manager             = BTEditorManager.CreateInstance(bt, btAsset);
            manager.btInspector = this;
        }
Exemplo n.º 5
0
 public static BTEditorManager CreateInstance(BehaviorTree bt, BTAsset asset)
 {
     if (Manager == null)
     {
         Manager = (BTEditorManager)ScriptableObject.CreateInstance(typeof(BTEditorManager));
         Manager.behaviorTree = bt;
         Manager.btAsset      = asset;
     }
     return(Manager);
 }
Exemplo n.º 6
0
        public static BTEditorManager CreateInstance(BehaviorTree bt, BTAsset asset)
        {
            if (Manager == null) {
                Manager = (BTEditorManager) ScriptableObject.CreateInstance (typeof(BTEditorManager));
                Manager.behaviorTree = bt;
                Manager.btAsset = asset;

                // When the user clicks on a node to select it, while viewing the behavior tree associated with a GO with a BehaviorTreeAgent component
                // we store the selection then switch the Unity Editor selection over to the appropriate BTAsset. Once the Manager for the BTAsset is
                // created (here!) we perform the original selection.
                if (QueuedSelectionFor == asset) {
                    Manager.SelectNode(bt.GetNodeByGUID(QueuedSelectionGUID));
                    QueuedSelectionFor = null;
                    QueuedSelectionGUID = null;
                }
            }
            return Manager;
        }
Exemplo n.º 7
0
        public static BTEditorManager CreateInstance(BehaviorTree bt, BTAsset asset)
        {
            if (Manager == null)
            {
                Manager = (BTEditorManager)ScriptableObject.CreateInstance(typeof(BTEditorManager));
                Manager.behaviorTree = bt;
                Manager.btAsset      = asset;

                // When the user clicks on a node to select it, while viewing the behavior tree associated with a GO with a BehaviorTreeAgent component
                // we store the selection then switch the Unity Editor selection over to the appropriate BTAsset. Once the Manager for the BTAsset is
                // created (here!) we perform the original selection.
                if (QueuedSelectionFor == asset)
                {
                    Manager.SelectNode(bt.GetNodeByGUID(QueuedSelectionGUID));
                    QueuedSelectionFor  = null;
                    QueuedSelectionGUID = null;
                }
            }
            return(Manager);
        }
Exemplo n.º 8
0
        public void SelectNode(Node node)
        {
            // Valid selection, but BTAsset is not selected in the project view, queue selection
            if (node != null && Selection.activeObject != btAsset) {
                QueuedSelectionFor = btAsset;
                QueuedSelectionGUID = node.GUID;
                Selection.activeObject = btAsset;
                return;
            }

            selectedNode = node;

            // Node is null, deselecting
            if (node == null && btInspector != null) {
                nodeInspector = null;
                btInspector.Repaint ();
                return;
            }

            // Node selected
            Editor newInspector = Editor.CreateEditor (node);
            if (newInspector != null) {
                nodeInspector = newInspector;
                nodeInspector.Repaint ();
                return;
            }
        }