Beispiel #1
0
    private void CreateMaterial()
    {
        MadDebug.Assert(!materialsLoaded, "materials already loaded");

        int materialsCount = Enum.GetNames(typeof(MaterialType)).Length;

        materials = new Material[materialsCount];

        materials[(int)MaterialType.StandardTransparent]    = new Material(Shader.Find("Custom/Energy Bar Toolkit/Unlit"));
        materials[(int)MaterialType.StandardTransparentPre] = new Material(Shader.Find("Custom/Energy Bar Toolkit/Unlit Pre"));
        materials[(int)MaterialType.HorizontalFill]         = new Material(Shader.Find("Custom/Energy Bar Toolkit/Horizontal Fill"));
        materials[(int)MaterialType.HorizontalFillPre]      = new Material(Shader.Find("Custom/Energy Bar Toolkit/Horizontal Fill Pre"));
        materials[(int)MaterialType.VerticalFill]           = new Material(Shader.Find("Custom/Energy Bar Toolkit/Vertical Fill"));
        materials[(int)MaterialType.VerticalFillPre]        = new Material(Shader.Find("Custom/Energy Bar Toolkit/Vertical Fill Pre"));
        materials[(int)MaterialType.ExpandFill]             = new Material(Shader.Find("Custom/Energy Bar Toolkit/Expand Fill"));
        materials[(int)MaterialType.ExpandFillPre]          = new Material(Shader.Find("Custom/Energy Bar Toolkit/Expand Fill Pre"));
        materials[(int)MaterialType.RadialFill]             = new Material(Shader.Find("Custom/Energy Bar Toolkit/Radial Fill"));
        materials[(int)MaterialType.RadialFillPre]          = new Material(Shader.Find("Custom/Energy Bar Toolkit/Radial Fill Pre"));

        foreach (var mat in materials)
        {
            mat.hideFlags = HideFlags.DontSave;
        }

        materialsLoaded = true;
    }
Beispiel #2
0
    protected Rect FindBounds(Texture2D texture)
    {
        int  left = -1, top = -1, right = -1, bottom = -1;
        bool expanded = false;

        Color32[] pixels;
        try {
            pixels = texture.GetPixels32();
        } catch (UnityException) { // catch not readable
            return(new Rect());
        }

        int w = texture.width;
        int h = texture.height;
        int x = 0, y = h - 1;

        for (int i = 0; i < pixels.Length; ++i)
        {
            var c = pixels[i];
            if (c.a != 0)
            {
                Expand(x, y, ref left, ref top, ref right, ref bottom);
                expanded = true;
            }

            if (++x == w)
            {
                y--;
                x = 0;
            }
        }


        MadDebug.Assert(expanded, "bar texture has no visible pixels");

        var pixelsRect     = new Rect(left, top, right - left + 1, bottom - top + 1);
        var normalizedRect = new Rect(
            pixelsRect.xMin / texture.width,
            1 - pixelsRect.yMax / texture.height,
            pixelsRect.xMax / texture.width - pixelsRect.xMin / texture.width,
            1 - pixelsRect.yMin / texture.height - (1 - pixelsRect.yMax / texture.height));

        return(normalizedRect);
    }
Beispiel #3
0
    private void DestroyMaterial()
    {
        MadDebug.Assert(materialsLoaded, "materials not loaded");

        foreach (var mat in materials)
        {
            if (Application.isPlaying)
            {
                Destroy(mat);
            }
            else
            {
                DestroyImmediate(mat);
            }
        }

        materialsLoaded = false;
        materials       = null;
    }
Beispiel #4
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    protected virtual void OnEnable()
    {
        energyBar = GetComponent <EnergyBar>();
        MadDebug.Assert(energyBar != null, "Cannot access energy bar?!");
    }