예제 #1
0
 protected string GetFuncName(string var)
 {
     if (!string.IsNullOrEmpty(var))
     {
         var = UILuaTools.GetVarName(var);
         string value = "set_" + var + "_" + this.NowType;
         return(value);
     }
     return(null);
 }
예제 #2
0
        /// <summary>
        /// 获取go的所有节点下,有特殊标记对应生成的定义,点击绑定,设置函数
        /// </summary>
        /// <param name="Obj"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        static public LuaFileData GetComponentInfo(GameObject Obj, string filePath)
        {
            string           className = FileTools.GetFilename(filePath, false);
            Transform        root      = Obj.transform;
            List <Transform> tfArray   = new List <Transform>();

            UITools.GetComponentsExclude <Transform>(root, tfArray, go => go.GetComponent <LuaBehaviour>() == null);
            tfArray.Sort(delegate(Transform t1, Transform t2) {
                return(t1.name.CompareTo(t2.name));
            });
            List <string> defineList                      = new List <string>();
            List <string> find_component                  = new List <string>();
            List <string> set_function                    = new List <string>();
            List <string> defaultTextComponent            = new List <string>();
            Dictionary <string, string> click_function    = new Dictionary <string, string>();
            List <Transform>            component_examine = new List <Transform>();

            //清空定义列表
            ClearDefine();
            foreach (Transform child in tfArray)
            {
                string childName = child.name;
                string obj_name  = null;
                string stype     = null;
                IsKeyword(childName, ref obj_name, ref stype);
                if (stype != null)
                {
                    string sstype = stype;
                    if (stype.Trim() != sstype)
                    {
                        bool       b  = UnityEditor.EditorUtility.DisplayDialog("控件名非法", "控件名首位含有空白字符", "OK");
                        GameObject go = child.gameObject;
                        if (b && go != null)
                        {
                            EditorGUIUtility.PingObject(go);
                            Selection.activeGameObject = go;
                        }
                        return(null);
                    }
                    string    widget_path = UILuaTools.GetPathByRoot(root, child);
                    Transform oldtrans    = ListContains(component_examine, childName);
                    if (oldtrans != null)
                    {
                        string     componentPath = root.name + "/" + widget_path;
                        string     desc          = string.Format("控件{0}重复,重复路径为:{1}", childName, componentPath);
                        bool       b             = UnityEditor.EditorUtility.DisplayDialog("控件名重复", desc, "OK");
                        GameObject go            = child.gameObject;
                        if (b && go != null)
                        {
                            EditorGUIUtility.PingObject(go);
                            Selection.activeGameObject = go;
                        }
                        return(null);
                    }
                    else
                    {
                        component_examine.Add(child);
                    }
                    ComponentBase component = ComponentMgr.Instance.GetObject(stype);
                    if (component != null)
                    {
                        string var           = obj_name;
                        string componentType = ComponentMgr.Instance.GetComponentType(component.NowType);
                        string define        = component.GetDefine(componentType, var);
                        string defineName    = component.GetVarByName(var);
                        //将对于变量名的object添加进列表,后面给luaBehaviour赋值
                        if (!string.IsNullOrEmpty(defineName))
                        {
                            Component c = child.gameObject.GetComponent(componentType);
                            if (c == null)
                            {
                                AddDefine(defineName, child.gameObject);
                            }
                            else
                            {
                                AddDefine(defineName, c);
                            }
                        }
                        string set_comp = component.Set(className, var, var);
                        //buttom特殊处理,与设置方法分开
                        if (stype == ComponentType.Button)
                        {
                            string find_comp = component.Find(var, widget_path);
                            if (find_comp != null)
                            {
                                find_component.Add(find_comp);
                            }
                            ButtonMould button = component as ButtonMould;
                            string      key    = button.GetFuncName(var);
                            if (set_comp != null)
                            {
                                click_function.Add(key, set_comp);
                            }
                        }
                        else
                        {
                            if (set_comp != null)
                            {
                                set_function.Add(set_comp);
                            }
                        }
                        if (define != null)
                        {
                            defineList.Add(define);
                        }
                    }
                }
            }
            return(new LuaFileData(className, defineList, find_component, set_function, null, click_function, defaultTextComponent));
        }