Beispiel #1
0
 private static void InsertBindViewFunction(UIWndAssetData data)
 {
     sb.AppendLine(string.Format("function {0}:BindView(uiWnd)", data.UIName));
     InsertTab();
     sb.AppendLine("self.uiWnd = uiWnd");
     InsertTab();
     sb.AppendLine("self.uiref = {}");
     for (int i = 0; i < data.UIComponentDatas.Count; i++)
     {
         var    cData    = data.UIComponentDatas[i];
         string typeCode = GetUIComponentCode(cData.SelectType);
         if (cData.IsSelect)
         {
             InsertTab();
             sb.AppendLine(string.Format("self.uiref.{0} = uiWnd.transform:Find(\"{1}\"){2}", cData.ComponentName, cData.ComponentPath, typeCode));
         }
         for (int j = 0; j < cData.EventDatas.Count; j++)
         {
             string eventName        = string.Concat("on", cData.EventDatas[j].EventType.ToString());
             string eventHandlerName = string.Concat("self.", cData.EventDatas[j].EventHandlerName);
             string goCode           = string.Format("uiWnd.transform:Find(\"{0}\").gameObject", cData.ComponentPath);
             if (cData.IsSelect)
             {
                 goCode = string.Format("self.uiref.{0}.gameObject", cData.ComponentName);
             }
             if (cData.EventDatas[j].EventType > EUIEventType.Deselect)
             {
                 if (cData.IsSelect)
                 {
                     InsertTab();
                     sb.AppendLine(string.Format("self.uiref.{0}.{1}:AddListener({2})", cData.ComponentName, eventName, eventHandlerName));
                 }
                 else
                 {
                     InsertTab();
                     sb.AppendLine(string.Format("self.uiref.{0} = uiWnd.transform:Find(\"{1}\"){2}", cData.ComponentName, cData.ComponentPath, typeCode));
                     InsertTab();
                     sb.AppendLine(string.Format("self.uiref.{0}.{1}:AddListener({2})", cData.ComponentName, eventName, eventHandlerName));
                 }
             }
             else
             {
                 InsertTab();
                 sb.AppendLine(string.Format("CS.CenturyGame.Framework.UI.EventTriggerListener.GetListener({0}):{1}('+', {2})", goCode, eventName, eventHandlerName));
             }
         }
     }
     InsertTab();
     sb.AppendLine("self.uiWnd.OnInit:AddListener(self.onInit)");
     InsertTab();
     sb.AppendLine("self.uiWnd.OnEnter:AddListener(self.onEnter)");
     InsertTab();
     sb.AppendLine("self.uiWnd.OnExit:AddListener(self.onExit)");
     InsertTab();
     sb.AppendLine("self.uiWnd.OnClose:AddListener(self.onClose)");
     InsertTab();
     sb.AppendLine("self.uiWnd.OnUpdate:AddListener(self.onUpdate)");
     InsertEnd();
 }
Beispiel #2
0
 public static void GenerateViewCode(UIWndAssetData data, string path)
 {
     BeginBuild();
     sb.AppendLine(string.Format("{0} = {1}", data.UIName, "{}"));
     sb.AppendLine();
     InsertBindViewFunction(data);
     File.WriteAllText(path, sb.ToString());
 }
Beispiel #3
0
        private UIWndAssetData CreateUIData(string fullPath, string uiName)
        {
            UIWndAssetData asset = null;
            string         path  = fullPath.Replace(Application.dataPath, "Assets");

            asset        = ScriptableObject.CreateInstance <UIWndAssetData>();
            asset.UIName = uiName;
            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.SaveAssets();
            return(asset);
        }
Beispiel #4
0
        public static void MergeLogicCode(UIWndAssetData data, string path)
        {
            BeginBuild();
            string[] readText = File.ReadAllLines(path);
            for (int i = 0; i < readText.Length; i++)
            {
                sb.AppendLine(readText[i]);
            }
            List <string> functionLines = new List <string>();

            ParseLuaFunction(readText, out functionLines);
            MergeLogic(data, readText, functionLines);
            File.WriteAllText(path, sb.ToString());
        }
Beispiel #5
0
        private static void MergeLogic(UIWndAssetData data, string[] oldCodes, List <string> existFuncLines)
        {
            List <string> functionList = new List <string>();

            for (int i = 0; i < data.UIComponentDatas.Count; i++)
            {
                for (int j = 0; j < data.UIComponentDatas[i].EventDatas.Count; j++)
                {
                    string funcName    = data.UIComponentDatas[i].EventDatas[j].EventHandlerName;
                    bool   isExistFunc = false;
                    for (int k = 0; k < existFuncLines.Count; k++)
                    {
                        if (existFuncLines[k].Contains(funcName))
                        {
                            isExistFunc = true;
                            break;
                        }
                    }
                    if (isExistFunc)
                    {
                        continue;
                    }
                    if (!functionList.Contains(funcName))
                    {
                        string[] args = new string[0];
                        if (data.UIComponentDatas[i].EventDatas[j].EventType < EUIEventType.Click)
                        {
                            args    = new string[2];
                            args[0] = "go";
                            args[1] = "evtData";
                        }
                        else if (data.UIComponentDatas[i].EventDatas[j].EventType > EUIEventType.Click)
                        {
                            args    = new string[1];
                            args[0] = "v";
                        }
                        InsertFunction(data.UIName, funcName, true, args);
                        functionList.Add(funcName);
                    }
                }
            }
        }
Beispiel #6
0
 private void Clear()
 {
     uiTransforms = new Transform[0];
     uiData       = null;
     if (uiObject != null)
     {
         DestroyImmediate(uiObject);
     }
     uiObject = null;
     componentMap.Clear();
     componentNames          = new string[0];
     componentPaths          = new string[0];
     m_GameObjectNames       = new string[0];
     m_GameObjectPaths       = new string[0];
     m_TextNames             = new string[0];
     m_TextPaths             = new string[0];
     m_ImageNames            = new string[0];
     m_ImagePaths            = new string[0];
     m_RawImageNames         = new string[0];
     m_RawImagePaths         = new string[0];
     m_ButtonNames           = new string[0];
     m_ButtonPaths           = new string[0];
     m_ToggleNames           = new string[0];
     m_TogglePaths           = new string[0];
     m_SliderNames           = new string[0];
     m_SliderPaths           = new string[0];
     m_ScrollbarNames        = new string[0];
     m_ScrollbarPaths        = new string[0];
     m_DropdownNames         = new string[0];
     m_DropdownPaths         = new string[0];
     m_InputFieldNames       = new string[0];
     m_InputFieldPaths       = new string[0];
     m_ScrollRectNames       = new string[0];
     m_ScrollRectPaths       = new string[0];
     selectComponentIndex    = -1;
     lastComponentIndex      = -1;
     removeEventIndex        = -1;
     selectComponentData     = null;
     lastSelectComponentType = default;
     componentFilterType     = default;
     IsGenerateLogic         = false;
 }
Beispiel #7
0
 public static void OverrideLogicCode(UIWndAssetData data, string path)
 {
     BeginBuild();
     string[] readText = File.ReadAllLines(path);
     foreach (string s in readText)
     {
         if (string.IsNullOrEmpty(s))
         {
             sb.AppendLine();
         }
         else
         {
             sb.AppendLine(s.Insert(0, "--"));
         }
     }
     sb.AppendLine("----------注释前一次代码的分割线----------");
     sb.AppendLine();
     WriteLogic(data);
     File.WriteAllText(path, sb.ToString());
 }
Beispiel #8
0
        private static void WriteLogic(UIWndAssetData data)
        {
            sb.AppendLine(string.Format("require 'ui/{0}View'", data.UIName));
            sb.AppendLine();
            sb.AppendLine(string.Format("local this = {0}", data.UIName));
            sb.AppendLine();
            List <string> functionList = new List <string>();

            for (int i = 0; i < data.UIComponentDatas.Count; i++)
            {
                for (int j = 0; j < data.UIComponentDatas[i].EventDatas.Count; j++)
                {
                    string funcName = data.UIComponentDatas[i].EventDatas[j].EventHandlerName;
                    if (!functionList.Contains(funcName))
                    {
                        string[] args = new string[0];
                        if (data.UIComponentDatas[i].EventDatas[j].EventType < EUIEventType.Click)
                        {
                            args    = new string[2];
                            args[0] = "go";
                            args[1] = "evtData";
                        }
                        else if (data.UIComponentDatas[i].EventDatas[j].EventType > EUIEventType.Click)
                        {
                            args    = new string[1];
                            args[0] = "v";
                        }
                        InsertFunction(data.UIName, funcName, true, args);
                        functionList.Add(funcName);
                    }
                }
            }
            InsertFunction(data.UIName, "onInit", true);
            InsertFunction(data.UIName, "onEnter", true);
            InsertFunction(data.UIName, "onExit", true);
            InsertFunction(data.UIName, "onClose", true);
            InsertFunction(data.UIName, "onUpdate", true);
        }
Beispiel #9
0
 public static void GenerateLogicCode(UIWndAssetData data, string path)
 {
     BeginBuild();
     WriteLogic(data);
     File.WriteAllText(path, sb.ToString());
 }
Beispiel #10
0
        private void CreateUI()
        {
            if (uiObject != null)
            {
                DestroyImmediate(uiObject);
                uiObject = null;
            }
            uiObject     = PrefabUtility.InstantiatePrefab(currPrefab) as GameObject;
            uiTransforms = uiObject.GetComponentsInChildren <Transform>();
            componentMap.Clear();
            List <UIComponentAssetData> textList       = new List <UIComponentAssetData>();
            List <UIComponentAssetData> imageList      = new List <UIComponentAssetData>();
            List <UIComponentAssetData> rawimageList   = new List <UIComponentAssetData>();
            List <UIComponentAssetData> buttonList     = new List <UIComponentAssetData>();
            List <UIComponentAssetData> toggleList     = new List <UIComponentAssetData>();
            List <UIComponentAssetData> sliderList     = new List <UIComponentAssetData>();
            List <UIComponentAssetData> scrollbarList  = new List <UIComponentAssetData>();
            List <UIComponentAssetData> dropdownList   = new List <UIComponentAssetData>();
            List <UIComponentAssetData> inputfieldList = new List <UIComponentAssetData>();
            List <UIComponentAssetData> scrollrectList = new List <UIComponentAssetData>();

            foreach (Transform t in uiTransforms)
            {
                if (t == uiObject.transform)
                {
                    continue;
                }
                UIComponentAssetData data = new UIComponentAssetData();
                data.IsSelect      = false;
                data.ComponentName = t.name;
                data.ComponentPath = Util.GetTransformPath(t, uiObject.transform);
                data.SelectType    = EUIComponentType.GameObject;
                if (!componentMap.ContainsKey(data.ComponentPath))
                {
                    componentMap.Add(data.ComponentPath, data);
                    if (t.GetComponent <Text>() != null)
                    {
                        textList.Add(data);
                    }
                    if (t.GetComponent <Image>() != null)
                    {
                        imageList.Add(data);
                    }
                    if (t.GetComponent <RawImage>() != null)
                    {
                        rawimageList.Add(data);
                    }
                    if (t.GetComponent <Button>() != null)
                    {
                        buttonList.Add(data);
                    }
                    if (t.GetComponent <Toggle>() != null)
                    {
                        toggleList.Add(data);
                    }
                    if (t.GetComponent <Slider>() != null)
                    {
                        sliderList.Add(data);
                    }
                    if (t.GetComponent <Scrollbar>() != null)
                    {
                        scrollbarList.Add(data);
                    }
                    if (t.GetComponent <Dropdown>() != null)
                    {
                        dropdownList.Add(data);
                    }
                    if (t.GetComponent <InputField>() != null)
                    {
                        inputfieldList.Add(data);
                    }
                    if (t.GetComponent <ScrollRect>() != null)
                    {
                        scrollrectList.Add(data);
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("提示", string.Format("{0}中已包含路径为{1}的节点,请检查预制体并重新命名", uiObject.name, data.ComponentPath), "确定");
                }
            }
            #region 组件类型筛选
            m_TextNames = new string[textList.Count];
            m_TextPaths = new string[textList.Count];
            for (int i = 0; i < textList.Count; i++)
            {
                m_TextNames[i] = textList[i].ComponentName;
                m_TextPaths[i] = textList[i].ComponentPath;
            }
            m_ImageNames = new string[imageList.Count];
            m_ImagePaths = new string[imageList.Count];
            for (int i = 0; i < imageList.Count; i++)
            {
                m_ImageNames[i] = imageList[i].ComponentName;
                m_ImagePaths[i] = imageList[i].ComponentPath;
            }
            m_RawImageNames = new string[rawimageList.Count];
            m_RawImagePaths = new string[rawimageList.Count];
            for (int i = 0; i < rawimageList.Count; i++)
            {
                m_RawImageNames[i] = rawimageList[i].ComponentName;
                m_RawImagePaths[i] = rawimageList[i].ComponentPath;
            }
            m_ButtonNames = new string[buttonList.Count];
            m_ButtonPaths = new string[buttonList.Count];
            for (int i = 0; i < buttonList.Count; i++)
            {
                m_ButtonNames[i] = buttonList[i].ComponentName;
                m_ButtonPaths[i] = buttonList[i].ComponentPath;
            }
            m_ToggleNames = new string[toggleList.Count];
            m_TogglePaths = new string[toggleList.Count];
            for (int i = 0; i < toggleList.Count; i++)
            {
                m_ToggleNames[i] = toggleList[i].ComponentName;
                m_TogglePaths[i] = toggleList[i].ComponentPath;
            }
            m_SliderNames = new string[sliderList.Count];
            m_SliderPaths = new string[sliderList.Count];
            for (int i = 0; i < sliderList.Count; i++)
            {
                m_SliderNames[i] = sliderList[i].ComponentName;
                m_SliderPaths[i] = sliderList[i].ComponentPath;
            }
            m_ScrollbarNames = new string[scrollbarList.Count];
            m_ScrollbarPaths = new string[scrollbarList.Count];
            for (int i = 0; i < scrollbarList.Count; i++)
            {
                m_ScrollbarNames[i] = scrollbarList[i].ComponentName;
                m_ScrollbarPaths[i] = scrollbarList[i].ComponentPath;
            }
            m_DropdownNames = new string[dropdownList.Count];
            m_DropdownPaths = new string[dropdownList.Count];
            for (int i = 0; i < dropdownList.Count; i++)
            {
                m_DropdownNames[i] = dropdownList[i].ComponentName;
                m_DropdownPaths[i] = dropdownList[i].ComponentPath;
            }
            m_InputFieldNames = new string[inputfieldList.Count];
            m_InputFieldPaths = new string[inputfieldList.Count];
            for (int i = 0; i < inputfieldList.Count; i++)
            {
                m_InputFieldNames[i] = inputfieldList[i].ComponentName;
                m_InputFieldPaths[i] = inputfieldList[i].ComponentPath;
            }
            m_ScrollRectNames = new string[scrollrectList.Count];
            m_ScrollRectPaths = new string[scrollrectList.Count];
            for (int i = 0; i < scrollrectList.Count; i++)
            {
                m_ScrollRectNames[i] = scrollrectList[i].ComponentName;
                m_ScrollRectPaths[i] = scrollrectList[i].ComponentPath;
            }
            m_GameObjectNames = new string[componentMap.Count];
            m_GameObjectPaths = new string[componentMap.Count];
            int index = 0;
            var e     = componentMap.GetEnumerator();
            while (e.MoveNext())
            {
                m_GameObjectNames[index] = e.Current.Value.ComponentName;
                m_GameObjectPaths[index] = e.Current.Value.ComponentPath;
                index++;
            }
            #endregion
            componentNames = m_GameObjectNames;
            componentPaths = m_GameObjectPaths;
            string fullPath = string.Concat(dataRoot, currPrefab.name, ".asset");
            if (File.Exists(fullPath))
            {
                uiData = AssetDatabase.LoadAssetAtPath <UIWndAssetData>(fullPath);
                AssetToEdit();
            }
            else
            {
                uiData = CreateUIData(fullPath, currPrefab.name);
            }
        }