(二十八)unity4.6學習Ugui中文文檔-------uGui Effect Tool,ugui-------ugui

來源:互聯網
上載者:User

(二十八)unity4.6學習Ugui中文文檔-------uGui Effect Tool,ugui-------ugui

瀏覽一下 GitHub ,找了找UGUI開源的東西 https://github.com/WestHillApps/uGUI-Effect-Tool


發現了 uGuiEffectTool (包括Blend【意義不大】 和 漸層)

這個是原始圖片


Blend的效果:

Blend的代碼:

using UnityEngine;using System.Collections.Generic;using UnityEngine.UI;namespace UiEffect{    [AddComponentMenu ("UI/Effects/Blend Color")]    [RequireComponent (typeof (Graphic))]    public class BlendColor : BaseVertexEffect    {        public enum BLEND_MODE        {            Multiply,            Additive,            Subtractive,            Override,        }        public BLEND_MODE blendMode = BLEND_MODE.Multiply;        public Color color = Color.grey;        Graphic graphic;        public override void ModifyVertices (List<UIVertex> vList)        {            if (IsActive () == false || vList == null || vList.Count == 0) {                return;            }            UIVertex tempVertex = vList[0];            for (int i = 0; i < vList.Count; i++) {                tempVertex = vList[i];                byte orgAlpha = tempVertex.color.a;                switch (blendMode) {                    case BLEND_MODE.Multiply:                        tempVertex.color *= color;                        break;                    case BLEND_MODE.Additive:                        tempVertex.color += color;                        break;                    case BLEND_MODE.Subtractive:                        tempVertex.color -= color;                        break;                    case BLEND_MODE.Override:                        tempVertex.color = color;                        break;                }                tempVertex.color.a = orgAlpha;                vList[i] = tempVertex;            }        }        /// <summary>        /// Refresh Blend Color on playing.        /// </summary>        public void Refresh ()        {            if (graphic == null) {                graphic = GetComponent<Graphic> ();            }            if (graphic != null) {                graphic.SetVerticesDirty ();            }        }    }}


Gradient效果:

Gradient代碼:

using UnityEngine;using System.Collections.Generic;using UnityEngine.UI;namespace UiEffect{    [AddComponentMenu ("UI/Effects/Gradient Color")]    [RequireComponent (typeof (Graphic))]    public class GradientColor : BaseVertexEffect    {        public enum DIRECTION        {            Vertical,            Horizontal,            Both,        }        public DIRECTION direction = DIRECTION.Both;        public Color colorTop = Color.white;        public Color colorBottom = Color.black;        public Color colorLeft = Color.red;        public Color colorRight = Color.blue;        Graphic graphic;        public override void ModifyVertices (List<UIVertex> vList)        {            if (IsActive () == false || vList == null || vList.Count == 0) {                return;            }            float topX = 0f, topY = 0f, bottomX = 0f, bottomY = 0f;            foreach (var vertex in vList) {                topX = Mathf.Max (topX, vertex.position.x);                topY = Mathf.Max (topY, vertex.position.y);                bottomX = Mathf.Min (bottomX, vertex.position.x);                bottomY = Mathf.Min (bottomY, vertex.position.y);            }            float width = topX - bottomX;            float height = topY - bottomY;            UIVertex tempVertex = vList[0];            for (int i = 0; i < vList.Count; i++) {                tempVertex = vList[i];                byte orgAlpha = tempVertex.color.a;                Color colorOrg = tempVertex.color;                Color colorV = Color.Lerp (colorBottom, colorTop, (tempVertex.position.y - bottomY) / height);                Color colorH = Color.Lerp (colorLeft, colorRight, (tempVertex.position.x - bottomX) / width);                switch (direction) {                    case DIRECTION.Both:                        tempVertex.color = colorOrg * colorV * colorH;                        break;                    case DIRECTION.Vertical:                        tempVertex.color = colorOrg * colorV;                        break;                    case DIRECTION.Horizontal:                        tempVertex.color = colorOrg * colorH;                        break;                }                tempVertex.color.a = orgAlpha;                vList[i] = tempVertex;            }        }        /// <summary>        /// Refresh Gradient Color on playing.        /// </summary>        public void Refresh ()        {            if (graphic == null) {                graphic = GetComponent<Graphic> ();            }            if (graphic != null) {                graphic.SetVerticesDirty ();            }        }    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.