Exemplo n.º 1
0
        public bool CheckIsTypeExists()
        {
            var parts        = Type.Split('.');
            var lastPart     = parts[parts.Length - 1].ToLower();
            var bracketIndex = lastPart.IndexOf('[');

            if (bracketIndex >= 0)
            {
                lastPart = lastPart.Substring(0, bracketIndex);
            }

            if (wellKnownTypes.Contains(lastPart))
            {
                return(true);
            }

            //if (typeof(string).Assembly.GetType(Type) != null)
            //    return true;
            //if (typeof(Vector2).Assembly.GetType(Type) != null)
            //    return true;
            if (UIGraphEditor.GetTypeByName(Type, "") != null)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private void OpenUserScript()
        {
            var node = FindNodeInGraph();

            if (node != null)
            {
                UIGraphEditor.OpenOrCreateUserScript(node);
            }
        }
Exemplo n.º 3
0
        public void GrabInfoAboutView(RectTransform rt)
        {
            if (rt == null)
            {
                return;
            }

            ViewInfo = new ViewInfo();
            ViewInfo.Members.Clear();

            void GrabMethods(Type type, bool checkAttr)
            {
                var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                foreach (var mi in methods)
                {
                    if (mi.Name.StartsWith("get_") ||
                        mi.Name.StartsWith("<"))
                    {
                        continue;//property getter
                    }
                    var attr = mi.GetCustomAttribute <VisibleInGraphAttribute>();
                    if (attr == null && checkAttr)
                    {
                        continue;
                    }
                    if (attr != null && !attr.Visible)
                    {
                        continue;
                    }

                    var parameters = mi.GetParameters();
                    var count      = parameters.Count(p => !p.HasDefaultValue);
                    if (count != 0)
                    {
                        if (attr == null || !attr.Visible)
                        {
                            continue;
                        }
                    }

                    ViewInfo.Members[mi.Name] = new ViewInfoItem {
                        Name = mi.Name, MethodInfo = mi
                    };
                }
            }

            void GrabEvents(Type type, bool checkAttr)
            {
                var events = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                foreach (var ei in events)
                {
                    var attr = ei.GetCustomAttribute <VisibleInGraphAttribute>();
                    if (attr == null && checkAttr)
                    {
                        continue;
                    }
                    if (attr != null && !attr.Visible)
                    {
                        continue;
                    }

                    ViewInfo.Members[ei.Name] = new ViewInfoItem {
                        Name = ei.Name, EventInfo = ei
                    };
                }
            }

            //grab components from scene
            foreach (var info in SceneInfoGrabber <BaseView> .GrabInfo(rt, true))
            {
                ViewInfo.Members[info.Key] = new ViewInfoItem {
                    Name = info.Key, Component = info.Value
                }
            }
            ;

            //grab exists fileds
            Type viewType = null;
            var  view     = rt.GetComponent <BaseView>();

            if (view != null)
            {
                viewType = view.GetType();
            }
            else
            {
                viewType = UIGraphEditor.GetTypeByName(rt.name, rt.gameObject.scene);
            }

            if (viewType != null)
            {
                var fields = viewType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var fi in fields)
                {
                    if (SceneInfoGrabber <BaseView> .WellKnownTypes.Contains(fi.FieldType) || typeof(BaseView).IsAssignableFrom(fi.FieldType))
                    {
                        var isAutogenerated = fi.GetCustomAttribute <AutoGeneratedAttribute>();
                        if (isAutogenerated != null)
                        {
                            //skip isAutogenerated fields => they will recretaed
                            continue;
                        }

                        ViewInfo.Members[fi.Name] = new ViewInfoItem {
                            Name = fi.Name, FieldInfo = fi
                        };
                    }
                }

                //grab argless public methods
                GrabMethods(viewType, false);

                //grab public events
                GrabEvents(viewType, false);
            }

            //grab argless public methods of base class
            GrabMethods(typeof(BaseView), true);

            //add linked Views
            foreach (var port in Outputs)
            {
                foreach (var linked in port.GetConnections())
                {
                    if (linked.node is ViewNode otherNode)
                    {
                        if (!ViewInfo.Members.ContainsKey(otherNode.name))
                        {
                            ViewInfo.Members[otherNode.name] = new ViewInfoItem()
                            {
                                Binded = otherNode.name, Name = otherNode.name, IsAutogenerated = true, IsAutogeneratedReallyExists = true
                            }
                        }
                        ;
                    }
                }
            }

            //remove Ports w/o members
            foreach (var port in Ports.ToArray())
            {
                if (port.ValueType == typeof(ActionInputPort) || port.ValueType == typeof(ActionOutputPort) || port.ValueType == typeof(EventPort))
                {
                    if (!ViewInfo.Members.ContainsKey(port.fieldName))
                    {
                        //remove port
                        RemoveDynamicPort(port);
                    }
                }
            }
        }
    }