Ejemplo n.º 1
0
    IEnumerator PreloadEditor()
    {
        yield return(null);

        MapLuaParser.LoadStructurePaths();
        yield return(null);

        BrushGenerator.Current.LoadBrushes();
        yield return(null);

        //Preload heavy gamedata files
        GetGamedataFile.GetZipFileInstance(GetGamedataFile.UnitsScd);
        yield return(null);

        yield return(null);

        GetGamedataFile.GetFAFZipFileInstance(GetGamedataFile.UnitsScd);
        yield return(null);

        yield return(null);

        yield return(null);

        SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
    }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        void ReadAllFolders()
        {
            if (Initialised)
            {
                return;
            }

            EnvType.ClearOptions();

            LoadedEnvPaths = new List <string>();
            List <Dropdown.OptionData> NewOptions = new List <Dropdown.OptionData>();

            if (!Directory.Exists(EnvPaths.GamedataPath))
            {
                Debug.LogWarning("Gamedata path not exist!");
                return;
            }

            HashSet <string> LoadedDirectorys = new HashSet <string>();
            ZipFile          zf = GetGamedataFile.GetZipFileInstance(GetGamedataFile.EnvScd);

            if (zf == null)
            {
                Debug.LogError("Unable to load ZipFile!");
                return;
            }
            foreach (ZipEntry zipEntry in zf)
            {
                if (zipEntry == null || !zipEntry.IsDirectory)
                {
                    continue;
                }

                string LocalName = zipEntry.Name.Replace("env/", "");

                if (string.IsNullOrEmpty(LocalName))
                {
                    continue;
                }

                LoadedDirectorys.Add(LocalName);

                int  ContSeparators = 0;
                char Separator      = ("/")[0];
                for (int i = 0; i < LocalName.Length; i++)
                {
                    if (LocalName[i] == Separator)
                    {
                        ContSeparators++;
                        if (ContSeparators > 1)
                        {
                            break;
                        }
                    }
                }
                if (ContSeparators > 1)
                {
                    continue;
                }

                LocalName = LocalName.Replace("/", "");

                LoadedEnvPaths.Add(LocalName);
                Dropdown.OptionData NewOptionInstance = new Dropdown.OptionData(LocalName);
                NewOptions.Add(NewOptionInstance);
            }

            // FAF
            zf = GetGamedataFile.GetFAFZipFileInstance(GetGamedataFile.EnvScd);
            if (zf != null)
            {
                foreach (ZipEntry zipEntry in zf)
                {
                    if (!zipEntry.IsDirectory)
                    {
                        continue;
                    }

                    string LocalName = zipEntry.Name.Replace("env/", "");

                    if (string.IsNullOrEmpty(LocalName))
                    {
                        continue;
                    }

                    if (LoadedDirectorys.Contains(LocalName))
                    {
                        continue;
                    }

                    LoadedDirectorys.Add(LocalName);

                    int  ContSeparators = 0;
                    char Separator      = ("/")[0];
                    for (int i = 0; i < LocalName.Length; i++)
                    {
                        if (LocalName[i] == Separator)
                        {
                            ContSeparators++;
                            if (ContSeparators > 1)
                            {
                                break;
                            }
                        }
                    }
                    if (ContSeparators > 1)
                    {
                        continue;
                    }

                    LocalName = LocalName.Replace("/", "");

                    LoadedEnvPaths.Add(LocalName);
                    Dropdown.OptionData NewOptionInstance = new Dropdown.OptionData(LocalName);
                    NewOptions.Add(NewOptionInstance);
                }
            }


            LoadedEnvPaths.Add(CurrentMapFolderPath);
            Dropdown.OptionData NewOptionInstance2 = new Dropdown.OptionData("Map folder");
            NewOptions.Add(NewOptionInstance2);

            LoadedEnvPaths.Add(CurrentMapPath);
            Dropdown.OptionData NewOptionInstance3 = new Dropdown.OptionData("On map");
            NewOptions.Add(NewOptionInstance3);

            EnvType.AddOptions(NewOptions);

            Initialised = true;
        }
        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;
        }
        void ReadAllFolders()
        {
            EnvType.ClearOptions();

            LoadedEnvPaths = new List <string>();
            List <Dropdown.OptionData> NewOptions = new List <Dropdown.OptionData>();

            if (!Directory.Exists(EnvPaths.GetGamedataPath()))
            {
                Debug.LogError("Gamedata path not exist!");
                return;
            }



            ZipFile zf = GetGamedataFile.GetZipFileInstance(GetGamedataFile.EnvScd);

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

                string LocalName = zipEntry.Name.Replace("env/", "");

                if (LocalName.Length == 0)
                {
                    continue;
                }

                int  ContSeparators = 0;
                char Separator      = ("/")[0];
                for (int i = 0; i < LocalName.Length; i++)
                {
                    if (LocalName[i] == Separator)
                    {
                        ContSeparators++;
                        if (ContSeparators > 1)
                        {
                            break;
                        }
                    }
                }
                if (ContSeparators > 1)
                {
                    continue;
                }

                LocalName = LocalName.Replace("/", "");

                LoadedEnvPaths.Add(LocalName);
                Dropdown.OptionData NewOptionInstance = new Dropdown.OptionData(LocalName);
                NewOptions.Add(NewOptionInstance);
            }

            LoadedEnvPaths.Add(CurrentMapFolderPath);
            Dropdown.OptionData NewOptionInstance2 = new Dropdown.OptionData("Map folder");
            NewOptions.Add(NewOptionInstance2);

            LoadedEnvPaths.Add(CurrentMapPath);
            Dropdown.OptionData NewOptionInstance3 = new Dropdown.OptionData("On map");
            NewOptions.Add(NewOptionInstance3);

            EnvType.AddOptions(NewOptions);
        }