コード例 #1
0
        private void setRedirObjField(AutoBindFieldInfo field, Object redirObj)
        {
            GameObject redirGameObject  = redirObj is GameObject ? (GameObject)redirObj : ((Component)redirObj).gameObject;
            GameObject prefabGameObject = getTargetGameObject(redirGameObject);

            if (prefabGameObject == null)
            {
                Debug.LogError(redirGameObject + "不是" + _gameObject + "的一部分", redirGameObject);
                return;
            }
            redirObj       = redirObj is GameObject ? (Object)prefabGameObject : prefabGameObject.GetComponent(redirObj.GetType());
            field.path     = _gameObject.transform.getChildPath(prefabGameObject.transform);
            _redirObjField = new KeyValuePair <Object, AutoBindFieldInfo>(redirObj, field);
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
0
 protected virtual void onGUIGenField(Object obj, AutoBindFieldInfo field)
 {
     EditorGUILayout.BeginHorizontal();
     EditorGUI.BeginDisabledGroup(!field.isGenerated);
     if (obj != null)
     {
         EditorGUI.BeginDisabledGroup(true);
         EditorGUILayout.ObjectField(obj, typeof(Object), true);
         EditorGUI.EndDisabledGroup();
     }
     else
     {
         Object redirObj = EditorGUILayout.ObjectField("丢失对象", null, field.targetType, true);
         if (redirObj != null)
         {
             setRedirObjField(field, redirObj);
         }
     }
     if (obj != null)
     {
         setSepecifiedFieldName(obj, EditorGUILayout.TextField(getSpecifiedFieldName(obj)));
     }
     else
     {
         EditorGUILayout.LabelField(field.fieldName);
     }
     EditorGUILayout.EndHorizontal();
     EditorGUILayout.BeginHorizontal();
     if (obj is RectTransform)
     {
         onGUIGenRectTransform(obj as RectTransform, field);
     }
     EditorGUILayout.Space();
     //子控件
     //删除组件
     if (GUILayout.Button("-", GUILayout.Width(25)))
     {
         _removeField = field;
     }
     EditorGUI.EndDisabledGroup();
     EditorGUILayout.EndHorizontal();
 }
コード例 #4
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);
            }
        }
コード例 #5
0
 protected virtual void onGenList(RectTransform transform, CodeMemberField field, AutoBindFieldInfo fieldInfo)
 {
 }
コード例 #6
0
        public override void onGen(AutoCompoGenerator generator, Animator component, bool isRootComponent, AutoBindFieldInfo info, CodeMemberField field)
        {
            AnimatorController controller = component.runtimeAnimatorController as AnimatorController;

            foreach (var parameter in controller.parameters)
            {
                string fieldName    = "ANIM_PARAM_";
                string animatorName = generator.genPropName4Field(field.Name);
                if (animatorName.EndsWith("Animator", StringComparison.OrdinalIgnoreCase))
                {
                    animatorName = animatorName.Substring(0, animatorName.Length - 8);
                }
                if (animatorName.StartsWith("_"))
                {
                    animatorName = animatorName.Substring(1, animatorName.Length - 1);
                }
                if (!(animatorName.StartsWith("as") && char.IsUpper(animatorName[2])))
                {
                    fieldName += animatorName.ToUpper() + "_";
                }
                fieldName += parameter.name.ToUpper();
                CodeMemberField Const = generator.genField("const string", fieldName, false);
                Const.InitExpression = Codo.String(parameter.name);
            }
        }
コード例 #7
0
        public override void onGen(AutoCompoGenerator generator, Button component, bool isRootComponent, AutoBindFieldInfo info, CodeMemberField field)
        {
            string name = field.Name.Substring(2, field.Name.Length - 2);

            name = name.headToUpper();
            //事件
            CodeMemberEvent Event;

            if (isRootComponent)
            {
                Event = generator.genEvent(typeof(Action).Name, "onClick", Codo.type(generator.type.Name));
            }
            else
            {
                Event = generator.genEvent(typeof(Action).Name, "on" + name + "Click", Codo.type(generator.type.Name));
            }
            //回调函数
            CodeMemberMethod callbackMethod;

            if (isRootComponent)
            {
                callbackMethod = generator.genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), "clickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            else
            {
                callbackMethod = generator.genMethod(MemberAttributes.Private | MemberAttributes.Final, typeof(void), name + "ClickCallback");
                callbackMethod.Statements.Add(new CodeConditionStatement(
                                                  new CodeBinaryOperatorExpression(Codo.getEvent(Event.Name), CodeBinaryOperatorType.IdentityInequality, Codo.Null),
                                                  Codo.getEvent(Event.Name).invoke(Codo.This).statement()));
            }
            //注册
            generator.initMethod.Statements.Add(Codo.getField(field.Name).getProp(AutoCompoGenerator.NAME_OF_ONCLICK)
                                                .getMethod(AutoCompoGenerator.NAME_OF_ADDLISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
            //注销
            generator.clearMethod.Statements.Add(Codo.getField(field.Name).getProp(AutoCompoGenerator.NAME_OF_ONCLICK)
                                                 .getMethod(AutoCompoGenerator.NAME_OF_REMOVELISTENER).invoke(Codo.getMethod(callbackMethod.Name)).statement());
        }
コード例 #8
0
 public abstract void onGen(AutoCompoGenerator generator, Component component, bool isRootComponent, AutoBindFieldInfo info, CodeMemberField field);