コード例 #1
0
        public static bool LoadUploadedBehaviorTree(out MyBehaviorDefinition definition)
        {
            MyBehaviorDefinition definition2 = LoadBehaviorTreeFromFile(Path.Combine(MyFileSystem.UserDataPath, "UploadTree" + DEFAULT_EXTENSION));

            definition = definition2;
            return(definition != null);
        }
コード例 #2
0
        public static bool LoadUploadedBehaviorTree(out MyBehaviorDefinition definition)
        {
            string dataPath = MyFileSystem.UserDataPath;
            MyBehaviorDefinition uploadedDefinition = LoadBehaviorTreeFromFile(Path.Combine(dataPath, "UploadTree" + DEFAULT_EXTENSION));

            definition = uploadedDefinition;
            return(definition != null);
        }
コード例 #3
0
 public bool RebuildBehaviorTree(MyBehaviorDefinition newDefinition, out MyBehaviorTree outBehaviorTree)
 {
     if (!this.m_BTDataByName.ContainsKey(newDefinition.Id.SubtypeId))
     {
         outBehaviorTree = null;
         return(false);
     }
     outBehaviorTree = this.m_BTDataByName[newDefinition.Id.SubtypeId].BehaviorTree;
     outBehaviorTree.ReconstructTree(newDefinition);
     return(true);
 }
コード例 #4
0
        private bool BuildBehaviorTree(MyBehaviorDefinition behaviorDefinition)
        {
            if (this.m_BTDataByName.ContainsKey(behaviorDefinition.Id.SubtypeId))
            {
                return(false);
            }
            MyBehaviorTree behaviorTree = new MyBehaviorTree(behaviorDefinition);

            behaviorTree.Construct();
            BTData data = new BTData(behaviorTree);

            this.m_BTDataByName.Add(behaviorDefinition.Id.SubtypeId, data);
            return(true);
        }
コード例 #5
0
        private bool BuildBehaviorTree(MyBehaviorDefinition behaviorDefinition)
        {
            Debug.Assert(!m_BTDataByName.ContainsKey(behaviorDefinition.Id.SubtypeId), "Tree with given behavior definition already exists.");
            if (m_BTDataByName.ContainsKey(behaviorDefinition.Id.SubtypeId))
            {
                return(false);
            }

            MyBehaviorTree newInstance = new MyBehaviorTree(behaviorDefinition);

            newInstance.Construct();
            BTData behaviorTreeData = new BTData(newInstance);

            m_BTDataByName.Add(behaviorDefinition.Id.SubtypeId, behaviorTreeData);
            return(true);
        }
コード例 #6
0
        private static MyBehaviorDefinition LoadBehaviorTreeFromFile(string path)
        {
            MyObjectBuilder_Definitions allDefinitions = null;

            MyObjectBuilderSerializer.DeserializeXML(path, out allDefinitions);

            if (allDefinitions != null && allDefinitions.AIBehaviors != null && allDefinitions.AIBehaviors.Length > 0)
            {
                var firstDef = allDefinitions.AIBehaviors[0]; // only one tree can be uploaded at one time

                MyBehaviorDefinition behaviorDefinition = new MyBehaviorDefinition();
                MyModContext         context            = new MyModContext();
                context.Init("BehaviorDefinition", Path.GetFileName(path));
                behaviorDefinition.Init(firstDef, context);
                return(behaviorDefinition);
            }
            return(null);
        }
コード例 #7
0
        private static MyBehaviorDefinition LoadBehaviorTreeFromFile(string path)
        {
            MyObjectBuilder_Definitions objectBuilder = null;

            MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Definitions>(path, out objectBuilder);
            if (((objectBuilder == null) || (objectBuilder.AIBehaviors == null)) || (objectBuilder.AIBehaviors.Length == 0))
            {
                return(null);
            }
            MyObjectBuilder_BehaviorTreeDefinition builder = objectBuilder.AIBehaviors[0];
            MyModContext modContext = new MyModContext();

            modContext.Init("BehaviorDefinition", Path.GetFileName(path), null);
            MyBehaviorDefinition definition1 = new MyBehaviorDefinition();

            definition1.Init(builder, modContext);
            return(definition1);
        }
コード例 #8
0
 private void OnUploadNewTree(ref System.Windows.Forms.Message msg)
 {
     if (this.m_behaviorTreeCollection != null)
     {
         MyBehaviorTree       outBehaviorTree = null;
         MyBehaviorDefinition definition      = null;
         if (MyBehaviorTreeCollection.LoadUploadedBehaviorTree(out definition) && this.m_behaviorTreeCollection.HasBehavior(definition.Id.SubtypeId))
         {
             this.m_botCollection.ResetBots(definition.Id.SubtypeName);
             this.m_behaviorTreeCollection.RebuildBehaviorTree(definition, out outBehaviorTree);
             this.m_botCollection.CheckCompatibilityWithBots(outBehaviorTree);
         }
         IntPtr zero = IntPtr.Zero;
         if (this.m_behaviorTreeCollection.TryGetValidToolWindow(out zero))
         {
             WinApi.PostMessage(zero, 0x404, IntPtr.Zero, IntPtr.Zero);
         }
     }
 }
コード例 #9
0
        private void OnUploadNewTree(ref Message msg)
        {
            if (m_behaviorTreeCollection != null)
            {
                MyBehaviorTree behaviorTree = null;
                MyBehaviorDefinition behaviorDefinition = null;
                bool success = MyBehaviorTreeCollection.LoadUploadedBehaviorTree(out behaviorDefinition);
                if (success && m_behaviorTreeCollection.HasBehavior(behaviorDefinition.Id.SubtypeId))
                {
                    m_botCollection.ResetBots(behaviorDefinition.Id.SubtypeName);
                    m_behaviorTreeCollection.RebuildBehaviorTree(behaviorDefinition, out behaviorTree);
                    m_botCollection.CheckCompatibilityWithBots(behaviorTree);
                }
                IntPtr toolWindowHandle = IntPtr.Zero;
#if !XB1
                if (m_behaviorTreeCollection.TryGetValidToolWindow(out toolWindowHandle))
                    WinApi.PostMessage(toolWindowHandle, MyWMCodes.BEHAVIOR_TOOL_TREE_UPLOAD_SUCCESS, IntPtr.Zero, IntPtr.Zero);
#endif // !XB1
            }
        }
コード例 #10
0
 public void ReconstructTree(MyBehaviorDefinition def)
 {
     m_behaviorDefinition = def;
     Construct();
 }
コード例 #11
0
 public MyBehaviorTree(MyBehaviorDefinition def)
 {
     m_behaviorDefinition = def;
     m_treeDesc           = new MyBehaviorTreeDesc();
 }