Inheritance: UnityEngine.ScriptableObject
Beispiel #1
0
        /*[MenuItem("Tools/Make Selected Atlas", false, 300)]
         * public static void ImportSelectedAtlas()
         * {
         *  UnityEngine.Object[] gos = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
         *
         *  List<string> resPaths = new List<string>();
         *
         *  for (int i = 0, count = gos.Length; i < count; i++)
         *  {
         *      string path = AssetDatabase.GetAssetPath(gos[i]);
         *      if (path.Contains("Res/Atlas"))
         *          resPaths.Add(path);
         *  }
         *
         *  if (resPaths.Count == 0)
         *  {
         *      Debugger.Log("please select a texture or a contain texture of folder !");
         *      return;
         *  }
         *  string spriteDir = Application.dataPath + "/Res/Resources/sprite";
         *
         *  int total = resPaths.Count;
         *  int current = 0;
         *  foreach (string assetPath in resPaths)
         *  {
         *      Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
         *      GameObject go = new GameObject(sprite.name);
         *      go.AddComponent<SpriteRenderer>().sprite = sprite;
         *      string dirName = spriteDir + "/" + assetPath.Replace(@"Assets/Res/Atlas/", string.Empty);
         *      dirName = dirName.Replace(sprite.name + ".png", string.Empty);
         *      dirName = dirName.Replace(sprite.name + ".tga", string.Empty);
         *      if (!Directory.Exists(dirName))
         *      {
         *          Directory.CreateDirectory(dirName);
         *      }
         *      string allPath = dirName + sprite.name + ".prefab";
         *      string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
         *
         *      PrefabUtility.CreatePrefab(prefabPath, go, ReplacePrefabOptions.ReplaceNameBased);
         *      GameObject.DestroyImmediate(go);
         *      current++;
         *      EditorUtility.DisplayProgressBar("打包图集", "当前进度", current / (float)total);
         *  }
         *  EditorUtility.ClearProgressBar();
         *  AssetDatabase.SaveAssets();
         *  AssetDatabase.Refresh();
         * }
         *
         * [MenuItem("Tools/AtlasMaker", false, 300)]
         * static private void Make()
         * {
         *  string spriteDir = Application.dataPath + "/Res/Resources/sprite";
         *
         *  if (Directory.Exists(spriteDir))
         *  {
         *      Directory.Delete(spriteDir, true);
         *      Directory.CreateDirectory(spriteDir);
         *  }
         *
         *  DirectoryInfo rootDirInfo = new DirectoryInfo(Application.dataPath + "/Res/Atlas");
         *  int total = rootDirInfo.GetFiles("*.png", SearchOption.AllDirectories).Length;
         *  total += rootDirInfo.GetFiles("*.tga", SearchOption.AllDirectories).Length;
         *  int current = 0;
         *  foreach (DirectoryInfo dirInfo in rootDirInfo.GetDirectories())
         *  {
         *      foreach (FileInfo pngFile in dirInfo.GetFiles("*.png", SearchOption.AllDirectories))
         *      {
         *          string allPath = pngFile.FullName;
         *          string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
         *          Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
         *          GameObject go = new GameObject(sprite.name);
         *          go.AddComponent<SpriteRenderer>().sprite = sprite;
         *          string dirName = spriteDir + "/" + dirInfo.Name;
         *          if (!Directory.Exists(dirName))
         *          {
         *              Directory.CreateDirectory(dirName);
         *          }
         *          allPath = dirName + "/" + sprite.name + ".prefab";
         *          string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
         *
         *          PrefabUtility.CreatePrefab(prefabPath, go, ReplacePrefabOptions.ReplaceNameBased);
         *          GameObject.DestroyImmediate(go);
         *          current++;
         *          EditorUtility.DisplayProgressBar("打包图集", "当前进度", current / (float)total);
         *      }
         *
         *      foreach (FileInfo tgaFile in dirInfo.GetFiles("*.tga", SearchOption.AllDirectories))
         *      {
         *          string allPath = tgaFile.FullName;
         *          string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
         *          Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
         *          GameObject go = new GameObject(sprite.name);
         *          go.AddComponent<SpriteRenderer>().sprite = sprite;
         *          string dirName = spriteDir + "/" + dirInfo.Name;
         *          if (!Directory.Exists(dirName))
         *          {
         *              Directory.CreateDirectory(dirName);
         *          }
         *          allPath = dirName + "/" + sprite.name + ".prefab";
         *          string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
         *
         *          PrefabUtility.CreatePrefab(prefabPath, go, ReplacePrefabOptions.ReplaceNameBased);
         *          GameObject.DestroyImmediate(go);
         *          current++;
         *          EditorUtility.DisplayProgressBar("打包图集", "当前进度", current / (float)total);
         *      }
         *  }
         *  EditorUtility.ClearProgressBar();
         *  AssetDatabase.SaveAssets();
         *  AssetDatabase.Refresh();
         * }
         *
         * [MenuItem("Tools/CheckAtlas", false, 300)]
         * public static void CheckAtlas()
         * {
         *  DirectoryInfo rootDirInfo = new DirectoryInfo(Application.dataPath + "/Res/Resources/sprite");
         *  bool isMiss = false;
         *  int count = 0;
         *  foreach (DirectoryInfo dirInfo in rootDirInfo.GetDirectories())
         *  {
         *      foreach (FileInfo prefabFile in dirInfo.GetFiles("*.prefab", SearchOption.AllDirectories))
         *      {
         *          string allPath = prefabFile.FullName;
         *          string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
         *          //assetPath = assetPath.Replace(".prefab",string.Empty);
         *          //Debugger.Log(assetPath);
         *          GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
         *          SpriteRenderer sprite = go.GetComponent<SpriteRenderer>();
         *          if (!sprite)
         *          {
         *              count++;
         *              isMiss = true;
         *              Debugger.LogError(assetPath + " is miss sprite !");
         *          }
         *      }
         *  }
         *
         *  if (isMiss)
         *      Debugger.LogError("atlas make fail! miss count:" + count);
         *  else
         *      Debugger.Log("atlas make success !");
         * }*/

        private static void ResPacker(UnityEngine.Object[] assets, string assetName)
        {
            if (assets == null)
            {
                return;
            }

            string path = "Assets/Res/Resources/sprite/" + assetName + "_asset.asset";

            UnityEngine.Object assetPackerObj = AssetDatabase.LoadMainAssetAtPath(path);
            AssetPacker        assetPacker    = null;

            if (assetPackerObj == null)
            {
                assetPacker      = ScriptableObject.CreateInstance <AssetPacker>();
                assetPacker.name = assetName;
                AssetDatabase.CreateAsset(assetPacker, path);
            }
            else
            {
                assetPacker = assetPackerObj as AssetPacker;
            }

            assetPacker.mAssets   = assets;
            assetPacker.hideFlags = HideFlags.NotEditable;
            EditorUtility.SetDirty(assetPacker);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Beispiel #2
0
    private static void PackRes(UnityEngine.Object[] assets)
    {
        if (assets == null)
        {
            return;
        }

        UnityEngine.Object assetPackerObj = AssetDatabase.LoadMainAssetAtPath(mPackResFilePath);
        AssetPacker        assetPacker    = null;

        if (assetPackerObj == null)
        {
            assetPacker      = ScriptableObject.CreateInstance <AssetPacker>();
            assetPacker.name = "res_asset_packer";
            AssetDatabase.CreateAsset(assetPacker, mPackResFilePath);
        }
        else
        {
            assetPacker = assetPackerObj as AssetPacker;
        }

        assetPacker.mAssets   = assets;
        assetPacker.hideFlags = HideFlags.NotEditable;
        DoMarkAssetBundle(assetPacker);
        EditorUtility.SetDirty(assetPacker);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Beispiel #3
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();
        }
Beispiel #4
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);
    }
    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);
    }
Beispiel #6
0
 private void ClearAssets()
 {
     if (EditorUtility.DisplayDialog(
             "注意",
             "清空已生成的资源包缓存后,\n之后生成资源包操作将重新生成所有资源。",
             "确定", "取消"))
     {
         AssetPacker.ClearEditorStreamingAssets();
     }
 }
Beispiel #7
0
    // Use this for initialization
    void Start()
    {
        Application.runInBackground = true;
        assetPacker = GetComponent <AssetPacker>();

        currentState = UpdateWaitingForResourcesLoaded;

#if UNITY_EDITOR
        skinDirectory = Directory.GetParent(Application.dataPath) + "\\" + skinDirectory;
#else
        skinDirectory = DirectoryHelper.GetMainDirectory() + "\\" + skinDirectory;
#endif

        Debug.Log("Loading skin from directory " + skinDirectory);

        if (Directory.Exists(skinDirectory))
        {
            SetupResourcesToLoad();

            // Collect all the files
            string[] filepaths = GetAllFiles(skinDirectory).ToArray();
            Dictionary <string, string> filepathsDictionary = new Dictionary <string, string>();

            int bgCount = 0;

            foreach (string path in filepaths)
            {
                filepathsDictionary.Add(Path.GetFileNameWithoutExtension(path), path);

                // System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(path), @"background-/([0-9]+)$");
                //if ( Path.GetFileNameWithoutExtension(path).Contains("background-\d+"))
                if (System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(path), @"background-[0-9]+").Success)
                {
                    resources.Add(new CustomTexture(Path.GetFileNameWithoutExtension(path), 1920, 1080));
                    ++bgCount;
                }
            }

            Debug.Log("Total backgrounds: " + bgCount);

            foreach (CustomResource resource in resources)
            {
                if (resource.InitWWW(filepathsDictionary))
                {
                    resourcesLoading.Add(resource);
                    resourcesDictionary.Add(resource.name, resource);
                }
            }
        }
        else
        {
            Debug.LogError("Custom Resources not found");
        }
    }
Beispiel #8
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();
        }
 public void clearAltas(string altasName)
 {
     if (_packers.ContainsKey(altasName))
     {
         AssetPacker packer = _packers[altasName];
         _packers.Remove(altasName);
         Destroy(packer.gameObject);
     }
     else
     {
         Debug.LogError("can not remove altas,because it can not find altas" + altasName);
     }
 }
        void Start()
        {
            // We just copy and paste files, so you don't have to do it manually.
            CopyPasteFoldersAndPNG(Application.dataPath + "/RuntimeSpriteSheetsGenerator/Demos/Sprites", Application.persistentDataPath);

            string[] files = Directory.GetFiles(Application.persistentDataPath + "/Textures", "*.png");

            assetPacker = GetComponent <AssetPacker>();

            assetPacker.OnProcessCompleted.AddListener(LaunchAnimations);

            assetPacker.AddTexturesToPack(files);
            assetPacker.Process();
        }
Beispiel #11
0
    static int set_mAssetPacker(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameResFactory obj  = (GameResFactory)o;
            AssetPacker    arg0 = (AssetPacker)ToLua.CheckUnityObject(L, 2, typeof(AssetPacker));
            obj.mAssetPacker = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index mAssetPacker on a nil value" : e.Message));
        }
    }
Beispiel #12
0
    static int get_mAssetPacker(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            GameResFactory obj = (GameResFactory)o;
            AssetPacker    ret = obj.mAssetPacker;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index mAssetPacker on a nil value" : e.Message));
        }
    }
Beispiel #13
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();
        }
Beispiel #14
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);
            }
        }
    }
Beispiel #15
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");
    }
Beispiel #16
0
        public static void PackAssets(string outputFolder, int packSize, string memoryFileExts,
                                      string unpackedFileExts, string assetFolder, bool compression)
        {
            AssetPacker.MaxsizeKilobytes = packSize;

            Console.WriteLine("Parsing File info...");

            AssetPackageInfo info = CreatePackageInfo(memoryFileExts, unpackedFileExts);

            Console.WriteLine("Creating Asset Pack(" + assetFolder + ")...");
            AssetResult ret = AssetPacker.PackAssets(assetFolder, outputFolder, info, compression);

            Console.WriteLine("Packaging " + ret.IndexList.Count + " Assets in " + ret.Packs.Count + " Packs.");

            Console.WriteLine("Saving Asset Pack to " + outputFolder);
            ret.Save();

            Console.WriteLine("Packaging Assets Finished.");
        }
        public override void LoadSounds()
        {
            mSoundDict.Clear();
            var dir = Path.Combine("resources", "sounds");

            if (!Directory.Exists(dir))
            {
                if (!Directory.Exists(Path.Combine("resources", "packs")))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            else
            {
                var items = Directory.GetFiles(dir, "*.wav");
                for (var i = 0; i < items.Length; i++)
                {
                    var filename = items[i].Replace(dir, "").TrimStart(Path.DirectorySeparatorChar).ToLower();
                    mSoundDict.Add(
                        RemoveExtension(filename),
                        new MonoSoundSource(
                            Path.Combine(dir, filename), Path.Combine(dir, items[i].Replace(dir, "").TrimStart(Path.DirectorySeparatorChar))
                            )
                        );
                }
            }

            // If we have a sound index file, load from it!
            if (File.Exists(Path.Combine("resources", "packs", "sound.index")))
            {
                SoundPacks = new AssetPacker(Path.Combine("resources", "packs", "sound.index"), Path.Combine("resources", "packs"));
                foreach (var item in SoundPacks.FileList)
                {
                    if (!mSoundDict.ContainsKey(RemoveExtension(item).ToLower()))
                    {
                        mSoundDict.Add(
                            RemoveExtension(item).ToLower(),
                            new MonoSoundSource(item, item)
                            );
                    }
                }
            }
        }
Beispiel #18
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);
    }
Beispiel #19
0
        private static void PrepareAssemblyFiles(string packPrefix, string[] files, Assembly asm,
                                                 AssemblyFileFactory factory)
        {
            int indexList = HasPackageFiles(files);

            if (indexList == -1)
            {
                return;
            }

            Logger.Log(LogType.Log, "Found Packed Files in Assembly: " + packPrefix, 10);

            string dir = packPrefix + "/packs";

            if (dir.StartsWith("/"))
            {
                dir = dir.Remove(0, 1);
            }

            string[] packs = IOManager.GetFiles(dir, "*.pack"); //Get only *.pack files
            Stream[] s     = new Stream[packs.Length];
            for (int i = 0; i < packs.Length; i++)
            {
                s[i] = IOManager.GetStream(packs[i]);
            }

            Stream indexStream = IOManager.GetStream(files[indexList]);
            Dictionary <string, Tuple <int, MemoryStream> >
            filesToUnpack =
                AssetPacker.UnpackAssets(indexStream,
                                         s); //Get Files in the Packs that need to be unpacked to file system

            if (filesToUnpack.Count > 0)
            {
                UnpackAssets(filesToUnpack);
            }


            Stream idxStream = IOManager.GetStream(files[indexList]);
            List <Tuple <string, AssetPointer> > packedFiles =
                AssetPacker.GetPointers(idxStream, packs, out bool compression);

            Logger.Log(LogType.Log,
                       "Parsing " + packedFiles.Count + " File from " + files[indexList] + " in " + packs.Length +
                       " Packages.", 10);

            foreach (Tuple <string, AssetPointer> assetPointer in packedFiles)
            {
                string assemblyPath = SanitizeFilename(packPrefix + "/" + assetPointer.Item1);
                string virtualPath  = SanitizeFilename(assetPointer.Item2.Path);
                if (_assemblyFiles.ContainsKey(virtualPath))
                {
                    Logger.Log(LogType.Log, "Overwriting File: " + assemblyPath + " => " + virtualPath, 10);
                    _assemblyFiles[virtualPath] =
                        factory(assemblyPath, compression, asm,
                                assetPointer.Item2);
                }
                else
                {
                    _assemblyFiles.Add(virtualPath,
                                       factory(assemblyPath, compression, asm,
                                               assetPointer.Item2));
                }
            }
        }
Beispiel #20
0
 private void EncryptLua()
 {
     AssetPacker.EncryptLua();
     AssetDatabase.Refresh();
 }
Beispiel #21
0
    // Use this for initialization
    void Start()
    {
        Application.runInBackground = true;
        assetPacker = GetComponent <AssetPacker>();

        currentState = UpdateWaitingForResourcesLoaded;

#if UNITY_EDITOR
        skinDirectory = Directory.GetParent(Application.dataPath) + "\\" + skinDirectory;
#else
        skinDirectory = DirectoryHelper.GetMainDirectory() + "\\" + skinDirectory;
#endif

        Debug.Log("Loading skin from directory " + skinDirectory);

        if (Directory.Exists(skinDirectory))
        {
            SetupResourcesToLoad();

            // Collect all the files
            string[] filepaths = GetAllFiles(skinDirectory).ToArray();
            Dictionary <string, string> filepathsDictionary = new Dictionary <string, string>();

            int bgCount = 0;

            foreach (string path in filepaths)
            {
                string assetKey = Path.GetFileNameWithoutExtension(path);
                if (!filepathsDictionary.ContainsKey(assetKey))
                {
                    filepathsDictionary.Add(assetKey, path);
                }
                else
                {
                    Debug.LogWarning("Found a duplicate custom asset with under a different file extenstion. Ignoring asset " + path);
                    continue;
                }

                // Checking if the file provided is a background. We have no limit on the amount of backgrounds we can load, so we can't pre-define them like we do above.
                if (System.Text.RegularExpressions.Regex.Match(assetKey, @"background-[0-9]+").Success)
                {
                    resources.Add(new CustomTexture(assetKey, 1920, 1080));
                    ++bgCount;
                }
            }

            Debug.Log("Total backgrounds: " + bgCount);

            foreach (CustomResource resource in resources)
            {
                if (resource.InitWWW(filepathsDictionary))
                {
                    resourcesLoading.Add(resource);
                    resourcesDictionary.Add(resource.name, resource);
                }
            }
        }
        else
        {
            Debug.LogError("Custom Resources not found");
        }
    }
Beispiel #22
0
 private void PackAssets()
 {
     AssetPacker.EncryptLua();
     AssetPacker.PackAssets();
     AssetPacker.GenFileList();
 }