Exemplo n.º 1
0
    protected void CreateSprite(string fileName)
    {
        var texture = BsaFileReader.LoadTexture("icons/" + fileName) as Texture2D;
        var rect    = new Rect(0, 0, texture.width, texture.height);
        var pivot   = new Vector2(0.5f, 0.5f);

        this.icon = Sprite.Create(texture, rect, pivot);
    }
Exemplo n.º 2
0
        public Texture LoadTexture()
        {
            var     path = "textures\\" + FileName;
            Texture texture;

            if (!textureCache.TryGetValue(path, out texture))
            {
                texture = BsaFileReader.LoadTexture(path);
                textureCache.Add(path, texture);
            }

            return(texture);
        }
Exemplo n.º 3
0
    private void OnEnable()
    {
        if (!Application.isPlaying && !string.IsNullOrEmpty(path))
        {
            var texture = BsaFileReader.LoadTexture("textures\\" + path) as Texture2D;

            if (texture == null)
            {
                return;
            }

            var image = GetComponent <Image>();
            sprite       = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            image.sprite = sprite;
        }
    }
        public static Texture2D GetTexture(int index)
        {
            if (index - 1 < 0)
            {
                index = records.Count - 1;
            }
            else
            {
                index -= 1;
            }

            var record          = records[index];
            var textureFilePath = record.texture;

            return(BsaFileReader.LoadTexture("textures\\" + textureFilePath) as Texture2D);
        }
Exemplo n.º 5
0
    private void Start()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        gameObject.name = path;

        var texture = BsaFileReader.LoadTexture("textures\\" + path) as Texture2D;

        var image  = GetComponent <Image>();
        var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);

        image.sprite = sprite;

        Destroy(this);
    }
Exemplo n.º 6
0
    public void Create(WeatherType weatherType, Material material)
    {
        var section = $"Weather {weatherType}";

        // Create the gradients
        skyGradient     = GetGradient(section, "Sky");
        fogGradient     = GetGradient(section, "Fog");
        ambientGradient = GetGradient(section, "Ambient");
        sunGradient     = GetGradient(section, "Sun");

        // Sky needs alpha keys for fading to night sky too
        skyGradient.alphaKeys = new GradientAlphaKey[]
        {
            new GradientAlphaKey(1, 19f / 24f),
            new GradientAlphaKey(0, 21f / 24f),
            new GradientAlphaKey(0, 4f / 24f),
            new GradientAlphaKey(1, 6f / 24f)
        };

        // Based on the following settings, plus sunrise/sunset times
        //Stars Post - Sunset Start = 1
        //Stars Pre-Sunrise Finish = 2
        //Stars Fading Duration = 2

        // Initializing some settings
        cloudTexture         = BsaFileReader.LoadTexture("textures/" + IniManager.GetString(section, "Cloud Texture")) as Texture2D;
        material.mainTexture = cloudTexture;

        RenderSettings.sun.transform.eulerAngles = new Vector3(90, 270, 0);
        RenderSettings.sun.shadows = LightShadows.Soft;

        RenderSettings.ambientMode = AmbientMode.Flat;

        RenderSettings.fog     = true;
        RenderSettings.fogMode = FogMode.Linear;

        RenderSettings.fogEndDistance   = Camera.main.farClipPlane;
        RenderSettings.fogStartDistance = RenderSettings.fogEndDistance * (1 - IniManager.GetFloat(section, $"Land Fog Day Depth"));
    }
Exemplo n.º 7
0
    private void Start()
    {
        gameObject.name = path;
        var texture = BsaFileReader.LoadTexture(path) as Texture2D;
        var image   = GetComponent <Image>();
        var sprite  = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);

        image.sprite = sprite;

        var button      = GetComponent <Button>();
        var overTexture = BsaFileReader.LoadTexture(overPath) as Texture2D;
        var overSprite  = Sprite.Create(overTexture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);

        var pressedTexture = BsaFileReader.LoadTexture(pressedPath) as Texture2D;
        var pressedSprite  = Sprite.Create(pressedTexture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);

        var spriteState = button.spriteState;

        spriteState.highlightedSprite = overSprite;
        spriteState.pressedSprite     = pressedSprite;

        button.spriteState = spriteState;
    }
        //public static MagicEffectRecord GetMagicEffectRecord(MagicEffectType key)
        //{
        //	MagicEffectRecord record;
        //	if (Records.TryGetValue(key, out record))
        //	{
        //		return record;
        //	}

        //	RecordHeader header;
        //	if (!Record.MagicEffectOffsets.TryGetValue(key, out header))
        //	{
        //		throw new KeyNotFoundException(key.ToString());
        //	}

        //	var previousPosition = EsmFileReader.reader.Position;
        //	EsmFileReader.reader.Position = header.DataOffset;
        //	var dataEndPos = header.DataOffset + header.DataSize;
        //	var data = CreateInstance<MagicEffectRecord>();
        //	(data as IRecordData).Initialize(EsmFileReader.reader, header);
        //	EsmFileReader.reader.Position = previousPosition;
        //	return data;
        //}

        public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
        {
            while (reader.BaseStream.Position < header.DataEndPos)
            {
                var type = (SubRecordType)reader.ReadInt32();
                var size = reader.ReadInt32();

                switch (type)
                {
                case SubRecordType.Index:
                    index = (MagicEffectType)reader.ReadInt32();
                    name  = index.ToString();
                    break;

                case SubRecordType.MagicEffectData:
                    magicEffectData = new MagicEffectData(reader);
                    break;

                case SubRecordType.ItemTexture:
                {
                    var texture = BsaFileReader.LoadTexture("icons/" + reader.ReadString(size)) as Texture2D;
                    var rect    = new Rect(0, 0, texture.width, texture.height);
                    var pivot   = new Vector2(0.5f, 0.5f);
                    itemTexture = Sprite.Create(texture, rect, pivot);
                    break;
                }

                case SubRecordType.ParticleTexture:
                {
                    var texture = BsaFileReader.LoadTexture("textures/" + reader.ReadString(size)) as Texture2D;
                    var rect    = new Rect(0, 0, texture.width, texture.height);
                    var pivot   = new Vector2(0.5f, 0.5f);
                    particleTexture = Sprite.Create(texture, rect, pivot);
                    break;
                }

                case SubRecordType.MagicCastVisual:
                    castVisual = reader.ReadString(size);
                    break;

                case SubRecordType.MagicBoltVisual:
                    boltVisual = reader.ReadString(size);
                    break;

                case SubRecordType.MagicHitVisual:
                    hitVisual = reader.ReadString(size);
                    break;

                case SubRecordType.MagicAreaVisual:
                    areaVisual = reader.ReadString(size);
                    break;

                case SubRecordType.Description:
                    description = reader.ReadString(size);
                    break;

                case SubRecordType.MagicCastSound:
                    castSound = reader.ReadString(size);
                    break;

                case SubRecordType.MagicBoltsound:
                    boltSound = reader.ReadString(size);
                    break;

                case SubRecordType.MagicHitSound:
                    hitSound = reader.ReadString(size);
                    break;

                case SubRecordType.MagicAreaSound:
                    areaSound = reader.ReadString(size);
                    break;
                }
            }

            records.Add(index, this);
        }
Exemplo n.º 9
0
    private void Awake()
    {
        textures = new Texture2D[32];
        for (var i = 0; i < textures.Length; i++)
        {
            var path    = $"textures/water/water{i:00}.dds";
            var texture = BsaFileReader.LoadTexture(path);
            textures[i] = texture as Texture2D;
        }


        CellManager.OnFinishedLoadingCells += SetupWater;

        //Camera.main.depthTextureMode = DepthTextureMode.Depth;
        //Shader.EnableKeyword("DEPTH_TEXTURE_ENABLED");

        meshFilter   = GetComponent <MeshFilter>();
        meshRenderer = GetComponent <MeshRenderer>();

        var vertices  = new Vector3[resolution * resolution];
        var texcoords = new Vector2[resolution * resolution];
        var indices   = new int[resolution * resolution * 6];

        for (int x = 0; x < resolution; x++)
        {
            for (int y = 0; y < resolution; y++)
            {
                Vector2 uv = new Vector3(x / (resolution - 1.0f), y / (resolution - 1.0f));

                texcoords[x + y * resolution] = uv;
                vertices[x + y * resolution]  = new Vector3(uv.x, uv.y, 0.0f);
            }
        }

        int num = 0;

        for (int x = 0; x < resolution - 1; x++)
        {
            for (int y = 0; y < resolution - 1; y++)
            {
                indices[num++] = x + y * resolution;
                indices[num++] = x + (y + 1) * resolution;
                indices[num++] = (x + 1) + y * resolution;

                indices[num++] = x + (y + 1) * resolution;
                indices[num++] = (x + 1) + (y + 1) * resolution;
                indices[num++] = (x + 1) + y * resolution;
            }
        }

        var bigNumber = 1e6f;
        var mesh      = new Mesh()
        {
            vertices  = vertices,
            uv        = texcoords,
            triangles = indices
        };

        mesh.bounds = new Bounds(Vector3.zero, new Vector3(bigNumber, 20.0f, bigNumber));
        mesh.MarkDynamic();
        meshFilter.sharedMesh = mesh;
    }