示例#1
0
        /// <summary>
        /// Binding关联
        /// </summary>
        /// <returns></returns>
        public virtual void CompleteCode(ComponentItem component, bool bindingAble)
        {
            foreach (var item in component.viewItems)
            {
                BindingMemberInvocations(component.name, item);
            }

            foreach (var item in component.eventItems)
            {
                switch (item.type)
                {
                case BindingType.NoBinding:
                    LocalEventInvocations(component.name, item, bindingAble);
                    break;

                case BindingType.Normal:
                case BindingType.WithTarget:
                    BindingEventInvocations(component.name, component.componentType, item);
                    break;

                default:
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// 分析代码的的组件信息
        /// </summary>
        /// <param name="component"></param>
        /// <param name="components"></param>
        public static void AnalysisComponent(MonoBehaviour component, List <ComponentItem> components, GenCodeRule rule)
        {
            var type = component.GetType();

            rule.nameSpace = type.Namespace;

            var propertys = type.GetProperties(BindingFlags.GetProperty | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var prop in propertys)
            {
                var support = typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(prop.PropertyType) ||
                              typeof(ScriptableObject).IsAssignableFrom(prop.PropertyType) ||
                              prop.PropertyType == typeof(GameObject);

                if (support)
                {
                    var compItem = components.Find(x => "m_" + x.name == prop.Name || x.name == prop.Name);

                    if (compItem == null)
                    {
                        compItem      = new ComponentItem();
                        compItem.name = prop.Name.Replace("m_", "");
                        components.Add(compItem);
                    }

                    var value = prop.GetValue(component, new object[0]);
                    if (value != null)
                    {
                        if (prop.PropertyType == typeof(GameObject))
                        {
                            compItem.target     = value as GameObject;
                            compItem.components = SortComponent(compItem.target);
                            var types = Array.ConvertAll(compItem.components, x => x.type);
                            compItem.componentID = Array.IndexOf(types, typeof(GameObject));
                        }
                        else if (typeof(ScriptableObject).IsAssignableFrom(prop.PropertyType))
                        {
                            compItem.UpdateAsScriptObject(value as ScriptableObject);
                        }
                        else
                        {
                            compItem.target     = (value as MonoBehaviour).gameObject;
                            compItem.components = SortComponent(compItem.target);
                            var types = Array.ConvertAll(compItem.components, x => x.type);
                            compItem.componentID = Array.IndexOf(types, value.GetType());
                        }
                    }
                }
            }

            ViewCoder coder = new ViewCoder();

            coder.AnalysisBinding(component, components.ToArray(), rule);
        }
示例#3
0
        /// <summary>
        /// 分析代码的的组件信息
        /// </summary>
        /// <param name="component"></param>
        /// <param name="components"></param>
        public static void AnalysisComponent(MonoBehaviour component, List <ComponentItem> components, GenCodeRule rule)
        {
            var fields = component.GetType().GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            fields = (from field in fields
                      let atts = field.GetCustomAttributes(false)
                                 from att in atts
                                 where att is SerializeField
                                 select field).ToArray();

            foreach (var field in fields)
            {
                if (typeof(UnityEngine.MonoBehaviour).IsAssignableFrom(field.FieldType) || typeof(ScriptableObject).IsAssignableFrom(field.FieldType))
                {
                    var compItem = components.Find(x => "m_" + x.name == field.Name || x.name == field.Name);

                    if (compItem == null)
                    {
                        compItem      = new ComponentItem();
                        compItem.name = field.Name.Replace("m_", "");
                        components.Add(compItem);
                    }

                    var value = field.GetValue(component);
                    if (value != null)
                    {
                        if (field.FieldType == typeof(GameObject))
                        {
                            compItem.target      = value as GameObject;
                            compItem.components  = SortComponent(compItem.target);
                            compItem.componentID = Array.IndexOf(compItem.components, typeof(GameObject));
                        }
                        else if (typeof(ScriptableObject).IsAssignableFrom(field.FieldType))
                        {
                            compItem.UpdateAsScriptObject(value as ScriptableObject);
                        }
                        else
                        {
                            compItem.target      = (value as MonoBehaviour).gameObject;
                            compItem.components  = SortComponent(compItem.target);
                            compItem.componentID = Array.IndexOf(Array.ConvertAll(compItem.components, x => x.type), value.GetType());
                        }
                    }
                }
            }
            AnalysisBindings(component, components, rule);
        }
示例#4
0
        /// <summary>
        /// Binding关联
        /// </summary>
        /// <returns></returns>
        public virtual void CompleteCode(ComponentItem component, bool bindingAble)
        {
            foreach (var item in component.viewItems)
            {
                BindingMemberInvocations(component.name, item);
            }

            foreach (var item in component.eventItems)
            {
                if (item.runtime)
                {
                    BindingEventInvocations(component.name, component.componentType, item);
                }
                else
                {
                    LocalEventInvocations(component.name, item, bindingAble);
                }
            }
        }
        /// <summary>
        /// PanelAction类型
        /// </summary>
        /// <param name="component"></param>
        /// <param name="eventItem"></param>
        /// <returns></returns>
        private Type GetPanelActionType(ComponentItem component, BindingEvent eventItem)
        {
            var type = eventItem.bindingTargetType.type;

            if (type != null)
            {
                Type typevalue = type;

                if (type.BaseType.IsGenericType)
                {
                    var    argumentList = new List <Type>(type.BaseType.GetGenericArguments());
                    Type[] arguments    = null;
                    switch (eventItem.type)
                    {
                    case BindingType.Simple:
                        arguments = argumentList.ToArray();
                        break;

                    case BindingType.Full:
                        argumentList.Add(component.componentType);
                        arguments = argumentList.ToArray();
                        break;

                    default:
                        break;
                    }

                    if (arguments.Length == 1)
                    {
                        typevalue = typeof(Binding.PanelAction <>).MakeGenericType(arguments);
                    }
                    else if (arguments.Length == 2)
                    {
                        typevalue = typeof(Binding.PanelAction <,>).MakeGenericType(arguments);
                    }
                    else if (arguments.Length == 3)
                    {
                        typevalue = typeof(Binding.PanelAction <, ,>).MakeGenericType(arguments);
                    }
                    else if (arguments.Length == 4)
                    {
                        typevalue = typeof(Binding.PanelAction <, , ,>).MakeGenericType(arguments);
                    }
                }
                else
                {
                    if (eventItem.type == BindingType.Simple)
                    {
                        typevalue = typeof(Binding.PanelAction);
                    }
                    else
                    {
                        typevalue = typeof(Binding.PanelAction <>).MakeGenericType(component.componentType);
                    }
                }
                return(typevalue);
            }
            else
            {
                return(null);
            }
        }