Example #1
0
        public static Texture2D AssignTextureFromPath(ref Material mat, string property, string path)
        {
            Texture2D Tex = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, path);

            Tex.wrapMode = TextureWrapMode.Clamp;
            mat.SetTexture(property, Tex);
            return(Tex);
        }
        int GenerateMapTextureButton(string loadPath, string absolutePath, GameObject Prefab)
        {
            Texture2D LoadedTex;

            string RelativePath = "/" + absolutePath.Replace(MapLuaParser.LoadedMapFolderPath, MapLuaParser.RelativeLoadedMapFolderPath);

            Debug.Log(RelativePath);

            try
            {
                LoadedTex = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.MapScd, RelativePath, false, false);
            }
            catch (System.Exception e)
            {
                LoadedTex = new Texture2D(128, 128);
                Debug.LogError("Can't load DDS texture: " + e);
                return(0);
            }


            string TexPath = "";

            if (RelativePath.EndsWith(".dds"))
            {
                TexPath = RelativePath.Replace(".dds", "");
            }
            else if (RelativePath.EndsWith(".DDS"))
            {
                TexPath = RelativePath.Replace(".DDS", "");
            }


            GameObject NewButton = Instantiate(Prefab) as GameObject;

            NewButton.transform.SetParent(Pivot, false);
            NewButton.GetComponent <ResourceObject>().SetImages(LoadedTex);
            NewButton.GetComponent <ResourceObject>().InstanceId     = LoadedTextures.Count;
            NewButton.GetComponent <ResourceObject>().NameField.text = TexPath;
            LoadedTextures.Add(LoadedTex);
            LoadedPaths.Add(RelativePath);

            if (RelativePath.ToLower() == SelectedObject.ToLower())
            {
                LastSelection = NewButton.GetComponent <ResourceObject>().Selected;
                LastSelection.SetActive(true);
                Pivot.GetComponent <RectTransform>().anchoredPosition = Vector2.up * 250 * Mathf.FloorToInt(LoadedPaths.Count / 5f);
            }

            return(1);
        }
Example #3
0
        IEnumerator GenerateList()
        {
            Loading.SetActive(true);
            Layout.enabled     = true;
            SizeFitter.enabled = true;

            int GenerateCount = 0;

            for (int i = 0; i < FoundUnits.Count; i++)
            {
                GetGamedataFile.UnitDB UnitDB = GetGamedataFile.LoadUnitBlueprintPreview(FoundUnits[i]);

                GameObject NewButton = Instantiate(Prefab) as GameObject;
                NewButton.transform.SetParent(Pivot, false);
                ResourceObject NewResObject = NewButton.GetComponent <ResourceObject>();
                NewResObject.RawImages[0].texture = IconBackgrounds[UnitDB.Icon];
                NewResObject.RawImages[1].texture = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, "/textures/ui/common/icons/units/" + UnitDB.CodeName + "_icon.dds", false, true, true);
                if (NewResObject.RawImages[1].texture == Texture2D.whiteTexture)
                {
                    NewResObject.RawImages[1].enabled = false;
                }
                NewResObject.InstanceId          = i;
                NewResObject.NameField.text      = UnitDB.CodeName;
                NewResObject.CustomTexts[0].text = SortDescription(UnitDB);
                NewResObject.CustomTexts[1].text = UnitDB.Name;
                NewButton.SetActive(CheckSorting(UnitDB));

                LoadedButtons.Add(NewResObject);
                LoadedUnits.Add(UnitDB);

                GenerateCount++;

                if (GenerateCount >= 7)
                {
                    GenerateCount = 0;
                    yield return(null);
                }
            }

            IsGenerated = true;

            yield return(null);

            Loading.SetActive(false);
            Layout.enabled     = false;
            SizeFitter.enabled = false;
            GeneratingList     = null;
            SortUnits();
        }
Example #4
0
        bool GenerateTextureButton(string localpath, string LocalName, GameObject Prefab)
        {
            if (!LocalName.ToLower().EndsWith(".dds"))
            {
                return(true);
            }
            Texture2D LoadedTex;

            try
            {
                LoadedTex = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.EnvScd, localpath, false, false);
            }
            catch (System.Exception e)
            {
                LoadedTex = new Texture2D(128, 128);
                Debug.LogWarning("Can't load DDS texture: " + e);
            }

            string TexPath = "";

            if (localpath.EndsWith(".dds"))
            {
                TexPath = LocalName.Replace(".dds", "");
            }
            else if (localpath.EndsWith(".DDS"))
            {
                TexPath = LocalName.Replace(".DDS", "");
            }


            GameObject NewButton = Instantiate(Prefab) as GameObject;

            NewButton.transform.SetParent(Pivot, false);
            NewButton.GetComponent <ResourceObject>().SetImages(LoadedTex);
            NewButton.GetComponent <ResourceObject>().InstanceId     = LoadedTextures.Count;
            NewButton.GetComponent <ResourceObject>().NameField.text = TexPath;
            LoadedTextures.Add(LoadedTex);
            LoadedPaths.Add(localpath);

            if (localpath.ToLower() == SelectedObject.ToLower())
            {
                LastSelection = NewButton.GetComponent <ResourceObject>().Selected;
                LastSelection.SetActive(true);
                Pivot.GetComponent <RectTransform>().anchoredPosition = Vector2.up * 250 * Mathf.FloorToInt(LoadedPaths.Count / 5f);
            }
            return(false);
        }
    public void SetWaterTextures()
    {
        Texture2D WaterRamp = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathWaterRamp, false, true, true);

        WaterRamp.wrapMode = TextureWrapMode.Clamp;
        Shader.SetGlobalTexture("_WaterRam", WaterRamp);

        try
        {
            Cubemap WaterReflection = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
            WaterMaterial.SetTexture("SkySampler", WaterReflection);
        }
        catch
        {
            WaterMaterial.SetTexture("SkySampler", DefaultWaterSky);
        }

        const int WaterAnisoLevel = 4;

        Texture2D WaterNormal = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[0].TexPath, false, true, true);

        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler0", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[1].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler1", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[2].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler2", WaterNormal);
        WaterNormal            = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.WaveTextures[3].TexPath, false, true, true);
        WaterNormal.anisoLevel = WaterAnisoLevel;
        WaterMaterial.SetTexture("NormalSampler3", WaterNormal);

        Shader.SetGlobalVector("normal1Movement", map.Water.WaveTextures[0].NormalMovement);
        Shader.SetGlobalVector("normal2Movement", map.Water.WaveTextures[1].NormalMovement);
        Shader.SetGlobalVector("normal3Movement", map.Water.WaveTextures[2].NormalMovement);
        Shader.SetGlobalVector("normal4Movement", map.Water.WaveTextures[3].NormalMovement);
        Shader.SetGlobalVector("normalRepeatRate", new Vector4(map.Water.WaveTextures[0].NormalRepeat, map.Water.WaveTextures[1].NormalRepeat, map.Water.WaveTextures[2].NormalRepeat, map.Water.WaveTextures[3].NormalRepeat));
    }
        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;
        }