Example #1
0
        void ReadAllFolders()
        {
            if (Initialised)
            {
                return;
            }

            EnvType.ClearOptions();

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

            if (!EnvPaths.GamedataExist)
            {
                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);
             * }*/

            string[] files = GetGamedataFile.GetFilesInPath("env/");
            //Debug.Log("Total env files: " + files.Length);

            char Separator = '/';

            for (int f = 0; f < files.Length; f++)
            {
                string LocalName = files[f].Replace("env/", "");

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

                LocalName = LocalName.Split(Separator)[0];

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

                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;
        }
Example #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
                 *      //}
                 *
                 * }*/


                SelectedDirectory = ("env/" + EnvType.options[EnvType.value].text + "/" + CategoryPaths[LastLoadedType]).ToLower();

                string[] files   = GetGamedataFile.GetFilesInPath(SelectedDirectory);
                bool     Breaked = false;

                for (int f = 0; f < files.Length; f++)
                {
                    string LocalName = files[f];

                    if (!IsProperFile(LocalName))
                    {
                        continue;
                    }

                    if (LoadZipEntry(LocalName, out Breaked))
                    {
                        continue;
                    }

                    if (Breaked)
                    {
                        break;
                    }

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

            yield return(null);

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

            Loading.SetActive(false);
            GeneratingList = null;
        }
        void ReadAllUnits()
        {
            FoundUnits.Clear();
            IconBackgrounds.Clear();

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

            if (!EnvPaths.GamedataExist)
            {
                Preferences.Open();
                GenericInfoPopup.ShowInfo("Gamedata path not exist!");
                return;
            }

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

            string[] files = GetGamedataFile.GetFilesInPath("units/");

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

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


            /*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"))
             *              {
             *                      if (LocalName.Split('/').Length <= 3) // Only from main folder
             *                      {
             *                              FoundUnits.Add(LocalName);
             *                      }
             *              }
             *      }
             * }
             *
             * Debug.Log("Found " + FoundUnits.Count + " units ( FAF: " + (FoundUnits.Count - Count) + ")");
             */

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

            FoundUnits.Sort();
            Initialised = true;
        }