public bool RemoveChild(UnityBtModel model)
 {
     int index = this.children.IndexOf(model);
     if (index >= 0) {
         var child = children[index];
         children.RemoveAt(index);
         // child.ResizeChildren(); // why do this?
         return true;
     }
     return false;
 }
 public void ScheduleChildReorder(UnityBtModel child, int newIndex)
 {
     scheduledReorders.Add(child, newIndex);
 }
        public static UnityBtModel NewInstance(UnityBtModel parent, UnityBtModel model, string modelClassName, int insertIndex)
        {
            if (model != null) { // We can explicitly set null values you see
                model.children = new List<UnityBtModel>();
                model.contextData = new List<ValueField>();
                model.ModelClassName = modelClassName;
            }
            if (parent != null) {
                // NOTE: This means the children list must be populated already, at least with nulls!
                if (insertIndex >= parent.children.Count) {
                    parent.children.Resize(insertIndex + 1, null);
                }
                parent.children[insertIndex] = model;
            }

            return model;
        }
 /// <summary>
 /// Sets a child at the given index to null
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool NullChild(UnityBtModel model)
 {
     int index = children.IndexOf(model);
     if (index == -1) {
         return false;
     }
     Debug.Log("Removing child at index " + index);
     children[index] = null;
     return true;
 }
 public static UnityBtModel NewInstance(UnityBtModel parent)
 {
     var model = new UnityBtModel();
     model.children = new List<UnityBtModel>();
     if (parent != null) {
         parent.children.Add(model);
     }
     return model;
 }
        public static UnityBtModel NewInstance(UnityBtModel parent, UnityBtModel model, string modelClassName)
        {
            if (model != null) { // We can explicitly set null values you see
                model.children = new List<UnityBtModel>();
                model.contextData = new List<ValueField>();
                model.ModelClassName = modelClassName;
            }
            if (parent != null) {
                parent.children.Add(model);
            }

            return model;
        }
 public SequenceExecutor()
 {
     this.rootModel = UnityBtModel.NewInstance(null, new UnityBtModel(), typeof(ModelSequence).ToString());
 }
        private void RecursiveLoadModelTree(UnityBtModel current, ModelTask root)
        {
            var childQueue = new Dictionary<ModelTask, UnityBtModel>();
            if (current.children != null && current.children.Count > 0) {
                foreach (var btModelChild in current.children) {
                    if (btModelChild == null || btModelChild.ModelClassName == null) {
                        continue;
                    }
                    var modelTask = btModelChild.Model;
                    root.Children.Add(modelTask);

                    if (btModelChild.children.Count > 0) {
                        childQueue.Add(modelTask, btModelChild);
                    }
                }
                foreach (var kvp in childQueue) {
                    RecursiveLoadModelTree(kvp.Value, kvp.Key);
                }
            }
        }
 public void OnAfterDeserialize()
 {
     using (var ms = new MemoryStream(serializedModelTree)) {
         ms.Position = 0;
         this.rootModel = DataSerializer.DeserializeProtoObject<UnityBtModel>(ms.ToArray());
     }
 }
 /// <summary>
 /// If new sequences are added via this sequence selector, they'll be attached as children to the given model.
 /// Hence the name relative root model.
 /// Additionaly you can specify the index at which the new model should be inserted.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="insertIndex"></param>
 public void SetRelativeRootModel(UnityBtModel model, int insertIndex)
 {
     this.rootModel = model;
     this.insertIndex = insertIndex;
     this.InternalInit();
 }
 /// <summary>
 /// If new sequences are added via this sequence selector, they'll be attached as children to the given model.
 /// Hence the name relative root model.
 /// </summary>
 /// <param name="model"></param>
 public void SetRelativeRootModel(UnityBtModel model)
 {
     this.rootModel = model;
     this.InternalInit();
 }