Esempio n. 1
0
        public static void ExportUIView()
        {
            var uiObj = Selection.activeGameObject;

            if (null == uiObj)
            {
                return;
            }
            var UIViewName = uiObj.name;

            if (!UIViewName.StartsWith("UI", StringComparison.CurrentCultureIgnoreCase))
            {
                UIViewName = "UI" + UIViewName;
            }
            UIViewName = UIViewName.Substring(0, 2).ToUpper() + UIViewName.Substring(2);  //ToUpperFirst

            uiObj.name = UIViewName;
            uiExportElementDic.Clear();
            nestExportInfoList.Clear();
            UICollection     = null;
            UIComponentIndex = -1;

            ProcessUIPrefab(uiObj);
            GenUIViewCode(UIViewName);
            var prefabPath = Constants.UIExportPrefabPath + UIViewName + ".prefab";

            ColaEditHelper.CreateOrReplacePrefab(uiObj, prefabPath);
            AssetDatabase.Refresh();
        }
Esempio n. 2
0
 private static void ProcessUIPrefab(GameObject gameObject)
 {
     if (null == gameObject)
     {
         return;
     }
     if (gameObject.CompareTag(Constants.UIViewTag))
     {
         UICollection = gameObject.AddSingleComponent <UIComponentCollection>();
         UICollection.Clear();
     }
     foreach (Transform transform in gameObject.transform)
     {
         if (transform.CompareTag(Constants.UIIgnoreTag))
         {
             continue;
         }
         ProcessUIPrefab(transform.gameObject);
         bool isHandled = false;
         foreach (var type in ExportComponentTypes)
         {
             var UIComp = transform.GetComponent(type);
             if (null != UIComp)
             {
                 UIComponentIndex++;
                 UICollection.Add(UIComp);
                 var componentName = "m_" + transform.name;
                 uiExportElementDic[componentName] = UIComponentIndex;
                 isHandled = true;
                 break;
             }
         }
         if (isHandled)
         {
             continue;
         }
         foreach (var type in ExportPropertyTypes)
         {
             var UIComp = transform.GetComponent(type);
             if (null != UIComp && transform.CompareTag(Constants.UIPropertyTag))
             {
                 UIComponentIndex++;
                 UICollection.Add(UIComp);
                 var componentName = "m_" + transform.name;
                 uiExportElementDic[componentName] = UIComponentIndex;
                 isHandled = true;
                 break;
             }
         }
     }
 }
Esempio n. 3
0
        private static void ProcessUIPrefab(GameObject gameObject)
        {
            if (null == gameObject)
            {
                return;
            }
            if (gameObject.CompareTag(Constants.UIViewTag))
            {
                UICollection = gameObject.AddSingleComponent <UIComponentCollection>();
                UICollection.Clear();
            }
            foreach (Transform transform in gameObject.transform)
            {
                if (transform.CompareTag(Constants.UIIgnoreTag))
                {
                    continue;
                }

                //处理UITableview

                if (transform.GetComponent <UITableViewCell>() != null)
                {
                    var info = new ExportInfo();
                    nestExportInfoList.Add(info);
                    var uiTableview = transform.gameObject.GetComponentInParent <UITableView>();
                    info.name = "m_" + uiTableview.transform.name;
                    var collection = transform.gameObject.AddSingleComponent <UIComponentCollection>();
                    collection.Clear();
                    info.uicollection = collection;
                    ProceseUITableview(transform.gameObject, info);
                }
                else
                {
                    ProcessUIPrefab(transform.gameObject);
                }

                bool isHandled = false;
                foreach (var type in ExportComponentTypes)
                {
                    var UIComp = transform.GetComponent(type);
                    if (null != UIComp)
                    {
                        UIComponentIndex++;
                        UICollection.Add(UIComp);
                        var componentName = "m_" + transform.name;
                        uiExportElementDic[componentName] = UIComponentIndex;
                        isHandled = true;
                        break;
                    }
                }
                if (isHandled)
                {
                    continue;
                }
                foreach (var type in ExportPropertyTypes)
                {
                    var UIComp = transform.GetComponent(type);
                    if (null != UIComp && transform.CompareTag(Constants.UIPropertyTag))
                    {
                        UIComponentIndex++;
                        UICollection.Add(UIComp);
                        var componentName = "m_" + transform.name;
                        uiExportElementDic[componentName] = UIComponentIndex;
                        isHandled = true;
                        break;
                    }
                }
            }
        }