Exemplo n.º 1
0
        IEnumerator GenerateList()
        {
            SelectedCategory = Category.value;
            if (!DontReload)
            {
                Clean();
            }
            else if (LastSelection)
            {
                LastSelection.SetActive(false);
            }
            Loading.SetActive(true);

            GeneratedId = 0;
            int Counter = 0;

            Layout.enabled     = true;
            SizeFitter.enabled = true;

            LastLoadedType = Category.value;

            if (LoadedEnvPaths[EnvType.value] == CurrentMapFolderPath)
            {
                if (MapLuaParser.IsMapLoaded)
                {
                    string LoadPath = MapLuaParser.LoadedMapFolderPath + "env/" + CategoryPaths[LastLoadedType];
                    Debug.Log("Try load assets from: " + LoadPath);
                    if (Directory.Exists(LoadPath))
                    {
                        string[] AllFiles = Directory.GetFiles(LoadPath, "*", SearchOption.AllDirectories);
                        Debug.Log("Found " + AllFiles.Length + " files in map folder");

                        for (int i = 0; i < AllFiles.Length; i++)
                        {
                            string path = AllFiles[i];

                            // Load Texture
                            switch (LastLoadedType)
                            {
                            case 0:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Texture);
                                }
                                break;

                            case 1:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Decal);
                                }
                                break;

                            case 2:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Decal);
                                }
                                break;

                            case 3:
                                if (path.ToLower().EndsWith(".bp"))
                                {
                                    Counter += GenerateMapPropButton(LoadPath, path, Prefab_Prop);
                                }
                                break;
                            }

                            if (Counter >= PauseEveryLoadedAsset)
                            {
                                Counter = 0;
                                yield return(null);
                            }
                        }
                        yield return(null);

                        yield return(null);
                    }
                }
            }
            else if (LoadedEnvPaths[EnvType.value] == CurrentMapPath)
            {
                if (LastLoadedType == 3)
                {
                    int Count = EditMap.PropsInfo.AllPropsTypes.Count;
                    Debug.Log("Found props: " + Count);

                    for (int i = 0; i < Count; i++)
                    {
                        LoadAtPath(GetGamedataFile.LocalBlueprintPath(EditMap.PropsInfo.AllPropsTypes[i].Blueprint), EditMap.PropsInfo.AllPropsTypes[i].PropObject.BP.Name);

                        Counter++;
                        if (Counter >= PauseEveryLoadedAsset)
                        {
                            Counter = 0;
                            yield return(null);
                        }
                    }
                }
                else
                {
                    yield return(null);

                    yield return(null);
                }
            }
            else
            {
                ZipFile zf     = null;
                ZipFile zf_faf = null;
                SelectedDirectory = ("env/" + EnvType.options[EnvType.value].text + "/" + CategoryPaths[LastLoadedType]).ToLower();
                try
                {
                    zf     = GetGamedataFile.GetZipFileInstance(GetGamedataFile.EnvScd);
                    zf_faf = GetGamedataFile.GetFAFZipFileInstance(GetGamedataFile.EnvScd);
                    bool HasFafFile = zf_faf != null;


                    yield return(null);

                    bool Breaked = false;
                    //bool ReplacedByFaf = false;

                    ZipEntry Current;
                    foreach (ZipEntry zipEntry in zf)
                    {
                        Current = zipEntry;

                        if (!Current.IsFile)
                        {
                            continue;
                        }

                        if (!IsProperFile(Current.Name))
                        {
                            continue;
                        }

                        //ReplacedByFaf = false;
                        if (HasFafFile)
                        {
                            ZipEntry FafEntry = zf_faf.GetEntry(Current.Name);
                            if (FafEntry != null && FafEntry.IsFile)
                            {
                                //Debug.Log("Replace " + Current.Name + "\nwith FAF file: " + FafEntry.Name);
                                Current = FafEntry;
                                //ReplacedByFaf = true;
                            }
                        }

                        if (LoadZipEntry(ref Current, out Breaked))
                        {
                            continue;
                        }

                        //if (ReplacedByFaf)
                        //	Debug.Log("Replace with FAF file: " + Current.Name);

                        if (Breaked)
                        {
                            break;
                        }

                        GeneratedId++;
                        Counter++;
                        if (Counter >= PauseEveryLoadedAsset)
                        {
                            Counter = 0;
                            yield return(null);
                        }
                    }

                    if (!Breaked && HasFafFile)
                    {
                        string[] NewFiles = GetGamedataFile.GetNewFafFiles(GetGamedataFile.EnvScd);

                        for (int i = 0; i < NewFiles.Length; i++)
                        {
                            if (!IsProperFile(NewFiles[i]))
                            {
                                continue;
                            }

                            Current = zf_faf.GetEntry(NewFiles[i]);
                            if (LoadZipEntry(ref Current, out Breaked))
                            {
                                continue;
                            }
                            //Debug.Log("New faf file: " + Current.Name);

                            if (Breaked)
                            {
                                break;
                            }

                            GeneratedId++;
                            Counter++;
                            if (Counter >= PauseEveryLoadedAsset)
                            {
                                Counter = 0;
                                yield return(null);
                            }
                        }
                    }
                }
                finally
                {
                    /*
                     * if (zf != null)
                     * {
                     *      zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                     *      zf.Close(); // Ensure we release resources
                     * }
                     */
                }
            }

            yield return(null);

            Layout.enabled     = false;
            SizeFitter.enabled = false;

            Loading.SetActive(false);
            GeneratingList = null;
        }
        IEnumerator GenerateList()
        {
            SelectedCategory = Category.value;
            if (!DontReload)
            {
                Clean();
            }
            else if (LastSelection)
            {
                LastSelection.SetActive(false);
            }
            Loading.SetActive(true);

            int Counter = 0;
            int Id      = 0;

            Layout.enabled     = true;
            SizeFitter.enabled = true;



            if (LoadedEnvPaths[EnvType.value] == CurrentMapFolderPath)
            {
                if (MapLuaParser.IsMapLoaded)
                {
                    string LoadPath = MapLuaParser.LoadedMapFolderPath + "env/" + CategoryPaths[Category.value];
                    Debug.Log("Try load assets from: " + LoadPath);
                    if (Directory.Exists(LoadPath))
                    {
                        string[] AllFiles = Directory.GetFiles(LoadPath, "*", SearchOption.AllDirectories);
                        Debug.Log("Found " + AllFiles.Length + " files in map folder");

                        for (int i = 0; i < AllFiles.Length; i++)
                        {
                            string path = AllFiles[i];

                            // Load Texture
                            switch (Category.value)
                            {
                            case 0:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Texture);
                                }
                                break;

                            case 1:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Decal);
                                }
                                break;

                            case 2:
                                if (path.ToLower().EndsWith(".dds"))
                                {
                                    Counter += GenerateMapTextureButton(LoadPath, path, Prefab_Decal);
                                }
                                break;

                            case 3:
                                if (path.ToLower().EndsWith(".bp"))
                                {
                                    Counter += GenerateMapPropButton(LoadPath, path, Prefab_Prop);
                                }
                                break;
                            }

                            if (Counter >= PauseEveryLoadedAsset)
                            {
                                Counter = 0;
                                yield return(null);
                            }
                        }
                        yield return(null);

                        yield return(null);
                    }
                }
            }
            else if (LoadedEnvPaths[EnvType.value] == CurrentMapPath)
            {
                if (Category.value == 3)
                {
                    int Count = EditMap.PropsInfo.AllPropsTypes.Count;
                    Debug.Log("Found props: " + Count);

                    for (int i = 0; i < Count; i++)
                    {
                        LoadAtPath(GetGamedataFile.LocalBlueprintPath(EditMap.PropsInfo.AllPropsTypes[i].Blueprint), EditMap.PropsInfo.AllPropsTypes[i].PropObject.BP.Name);

                        Counter++;
                        if (Counter >= PauseEveryLoadedAsset)
                        {
                            Counter = 0;
                            yield return(null);
                        }
                    }
                }
                else
                {
                    yield return(null);

                    yield return(null);
                }
            }
            else
            {
                ZipFile zf = null;
                try
                {
                    zf = GetGamedataFile.GetZipFileInstance(GetGamedataFile.EnvScd);

                    yield return(null);


                    foreach (ZipEntry zipEntry in zf)
                    {
                        if (!zipEntry.IsFile)
                        {
                            continue;
                        }
                        string LocalPath = "env/" + EnvType.options[EnvType.value].text + "/" + CategoryPaths[Category.value];
                        if (!zipEntry.Name.ToLower().StartsWith(LocalPath.ToLower()))
                        {
                            continue;
                        }


                        if (DontReload)
                        {
                            if (zipEntry.Name.ToLower() == SelectedObject.ToLower())
                            {
                                LastSelection = Pivot.GetChild(Id).GetComponent <ResourceObject>().Selected;
                                LastSelection.SetActive(true);
                                Pivot.GetComponent <RectTransform>().anchoredPosition = Vector2.up * 250 * Mathf.FloorToInt(Id / 5f);
                                break;
                            }
                        }
                        else
                        {
                            string LocalName = zipEntry.Name.Remove(0, LocalPath.Length);


                            LoadAtPath(zipEntry.Name, LocalName);
                        }

                        Id++;
                        Counter++;
                        if (Counter >= PauseEveryLoadedAsset)
                        {
                            Counter = 0;
                            yield return(null);
                        }
                    }
                }
                finally
                {
                    /*
                     * if (zf != null)
                     * {
                     *      zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                     *      zf.Close(); // Ensure we release resources
                     * }
                     */
                }
            }

            yield return(null);

            Layout.enabled     = false;
            SizeFitter.enabled = false;

            Loading.SetActive(false);
            GeneratingList = null;
        }