Beispiel #1
0
    void UpdateReferences(List <BeeHIVEAgent> agents, string treeName)
    {
        ScriptableTree tree = AssetDatabase.LoadAssetAtPath <ScriptableTree>("Assets/BeeHIVE/Trees/" + treeName + ".asset");

        foreach (BeeHIVEAgent a in agents)
        {
            a.behaviorTreeObj = tree;
            EditorUtility.SetDirty(a);
        }
    }
Beispiel #2
0
    public static BH_BehaviorTree LoadTree(ScriptableTree tree)
    {
        BH_BehaviorTree t;

        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream    s  = new MemoryStream(tree.behaviorTreeData);

        t = (BH_BehaviorTree)bf.Deserialize(s);
        s.Close();

        return(t);
    }
Beispiel #3
0
    void SaveTree(BH_BehaviorTree tree, string name)
    {
        List <BeeHIVEAgent> agents = GetReferencesThatUse(name);

        string         filepath = "Assets/BeeHIVE/Trees/" + name + ".asset";
        ScriptableTree sTree    = ScriptableObject.CreateInstance <ScriptableTree> ();

        byte []         buffer = new byte[5122];
        BinaryFormatter bf     = new BinaryFormatter();
        MemoryStream    s      = new MemoryStream(buffer);

        bf.Serialize(s, tree);

        sTree.behaviorTreeData = buffer;
        AssetDatabase.CreateAsset(sTree, filepath);
        AssetDatabase.SaveAssets();

        if (agents.Count > 0)
        {
            UpdateReferences(agents, name);
        }
    }