123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using CommonLang.IO;
- using System.Reflection;
- using CommonUI_Unity3D.Impl;
- namespace CommonUI_Unity3D.Impl
- {
- public static class UnityShaders
- {
- public static void InitShaders()
- {
- Debug.Log("- InitShaders ");
- UI_IMG_BASE_Shader = new Material(Shader.Find("iPhone/MFUI_Image"));
- UI_IMG_GRAY_Shader = new Material(Shader.Find("iPhone/MFUI_ImageGray"));
- UI_M3Z_BASE_Shader = new Material(Shader.Find("iPhone/MFUI_ImageMask"));
- UI_M3Z_GRAY_Shader = new Material(Shader.Find("iPhone/MFUI_ImageMaskGray"));
- UI_TXT_BASE_Shader = new Material(Shader.Find("iPhone/MFUI_Text"));
- UI_TXT_GRAY_Shader = new Material(Shader.Find("iPhone/MFUI_TextGray"));
- UI_Shape_Shader = new Material(Shader.Find("iPhone/MFUI_Shape"));
- UI_IMG_BASE_Shader.mainTextureScale = new Vector2(1, 1);
- UI_IMG_GRAY_Shader.mainTextureScale = new Vector2(1, 1);
- UI_M3Z_BASE_Shader.mainTextureScale = new Vector2(1, 1);
- UI_M3Z_GRAY_Shader.mainTextureScale = new Vector2(1, 1);
- UI_IMG_BASE_Shader.color = UnityEngine.Color.white;
- UI_IMG_GRAY_Shader.color = UnityEngine.Color.white;
- UI_M3Z_BASE_Shader.color = UnityEngine.Color.white;
- UI_M3Z_GRAY_Shader.color = UnityEngine.Color.white;
- UI_TXT_BASE_Shader.color = UnityEngine.Color.white;
- UI_TXT_GRAY_Shader.color = UnityEngine.Color.white;
- UI_Shape_Shader.color = UnityEngine.Color.white;
- UI_Image_Shader = Shader.Find("MFUGUI/Image");
- UI_ImageM3Z_Shader = Shader.Find("MFUGUI/ImageM3Z");
- UI_TextGray_Shader = Shader.Find("MFUGUI/TextGray");
- }
- public static Shader UI_Image_Shader { get; private set; }
- public static Shader UI_ImageM3Z_Shader { get; private set; }
- public static Shader UI_TextGray_Shader { get; private set; }
- public static Material CreateMaterialUGUI(UnityImage text)
- {
- if (text.TextureMask == null)
- {
- Material ret = new Material(UI_Image_Shader);
- ret.mainTextureScale = new Vector2(1, 1);
- ret.color = UnityEngine.Color.white;
- ret.mainTexture = text.Texture;
- //ret.SetFloat("_Gray", 1);
- ret.SetPass(0);
- return ret;
- }
- else
- {
- Material ret = new Material(UI_ImageM3Z_Shader);
- ret.mainTextureScale = new Vector2(1, 1);
- ret.color = UnityEngine.Color.white;
- ret.mainTexture = text.Texture;
- ret.SetTexture("_MaskTex", text.TextureMask);
- //ret.SetFloat("_Gray", 1);
- ret.SetPass(0);
- return ret;
- }
- }
- public static Material UI_IMG_BASE_Shader { get; private set; }
- public static Material UI_IMG_GRAY_Shader { get; private set; }
- public static Material UI_M3Z_BASE_Shader { get; private set; }
- public static Material UI_M3Z_GRAY_Shader { get; private set; }
- public static Material UI_TXT_BASE_Shader { get; private set; }
- public static Material UI_TXT_GRAY_Shader { get; private set; }
- public static Material UI_Shape_Shader;
- private static Color mColorShape = Color.white;
- private static Color mColorImage = Color.white;
- private static CommonUI.Display.Blend mBlend = CommonUI.Display.Blend.BLEND_MODE_NORMAL;
- public static void BeginText(UnityTextLayer text)
- {
- switch (mBlend)
- {
- case CommonUI.Display.Blend.BLEND_MODE_GRAY:
- UI_TXT_GRAY_Shader.mainTexture = text.mTexture;
- UI_TXT_GRAY_Shader.SetPass(0);
- break;
- default:
- UI_TXT_BASE_Shader.mainTexture = text.mTexture;
- UI_TXT_BASE_Shader.SetPass(0);
- break;
- }
- }
- public static void BeginImage(IUnityImageInterface image)
- {
- if (image.TextureMask == null)
- {
- switch (mBlend)
- {
- case CommonUI.Display.Blend.BLEND_MODE_GRAY:
- UI_IMG_GRAY_Shader.mainTexture = image.Texture;
- UI_IMG_GRAY_Shader.SetPass(0);
- break;
- default:
- UI_IMG_BASE_Shader.mainTexture = image.Texture;
- UI_IMG_BASE_Shader.SetPass(0);
- break;
- }
- }
- else
- {
- switch (mBlend)
- {
- case CommonUI.Display.Blend.BLEND_MODE_GRAY:
- UI_M3Z_GRAY_Shader.mainTexture = image.Texture;
- UI_M3Z_GRAY_Shader.SetTexture("_MaskTex", image.TextureMask);
- UI_M3Z_GRAY_Shader.SetPass(0);
- break;
- default:
- UI_M3Z_BASE_Shader.mainTexture = image.Texture;
- UI_M3Z_BASE_Shader.SetTexture("_MaskTex", image.TextureMask);
- UI_M3Z_BASE_Shader.SetPass(0);
- break;
- }
- }
- }
- public static void BeginShape()
- {
- UI_Shape_Shader.SetPass(0);
- }
- public static void SetColor(UnityEngine.Color color)
- {
- mColorShape = color;
- UI_Shape_Shader.SetColor("_clrBase", mColorShape);
- }
- public static void SetAlpha(float a)
- {
- mColorShape.a = a;
- mColorImage.a = a;
- UI_IMG_BASE_Shader.SetColor("_clrBase", mColorImage);
- UI_IMG_GRAY_Shader.SetColor("_clrBase", mColorImage);
- UI_M3Z_BASE_Shader.SetColor("_clrBase", mColorImage);
- UI_M3Z_GRAY_Shader.SetColor("_clrBase", mColorImage);
- UI_TXT_BASE_Shader.SetColor("_clrBase", mColorImage);
- UI_TXT_GRAY_Shader.SetColor("_clrBase", mColorImage);
- UI_Shape_Shader.SetColor("_clrBase", mColorShape);
- }
- public static void SetBlend(CommonUI.Display.Blend blend)
- {
- mBlend = blend;
- }
- }
- }
|