Exemple #1
0
        void onGUIGenRectTransform(RectTransform transform, AutoBindFieldInfo field)
        {
            //如果是RectTransform,那么可以当列表。
            bool isList = field.getValueOrDefault <bool>("isList");

            if (EditorGUILayoutHelper.toggle("列表", isList, out isList))
            {
                field.propDict["isList"] = isList;
            }
            if (isList)
            {
                GameObject template = field.getValueOrDefault <GameObject>("template");
                if (EditorGUILayoutHelper.objectField("列表模板", template, out template, true))
                {
                    field.propDict["template"] = template;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 默认生成字段,属性,以及初始化语句(一个常量用于自动查找)。
        /// </summary>
        /// <param name="component"></param>
        protected virtual void genCompo(Component component, AutoBindFieldInfo fieldInfo)
        {
            //字段
            var field = genField4Compo(component, genFieldName4Compo(component));
            //常量
            var constField = genField("const string", "PATH" + field.Name.ToUpper(), false);

            constField.InitExpression = Codo.String(fieldInfo.path);
            //属性
            var prop = genProp4Compo(component, genPropName4Field(field.Name), field.Name);

            //初始化
            addTypeUsing(typeof(TransformHelper));
            _initMethod.Statements.append(Codo.getField(field.Name).assign(Codo.getProp(NAME_OF_TRANSFORM)
                                                                           .getMethod(NAME_OF_FIND).invoke(Codo.getField("PATH" + field.Name.ToUpper()))
                                                                           .getMethod(NAME_OF_GETCOMPO, Codo.type(component.GetType().Name)).invoke()));
            //特殊组件处理
            foreach (var pair in _compoGenDict)
            {
                if (pair.Key == component.GetType() || component.GetType().IsSubclassOf(pair.Key))
                {
                    pair.Value.onGen(this, component, component.gameObject == rootGameObject, fieldInfo, field);
                    return;
                }
            }
            if (component is Button)
            {
                onGenButton(component as Button, component.gameObject == rootGameObject, field, prop);
            }
            else if (component is Animator)
            {
                onGenAnimator(component as Animator, field, prop);
            }
            else if (component is RectTransform && fieldInfo.getValueOrDefault <bool>("isList"))
            {
                onGenList(component as RectTransform, field, fieldInfo);
            }
        }