Esempio n. 1
0
        ///<summary>
        /// 处理要生成的LuaScripts
        /// mUINameLow:开头小写的UIName
        /// assetPath:prefab的AB包名
        /// prefabName:prefab的资源名
        ///</summary>
        void DealLuaScripts(string mUINameLow, string assetPath, string prefabName)
        {
            //处理View.lua
            string viewLua = UICreatorPathTools.ReadLuaText(ScriptName.View).Replace("ClassName", (mUIName + "View"));

            viewLua = viewLua.Replace("ViewName", (mUINameLow + "View"));
            viewLua = viewLua.Replace("AssetPath", assetPath);
            viewLua = viewLua.Replace("AssetName", prefabName);

            //处理model.lua
            string modelLua  = string.Empty;
            string modelName = "nil";

            if (isNeedModel)
            {
                modelName = "\"" + mUIName.ToLower() + "_model\"";
                modelLua  = UICreatorPathTools.ReadLuaText(ScriptName.Model).Replace("ClassName", (mUIName + "Model"));
                modelLua  = modelLua.Replace("ModelName", (mUINameLow + "Model"));
            }

            //处理module.lua
            string moduleLua = UICreatorPathTools.ReadLuaText(ScriptName.Module).Replace("ClassName", (mUIName + "Module"));

            moduleLua = moduleLua.Replace("PackageName", packageNames[packageIndex]);
            moduleLua = moduleLua.Replace("UIName", mUIName.ToLower());
            moduleLua = moduleLua.Replace("ModelName", modelName);

            string outLuaDir = UICreatorPathTools.GetLuaDir(packageNames[packageIndex], mUIName);

            if (!Directory.Exists(outLuaDir))
            {
                Directory.CreateDirectory(outLuaDir);
            }

            string viewLuaPath = outLuaDir + mUIName.ToLower() + "_view.lua";

            if (File.Exists(viewLuaPath))
            {
                FileUtil.DeleteFileOrDirectory(viewLuaPath);
            }
            FileUtility.SaveFile(viewLuaPath, viewLua);

            string moduleLuaPath = outLuaDir + mUIName.ToLower() + "_module.lua";

            if (File.Exists(moduleLuaPath))
            {
                FileUtil.DeleteFileOrDirectory(moduleLuaPath);
            }
            FileUtility.SaveFile(moduleLuaPath, moduleLua);

            if (isNeedModel)
            {
                string modelLuaPath = outLuaDir + mUIName.ToLower() + "_model.lua";
                if (File.Exists(modelLuaPath))
                {
                    FileUtil.DeleteFileOrDirectory(modelLuaPath);
                }
                FileUtility.SaveFile(modelLuaPath, modelLua);
            }
        }
Esempio n. 2
0
        void DealPrefab(string prefabName)
        {
            string prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_Null.prefab";

            switch (uiTypeIndex)
            {
            case 1:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowBase.prefab";
                break;

            case 2:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowDialog.prefab";
                break;

            case 3:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowFullScreen.prefab";
                break;
            }

            Debug.Log(prefabPath);

            GameObject go = HelpFunEditor.InstantiateGameObject(GameObject.Find(UICreatorPathTools.mTestViewPath).gameObject,
                                                                AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath)
                                                                );

            var eventCollector = go.GetComponent <UGUIExtend.GameEventCollector>();

            eventCollector.packageName = packageNames[packageIndex].ToLower();
            eventCollector.moduleName  = mUIName.ToLower();

            SetGameObject(go);

            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.7f);

            string outResDir = UICreatorPathTools.GetResDir(packageNames[packageIndex], mUIName);

            if (!Directory.Exists(outResDir))
            {
                Directory.CreateDirectory(outResDir);
            }
            string createPrefab = string.Format("{0}" + outResDir.Replace(Application.dataPath, "") + prefabName + ".prefab", "Assets");           //(outResDir+ prefabName + ".prefab").Replace(Application.dataPath.Replace("Assets/",""),"");

            Debug.Log("createPrefab = " + createPrefab);
            Object tempPrefab = PrefabUtility.CreateEmptyPrefab(createPrefab);

            PrefabUtility.ReplacePrefab(go, tempPrefab);

            GameObject.DestroyImmediate(go);

            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.8f);

            go = HelpFunEditor.InstantiatePrefab(GameObject.Find(UICreatorPathTools.mTestViewPath).gameObject,
                                                 AssetDatabase.LoadAssetAtPath <GameObject>(createPrefab)
                                                 );

            SetGameObject(go);
            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.9f);
        }