private NodeBase GameObjectToNode(GameObject go)
 {
     if (go != null)
     {
         NodeDefine nodeDefine = go.GetComponent <NodeDefine>();
         if (nodeDefine != null)
         {
             NodeBase node = nodeDefine.CreateNode();
             if (node != null)
             {
                 nodeCreateInfo.Add(nodeDefine, node);
             }
             return(node);
         }
     }
     return(null);
 }
示例#2
0
        private void OnEnable()
        {
            Collect();
            nodeDefine      = serializedObject.targetObject as NodeDefine;
            nodeFullName    = this.serializedObject.FindProperty("nodeFullName");
            displayName     = this.serializedObject.FindProperty("displayName");
            nodeDescription = this.serializedObject.FindProperty("nodeDescription");

            for (int i = 0, len = nodeTypes.Length; i < len; ++i)
            {
                if (nodeNames[i] == nodeFullName.stringValue)
                {
                    selected = i;
                }
            }

            OnSelectIndexChanged();
        }
        private static bool CreateTreeAssetValidateFunction()
        {
            if (Selection.objects.Length != 1)
            {
                return(false);
            }

            GameObject go = Selection.activeGameObject;

            if (null == go)
            {
                return(false);
            }

            NodeDefine nodeDefine = go.GetComponent <NodeDefine>();

            if (nodeDefine == null)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        private static void DrawHierarchyIcon(int instanceID, Rect selectionRect)
        {
            GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            if (gameObject != null)
            {
                NodeDefine node = gameObject.GetComponent <NodeDefine>();
                if (node == null)
                {
                    return;
                }

                Type type = node.GetNodeType();
                if (type != null)
                {
                    // draw custom icon
                    var nodeIconAttributes = type.GetCustomAttributes(typeof(NodeIconAttribute), true);
                    if (nodeIconAttributes.Length > 0)
                    {
                        var    attribute = nodeIconAttributes[0] as NodeIconAttribute;
                        string filePath  = attribute.iconPath;
                        if (!cachedTexture.ContainsKey(filePath))
                        {
                            cachedTexture.Add(filePath, AssetDatabase.LoadAssetAtPath <Texture2D>(filePath));
                        }
                        Texture2D tex = cachedTexture[filePath];
                        if (tex != null)
                        {
                            DrawIcon(instanceID, selectionRect, tex);
                            return;
                        }
                    }

                    // draw preset icons
                    if (type.IsSubclassOf(typeof(NodeAction)))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeAction]);
                        return;
                    }
                    if (type.IsSubclassOf(typeof(NodeCondition)))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeCondition]);
                        return;
                    }
                    if (type.IsSubclassOf(typeof(NodeDecorator)))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeDecorator]);
                        return;
                    }

                    if (type == typeof(NodeSequence))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeSequence]);
                        return;
                    }
                    if (type == typeof(NodeSelector))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeSelector]);
                        return;
                    }
                    if (type == typeof(NodeParallel))
                    {
                        DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeParallel]);
                        return;
                    }
                }



                // default
                DrawIcon(instanceID, selectionRect, TextureAssets.TextureDict[PresetNodeIcons.NodeBase]);
            }
        }