コード例 #1
0
    public static ZipFile GetZipFileInstance(string scd)
    {
        if (!Init)
        {
            ZipConstants.DefaultCodePage = 0;
            Init = true;
        }

        if (!ScdFiles.ContainsKey(scd))
        {
            FileStream fs         = File.OpenRead(EnvPaths.GetGamedataPath() + scd);
            ZipFile    NewZipFile = new ZipFile(fs);
            ScdFiles.Add(scd, NewZipFile);
        }

        return(ScdFiles[scd]);
    }
コード例 #2
0
        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);
        }
コード例 #3
0
    public IEnumerator LoadScmapFile()
    {
        //UnloadMap();

        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        //Debug.Log("Load SCMAP file: " + path);


        if (map.Load(path))
        {
            UpdateLighting();
            Skybox.LoadSkybox();
        }
        else
        {
            Debug.LogError("File not found");
            StopCoroutine("LoadScmapFile");
        }


        if (map.VersionMinor >= 60)
        {
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GetGamedataPath();

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);



        /*
         * // Cubemap
         * Texture2D Cubemap = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
         * Debug.Log(Cubemap.width);
         * Cubemap cb = new Cubemap(Cubemap.width, TextureFormat.RGB24, Cubemap.mipmapCount > 1);
         * cb.SetPixels(Cubemap.GetPixels(), CubemapFace.PositiveX);
         * WaterMaterial.SetTexture("_Reflection", cb);
         */

        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();



        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
        //Debug.Log("Scmap load complited");

        //GetGamedataFile.UnitObject NewUnit = new GetGamedataFile.UnitObject();
    }
コード例 #4
0
 void Awake()
 {
     Current = this;
     ResBrowser.Instantiate();
     EnvPaths.CurrentGamedataPath = EnvPaths.GetGamedataPath();
 }
コード例 #5
0
    IEnumerator LoadingFile()
    {
        while (SavingMapProcess)
        {
            yield return(null);
        }

        Undo.Current.Clear();

        bool   AllFilesExists = true;
        string Error          = "";

        if (!System.IO.Directory.Exists(FolderParentPath))
        {
            Error = "Map folder does not exist:\n" + FolderParentPath;
            Debug.LogError(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists && !System.IO.File.Exists(LoadedMapFolderPath + ScenarioFileName + ".lua"))
        {
            AllFilesExists = SearchForScenario();

            if (!AllFilesExists)
            {
                Error = "Scenario.lua does not exist:\n" + LoadedMapFolderPath + ScenarioFileName + ".lua";
                Debug.LogError(Error);
            }
        }

        if (AllFilesExists)
        {
            string ScenarioText = System.IO.File.ReadAllText(LoadedMapFolderPath + ScenarioFileName + ".lua");

            if (!ScenarioText.StartsWith("version = 3") && ScenarioText.StartsWith("version ="))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Wrong scenario file version. Should be 3, is " + ScenarioText.Remove(11).Replace("version =", "");
                    Debug.LogError(Error);
                }
            }


            if (AllFilesExists && !ScenarioText.StartsWith("version = 3"))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Selected file is not a proper scenario.lua file. ";
                    Debug.LogError(Error);
                }
            }
        }

        if (AllFilesExists && !System.IO.File.Exists(EnvPaths.GetGamedataPath() + "/env.scd"))
        {
            Error = "No source files in gamedata folder: " + EnvPaths.GetGamedataPath();
            Debug.LogError(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists)
        {
            // Begin load
            LoadRecentMaps.MoveLastMaps(ScenarioFileName, FolderName, FolderParentPath);
            LoadingMapProcess = true;
            InfoPopup.Show(true, "Loading map...\n( " + ScenarioFileName + ".lua" + " )");
            EditMenu.gameObject.SetActive(true);
            Background.SetActive(false);
            yield return(null);

            ScenarioLuaFile = new ScenarioLua();
            SaveLuaFile     = new SaveLua();
            TablesLuaFile   = new TablesLua();
            AsyncOperation ResUn = Resources.UnloadUnusedAssets();
            while (!ResUn.isDone)
            {
                yield return(null);
            }

            // Scenario LUA
            if (ScenarioLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }


            CameraControler.Current.MapSize = Mathf.Max(ScenarioLuaFile.Data.Size[0], ScenarioLuaFile.Data.Size[1]);
            CameraControler.Current.RestartCam();


            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.map + ")");
            yield return(null);

            // SCMAP
            var LoadScmapFile = HeightmapControler.StartCoroutine(ScmapEditor.Current.LoadScmapFile());
            yield return(LoadScmapFile);

            CameraControler.Current.RestartCam();

            EditMenu.MapInfoMenu.SaveAsFa.isOn = HeightmapControler.map.VersionMinor >= 60;
            EditMenu.MapInfoMenu.SaveAsSc.isOn = !EditMenu.MapInfoMenu.SaveAsFa.isOn;

            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.save + ")");
            yield return(null);

            if (loadSave)
            {
                // Save LUA
                SaveLuaFile.Load();
                SetSaveLua();
                //LoadSaveLua();
                yield return(null);
            }

            //GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(MapLuaParser.Current.MapCenterPoint, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEB0201").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.forward * 0.7f, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEL0001").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.left * 0.3f, Quaternion.identity);

            /*
             * //4k Sparkys with GPU instancing
             * for (int x = 0; x < 63; x++)
             * {
             *      for(int y = 0; y < 63; y++)
             *      {
             *              Vector3 Pos = MapLuaParser.Current.MapCenterPoint + new Vector3(x * -0.1f, 0, y * -0.1f);
             *              GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(Pos, Quaternion.identity);
             *      }
             * }
             */

            // Load Props
            if (LoadProps)
            {
                PropsMenu.gameObject.SetActive(true);

                PropsMenu.AllowBrushUpdate = false;
                PropsMenu.StartCoroutine(PropsMenu.LoadProps());
                while (PropsMenu.LoadingProps)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading props " + PropsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Props.Count + ")");
                    yield return(null);
                }

                PropsMenu.gameObject.SetActive(false);
            }

            if (LoadDecals)
            {
                DecalsMenu.gameObject.SetActive(true);

                //DecalsMenu.AllowBrushUpdate = false;
                DecalsMenu.StartCoroutine(DecalsMenu.LoadDecals());
                while (DecalsInfo.LoadingDecals)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading decals " + DecalsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Decals.Count + ")");
                    yield return(null);
                }

                DecalsMenu.gameObject.SetActive(false);
            }

            if (TablesLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }

            InfoPopup.Show(false);
            WindowStateSever.WindowStateSaver.ChangeWindowName(FolderName);
            LoadingMapProcess = false;


            RenderMarkersConnections.Current.UpdateConnections();

            EditMenu.Categorys[0].GetComponent <MapInfo>().UpdateFields();
        }
        else
        {
            ResetUI();
            ReturnLoadingWithError(Error);
        }
    }