Example #1
0
        protected void OnEnable()
        {
            titleContent       = new GUIContent("Node Explorer", EditorGUIUtility.Load("React/ReactIcon.png") as Texture2D);
            categories["Core"] = new List <SearchResult>();

            foreach (var registeredType in ReactTypeRegister.AllTypes)
            {
                var type = registeredType.type;
                if (ReactTypeRegister.IsCoreNode(type) || ReactTypeRegister.IsCoreDecorator(type))
                {
                    categories["Core"].Add(new SearchResult()
                    {
                        niceName = registeredType.niceName, type = registeredType.type, signature = registeredType.signature
                    });
                }
                else
                {
                    var parts = registeredType.menuPath.Split('/');
                    List <SearchResult> results;
                    if (!categories.TryGetValue(parts[0], out results))
                    {
                        results = categories[parts[0]] = new List <SearchResult>();
                    }
                    results.Add(new SearchResult()
                    {
                        niceName = registeredType.niceName, type = registeredType.type, signature = registeredType.signature
                    });
                }
            }
            view = position;
        }
Example #2
0
        void PreProcessGraph(Root root, BaseNode node)
        {
            if (node is Label)
            {
                labels.Add(((Label)node).id);
            }
            foreach (var fi in ReactTypeRegister.GetFields(node))
            {
            }
            var branch = node as BranchNode;

            if (branch != null)
            {
                foreach (var child in branch.Children)
                {
                    PreProcessGraph(root, child);
                }
            }
            var decorator = node as DecoratorNode;

            if (decorator != null && decorator.Child != null)
            {
                PreProcessGraph(root, decorator.Child);
            }
        }
Example #3
0
        public static void DrawFields(BaseNode node, bool focus, bool active)
        {
            var fields = ReactTypeRegister.GetFields(node);

            foreach (var f in fields)
            {
                if (f.IsStatic)
                {
                    continue;
                }
                if (f.Name == "enabled")
                {
                    continue;
                }
                if (f.Name == "Reactor")
                {
                    continue;
                }
                if (focus)
                {
                    GUI.SetNextControlName("FirstFocus");
                }
                // if (active)
                DrawFieldEditor(f, node);
                // else
                // DrawFieldLabels(f, node);
            }
            if (node is SuperNode)
            {
                node.rect.height *= 2;
            }
        }
Example #4
0
        internal bool IsValidParent(System.Type childType, BaseNode parent)
        {
            var childIsCore = ReactTypeRegister.IsCoreDecorator(childType);

            if (childType == typeof(Root))
            {
                return(false);
            }
            var parentIsRoot = parent == root;

            if (parentIsRoot && !childIsCore)
            {
                return(false);
            }
            if (parentIsRoot && childIsCore && childType != typeof(OnMessage))
            {
                foreach (var child in ((IParentNode)parent).GetChildren())
                {
                    if (child.GetType() == childType)
                    {
                        return(false);
                    }
                }
            }
            if (!(parent is IParentNode))
            {
                return(false);
            }
            if (childIsCore && !parentIsRoot)
            {
                return(false);
            }
            return(true);
        }
Example #5
0
        void AddNodeAfterCompile()
        {
            var newType = ReactTypeRegister.Find(instance.generatedNodeToAdd);

            if (!target.AddNode(newType))
            {
                Debug.LogError("Could not add new type: " + instance.generatedNodeToAdd);
            }
            generatedNodeToAdd = string.Empty;
            CloseAndSaveState();
        }
Example #6
0
        static void CreateClassesForType(System.Type type)
        {
            foreach (var p in type.GetProperties())
            {
                if (ReactTypeRegister.IsSupportedParameter(p.PropertyType))
                {
                    if (p.GetCustomAttributes(typeof(ObsoleteAttribute), true).Length > 0)
                    {
                        continue;
                    }
                    if (ReactTypeRegister.excludedNames.Contains(p.Name))
                    {
                        continue;
                    }

                    if (p.PropertyType == typeof(bool))
                    {
                        if (p.CanRead)
                        {
                            var stat = p.GetGetMethod().IsStatic;
                            AddCandidateClass(type, null, p.Name, null, stat, "If", stat ? staticIfTemplate : ifTemplate);
                            AddCandidateClass(type, null, p.Name, null, stat, "Condition", stat ? staticConditionTemplate : conditionTemplate);
                        }
                    }
                    if (p.CanWrite)
                    {
                        var pmi = p.GetSetMethod();
                        if (pmi == null)
                        {
                            break;
                        }
                        var stat = pmi.IsStatic;
                        AddCandidateClass(type, p.PropertyType, p.Name, null, stat, "Set", stat ? staticSetTemplate : setTemplate);
                    }
                }
            }
            foreach (var mi in type.GetMethods())
            {
                if (!ReactTypeRegister.IsSupportedMethod(mi))
                {
                    continue;
                }

                if (mi.ReturnType == typeof(bool))
                {
                    AddCandidateClass(type, null, mi.Name, mi.GetParameters(), mi.IsStatic, "If", mi.IsStatic ? staticIfTemplate : ifTemplate);
                    AddCandidateClass(type, null, mi.Name, mi.GetParameters(), mi.IsStatic, "Condition", mi.IsStatic ? staticConditionTemplate : conditionTemplate);
                }
                if (mi.ReturnType == typeof(void))
                {
                    AddCandidateClass(type, null, mi.Name, mi.GetParameters(), mi.IsStatic, "Function", mi.IsStatic ? staticFunctionTemplate : functionTemplate);
                }
            }
        }
        void PerformDrag()
        {
            Undo.RecordObject(target, "Drag & Drop");
            var oldParent = dragNode.nodeParent as IParentNode;
            var newParent = dropZone.parent as IParentNode;

            if (ReactTypeRegister.IsCoreDecorator(dragNode.GetType()) && newParent != root)
            {
                EditorApplication.Beep();
                return;
            }
            newParent.Insert(dropZone.index, BaseNode.Clone(dragNode));
            if (!Event.current.shift)
            {
                oldParent.Remove(dragNode);
            }
            ExitDrag();
        }
Example #8
0
        static void AddCandidateClass(Type type, Type propertyType, string name, ParameterInfo[] parameters, bool isStatic, string prefix, string template)
        {
            var className = "";

            if (propertyType == null)
            {
                className = prefix + "_" + type.Name + "_" + name + "_";
                var signature = "";
                if (parameters != null)
                {
                    signature = string.Join("_", (from i in parameters
                                                  select i.Name).ToArray());
                }
                className += signature;
            }
            else
            {
                className = prefix + "_" + type.Name + "_" + name + "";
            }

            if (ReactTypeRegister.Find(className) == null)
            {
                var candidate = new ReactCandidateClass()
                {
                    type         = type,
                    propertyType = propertyType,
                    name         = name,
                    parameters   = parameters,
                    isStatic     = isStatic,
                    prefix       = prefix,
                    template     = template,
                    className    = className
                };
                candidates.Add(candidate);
                List <ReactCandidateClass> clist;
                if (!typeMap.TryGetValue(type, out clist))
                {
                    typeMap[type] = clist = new List <ReactCandidateClass>();
                }
                clist.Add(candidate);
            }
        }
Example #9
0
        public void LoadDefaultResults()
        {
            foreach (var registeredType in ReactTypeRegister.AllTypes)
            {
                var type = registeredType.type;
                if (ReactTypeRegister.IsCoreNode(type) || ReactTypeRegister.IsCoreDecorator(type))
                {
                    if (target.IsValidParent(registeredType.type, target.reactor.hotNode))
                    {
                        searchResults.Add(new SearchResult()
                        {
                            niceName = registeredType.niceName, type = registeredType.type, signature = registeredType.signature
                        });
                    }
                }
            }
            searchResults.Sort((A, B) => A.niceName.CompareTo(B.niceName));

            titleContent = new GUIContent("Node Search", EditorGUIUtility.Load("React/ReactIcon.png") as Texture2D);
        }
Example #10
0
 void DrawDecorator(DecoratorNode decorator)
 {
     //if node is a decorator, draw child and widgets.
     if (decorator != null)
     {
         if (ReactTypeRegister.IsCoreDecorator(decorator.GetType()))
         {
             DrawCoreDecorator(decorator);
         }
         if (decorator.Child != null)
         {
             cursor.x += decorator.rect.width + SPACING.x;
             cursor.y -= decorator.rect.height + SPACING.x / 2;
             Draw(decorator.Child, decorator);
             // var left = decorator.rect.xMax;
             // var mid = decorator.rect.center.y;
             // var right = decorator.Child.rect.xMin;
             // ReactEditorUtility.DrawLine(new Vector2(left, mid), new Vector3(right, mid), Color.white);
             cursor.x -= decorator.rect.width + SPACING.x;
         }
         dropZones.Add(new DropZone(decorator, decorator.rect));
     }
 }
Example #11
0
        static string CreatePropertyClass(string className, Type componentType, Type propertyType, bool isStatic, string propertyName, string prefix, string template)
        {
            if (componentType == null)
            {
                return("");
            }
            var usings = new HashSet <string>();
            var code   = "";

            if (isStatic)
            {
                code = string.Format("{0}.{1}", componentType.Name, propertyName);
            }
            else
            {
                code = string.Format("Component.{1}", componentType.FullName, propertyName);
            }
            usings.Add(componentType.Namespace);
            usings.Add(propertyType.Namespace);
            var subPath = System.IO.Path.Combine(outputPath, componentType.Namespace ?? "");

            System.IO.Directory.CreateDirectory(subPath);
            var filePath     = System.IO.Path.Combine(subPath, className + ".cs");
            var onEnableCode = "";
            var menuRoot     = "";
            var menuPath     = menuRoot + componentType.Name + "/" + prefix + "/" + propertyName;
            var niceName     = componentType.Name + "." + propertyName;
            var fields       = "";
            var helpText     = "";
            var attributes   = "";

            fields += string.Format("        public {0} {1};\n", ReactTypeRegister.ShortTypeName(propertyType), "value");


            var usingDecs = "";

            foreach (var u in usings)
            {
                if (u != null && u != string.Empty && u != "UnityEngine" && u != "React")
                {
                    usingDecs += "using " + u + ";\n";
                }
            }
            var classCode = template
                            .Replace("[USING]", usingDecs)
                            .Replace("[ATTRIBUTES]", attributes)
                            .Replace("[CLASSNAME]", className)
                            .Replace("[CODE]", code)
                            .Replace("[PROPERTYNAME]", propertyName)
                            .Replace("[COMPONENTTYPE]", componentType.Name)
                            .Replace("[PROPERTY_TYPE]", fields)
                            .Replace("[MENUPATH]", menuPath)
                            .Replace("[NICENAME]", niceName)
                            .Replace("[ONENABLE_CODE]", onEnableCode)
                            .Replace("[HELPTEXT]", helpText)
                            .Replace("[COLOR]", CreateColor(className));

            classCode.Replace("\n\n", "\n");
            System.IO.File.WriteAllText(filePath, classCode);
            return(className);
        }
Example #12
0
        static string CreateClass(string className, Type type, string methodName, ParameterInfo[] parameters, bool isStatic, string prefix, string template)
        {
            if (type == null)
            {
                return("");
            }
            var usings        = new HashSet <string>();
            var componentName = type.Name.ToLower();
            var componentType = type.FullName.Replace("+", ".");

            usings.Add(type.Namespace);

            var fields     = "";
            var argList    = new List <string>();
            var args       = "";
            var helpText   = "";
            var attributes = "";

            if (parameters != null)
            {
                foreach (var p in parameters)
                {
                    var varName = Sanitise(p.Name);
                    fields += string.Format("        public {0} {1};\n", ReactTypeRegister.ShortTypeName(p.ParameterType), varName);
                    argList.Add(varName);
                    usings.Add(p.ParameterType.Namespace);
                }
                args = string.Join(", ", argList.ToArray());
            }

            var code = "";

            if (isStatic)
            {
                componentName = componentType;
            }
            else
            {
                componentName = "Component";
            }

            if (parameters == null) //This is a property or field.
            {
                code = string.Format("{0}.{1}", componentName, methodName);
            }
            else
            {
                code = string.Format("{0}.{1}({2})", componentName, methodName, args);
            }

            var polymorphic = false;

            try
            {
                type.GetMethod(methodName);
            }
            catch (AmbiguousMatchException)
            {
                polymorphic = true;
            }
            var signature = "";

            if (parameters != null)
            {
                signature = string.Join("_", (from i in parameters
                                              select i.Name).ToArray());
            }
            var subPath = System.IO.Path.Combine(outputPath, type.Namespace ?? "");

            System.IO.Directory.CreateDirectory(subPath);
            var filePath     = System.IO.Path.Combine(subPath, className + ".cs");
            var onEnableCode = "";
            var componentDec = "";

            var menuRoot = "";
            var menuName = "";

            if (parameters != null && parameters.Length > 0 && polymorphic)
            {
                menuName = string.Format("/({0})", string.Join(", ", signature.Split('_')));
            }
            var menuPath = menuRoot + type.Name + "/" + prefix + "/" + methodName + menuName;
            var niceName = type.Name + "." + methodName;

            signature = " (" + signature.Replace('_', ',') + ")";
            var usingDecs = "";

            foreach (var u in usings)
            {
                if (u != null && u != string.Empty && u != "UnityEngine" && u != "React")
                {
                    usingDecs += "using " + u + ";\n";
                }
            }

            var classCode = template
                            .Replace("[USING]", usingDecs)
                            .Replace("[ATTRIBUTES]", attributes)
                            .Replace("[CLASSNAME]", className)
                            .Replace("[CODE]", code)
                            .Replace("[COMPONENTNAME]", componentName)
                            .Replace("[COMPONENTTYPE]", componentType)
                            .Replace("[FIELDS]", fields)
                            .Replace("[MENUPATH]", menuPath)
                            .Replace("[NICENAME]", niceName)
                            .Replace("[ONENABLE_CODE]", onEnableCode)
                            .Replace("[SIGNATURE]", signature)
                            .Replace("[COMPONENT_DEC]", componentDec)
                            .Replace("[HELPTEXT]", helpText)
                            .Replace("[METHODNAME]", methodName)
                            .Replace("[ARGS]", args)
                            .Replace("[COLOR]", CreateColor(className));

            classCode.Replace("\n\n", "\n");
            System.IO.File.WriteAllText(filePath, classCode);
            return(className);
        }