Example #1
0
        public static BTTree CloneTree(BTTree behaviorTree)
        {
            BTTree treeClone = Instantiate <BTTree>(behaviorTree);

            treeClone.root = CloneNode(behaviorTree.root);
            return(treeClone);
        }
Example #2
0
        void OnGUI()
        {
            // Create a box for selecting the behavior tree.
            // Ironically, this has to be outside of the try-catch
            // otherwise we'll get uncaught exceptions.
            _behaviorTree =
                (BTTree)EditorGUILayout.ObjectField(
                    "Behavior Tree",
                    _behaviorTree,
                    typeof(BTTree),
                    false);

            try
            {
                // only draw editor if a behavior tree is selected
                if (_behaviorTree)
                {
                    // Perform initial setup.
                    CreateTypeLists();
                    LoadResources();
                    BuildEditorData();

                    CreateGUI();
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
Example #3
0
        public static void CreateBehaviorTreeAsset()
        {
            // Create behavior tree asset.
            BTTree behaviorTreeAsset = ScriptableObject.CreateInstance <BTTree>();
            int    i = 0;

            while (true)
            {
                if (AssetDatabase.LoadAssetAtPath <BTTree>("Assets/BT" + i.ToString() + ".asset"))
                {
                    i++;
                    if (i > 10000)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            AssetDatabase.CreateAsset(behaviorTreeAsset, "Assets/BT" + i.ToString() + ".asset");

            // Add root node to behavior tree.
            BTNode newNode = ScriptableObject.CreateInstance <BTActionBlank>();

            newNode.id = newNode.GetInstanceID();             // generate a unique ID for the node.
            Debug.Log(behaviorTreeAsset._editorData);
            if (behaviorTreeAsset._editorData == null)
            {
                behaviorTreeAsset._editorData = new List <EditorData> ();
            }
            behaviorTreeAsset._editorData.Add(new EditorData(newNode, null));
            behaviorTreeAsset.root = newNode;
            AssetDatabase.AddObjectToAsset(newNode, behaviorTreeAsset);

            // Set asset as the active object.
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = behaviorTreeAsset;
        }
Example #4
0
		void OnGUI()
		{
			// Create a box for selecting the behavior tree.
			// Ironically, this has to be outside of the try-catch
			// otherwise we'll get uncaught exceptions.
			_behaviorTree =
				(BTTree)EditorGUILayout.ObjectField(
					"Behavior Tree",
					_behaviorTree,
					typeof( BTTree ),
					false );

			try
			{
				// only draw editor if a behavior tree is selected
				if ( _behaviorTree )
				{
					// Perform initial setup.
					CreateTypeLists();
					LoadResources();
					BuildEditorData();

					CreateGUI();
				}
			}
			catch ( Exception e )
			{
				Debug.LogError( e );
			}
		}