コード例 #1
0
ファイル: NodeDesigner.cs プロジェクト: mengtest/StateTree
        public NodeConnection CreateNodeConnection(bool incomingNodeConnection)
        {
            NodeConnection nodeConnection = ScriptableObject.CreateInstance <NodeConnection>();

            nodeConnection.LoadConnection(this, (!incomingNodeConnection) ? NodeConnectionType.Outgoing : NodeConnectionType.Incoming);
            return(nodeConnection);
        }
コード例 #2
0
ファイル: NodeDesigner.cs プロジェクト: mengtest/StateTree
        public void LoadTask(Task task, Behavior owner, ref int id)
        {
            if (task == null)
            {
                return;
            }
            mTask       = task;
            mTask.Owner = owner;
            mTask.ID    = id++;
            mTask.NodeData.NodeDesigner = this;
            mTask.NodeData.InitWatchedFields(mTask);
            if (!mTask.NodeData.FriendlyName.Equals(string.Empty))
            {
                mTask.FriendlyName          = mTask.NodeData.FriendlyName;
                mTask.NodeData.FriendlyName = string.Empty;
            }
            LoadTaskIcon();
            Init();
            RequiredComponentAttribute[] array;
            if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0)
            {
                Type componentType = array[0].ComponentType;
                if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null)
                {
                    mTask.Owner.gameObject.AddComponent(componentType);
                }
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(mTask.GetType());
            BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            for (int i = baseClasses.Count - 1; i > -1; i--)
            {
                FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr);
                for (int j = 0; j < fields.Length; j++)
                {
                    if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract)
                    {
                        SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable;
                        if (sharedVariable == null)
                        {
                            sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable);
                        }
                        if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute)))
                        {
                            sharedVariable.IsShared = true;
                        }
                        fields[j].SetValue(mTask, sharedVariable);
                    }
                }
            }
            if (isParent)
            {
                ParentTask parentTask = this.mTask as ParentTask;
                if (parentTask.Children != null)
                {
                    for (int k = 0; k < parentTask.Children.Count; k++)
                    {
                        NodeDesigner nodeDesigner = CreateInstance <NodeDesigner>();
                        nodeDesigner.LoadTask(parentTask.Children[k], owner, ref id);
                        NodeConnection nodeConnection = CreateInstance <NodeConnection>();
                        nodeConnection.LoadConnection(this, NodeConnectionType.Fixed);
                        AddChildNode(nodeDesigner, nodeConnection, true, true, k);
                    }
                }
                mConnectionIsDirty = true;
            }
        }