Example #1
0
        public static void CheckLocalize()
        {
            var loc = AssetDatabase.LoadAssetAtPath <Localization>("Assets/RefAssets/Launch/Localization.asset");

            loc.Reset();
            loc.currentLang = "zhCN";
            loc.MarkLocalization();

            // 记录自定义的需要本地化的字符串
            foreach (var txt in loc.customTexts)
            {
                if (string.IsNullOrEmpty(txt))
                {
                    continue;
                }

                if (!loc.IsLocalized(txt))
                {
                    AssetPacker.Log("自定义文本添加:{0}", txt);
                }
                loc.Set(txt, txt);
            }

            // 记录UI中需要本地化的字符串
            var paths = AssetDatabase.GetAssetPathsFromAssetBundle("ui.unity3d");

            foreach (var p in paths)
            {
                var prefab = AssetDatabase.LoadAssetAtPath(p, typeof(GameObject)) as GameObject;
                if (!prefab)
                {
                    continue;
                }

                var lbs = prefab.GetComponentsInChildren <UILabel>(true);
                foreach (var lb in lbs)
                {
                    if (!lb.localize)
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(lb.rawText))
                    {
                        continue;
                    }

                    if (!loc.IsLocalized(lb.rawText))
                    {
                        AssetPacker.Log("静态文本添加:{0} @{1}/{2}", lb.rawText,
                                        prefab.name, lb.rectTransform.GetHierarchy(prefab.transform));
                    }
                    loc.Set(lb.rawText, lb.rawText);
                }
            }
            loc.SaveLocalization();

            AssetPacker.Log("检查本地化: 已完成。");
            AssetDatabase.Refresh();
        }
Example #2
0
    private void BuildApp()
    {
        const string fileName = "TSK";

#if UNITY_STANDALONE_WIN
        const string FolderName = "PC";
        const string packName   = fileName + ".exe";
#elif UNITY_STANDALONE_OSX
        const string FolderName = "MAC";
        const string packName   = fileName + ".app";
#elif UNITY_ANDROID
        const string FolderName = "AND";
        const string packName   = fileName + ".apk";
#elif UNITY_IOS
        const string FolderName = "IOS";
        const string packName   = fileName + ".ipa";
#endif

#if RY_DEBUG
        const BuildOptions bo = BuildOptions.AllowDebugging | BuildOptions.ConnectWithProfiler;
#else
        const BuildOptions bo = BuildOptions.None;
#endif
        //var verInfo = VersionMgr.LoadAppVersion();
        VersionMgr.SaveAppVersion(GitTools.getVerInfo());
        AssetDatabase.Refresh();

        //清空PC执行文件目录的缓存文件。
        string ProductPath   = Application.dataPath + "/../../Products";
        string ProductPCPath = Path.Combine(ProductPath, FolderName);
        string BuildName     = ProductPCPath + "/" + packName;

        if (!Directory.Exists(ProductPath))
        {
            Directory.CreateDirectory(ProductPath);
        }
        if (!Directory.Exists(ProductPCPath))
        {
            Directory.CreateDirectory(ProductPCPath);
        }

        //开始打游戏包
        BuildPipeline.BuildPlayer(new string[] {
            "Assets/Scenes/ZERO.unity",
        }, BuildName, AssetPacker.buildTarget, bo);

#if UNITY_STANDALONE
        AssetPacker.Log("Coping Essets ...");
        SystemTools.CopyDirectory(Application.dataPath + "/../Essets", ProductPCPath + "/Essets");
#endif

#if UNITY_IOS
        XCodePostProcess.OnPostProcessBuild(BuildName);
#endif

        AssetPacker.Log("Build Done: " + BuildName);
    }
Example #3
0
    public static void RemoveUnusedAssest()
    {
        AssetDatabase.RemoveUnusedAssetBundleNames();
        var           list = new List <string>(AssetDatabase.GetAllAssetBundleNames());
        DirectoryInfo dir  = new DirectoryInfo(AssetBundleLoader.streamingRootPath);

        FileInfo[] files  = dir.GetFiles("*.unity3d", SearchOption.AllDirectories);
        var        index  = AssetBundleLoader.streamingRootPath.Length + 1;
        int        nCount = 0;

        foreach (var f in files)
        {
            var abName = f.FullName.Substring(index).Replace('\\', '/');
            if (list.Contains(abName))
            {
                continue;
            }

            f.Delete();
            File.Delete(f.FullName + ".manifest");

            nCount += 1;
            AssetPacker.Log("删除废弃的资源包: {0}", abName);
        }

        // Remove empty directories
        var dirList = new List <string>();

        for (int i = 0; i < list.Count; ++i)
        {
            string root = Path.GetDirectoryName(list[i]);
            for (; !string.IsNullOrEmpty(root); root = Path.GetDirectoryName(root))
            {
                if (!dirList.Contains(root))
                {
                    dirList.Add(root);
                }
            }
        }

        var subs = dir.GetDirectories("*", SearchOption.AllDirectories);

        foreach (var d in subs)
        {
            var abRoot = d.FullName.Substring(index).Replace('\\', '/');
            if (dirList.Contains(abRoot))
            {
                continue;
            }

            d.Delete();
            AssetPacker.Log("删除空的资源目录: {0}", abRoot);
        }

        AssetPacker.Log("共删除{0}个废弃的资源包", nCount);
    }
Example #4
0
        public static void ClearIconReference()
        {
            var paths = AssetDatabase.GetAssetPathsFromAssetBundle("ui.unity3d");

            foreach (var p in paths)
            {
                var prefab = AssetDatabase.LoadAssetAtPath(p, typeof(GameObject)) as GameObject;
                if (prefab)
                {
                    GameObject go   = GameObject.Instantiate(prefab);
                    bool       flag = false;

                    var imgs = go.GetComponentsInChildren <Image>(true);
                    foreach (var img in imgs)
                    {
                        if (!img.sprite)
                        {
                            continue;
                        }
                        var ai = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(img.sprite));
                        if (ai && !string.IsNullOrEmpty(ai.assetBundleName))
                        {
                            AssetPacker.Log("清除{0} <- {1}/{2}", img.sprite, prefab.name, img.GetHierarchy(go.transform));
                            img.sprite = null;
                            flag       = true;
                        }
                    }

                    var rawImgs = go.GetComponentsInChildren <RawImage>(true);
                    foreach (var img in rawImgs)
                    {
                        if (!img.texture)
                        {
                            continue;
                        }
                        var ai = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(img.texture));
                        if (ai && !string.IsNullOrEmpty(ai.assetBundleName))
                        {
                            AssetPacker.Log("清除{0} <- {1}/{2}", img.texture, prefab.name, img.GetHierarchy(go.transform));
                            img.texture = null;
                            flag        = true;
                        }
                    }

                    if (flag)
                    {
                        PrefabUtility.ReplacePrefab(go, prefab, ReplacePrefabOptions.ReplaceNameBased);
                    }
                    GameObject.DestroyImmediate(go);
                }
            }
            AssetPacker.Log("清除UI图标引用: 已完成。");
            AssetDatabase.SaveAssets();
        }
Example #5
0
    public static void UpdateAssets()
    {
        var srcDir = AssetPacker.EditorStreamingAssetsPath;
        var dstDir = AssetPacker.StreamingAssetsPath;

        AssetPacker.Log("Copying {0} -> {1}", srcDir, dstDir);

        AssetPacker.ClearStreamingAssets();

        SystemTools.CopyDirectory(srcDir, dstDir, "*.unity3d");

        File.Copy(srcDir + "/filelist.bytes", dstDir + "/filelist.bytes", true);

        AssetPacker.ClearEditorPersistentAssets();

        AssetDatabase.Refresh();

        AssetPacker.Log("Copying Done");
    }
Example #6
0
        public static void MarkLocalize()
        {
            var paths = AssetDatabase.GetAssetPathsFromAssetBundle("ui.unity3d");

            foreach (var p in paths)
            {
                var prefab = AssetDatabase.LoadAssetAtPath(p, typeof(GameObject)) as GameObject;
                if (prefab)
                {
                    GameObject go   = GameObject.Instantiate(prefab);
                    bool       flag = false;

                    var lbs = go.GetComponentsInChildren <UILabel>(true);
                    foreach (var lb in lbs)
                    {
                        var c = lb.name[lb.name.Length - 1];
                        if (c == '=' || c == '_')
                        {
                            if (!lb.localize)
                            {
                                lb.localize = true;
                                flag        = true;
                                AssetPacker.Log("勾选本地化: {0}/{1}", prefab.name, lb.rectTransform.GetHierarchy(go.transform));
                            }
                        }
                        else if (lb.localize)
                        {
                            LogMgr.W("不正确的本地化勾选:{0}/{1}",
                                     prefab.name, lb.rectTransform.GetHierarchy(go.transform));
                        }
                    }

                    if (flag)
                    {
                        AssetPacker.Log("替换:{0}", prefab);
                        PrefabUtility.ReplacePrefab(go, prefab, ReplacePrefabOptions.ReplaceNameBased);
                    }
                    GameObject.DestroyImmediate(go);
                }
            }
            AssetPacker.Log("标志本地化: 已完成。");
            AssetDatabase.SaveAssets();
        }
Example #7
0
    /// <summary>
    /// 目录下的资源以各自的名称独立命名
    /// </summary>
    private static void markSingleAssetName(string rootDir, string pattern, string group)
    {
        var rootPath = "Assets/" + rootDir;
        var dir      = new DirectoryInfo(rootPath);
        var files    = dir.GetFiles(pattern);

        foreach (var f in files)
        {
            var assetPath = rootPath + "/" + f.Name;
            var ai        = AssetImporter.GetAtPath(assetPath);
            if (ai)
            {
                string assetName = Path.GetFileNameWithoutExtension(f.Name);
                string abName    = string.Format("{0}/{1}.unity3d", group, assetName).ToLower();
                ai.assetBundleName = abName;
                AssetPacker.Log("设置了资源名称: {0} -> {1}", ai.assetPath, abName);
            }
        }
    }
Example #8
0
    /// <summary>
    /// 将目录下的资源以目录名命名
    /// </summary>
    private static void markPackedAssetName(
        DirectoryInfo dir,
        string abName,
        string pattern,
        SearchOption searchOption = SearchOption.TopDirectoryOnly)
    {
        int index = Application.dataPath.Length + 1;
        var files = dir.GetFiles(pattern, searchOption);
        int count = 0;

        foreach (var f in files)
        {
            var assetPath = "Assets/" + f.FullName.Substring(index);
            var ai        = AssetImporter.GetAtPath(assetPath);
            if (ai)
            {
                ai.assetBundleName = abName;
                count += 1;
            }
        }
        AssetPacker.Log("设置了资源名称: Assets/{0} -> {1}。共{2}个资源", dir.FullName.Substring(index), abName, count);
    }