Exemple #1
0
        public void SetGradientKey(Color[] _colors, float[] _alpha)
        {
            GradientColorKey[] newColorKeys = new GradientColorKey[_colors.Length];
            GradientAlphaKey[] newAlphaKeys = new GradientAlphaKey[_colors.Length];

            for (int i = 0; i < _colors.Length; ++i)
            {
                float time = i / (_colors.Length - 1);
                newColorKeys[i].color = _colors[i];
                newColorKeys[i].time  = time;

                newAlphaKeys[i].alpha = _alpha[i];
                newAlphaKeys[i].time  = time;
            }
            EffectGradient.SetKeys(newColorKeys, newAlphaKeys);
        }
Exemple #2
0
        public void SetGradientAlphaKey(params float[] _alpha)
        {
            GradientColorKey[] newColorKeys = new GradientColorKey[_alpha.Length];
            GradientAlphaKey[] newAlphaKeys = new GradientAlphaKey[_alpha.Length];

            for (int i = 0; i < _alpha.Length; ++i)
            {
                float time = i / (_alpha.Length - 1);
                newColorKeys[i].color = i < EffectGradient.colorKeys.Length ? EffectGradient.colorKeys[i].color : Color.white;
                newColorKeys[i].time  = time;

                newAlphaKeys[i].alpha = _alpha[i];
                newAlphaKeys[i].time  = time;
            }
            EffectGradient.SetKeys(newColorKeys, newAlphaKeys);
        }
    void MiddleModify(List <UIVertex> _vertexList, VertexHelper helper)
    {
        int   nCount = _vertexList.Count;
        float left   = _vertexList[0].position.x;
        float right  = _vertexList[0].position.x;
        float x      = 0f;

        for (int i = nCount - 1; i >= 1; --i)
        {
            x = _vertexList[i].position.x;


            if (x > right)
            {
                right = x;
            }
            else if (x < left)
            {
                left = x;
            }
        }
        float    width  = 1f / (right - left);
        float    middle = (right + left) / 2.0f;
        UIVertex vertex = new UIVertex();


        for (int i = 0; i < helper.currentVertCount; i++)
        {
            helper.PopulateUIVertex(ref vertex, i);


            vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(Math.Abs(vertex.position.x - middle) * width * 2 - Offset));


            helper.SetUIVertex(vertex, i);
        }
    }
    void VerticalModify(List <UIVertex> _vertexList, VertexHelper helper)
    {
        int   nCount = _vertexList.Count;
        float bottom = _vertexList[0].position.y;
        float top    = _vertexList[0].position.y;
        float y      = 0f;

        for (int i = nCount - 1; i >= 1; --i)
        {
            y = _vertexList[i].position.y;


            if (y > top)
            {
                top = y;
            }
            else if (y < bottom)
            {
                bottom = y;
            }
        }
        float    height = 1f / (top - bottom);
        UIVertex vertex = new UIVertex();


        for (int i = 0; i < helper.currentVertCount; i++)
        {
            helper.PopulateUIVertex(ref vertex, i);


            vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset));


            helper.SetUIVertex(vertex, i);
        }
    }
Exemple #5
0
        public override void ModifyMesh(VertexHelper helper)
        {
            if (!IsActive() || helper.currentVertCount == 0)
            {
                return;
            }

            List <UIVertex> _vertexList = new List <UIVertex>();

            helper.GetUIVertexStream(_vertexList);

            int nCount = _vertexList.Count;

            switch (GradientType)
            {
            case Type.Horizontal: {
                float left  = _vertexList[0].position.x;
                float right = _vertexList[0].position.x;
                float x     = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    x = _vertexList[i].position.x;

                    if (x > right)
                    {
                        right = x;
                    }
                    else if (x < left)
                    {
                        left = x;
                    }
                }

                float    width  = 1f / (right - left);
                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.x - left) * width - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;

            case Type.Vertical: {
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;
                float y      = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float    height = 1f / (top - bottom);
                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;

            case Type.Diamond: {
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;
                float y      = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float height = 1f / (top - bottom);

                helper.Clear();
                for (int i = 0; i < nCount; i++)
                {
                    helper.AddVert(_vertexList[i]);
                }

                float    center        = (bottom + top) / 2f;
                UIVertex centralVertex = new UIVertex();
                centralVertex.position = (Vector3.right + Vector3.up) * center + Vector3.forward * _vertexList[0].position.z;
                centralVertex.normal   = _vertexList[0].normal;
                centralVertex.color    = Color.white;
                helper.AddVert(centralVertex);

                for (int i = 1; i < nCount; i++)
                {
                    helper.AddTriangle(i - 1, i, nCount);
                }
                helper.AddTriangle(0, nCount - 1, nCount);

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Vector3.Distance(vertex.position, centralVertex.position) * height - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;

            case Type.Radial: {
                float left   = _vertexList[0].position.x;
                float right  = _vertexList[0].position.x;
                float bottom = _vertexList[0].position.y;
                float top    = _vertexList[0].position.y;

                float x = 0f;
                float y = 0f;

                for (int i = nCount - 1; i >= 1; --i)
                {
                    x = _vertexList[i].position.x;

                    if (x > right)
                    {
                        right = x;
                    }
                    else if (x < left)
                    {
                        left = x;
                    }

                    y = _vertexList[i].position.y;

                    if (y > top)
                    {
                        top = y;
                    }
                    else if (y < bottom)
                    {
                        bottom = y;
                    }
                }

                float width  = 1f / (right - left);
                float height = 1f / (top - bottom);

                helper.Clear();

                float    centerX       = (right + left) / 2f;
                float    centerY       = (bottom + top) / 2f;
                float    radiusX       = (right - left) / 2f;
                float    radiusY       = (top - bottom) / 2f;
                UIVertex centralVertex = new UIVertex();
                centralVertex.position = Vector3.right * centerX + Vector3.up * centerY + Vector3.forward * _vertexList[0].position.z;
                centralVertex.normal   = _vertexList[0].normal;
                centralVertex.color    = Color.white;

                int steps = 64;
                for (int i = 0; i < steps; i++)
                {
                    UIVertex curVertex = new UIVertex();
                    float    angle     = (float)i * 360f / (float)steps;
                    float    curX      = Mathf.Cos(Mathf.Deg2Rad * angle) * radiusX;
                    float    curY      = Mathf.Sin(Mathf.Deg2Rad * angle) * radiusY;

                    curVertex.position = Vector3.right * curX + Vector3.up * curY + Vector3.forward * _vertexList[0].position.z;
                    curVertex.normal   = _vertexList[0].normal;
                    curVertex.color    = Color.white;
                    helper.AddVert(curVertex);
                }

                helper.AddVert(centralVertex);

                for (int i = 1; i < steps; i++)
                {
                    helper.AddTriangle(i - 1, i, steps);
                }
                helper.AddTriangle(0, steps - 1, steps);

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Mathf.Sqrt(
                                                      Mathf.Pow(Mathf.Abs(vertex.position.x - centerX) * width, 2f) +
                                                      Mathf.Pow(Mathf.Abs(vertex.position.y - centerY) * height, 2f)) * 2f - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;
            }
        }
        public override void ModifyMesh(VertexHelper helper)
        {
            if (!IsActive() || helper.currentVertCount == 0)
            {
                return;
            }

            List <UIVertex> _vertexList = new List <UIVertex>();

            helper.GetUIVertexStream(_vertexList);

            int nCount = _vertexList.Count;

            switch (GradientType)
            {
            case Type.Horizontal:
            case Type.Vertical:
            {
                Rect  bounds = GetBounds(_vertexList);
                float min    = bounds.xMin;
                float w      = bounds.width;
                Func <UIVertex, float> GetPosition = v => v.position.x;

                if (GradientType == Type.Vertical)
                {
                    min         = bounds.yMin;
                    w           = bounds.height;
                    GetPosition = v => v.position.y;
                }

                float width      = 1f / w / Zoom;
                float zoomOffset = (1 - (1 / Zoom)) * 0.5f;
                float offset     = (Offset * (1 - zoomOffset)) - zoomOffset;

                if (ModifyVertices)
                {
                    SplitTrianglesAtGradientStops(_vertexList, bounds, zoomOffset, helper);
                }

                UIVertex vertex = new UIVertex();
                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);
                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((GetPosition(vertex) - min) * width - offset));
                    helper.SetUIVertex(vertex, i);
                }
            }
            break;

            case Type.Diamond:
            {
                Rect bounds = GetBounds(_vertexList);

                float   height = 1f / bounds.height / Zoom;
                float   radius = bounds.center.y / 2f;
                Vector3 center = (Vector3.right + Vector3.up) * radius + Vector3.forward * _vertexList[0].position.z;

                if (ModifyVertices)
                {
                    helper.Clear();
                    for (int i = 0; i < nCount; i++)
                    {
                        helper.AddVert(_vertexList[i]);
                    }

                    UIVertex centralVertex = new UIVertex();
                    centralVertex.position = center;
                    centralVertex.normal   = _vertexList[0].normal;
                    centralVertex.uv0      = new Vector2(0.5f, 0.5f);
                    centralVertex.color    = Color.white;
                    helper.AddVert(centralVertex);

                    for (int i = 1; i < nCount; i++)
                    {
                        helper.AddTriangle(i - 1, i, nCount);
                    }
                    helper.AddTriangle(0, nCount - 1, nCount);
                }

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Vector3.Distance(vertex.position, center) * height - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;

            case Type.Radial:
            {
                Rect bounds = GetBounds(_vertexList);

                float width  = 1f / bounds.width / Zoom;
                float height = 1f / bounds.height / Zoom;

                if (ModifyVertices)
                {
                    helper.Clear();

                    float    radiusX       = bounds.width / 2f;
                    float    radiusY       = bounds.height / 2f;
                    UIVertex centralVertex = new UIVertex();
                    centralVertex.position = Vector3.right * bounds.center.x + Vector3.up * bounds.center.y + Vector3.forward * _vertexList[0].position.z;
                    centralVertex.normal   = _vertexList[0].normal;
                    centralVertex.uv0      = new Vector2(0.5f, 0.5f);
                    centralVertex.color    = Color.white;

                    int steps = 64;
                    for (int i = 0; i < steps; i++)
                    {
                        UIVertex curVertex = new UIVertex();
                        float    angle     = (float)i * 360f / (float)steps;
                        float    cosX      = Mathf.Cos(Mathf.Deg2Rad * angle);
                        float    cosY      = Mathf.Sin(Mathf.Deg2Rad * angle);

                        curVertex.position = Vector3.right * cosX * radiusX + Vector3.up * cosY * radiusY + Vector3.forward * _vertexList[0].position.z;
                        curVertex.normal   = _vertexList[0].normal;
                        curVertex.uv0      = new Vector2((cosX + 1) * 0.5f, (cosY + 1) * 0.5f);
                        curVertex.color    = Color.white;
                        helper.AddVert(curVertex);
                    }

                    helper.AddVert(centralVertex);

                    for (int i = 1; i < steps; i++)
                    {
                        helper.AddTriangle(i - 1, i, steps);
                    }
                    helper.AddTriangle(0, steps - 1, steps);
                }

                UIVertex vertex = new UIVertex();

                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);

                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                  Mathf.Sqrt(
                                                      Mathf.Pow(Mathf.Abs(vertex.position.x - bounds.center.x) * width, 2f) +
                                                      Mathf.Pow(Mathf.Abs(vertex.position.y - bounds.center.y) * height, 2f)) * 2f - Offset));

                    helper.SetUIVertex(vertex, i);
                }
            }
            break;
            }
        }
            public override void ModifyMesh(VertexHelper helper)
            {
                if (!IsActive() || helper.currentVertCount == 0)
                {
                    return;
                }

                List <UIVertex> _vertexList = new List <UIVertex>();

                helper.GetUIVertexStream(_vertexList);

                int nCount = _vertexList.Count;

                switch (GradientType)
                {
                case Type.Horizontal:
                {
                    float left  = _vertexList[0].position.x;
                    float right = _vertexList[0].position.x;
                    float x     = 0f;

                    for (int i = nCount - 1; i >= 1; --i)
                    {
                        x = _vertexList[i].position.x;

                        if (x > right)
                        {
                            right = x;
                        }
                        else if (x < left)
                        {
                            left = x;
                        }
                    }

                    float    width  = 1f / (right - left);
                    UIVertex vertex = new UIVertex();

                    for (int i = 0; i < helper.currentVertCount; i++)
                    {
                        helper.PopulateUIVertex(ref vertex, i);

                        vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.x - left) * width - Offset));

                        helper.SetUIVertex(vertex, i);
                    }
                }
                break;

                case Type.Vertical:
                {
                    float bottom = _vertexList[0].position.y;
                    float top    = _vertexList[0].position.y;
                    float y      = 0f;

                    for (int i = nCount - 1; i >= 1; --i)
                    {
                        y = _vertexList[i].position.y;

                        if (y > top)
                        {
                            top = y;
                        }
                        else if (y < bottom)
                        {
                            bottom = y;
                        }
                    }

                    float    height = 1f / (top - bottom);
                    UIVertex vertex = new UIVertex();

                    for (int i = 0; i < helper.currentVertCount; i++)
                    {
                        helper.PopulateUIVertex(ref vertex, i);

                        vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - bottom) * height - Offset));

                        helper.SetUIVertex(vertex, i);
                    }
                }
                break;
                }
            }
Exemple #8
0
            public override void ModifyMesh(VertexHelper helper)
            {
                if (!IsActive() || helper.currentVertCount == 0)
                {
                    return;
                }

                List <UIVertex> _vertexList = new List <UIVertex>();

                helper.GetUIVertexStream(_vertexList);
                int nCount = _vertexList.Count;

                switch (GradientType)
                {
                case Type.Horizontal:
                case Type.Vertical:
                {
                    Rect  bounds = GetBounds(_vertexList);
                    float min    = bounds.xMin;
                    float w      = bounds.width;
                    Func <UIVertex, float> GetPosition = v => v.position.x;

                    if (GradientType == Type.Vertical)
                    {
                        min         = bounds.yMin;
                        w           = bounds.height;
                        GetPosition = v => v.position.y;
                    }

                    float width      = w == 0f ? 0f : 1f / w / Zoom;
                    float zoomOffset = (1 - (1 / Zoom)) * 0.5f;
                    float offset     = (Offset * (1 - zoomOffset)) - zoomOffset;

                    if (ModifyVertices)
                    {
                        SplitTrianglesAtGradientStops(_vertexList, bounds, zoomOffset, helper);
                    }

                    UIVertex vertex = new UIVertex();
                    for (int i = 0; i < helper.currentVertCount; i++)
                    {
                        helper.PopulateUIVertex(ref vertex, i);
                        vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((GetPosition(vertex) - min) * width - offset));
                        helper.SetUIVertex(vertex, i);
                    }
                }
                break;

                case Type.Diamond:
                {
                    Rect    bounds = GetBounds(_vertexList);
                    float   height = bounds.height == 0f ? 0f : 1f / bounds.height / Zoom;
                    float   radius = bounds.center.y / 2f;
                    Vector3 center = (Vector3.right + Vector3.up) * radius + Vector3.forward * _vertexList[0].position.z;

                    if (ModifyVertices)
                    {
                        helper.Clear();
                        for (int i = 0; i < nCount; i++)
                        {
                            helper.AddVert(_vertexList[i]);
                        }

                        UIVertex centralVertex = new UIVertex();
                        centralVertex.position = center;
                        centralVertex.normal   = _vertexList[0].normal;
                        centralVertex.uv0      = new Vector2(0.5f, 0.5f);
                        centralVertex.color    = Color.white;
                        helper.AddVert(centralVertex);

                        for (int i = 1; i < nCount; i++)
                        {
                            helper.AddTriangle(i - 1, i, nCount);
                        }
                        helper.AddTriangle(0, nCount - 1, nCount);
                    }

                    UIVertex vertex = new UIVertex();

                    for (int i = 0; i < helper.currentVertCount; i++)
                    {
                        helper.PopulateUIVertex(ref vertex, i);
                        vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate(
                                                      Vector3.Distance(vertex.position, center) * height - Offset));
                        helper.SetUIVertex(vertex, i);
                    }
                }
                break;
                }
            }
Exemple #9
0
        public override void ModifyMesh(VertexHelper helper)
        {
            if (!IsActive() || helper.currentVertCount == 0)
            {
                return;
            }
            List <UIVertex> list = new List <UIVertex>();

            helper.GetUIVertexStream(list);
            int count = list.Count;

            switch (GradientType)
            {
            case Type.Horizontal:
            {
                float num6 = list[0].position.x;
                float num7 = list[0].position.x;
                float num8 = 0f;
                for (int num9 = count - 1; num9 >= 1; num9--)
                {
                    num8 = list[num9].position.x;
                    if (num8 > num7)
                    {
                        num7 = num8;
                    }
                    else if (num8 < num6)
                    {
                        num6 = num8;
                    }
                }
                float    num10   = 1f / (num7 - num6);
                UIVertex vertex2 = default(UIVertex);
                for (int j = 0; j < helper.currentVertCount; j++)
                {
                    helper.PopulateUIVertex(ref vertex2, j);
                    vertex2.color = BlendColor(vertex2.color, EffectGradient.Evaluate((vertex2.position.x - num6) * num10 - Offset));
                    helper.SetUIVertex(vertex2, j);
                }
                break;
            }

            case Type.Vertical:
            {
                float num  = list[0].position.y;
                float num2 = list[0].position.y;
                float num3 = 0f;
                for (int num4 = count - 1; num4 >= 1; num4--)
                {
                    num3 = list[num4].position.y;
                    if (num3 > num2)
                    {
                        num2 = num3;
                    }
                    else if (num3 < num)
                    {
                        num = num3;
                    }
                }
                float    num5   = 1f / (num2 - num);
                UIVertex vertex = default(UIVertex);
                for (int i = 0; i < helper.currentVertCount; i++)
                {
                    helper.PopulateUIVertex(ref vertex, i);
                    vertex.color = BlendColor(vertex.color, EffectGradient.Evaluate((vertex.position.y - num) * num5 - Offset));
                    helper.SetUIVertex(vertex, i);
                }
                break;
            }
            }
        }