Пример #1
0
        void ReadAllUnits()
        {
            FoundUnits.Clear();
            IconBackgrounds.Clear();

            ZipFile zf     = GetGamedataFile.GetZipFileInstance(GetGamedataFile.UnitsScd);
            ZipFile FAF_zf = GetGamedataFile.GetFAFZipFileInstance(GetGamedataFile.UnitsScd);

            if (zf == null)
            {
                Preferences.Open();
                GenericInfoPopup.ShowInfo("Gamedata path not exist!");
                return;
            }

            IconBackgrounds.Add("land", GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, "/textures/ui/common/icons/units/land_up.dds", false, true, true));
            IconBackgrounds.Add("amph", GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, "/textures/ui/common/icons/units/amph_up.dds", false, true, true));
            IconBackgrounds.Add("sea", GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, "/textures/ui/common/icons/units/sea_up.dds", false, true, true));
            IconBackgrounds.Add("air", GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, "/textures/ui/common/icons/units/air_up.dds", false, true, true));

            foreach (ZipEntry zipEntry in zf)
            {
                if (zipEntry.IsDirectory)
                {
                    continue;
                }

                string LocalName = zipEntry.Name;
                if (LocalName.ToLower().EndsWith("mesh.bp"))
                {
                    continue;
                }

                if (LocalName.ToLower().EndsWith(".bp") && LocalName.Split('/').Length <= 3)
                {
                    FoundUnits.Add(LocalName);
                }
            }
            int Count = FoundUnits.Count;

            if (FAF_zf != null)
            {
                string[] NewFiles = GetGamedataFile.GetNewFafFiles(GetGamedataFile.UnitsScd);

                for (int i = 0; i < NewFiles.Length; i++)
                {
                    string LocalName = NewFiles[i];
                    if (LocalName.ToLower().EndsWith("mesh.bp"))
                    {
                        continue;
                    }

                    if (LocalName.ToLower().EndsWith(".bp") && LocalName.Split('/').Length <= 3)
                    {
                        FoundUnits.Add(LocalName);
                    }
                }
            }

            Debug.Log("Found " + FoundUnits.Count + " units ( FAF: " + (FoundUnits.Count - Count) + ")");

            FoundUnits.Sort();
            Initialised = true;
        }
Пример #2
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;
        }