This commit is contained in:
Caiyanpeng committed 2021-12-28 11:25:09 +08:00
1 parent a2b44262f7
commit 2b390717c2
130 files changed
+21774 -2581

No files matched your search

+12 -2
View File
@@ -33,13 +33,24 @@ namespace Assets.Scripts.UI.Control
protected void Awake()
{
#if !(UNITY_ANDROID || UNITY_IOS)
//pc版依然让tooltip变成下面的
var newtool = transform.Find("Tooltips").gameObject;
var newrect = newtool.GetComponent<RectTransform>();
newrect.anchorMin = new Vector2(0.5f, 1);
newrect.anchorMax = new Vector2(0.5f, 1);
newrect.pivot = new Vector2(0.5f, 1);
newrect.anchoredPosition = new Vector2(0, -50);
//newrect.transform.localPosition = newrect.GetTruePosition(new Vector2(0, -50));
// -16 -66 0 -50
#endif
outline = this.GetComponent<Outline>();
if (mType == Type.Border && outline == null)
{
outline = this.gameObject.AddComponent<Outline>();
outline.effectDistance = new Vector2(2, 2);
}
//设置光标
//cursor = Resources.Load<Texture2D>("Images/PointerButtonHover");
@@ -75,7 +86,6 @@ namespace Assets.Scripts.UI.Control
}
}
tooltips.SetActive(false);
mButton = this.GetComponent<Button>();
InitColor();
+20 -6
View File
@@ -1,4 +1,5 @@
using Assets.Scripts.UI.Control;
using Assets.Scripts;
using Assets.Scripts.UI.Control;
using DG.Tweening;
using System;
using System.Collections;
@@ -16,16 +17,19 @@ public class NewMainNav : MonoBehaviour
float delayTime = 0;
private List<string> typeArray = new List<string>()
{
"Back","Exit","Home","Device","Delay","Setting","Support"
"Back","Exit","Home","Device","Delay","Setting","Support","Avatar"
};
private List<int> indexs = new List<int>();
private int? shrinkIndex = null;
/// <summary>
/// 0,1,2,3,4,5,6
/// "Back","Exit","Home","Device","Delay","Setting","Support"
///
/// </summary>
public void SetButtonActive(List<int> indexs)
/// <param name="indexs">1:"Exit",3:"Device",4:"Delay",5:"Setting",6:"Support",7:"Avatar"</param>
/// <param name="shrinkIndex">0:"Back",2:"Home",null:仅PF</param>
public void SetButtonActive(List<int> indexs,int? shrinkIndex = null)
{
this.indexs = indexs;
this.shrinkIndex = shrinkIndex;
SetExpand(false);
//List<string> types = new List<string>();
//if (indexs != null)
@@ -48,6 +52,11 @@ public class NewMainNav : MonoBehaviour
{
types = typeArray.Where((x, i) => indexs.Contains(i)).ToList();
}
string shrinkName = null;
if (shrinkIndex.HasValue && (shrinkIndex == 0 || shrinkIndex == 2))
{
shrinkName = typeArray[shrinkIndex.Value];
}
foreach (Transform item in transform)
{
if (flag)
@@ -67,13 +76,18 @@ public class NewMainNav : MonoBehaviour
}
else
{
item.gameObject.SetActive(item.name == "PF");
item.gameObject.SetActive(item.name == "PF"|| item.name == shrinkName);
}
}
}
private void Awake()
{
Utils.DisplayHead(transform.Find("Avatar").GetComponent<Image>(), App.CurrentUser.WxHeadImg);
UIManager.AddEvent(transform.Find("Avatar").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowUserInfoPanel();
});
UIManager.AddEvent(transform.Find("PF").gameObject, EventTriggerType.PointerClick, b =>
{
SetExpand(true);
@@ -19,9 +19,10 @@ public class NewRouteItemController : MonoBehaviour
{
}
public MapRouteAreaItem Area { get; private set; }
public void Initial(MapRouteAreaItem area, Dictionary<string, Texture> caches = null)
{
this.Area = area;
transform.Find("Panel/Text").GetComponent<Text>().text = area.Name;
GetComponent<Button>().onClick.RemoveAllListeners();
GetComponent<Button>().onClick.AddListener(() =>
@@ -38,6 +38,10 @@ public class HomeController : PFUIPanel
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> { 1, 3, 4, 6 });
UIManager.AddEvent(transform.Find("TodayData/Avatar").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowUserInfoPanel();
});
#else
mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
mainNav.ShowExit();
@@ -231,6 +235,15 @@ public class HomeController : PFUIPanel
DateTime.Compare(App.CurrentUser.LastUpdateFtpTime, App.CurrentUser.LastUpdateWeightTime)>0
? App.CurrentUser.LastUpdateFtpTime.ToString("dd.MM.yyyy")
: App.CurrentUser.LastUpdateWeightTime.ToString("dd.MM.yyyy");
//新版设计稿
var todayData = transform.Find("TodayData");
Utils.DisplayHead(todayData.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
todayData.Find("Datas/Distance/Value").GetComponent<Text>().text = $"{summary.TotalDistance.ToString("#0")}KM";
todayData.Find("Datas/Climb/Value").GetComponent<Text>().text = $"{double.Parse(summary.TotalClimb, CultureInfo.InvariantCulture).ToString("0")}M";
todayData.Find("Datas/Carlories/Value").GetComponent<Text>().text = $"{summary.TotalKj.ToString("#0")}KCAL";
todayData.Find("Datas/Distance/Rank").GetComponent<Text>().text = summary.CurrentTotalDistance==0? "——" : $"+{summary.CurrentTotalDistance.ToString("#0")}";
todayData.Find("Datas/Climb/Rank").GetComponent<Text>().text = summary.CurrentTotalClimb == 0 ? "——" : $"+{summary.CurrentTotalClimb.ToString("#0")}";
todayData.Find("Datas/Carlories/Rank").GetComponent<Text>().text = summary.CurrentTotalKcal == 0 ? "——" : $"+{summary.CurrentTotalKcal.ToString("#0")}";
}
async void GetSummary()
{
@@ -13,7 +13,11 @@ public class NewRouteDetailController : PFUIPanel
Dictionary<string, Texture> caches;
GameObject map;
ScrollRect scroll;
Dictionary<bool, Sprite> FavDict = new Dictionary<bool, Sprite>()
{
{false,Resources.Load<Sprite>("Images/NewDesign/icon_heji_unlike") },
{true,Resources.Load<Sprite>("Images/NewDesign/icon_heji_like") },
};
protected override void Awake()
{
caches = new Dictionary<string, Texture>();
@@ -47,7 +51,35 @@ public class NewRouteDetailController : PFUIPanel
}
void Start()
{
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("Tmp/MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> { 0, 3, 4, 6, 7 }, 0);
UIManager.AddEvent(transform.Find("Container/Left/Fav").gameObject, EventTriggerType.PointerClick, async b =>
{
Assets.Scripts.Apis.JsonResult<object> res = null;
var act = ((PointerEventData)b).pointerEnter.GetComponent<Image>().sprite.name == "icon_heji_like";
if (act)
{
res = await ConfigHelper.mapApi.CancelAreaFav(area.Id);
}
else
{
res = await ConfigHelper.mapApi.AddAreaFav(area.Id);
}
if (res.result)
{
b.selectedObject.GetComponent<Image>().sprite = FavDict[!act];
Utils.showToast(null, App.GetLocalString("Success"), type: 1);
}
else
{
Utils.showToast(null, res.errMsg);
}
});
#else
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
#endif
var rect = transform.GetComponent<RectTransform>();
rect.offsetMax = new Vector2(rect.offsetMax.x, 0);
rect.offsetMin = new Vector2(rect.offsetMin.x, 0);
@@ -96,8 +128,10 @@ public class NewRouteDetailController : PFUIPanel
.text = string.Empty;
if (area.BannerImage != null)
{
Utils.DisplayImageTempDict(left.Find("Icon").GetComponent<RawImage>(), area.BannerImage, caches);
Utils.DisplayImageTempDict(left.Find("Icon").GetComponent<RawImage>(), area.CoverImage, caches);
Utils.DisplayImageTempDict(left.Find("Thumbnail").GetComponent<RawImage>(), area.CoverImage, caches);
}
//transform.Find("Container/Left/Fav").GetComponent<Image>().sprite;
left.Find("Name").GetComponent<Text>().text = area.Name;
GetData();
GetList();
@@ -21,6 +21,20 @@ public class NewRouteOverviewController: PFUIPanel
{
caches = new Dictionary<string, Texture>();
scroll = transform.Find("Container/Right/Scroll View").GetComponent<ScrollRect>();
scroll.onValueChanged.RemoveAllListeners();
scroll.onValueChanged.AddListener(p=>
{
var rect = transform.Find("Container").GetComponent<RectTransform>();
Debug.Log($"{rect.offsetMin} {rect.offsetMax}");
if (p.y < 0.9)
{
DOTween.To(() => rect.offsetMax, x => rect.offsetMax = x, new Vector2(rect.offsetMax.x, -10), 0.5f);
}
else
{
DOTween.To(() => rect.offsetMax, x => rect.offsetMax = x, new Vector2(rect.offsetMax.x, -68), 0.5f);
}
});
UIManager.AddEvent(scroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
}
@@ -50,6 +64,8 @@ public class NewRouteOverviewController: PFUIPanel
tmpGroup = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteGroup");
tmpItem = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteItem");
#else
var nav = transform.Find("Tmp/MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> { 2, 3, 4, 6, 7 }, 2);
var rect = transform.GetComponent<RectTransform>();
rect.offsetMax = new Vector2(rect.offsetMax.x, 0);
rect.offsetMin = new Vector2(rect.offsetMin.x, 0);
@@ -182,8 +198,6 @@ public class NewRouteOverviewController: PFUIPanel
/// <summary>
/// 绑定头像
/// </summary>
void ToList(string type)
{
App.CurrentRouteType = type;// "";
+3 -2
View File
@@ -1,8 +1,9 @@
fileFormatVersion: 2
guid: d3d31d70cf492e34096ffdc82042d396
guid: 04feaefc7cdee4c13abcd553a1a6e3a9
folderAsset: yes
timeCreated: 1528368324
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -12,7 +12,7 @@ using System.Linq;
#endif
#endif
namespace Assets.Scripts.UI.UIEffect.Common
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Base class for effects that modify the generated Mesh.
@@ -27,10 +27,10 @@ namespace Assets.Scripts.UI.UIEffect.Common
#if TMP_PRESENT
static readonly List<Vector2> s_Uv0 = new List<Vector2> (4096);
static readonly List<Vector2> s_Uv1 = new List<Vector2> (4096);
#if UNITY_2017_1_OR_NEWER
#if UNITY_2017_1_OR_NEWER
static readonly List<Vector2> s_Uv2 = new List<Vector2> (4096);
static readonly List<Vector2> s_Uv3 = new List<Vector2> (4096);
#endif
#endif
static readonly List<Vector3> s_Vertices = new List<Vector3> (4096);
static readonly List<int> s_Indices = new List<int> (4096);
static readonly List<Vector3> s_Normals = new List<Vector3> (4096);
@@ -42,7 +42,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
static readonly List<UIVertex> s_UIVertices = new List<UIVertex> (4096);
static readonly List<BaseMeshEffect> s_TmpEffects = new List<BaseMeshEffect>(4);
#endif
static readonly Material[] s_EmptyMaterials = new Material[0];
static readonly Material [] s_EmptyMaterials = new Material [0];
//################################
@@ -51,12 +51,12 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// The Graphic attached to this GameObject.
/// </summary>
public Graphic graphic { get { Initialize(); return _graphic; } }
public Graphic graphic { get { Initialize (); return _graphic; } }
/// <summary>
/// The CanvasRenderer attached to this GameObject.
/// </summary>
public CanvasRenderer canvasRenderer { get { Initialize(); return _canvasRenderer; } }
public CanvasRenderer canvasRenderer { get { Initialize (); return _canvasRenderer; } }
#if TMP_PRESENT
/// <summary>
@@ -68,7 +68,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// The RectTransform attached to this GameObject.
/// </summary>
public RectTransform rectTransform { get { Initialize(); return _rectTransform; } }
public RectTransform rectTransform { get { Initialize (); return _rectTransform; } }
#if UNITY_5_6_OR_NEWER
/// <summary>
@@ -146,7 +146,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
#endif
if (graphic)
{
_materials[0] = graphic.material;
_materials [0] = graphic.material;
return _materials;
}
else
@@ -160,7 +160,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// Call used to modify mesh. (legacy)
/// </summary>
/// <param name="mesh">Mesh.</param>
public virtual void ModifyMesh(Mesh mesh)
public virtual void ModifyMesh (Mesh mesh)
{
}
@@ -168,14 +168,14 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// Call used to modify mesh.
/// </summary>
/// <param name="vh">VertexHelper.</param>
public virtual void ModifyMesh(VertexHelper vh)
public virtual void ModifyMesh (VertexHelper vh)
{
}
/// <summary>
/// Mark the vertices as dirty.
/// </summary>
public virtual void SetVerticesDirty()
public virtual void SetVerticesDirty ()
{
#if TMP_PRESENT
if (textMeshPro)
@@ -213,11 +213,11 @@ namespace Assets.Scripts.UI.UIEffect.Common
#endif
if (graphic)
{
graphic.SetVerticesDirty();
graphic.SetVerticesDirty ();
}
}
public void ShowTMProWarning(Shader shader, Shader mobileShader, Shader spriteShader, System.Action<Material> onCreatedMaterial)
public void ShowTMProWarning (Shader shader, Shader mobileShader, Shader spriteShader, System.Action<Material> onCreatedMaterial)
{
#if UNITY_EDITOR && TMP_PRESENT
if(!textMeshPro || !textMeshPro.fontSharedMaterial)
@@ -324,14 +324,14 @@ namespace Assets.Scripts.UI.UIEffect.Common
protected virtual bool isLegacyMeshModifier { get { return false; } }
protected virtual void Initialize()
protected virtual void Initialize ()
{
if (!_initialized)
{
_initialized = true;
_graphic = _graphic ?? GetComponent<Graphic>();
_canvasRenderer = _canvasRenderer ?? GetComponent<CanvasRenderer>();
_rectTransform = _rectTransform ?? GetComponent<RectTransform>();
_graphic = _graphic ?? GetComponent<Graphic> ();
_canvasRenderer = _canvasRenderer ?? GetComponent<CanvasRenderer> ();
_rectTransform = _rectTransform ?? GetComponent<RectTransform> ();
#if TMP_PRESENT
_textMeshPro = _textMeshPro ?? GetComponent<TMP_Text> ();
#endif
@@ -341,10 +341,10 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
protected override void OnEnable ()
{
_initialized = false;
SetVerticesDirty();
SetVerticesDirty ();
#if TMP_PRESENT
if (textMeshPro)
{
@@ -366,7 +366,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
var canvas = graphic.canvas;
if (canvas && (canvas.additionalShaderChannels & channels) != channels)
{
Debug.LogWarningFormat(this, "Enable {1} of Canvas.additionalShaderChannels to use {0}.", GetType().Name, channels);
Debug.LogWarningFormat (this, "Enable {1} of Canvas.additionalShaderChannels to use {0}.", GetType ().Name, channels);
}
}
#endif
@@ -375,12 +375,12 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// This function is called when the behaviour becomes disabled () or inactive.
/// </summary>
protected override void OnDisable()
protected override void OnDisable ()
{
#if TMP_PRESENT
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove (OnTextChanged);
#endif
SetVerticesDirty();
SetVerticesDirty ();
#if UNITY_EDITOR && TMP_PRESENT
if (graphic && textMeshPro)
@@ -394,7 +394,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// LateUpdate is called every frame, if the Behaviour is enabled.
/// </summary>
protected virtual void LateUpdate()
protected virtual void LateUpdate ()
{
#if TMP_PRESENT
if (textMeshPro)
@@ -411,18 +411,18 @@ namespace Assets.Scripts.UI.UIEffect.Common
/// <summary>
/// Callback for when properties have been changed by animation.
/// </summary>
protected override void OnDidApplyAnimationProperties()
protected override void OnDidApplyAnimationProperties ()
{
SetVerticesDirty();
SetVerticesDirty ();
}
#if UNITY_EDITOR
/// <summary>
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
/// </summary>
protected override void OnValidate()
protected override void OnValidate ()
{
SetVerticesDirty();
SetVerticesDirty ();
}
#endif
@@ -434,7 +434,7 @@ namespace Assets.Scripts.UI.UIEffect.Common
CanvasRenderer _canvasRenderer;
RectTransform _rectTransform;
Graphic _graphic;
Material[] _materials = new Material[1];
Material [] _materials = new Material [1];
#if TMP_PRESENT
bool _isTextMeshProActive;
@@ -532,12 +532,12 @@ namespace Assets.Scripts.UI.UIEffect.Common
mesh.GetTangents (s_Tangents);
mesh.GetIndices (s_Indices, 0);
#if UNITY_2017_1_OR_NEWER
#if UNITY_2017_1_OR_NEWER
mesh.GetUVs (2, s_Uv2);
mesh.GetUVs (3, s_Uv3);
bool useUv2 = 0 < s_Uv2.Count;
bool useUv3 = 0 < s_Uv3.Count;
#endif
#endif
s_UIVertices.Clear();
UIVertex v = default(UIVertex);
@@ -547,12 +547,12 @@ namespace Assets.Scripts.UI.UIEffect.Common
v.color = s_Colors[i];
v.uv0 = s_Uv0[i];
v.uv1 = s_Uv1[i];
#if UNITY_2017_1_OR_NEWER
#if UNITY_2017_1_OR_NEWER
if (useUv2 && i < s_Uv2.Count)
v.uv2 = s_Uv2[i];
if (useUv3 && i < s_Uv3.Count)
v.uv3 = s_Uv3[i];
#endif
#endif
v.normal = s_Normals[i];
v.tangent = s_Tangents[i];
@@ -562,4 +562,4 @@ namespace Assets.Scripts.UI.UIEffect.Common
}
#endif
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c52a957894a7bbf418d6b190bd7816a3
guid: 229ee7044e2514b0e9bd9fd40a2baa3a
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,13 @@
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Blur effect mode.
/// </summary>
public enum BlurMode
{
None = 0,
FastBlur = 1,
MediumBlur = 2,
DetailBlur = 3,
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5645838b01af8764d8f381f04b62b9a2
timeCreated: 1528296875
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Color effect mode.
/// </summary>
public enum ColorMode
{
Multiply = 0,
Fill = 1,
Add = 2,
Subtract = 3,
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e6ba1e487e0a19644afde2bd5531bd04
timeCreated: 1528296875
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,112 @@
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Area for effect.
/// </summary>
public enum EffectArea
{
RectTransform,
Fit,
Character,
}
public static class EffectAreaExtensions
{
static readonly Rect rectForCharacter = new Rect(0, 0, 1, 1);
static readonly Vector2 [] splitedCharacterPosition = { Vector2.up, Vector2.one, Vector2.right, Vector2.zero };
/// <summary>
/// Gets effect for area.
/// </summary>
public static Rect GetEffectArea (this EffectArea area, VertexHelper vh, Rect rectangle, float aspectRatio = -1)
{
Rect rect = default(Rect);
switch (area)
{
case EffectArea.RectTransform:
rect = rectangle;
break;
case EffectArea.Character:
rect = rectForCharacter;
break;
case EffectArea.Fit:
// Fit to contents.
UIVertex vertex = default (UIVertex);
float xMin = float.MaxValue;
float yMin = float.MaxValue;
float xMax = float.MinValue;
float yMax = float.MinValue;
for (int i = 0; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vertex, i);
float x = vertex.position.x;
float y = vertex.position.y;
xMin = Mathf.Min(xMin, x);
yMin = Mathf.Min(yMin, y);
xMax = Mathf.Max(xMax, x);
yMax = Mathf.Max(yMax, y);
}
rect.Set (xMin, yMin, xMax - xMin, yMax - yMin);
break;
default:
rect = rectangle;
break;
}
if(0 < aspectRatio)
{
if (rect.width < rect.height)
{
rect.width = rect.height * aspectRatio;
}
else
{
rect.height = rect.width / aspectRatio;
}
}
return rect;
}
/// <summary>
/// Gets position factor for area.
/// </summary>
public static void GetPositionFactor (this EffectArea area, int index, Rect rect, Vector2 position, bool isText, bool isTMPro, out float x, out float y)
{
if (isText && area == EffectArea.Character)
{
index = isTMPro ? (index + 3) % 4 : index % 4;
x = splitedCharacterPosition [index].x;
y = splitedCharacterPosition [index].y;
}
else if (area == EffectArea.Fit)
{
x = Mathf.Clamp01 ((position.x - rect.xMin) / rect.width);
y = Mathf.Clamp01 ((position.y - rect.yMin) / rect.height);
}
else
{
x = Mathf.Clamp01 (position.x / rect.width + 0.5f);
y = Mathf.Clamp01 (position.y / rect.height + 0.5f);
}
}
/// <summary>
/// Normalize vertex position by local matrix.
/// </summary>
public static void GetNormalizedFactor (this EffectArea area, int index, Matrix2x3 matrix, Vector2 position, bool isText, out Vector2 nomalizedPos)
{
if (isText && area == EffectArea.Character)
{
nomalizedPos = matrix * splitedCharacterPosition [(index + 3) % 4];
}
else
{
nomalizedPos = matrix * position;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a78f43d1382a048a99411472ca714e1b
timeCreated: 1528636556
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,156 @@
using UnityEngine;
using System;
using System.Collections.Generic;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Effect player.
/// </summary>
[Serializable]
public class EffectPlayer
{
//################################
// Public Members.
//################################
/// <summary>
/// Gets or sets a value indicating whether is playing.
/// </summary>
[Header("Effect Player")]
[Tooltip("Playing.")]
public bool play = false;
/// <summary>
/// Gets or sets the delay before looping.
/// </summary>
[Tooltip("Initial play delay.")]
[Range(0f, 10f)]
public float initialPlayDelay = 0;
/// <summary>
/// Gets or sets the duration.
/// </summary>
[Tooltip("Duration.")]
[Range(0.01f,10f)]
public float duration = 1;
/// <summary>
/// Gets or sets a value indicating whether can loop.
/// </summary>
[Tooltip("Loop.")]
public bool loop = false;
/// <summary>
/// Gets or sets the delay before looping.
/// </summary>
[Tooltip("Delay before looping.")]
[Range(0f,10f)]
public float loopDelay = 0;
/// <summary>
/// Gets or sets the update mode.
/// </summary>
[Tooltip("Update mode")]
public AnimatorUpdateMode updateMode = AnimatorUpdateMode.Normal;
static List<Action> s_UpdateActions;
/// <summary>
/// Register player.
/// </summary>
public void OnEnable(Action<float> callback = null)
{
if (s_UpdateActions == null)
{
s_UpdateActions = new List<Action>();
Canvas.willRenderCanvases += () =>
{
var count = s_UpdateActions.Count;
for (int i = 0; i < count; i++)
{
s_UpdateActions[i].Invoke();
}
};
}
s_UpdateActions.Add(OnWillRenderCanvases);
if (play)
{
_time = -initialPlayDelay;
}
else
{
_time = 0;
}
_callback = callback;
}
/// <summary>
/// Unregister player.
/// </summary>
public void OnDisable()
{
_callback = null;
s_UpdateActions.Remove(OnWillRenderCanvases);
}
/// <summary>
/// Start playing.
/// </summary>
public void Play(bool reset, Action<float> callback = null)
{
if (reset)
{
_time = 0;
}
play = true;
if (callback != null)
{
_callback = callback;
}
}
/// <summary>
/// Stop playing.
/// </summary>
public void Stop(bool reset)
{
if (reset)
{
_time = 0;
if (_callback != null)
{
_callback(_time);
}
}
play = false;
}
//################################
// Private Members.
//################################
float _time = 0;
Action<float> _callback;
void OnWillRenderCanvases()
{
if (!play || !Application.isPlaying || _callback == null)
{
return;
}
_time += updateMode == AnimatorUpdateMode.UnscaledTime
? Time.unscaledDeltaTime
: Time.deltaTime;
var current = _time / duration;
if (duration <= _time)
{
play = loop;
_time = loop ? -loopDelay : 0;
}
_callback(current);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1656fb67110cd44298010d95c324e87a
timeCreated: 1528296875
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,95 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect
{
public class MaterialCache
{
public ulong hash { get; private set; }
public int referenceCount { get; private set; }
public Texture texture { get; private set; }
public Material material { get; private set; }
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
static void ClearCache()
{
foreach (var cache in materialCaches)
{
cache.material = null;
}
materialCaches.Clear();
}
#endif
public static List<MaterialCache> materialCaches = new List<MaterialCache>();
public static MaterialCache Register(ulong hash, Texture texture, System.Func<Material> onCreateMaterial)
{
var cache = materialCaches.FirstOrDefault(x => x.hash == hash);
if (cache != null && cache.material)
{
if (cache.material)
{
cache.referenceCount++;
}
else
{
materialCaches.Remove(cache);
cache = null;
}
}
if (cache == null)
{
cache = new MaterialCache()
{
hash = hash,
material = onCreateMaterial(),
referenceCount = 1,
};
materialCaches.Add(cache);
}
return cache;
}
public static MaterialCache Register(ulong hash, System.Func<Material> onCreateMaterial)
{
var cache = materialCaches.FirstOrDefault(x => x.hash == hash);
if (cache != null)
{
cache.referenceCount++;
}
if (cache == null)
{
cache = new MaterialCache()
{
hash = hash,
material = onCreateMaterial(),
referenceCount = 1,
};
materialCaches.Add(cache);
}
return cache;
}
public static void Unregister(MaterialCache cache)
{
if (cache == null)
{
return;
}
cache.referenceCount--;
if (cache.referenceCount <= 0)
{
MaterialCache.materialCaches.Remove(cache);
cache.material = null;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2160d2c55a6100642b6c7ba09df935da
timeCreated: 1528509206
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,126 @@
#if UNITY_EDITOR
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect
{
public class MaterialResolver
{
static readonly StringBuilder s_StringBuilder = new StringBuilder();
static readonly Dictionary<string, Material> s_MaterialMap = new Dictionary<string, Material>();
public static Material GetOrGenerateMaterialVariant(Shader shader, params object[] append)
{
if (!shader)
{
return null;
}
Material mat = null;
string variantName = GetVariantName(shader, append);
if (s_MaterialMap.TryGetValue(variantName, out mat) && mat)
{
return mat;
}
string[] keywords = append.Where(x => 0 < (int)x)
.Select(x => x.ToString().ToUpper())
.ToArray();
mat = GetMaterial(shader, append);
if (mat)
{
if (!mat.shaderKeywords.OrderBy(x => x).SequenceEqual(keywords.OrderBy(x => x)))
{
mat.shaderKeywords = keywords;
EditorUtility.SetDirty(mat);
if (!Application.isPlaying)
{
EditorApplication.delayCall += AssetDatabase.SaveAssets;
}
}
return mat;
}
if (s_MaterialMap.TryGetValue(variantName, out mat) && mat)
{
return mat;
}
Debug.Log("Generate material : " + variantName);
mat = new Material(shader);
mat.shaderKeywords = keywords;
mat.name = variantName;
mat.hideFlags |= HideFlags.NotEditable;
s_MaterialMap[variantName] = mat;
bool isMainAsset = append.Cast<int>().All(x => x == 0);
EditorApplication.delayCall += () => SaveMaterial(mat, shader, isMainAsset);
return mat;
}
static void SaveMaterial(Material mat, Shader shader, bool isMainAsset)
{
string materialPath = GetDefaultMaterialPath(shader);
#if UIEFFECT_SEPARATE
string dir = Path.GetDirectoryName(materialPath);
materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
isMainAsset = true;
#endif
if (isMainAsset)
{
Directory.CreateDirectory(Path.GetDirectoryName(materialPath));
AssetDatabase.CreateAsset(mat, materialPath);
}
else
{
GetOrGenerateMaterialVariant(shader);
mat.hideFlags |= HideFlags.HideInHierarchy;
AssetDatabase.AddObjectToAsset(mat, materialPath);
}
AssetDatabase.SaveAssets();
}
public static Material GetMaterial(Shader shader, params object[] append)
{
string variantName = GetVariantName(shader, append);
return AssetDatabase.FindAssets("t:Material " + Path.GetFileName(shader.name))
.Select(x => AssetDatabase.GUIDToAssetPath(x))
.SelectMany(x => AssetDatabase.LoadAllAssetsAtPath(x))
.OfType<Material>()
.FirstOrDefault(x => x.name == variantName);
}
public static string GetDefaultMaterialPath(Shader shader)
{
var name = Path.GetFileName(shader.name);
return AssetDatabase.FindAssets("t:Material " + name)
.Select(x => AssetDatabase.GUIDToAssetPath(x))
.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == name)
?? ("Assets/" + name + ".mat");
}
public static string GetVariantName(Shader shader, params object[] append)
{
s_StringBuilder.Length = 0;
#if UIEFFECT_SEPARATE
s_StringBuilder.Append("[Separated] ");
#endif
s_StringBuilder.Append(Path.GetFileName(shader.name));
foreach (object mode in append.Where(x=>0<(int)x))
{
s_StringBuilder.Append("-");
s_StringBuilder.Append(mode.ToString());
}
return s_StringBuilder.ToString();
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 70261fa2760d4c040ac28aebb1f155fb
timeCreated: 1528297353
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Matrix2x3.
/// </summary>
public struct Matrix2x3
{
public float m00, m01, m02, m10, m11, m12;
public Matrix2x3(Rect rect, float cos, float sin)
{
const float center = 0.5f;
float dx = -rect.xMin / rect.width - center;
float dy = -rect.yMin / rect.height - center;
m00 = cos / rect.width;
m01 = -sin / rect.height;
m02 = dx * cos - dy * sin + center;
m10 = sin / rect.width;
m11 = cos / rect.height;
m12 = dx * sin + dy * cos + center;
}
public static Vector2 operator*(Matrix2x3 m, Vector2 v)
{
return new Vector2(
(m.m00 * v.x) + (m.m01 * v.y) + m.m02,
(m.m10 * v.x) + (m.m11 * v.y) + m.m12
);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5a9b962044ca64867b713425f7e5daab
timeCreated: 1527590245
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Packer
{
/// <summary>
/// Pack 4 low-precision [0-1] floats values to a float.
/// Each value [0-1] has 64 steps(6 bits).
/// </summary>
public static float ToFloat(float x, float y, float z, float w)
{
x = x < 0 ? 0 : 1 < x ? 1 : x;
y = y < 0 ? 0 : 1 < y ? 1 : y;
z = z < 0 ? 0 : 1 < z ? 1 : z;
w = w < 0 ? 0 : 1 < w ? 1 : w;
const int PRECISION = (1 << 6) - 1;
return (Mathf.FloorToInt(w * PRECISION) << 18)
+ (Mathf.FloorToInt(z * PRECISION) << 12)
+ (Mathf.FloorToInt(y * PRECISION) << 6)
+ Mathf.FloorToInt(x * PRECISION);
}
/// <summary>
/// Pack 4 low-precision [0-1] floats values to a float.
/// Each value [0-1] has 64 steps(6 bits).
/// </summary>
public static float ToFloat(Vector4 factor)
{
return ToFloat(Mathf.Clamp01(factor.x), Mathf.Clamp01(factor.y), Mathf.Clamp01(factor.z), Mathf.Clamp01(factor.w));
}
/// <summary>
/// Pack 1 middle-precision & 2 low-precision [0-1] floats values to a float.
/// z value [0-1] has 4096 steps(12 bits) and xy value [0-1] has 64 steps(6 bits).
/// </summary>
public static float ToFloat(float x, float y, float z)
{
x = x < 0 ? 0 : 1 < x ? 1 : x;
y = y < 0 ? 0 : 1 < y ? 1 : y;
z = z < 0 ? 0 : 1 < z ? 1 : z;
const int PRECISION = (1 << 8) - 1;
return (Mathf.FloorToInt(z * PRECISION) << 16)
+ (Mathf.FloorToInt(y * PRECISION) << 8)
+ Mathf.FloorToInt(x * PRECISION);
}
/// <summary>
/// Pack 2 low-precision [0-1] floats values to a float.
/// Each value [0-1] has 4096 steps(12 bits).
/// </summary>
public static float ToFloat(float x, float y)
{
x = x < 0 ? 0 : 1 < x ? 1 : x;
y = y < 0 ? 0 : 1 < y ? 1 : y;
const int PRECISION = (1 << 12) - 1;
return (Mathf.FloorToInt(y * PRECISION) << 12)
+ Mathf.FloorToInt(x * PRECISION);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b4970b3a69d3b472b8d66c1d92ec7bad
timeCreated: 1527590285
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,190 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using System;
namespace Assets.Scripts.UI.UIEffect
{
public interface IParameterTexture
{
int parameterIndex { get; set; }
ParameterTexture ptex { get; }
}
/// <summary>
/// Parameter texture.
/// </summary>
[System.Serializable]
public class ParameterTexture
{
//################################
// Public Members.
//################################
/// <summary>
/// Initializes a new instance of the <see cref="Assets.Scripts.UI.UIEffect.ParameterTexture"/> class.
/// </summary>
/// <param name="channels">Channels.</param>
/// <param name="instanceLimit">Instance limit.</param>
/// <param name="propertyName">Property name.</param>
public ParameterTexture(int channels, int instanceLimit, string propertyName)
{
_propertyName = propertyName;
_channels = ((channels - 1) / 4 + 1) * 4;
_instanceLimit = ((instanceLimit - 1) / 2 + 1) * 2;
_data = new byte[_channels * _instanceLimit];
_stack = new Stack<int>(_instanceLimit);
for (int i = 1; i < _instanceLimit + 1; i++)
{
_stack.Push(i);
}
}
/// <summary>
/// Register the specified target.
/// </summary>
/// <param name="target">Target.</param>
public void Register(IParameterTexture target)
{
Initialize();
if (target.parameterIndex <= 0 && 0 < _stack.Count)
{
target.parameterIndex = _stack.Pop();
// Debug.LogFormat("<color=green>@@@ Register {0} : {1}</color>", target, target.parameterIndex);
}
}
/// <summary>
/// Unregister the specified target.
/// </summary>
/// <param name="target">Target.</param>
public void Unregister(IParameterTexture target)
{
if (0 < target.parameterIndex)
{
// Debug.LogFormat("<color=red>@@@ Unregister {0} : {1}</color>", target, target.parameterIndex);
_stack.Push(target.parameterIndex);
target.parameterIndex = 0;
}
}
/// <summary>
/// Sets the data.
/// </summary>
/// <param name="target">Target.</param>
/// <param name="channelId">Channel identifier.</param>
/// <param name="value">Value.</param>
public void SetData(IParameterTexture target, int channelId, byte value)
{
int index = (target.parameterIndex - 1) * _channels + channelId;
if (0 < target.parameterIndex && _data[index] != value)
{
_data[index] = value;
_needUpload = true;
}
}
/// <summary>
/// Sets the data.
/// </summary>
/// <param name="target">Target.</param>
/// <param name="channelId">Channel identifier.</param>
/// <param name="value">Value.</param>
public void SetData(IParameterTexture target, int channelId, float value)
{
SetData(target, channelId, (byte)(Mathf.Clamp01(value) * 255));
}
/// <summary>
/// Registers the material.
/// </summary>
/// <param name="mat">Mat.</param>
public void RegisterMaterial(Material mat)
{
if (_propertyId == 0)
{
_propertyId = Shader.PropertyToID(_propertyName);
}
if (mat)
{
mat.SetTexture(_propertyId, _texture);
}
}
/// <summary>
/// Gets the index of the normalized.
/// </summary>
/// <returns>The normalized index.</returns>
/// <param name="target">Target.</param>
public float GetNormalizedIndex(IParameterTexture target)
{
return ((float)target.parameterIndex - 0.5f) / _instanceLimit;
}
//################################
// Private Members.
//################################
Texture2D _texture;
bool _needUpload;
int _propertyId;
readonly string _propertyName;
readonly int _channels;
readonly int _instanceLimit;
readonly byte[] _data;
readonly Stack<int> _stack;
static List<Action> updates;
/// <summary>
/// Initialize this instance.
/// </summary>
void Initialize()
{
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying && UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
{
return;
}
#endif
if (updates == null)
{
updates = new List<Action>();
Canvas.willRenderCanvases += () =>
{
var count = updates.Count;
for (int i = 0; i < count; i++)
{
updates[i].Invoke();
}
};
}
if (!_texture)
{
bool isLinear = QualitySettings.activeColorSpace == ColorSpace.Linear;
_texture = new Texture2D(_channels / 4, _instanceLimit, TextureFormat.RGBA32, false, isLinear);
_texture.filterMode = FilterMode.Point;
_texture.wrapMode = TextureWrapMode.Clamp;
updates.Add(UpdateParameterTexture);
_needUpload = true;
}
}
void UpdateParameterTexture()
{
if (_needUpload && _texture)
{
_needUpload = false;
_texture.LoadRawTextureData(_data);
_texture.Apply(false, false);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 65eafa89b3a3a494a99e185423ba6cad
timeCreated: 1533006319
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Shadow effect style.
/// </summary>
public enum ShadowStyle
{
None = 0,
Shadow,
Outline,
Outline8,
Shadow3,
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b0eda5bf10146491c9cfe6a31c66f9a7
timeCreated: 1528296875
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,14 @@
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Effect mode.
/// </summary>
public enum EffectMode
{
None = 0,
Grayscale = 1,
Sepia = 2,
Nega = 3,
Pixel = 4,
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 092769547c242d74cbad96631a00963f
timeCreated: 1528296875
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,165 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Abstract effect base for UI.
/// </summary>
[DisallowMultipleComponent]
public abstract class UIEffectBase : BaseMeshEffect, IParameterTexture
#if UNITY_EDITOR
, ISerializationCallbackReceiver
#endif
{
protected static readonly Vector2[] splitedCharacterPosition = { Vector2.up, Vector2.one, Vector2.right, Vector2.zero };
protected static readonly List<UIVertex> tempVerts = new List<UIVertex>();
[HideInInspector]
[SerializeField] int m_Version;
[SerializeField] protected Material m_EffectMaterial;
/// <summary>
/// Gets or sets the parameter index.
/// </summary>
public int parameterIndex { get; set; }
/// <summary>
/// Gets the parameter texture.
/// </summary>
public virtual ParameterTexture ptex { get { return null; } }
/// <summary>
/// Gets target graphic for effect.
/// </summary>
public Graphic targetGraphic { get { return graphic; } }
/// <summary>
/// Gets material for effect.
/// </summary>
public Material effectMaterial { get { return m_EffectMaterial; } }
#if UNITY_EDITOR
protected override void Reset()
{
m_Version = 300;
OnValidate();
}
/// <summary>
/// Raises the validate event.
/// </summary>
protected override void OnValidate()
{
base.OnValidate ();
var mat = GetMaterial();
if (m_EffectMaterial != mat)
{
m_EffectMaterial = mat;
UnityEditor.EditorUtility.SetDirty(this);
}
ModifyMaterial();
SetVerticesDirty ();
SetDirty ();
}
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
UnityEditor.EditorApplication.delayCall += UpgradeIfNeeded;
}
protected bool IsShouldUpgrade(int expectedVersion)
{
if (m_Version < expectedVersion)
{
Debug.LogFormat(gameObject, "<b>{0}({1})</b> has been upgraded: <i>version {2} -> {3}</i>", name, GetType().Name, m_Version, expectedVersion);
m_Version = expectedVersion;
//UnityEditor.EditorApplication.delayCall += () =>
{
UnityEditor.EditorUtility.SetDirty(this);
if (!Application.isPlaying && gameObject && gameObject.scene.IsValid())
{
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene);
}
}
;
return true;
}
return false;
}
protected virtual void UpgradeIfNeeded()
{
}
/// <summary>
/// Gets the material.
/// </summary>
/// <returns>The material.</returns>
protected virtual Material GetMaterial()
{
return null;
}
#endif
/// <summary>
/// Modifies the material.
/// </summary>
public virtual void ModifyMaterial()
{
targetGraphic.material = isActiveAndEnabled ? m_EffectMaterial : null;
}
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable ();
if (ptex != null)
{
ptex.Register(this);
}
ModifyMaterial();
SetVerticesDirty();
SetDirty();
}
/// <summary>
/// This function is called when the behaviour becomes disabled () or inactive.
/// </summary>
protected override void OnDisable()
{
base.OnDisable ();
ModifyMaterial ();
SetVerticesDirty();
if (ptex != null)
{
ptex.Unregister(this);
}
}
/// <summary>
/// Mark the UIEffect as dirty.
/// </summary>
protected virtual void SetDirty()
{
SetVerticesDirty();
}
protected override void OnDidApplyAnimationProperties()
{
SetDirty();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e8b7ed62cf1444b4ebfc5e5338bc6682
timeCreated: 1485321967
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ee1bfc8c299e6482cb7175ba2f94495a
folderAsset: yes
timeCreated: 1487152270
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect.Editors
{
public class BaseMeshEffectEditor : Editor
{
List<MaterialEditor> _materialEditors = new List<MaterialEditor> ();
protected virtual void OnEnable ()
{
ClearMaterialEditors ();
}
protected virtual void OnDisable ()
{
ClearMaterialEditors ();
}
void ClearMaterialEditors ()
{
foreach (var e in _materialEditors)
{
if (e)
{
DestroyImmediate (e);
}
}
_materialEditors.Clear ();
}
protected void ShowMaterialEditors (Material [] materials, int startIndex, int count)
{
for (int i = 0; i < count; i++)
{
if (_materialEditors.Count == i)
{
_materialEditors.Add (null);
}
var mat = materials [startIndex + i];
var editor = _materialEditors [i];
if (editor && editor.target != mat)
{
DestroyImmediate (editor);
editor = null;
}
if (!editor)
{
editor = _materialEditors [i] = Editor.CreateEditor (mat) as MaterialEditor;
}
editor.DrawHeader ();
editor.OnInspectorGUI ();
}
}
protected void ShowCanvasChannelsWarning ()
{
BaseMeshEffect effect = target as BaseMeshEffect;
if (!effect || !effect.graphic)
{
return;
}
#if UNITY_5_6_OR_NEWER
AdditionalCanvasShaderChannels channels = effect.requiredChannels;
var canvas = effect.graphic.canvas;
if (canvas && (canvas.additionalShaderChannels & channels) != channels)
{
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox (string.Format ("Enable {1} of Canvas.additionalShaderChannels to use {0}.", effect.GetType ().Name, channels), MessageType.Warning);
if (GUILayout.Button ("Fix"))
{
canvas.additionalShaderChannels |= channels;
}
EditorGUILayout.EndHorizontal ();
}
#endif
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7ddf2f64ff7af4a9f9b5ba45f40302bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System.Collections;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// Remove deprecated files in old .unitypackage, after compiling.
/// </summary>
public class DeprecatedRemover
{
/// <summary>
/// GUIDs of deprecated files.
/// </summary>
static readonly List<string> DeprecatedFiles = new List<string>()
{
"156b57fee6ef941958e66a129ce387e2", // UICustomEffect.cs
"a4961e148a8cd4fe0b84dddc2741894a", // UICustomEffectEditor.cs
"7b1ed09bdf5e54042b5cd1fbe69361bf", // MaterialBundle.cs
};
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
static void RemoveFiles()
{
// The deprecated file path that exists.
var files = DeprecatedFiles.Select(x => AssetDatabase.GUIDToAssetPath(x))
.Where(x => File.Exists(x))
.ToArray();
if (files.Any())
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<b><color=orange>[{0}]</color></b> {1} files have been removed.\n", typeof(DeprecatedRemover).Name, files.Length);
foreach (var path in files)
{
AssetDatabase.DeleteAsset(path);
sb.AppendFormat(" - {0}\n", path);
}
AssetDatabase.Refresh();
UnityEngine.Debug.Log(sb);
}
}
#endif
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6955fce24c79542af9ba39b3cf6f610f
timeCreated: 1536108312
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,181 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIDissolve))]
[CanEditMultipleObjects]
public class UIDissolveEditor : BaseMeshEffectEditor
{
static int s_NoiseTexId;
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable ();
_spMaterial = serializedObject.FindProperty("m_EffectMaterial");
_spEffectFactor = serializedObject.FindProperty("m_EffectFactor");
_spEffectArea = serializedObject.FindProperty("m_EffectArea");
_spKeepAspectRatio = serializedObject.FindProperty("m_KeepAspectRatio");
_spWidth = serializedObject.FindProperty("m_Width");
_spColor = serializedObject.FindProperty("m_Color");
_spSoftness = serializedObject.FindProperty("m_Softness");
_spColorMode = serializedObject.FindProperty("m_ColorMode");
_spNoiseTexture = serializedObject.FindProperty("m_NoiseTexture");
_spKeepAspectRatio = serializedObject.FindProperty("m_KeepAspectRatio");
_spReverse = serializedObject.FindProperty("m_Reverse");
var player = serializedObject.FindProperty("m_Player");
_spPlay = player.FindPropertyRelative("play");
_spDuration = player.FindPropertyRelative("duration");
_spInitialPlayDelay = player.FindPropertyRelative("initialPlayDelay");
_spLoop = player.FindPropertyRelative("loop");
_spLoopDelay = player.FindPropertyRelative("loopDelay");
_spUpdateMode = player.FindPropertyRelative("updateMode");
s_NoiseTexId = Shader.PropertyToID ("_NoiseTex");
_shader = Shader.Find ("TextMeshPro/Distance Field (UIDissolve)");
_mobileShader = Shader.Find ("TextMeshPro/Mobile/Distance Field (UIDissolve)");
_spriteShader = Shader.Find ("TextMeshPro/Sprite (UIDissolve)");
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
foreach (var d in targets.Cast<UIDissolve> ())
{
var mat = d.material;
if (d.isTMPro && mat && mat.HasProperty(s_NoiseTexId))
{
ColorMode colorMode =
mat.IsKeywordEnabled ("ADD") ? ColorMode.Add
: mat.IsKeywordEnabled ("SUBTRACT") ? ColorMode.Subtract
: mat.IsKeywordEnabled ("FILL") ? ColorMode.Fill
: ColorMode.Multiply;
Texture noiseTexture = mat.GetTexture(s_NoiseTexId);
if (d.colorMode != colorMode || d.noiseTexture != noiseTexture)
{
var so = new SerializedObject (d);
so.FindProperty ("m_ColorMode").intValue = (int)colorMode;
so.FindProperty ("m_NoiseTexture").objectReferenceValue = noiseTexture;
so.ApplyModifiedProperties ();
}
}
}
serializedObject.Update();
//================
// Effect material.
//================
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
EditorGUILayout.PropertyField(_spEffectFactor);
EditorGUILayout.PropertyField(_spWidth);
EditorGUILayout.PropertyField(_spSoftness);
EditorGUILayout.PropertyField(_spColor);
bool isAnyTMPro = targets.Cast<UIDissolve>().Any(x => x.isTMPro);
using (new EditorGUI.DisabledGroupScope (isAnyTMPro))
{
EditorGUILayout.PropertyField (_spColorMode);
EditorGUILayout.PropertyField (_spNoiseTexture);
}
//================
// Advanced option.
//================
EditorGUILayout.PropertyField(_spEffectArea);
EditorGUILayout.PropertyField(_spKeepAspectRatio);
//================
// Effect player.
//================
EditorGUILayout.PropertyField(_spPlay);
EditorGUILayout.PropertyField(_spDuration);
EditorGUILayout.PropertyField(_spInitialPlayDelay);
EditorGUILayout.PropertyField(_spLoop);
EditorGUILayout.PropertyField(_spLoopDelay);
EditorGUILayout.PropertyField(_spUpdateMode);
EditorGUILayout.PropertyField(_spReverse);
// Debug.
using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
{
GUILayout.Label("Debug");
if (GUILayout.Button("Play", "ButtonLeft"))
{
(target as UIDissolve).Play();
}
if (GUILayout.Button("Stop", "ButtonRight"))
{
(target as UIDissolve).Stop();
}
}
var c = target as UIDissolve;
c.ShowTMProWarning (_shader, _mobileShader, _spriteShader, mat => {
if(mat.shader == _spriteShader)
{
mat.shaderKeywords = c.material.shaderKeywords;
mat.SetTexture ("_NoiseTex", c.material.GetTexture ("_NoiseTex"));
}
});
ShowCanvasChannelsWarning ();
ShowMaterialEditors (c.materials, 1, c.materials.Length - 1);
serializedObject.ApplyModifiedProperties();
}
//################################
// Private Members.
//################################
SerializedProperty _spMaterial;
SerializedProperty _spEffectFactor;
SerializedProperty _spWidth;
SerializedProperty _spColor;
SerializedProperty _spSoftness;
SerializedProperty _spColorMode;
SerializedProperty _spNoiseTexture;
SerializedProperty _spEffectArea;
SerializedProperty _spKeepAspectRatio;
SerializedProperty _spReverse;
SerializedProperty _spPlay;
SerializedProperty _spLoop;
SerializedProperty _spLoopDelay;
SerializedProperty _spDuration;
SerializedProperty _spInitialPlayDelay;
SerializedProperty _spUpdateMode;
Shader _shader;
Shader _mobileShader;
Shader _spriteShader;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f7f7349a5d61649b69946853317db047
timeCreated: 1538806040
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,188 @@
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using DesamplingRate = Assets.Scripts.UI.UIEffect.UIEffectCapturedImage.DesamplingRate;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffectCapturedImage editor.
/// </summary>
[CustomEditor(typeof(UIEffectCapturedImage))]
[CanEditMultipleObjects]
public class UIEffectCapturedImageEditor : RawImageEditor
{
//################################
// Constant or Static Members.
//################################
public enum QualityMode : int
{
Fast = (DesamplingRate.x2 << 0) + (DesamplingRate.x2 << 4) + (FilterMode.Bilinear << 8) + (2 << 10),
Medium = (DesamplingRate.x1 << 0) + (DesamplingRate.x1 << 4) + (FilterMode.Bilinear << 8) + (3 << 10),
Detail = (DesamplingRate.None << 0) + (DesamplingRate.x1 << 4) + (FilterMode.Bilinear << 8) + (5 << 10),
Custom = -1,
}
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
_spTexture = serializedObject.FindProperty("m_Texture");
_spColor = serializedObject.FindProperty("m_Color");
_spRaycastTarget = serializedObject.FindProperty("m_RaycastTarget");
_spDesamplingRate = serializedObject.FindProperty("m_DesamplingRate");
_spReductionRate = serializedObject.FindProperty("m_ReductionRate");
_spFilterMode = serializedObject.FindProperty("m_FilterMode");
_spIterations = serializedObject.FindProperty("m_BlurIterations");
_spKeepSizeToRootCanvas = serializedObject.FindProperty("m_FitToScreen");
_spBlurMode = serializedObject.FindProperty("m_BlurMode");
_spCaptureOnEnable = serializedObject.FindProperty("m_CaptureOnEnable");
_customAdvancedOption = (qualityMode == QualityMode.Custom);
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
var graphic = (target as UIEffectCapturedImage);
serializedObject.Update();
//================
// Basic properties.
//================
EditorGUILayout.PropertyField(_spTexture);
EditorGUILayout.PropertyField(_spColor);
EditorGUILayout.PropertyField(_spRaycastTarget);
//================
// Capture effect.
//================
GUILayout.Space(10);
EditorGUILayout.LabelField("Capture Effect", EditorStyles.boldLabel);
UIEffectEditor.DrawEffectProperties(serializedObject, "m_EffectColor");
//================
// Advanced option.
//================
GUILayout.Space(10);
EditorGUILayout.LabelField("Advanced Option", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_spCaptureOnEnable);// CaptureOnEnable.
EditorGUILayout.PropertyField(_spKeepSizeToRootCanvas);// Keep Graphic Size To RootCanvas.
EditorGUI.BeginChangeCheck();
QualityMode quality = qualityMode;
quality = (QualityMode)EditorGUILayout.EnumPopup("Quality Mode", quality);
if (EditorGUI.EndChangeCheck())
{
_customAdvancedOption = (quality == QualityMode.Custom);
qualityMode = quality;
}
// When qualityMode is `Custom`, show advanced option.
if (_customAdvancedOption)
{
if (_spBlurMode.intValue != 0)
{
EditorGUILayout.PropertyField(_spIterations);// Iterations.
}
DrawDesamplingRate(_spReductionRate);// Reduction rate.
EditorGUILayout.Space();
EditorGUILayout.LabelField("Result Texture Setting", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_spFilterMode);// Filter Mode.
DrawDesamplingRate(_spDesamplingRate);// Desampling rate.
}
serializedObject.ApplyModifiedProperties();
// Debug.
using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
{
GUILayout.Label("Debug");
if (GUILayout.Button("Capture", "ButtonLeft"))
{
graphic.Release();
EditorApplication.delayCall += graphic.Capture;
}
EditorGUI.BeginDisabledGroup(!(target as UIEffectCapturedImage).capturedTexture);
if (GUILayout.Button("Release", "ButtonRight"))
{
graphic.Release();
}
EditorGUI.EndDisabledGroup();
}
}
//################################
// Private Members.
//################################
const int Bits4 = (1 << 4) - 1;
const int Bits2 = (1 << 2) - 1;
bool _customAdvancedOption = false;
SerializedProperty _spTexture;
SerializedProperty _spColor;
SerializedProperty _spRaycastTarget;
SerializedProperty _spDesamplingRate;
SerializedProperty _spReductionRate;
SerializedProperty _spFilterMode;
SerializedProperty _spBlurMode;
SerializedProperty _spIterations;
SerializedProperty _spKeepSizeToRootCanvas;
SerializedProperty _spCaptureOnEnable;
QualityMode qualityMode
{
get
{
if (_customAdvancedOption)
return QualityMode.Custom;
int qualityValue = (_spDesamplingRate.intValue << 0)
+ (_spReductionRate.intValue << 4)
+ (_spFilterMode.intValue << 8)
+ (_spIterations.intValue << 10);
return System.Enum.IsDefined(typeof(QualityMode), qualityValue) ? (QualityMode)qualityValue : QualityMode.Custom;
}
set
{
if (value != QualityMode.Custom)
{
int qualityValue = (int)value;
_spDesamplingRate.intValue = (qualityValue >> 0) & Bits4;
_spReductionRate.intValue = (qualityValue >> 4) & Bits4;
_spFilterMode.intValue = (qualityValue >> 8) & Bits2;
_spIterations.intValue = (qualityValue >> 10) & Bits4;
}
}
}
/// <summary>
/// Draws the desampling rate.
/// </summary>
void DrawDesamplingRate(SerializedProperty sp)
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(sp);
int w, h;
(target as UIEffectCapturedImage).GetDesamplingSize((UIEffectCapturedImage.DesamplingRate)sp.intValue, out w, out h);
GUILayout.Label(string.Format("{0}x{1}", w, h), EditorStyles.miniLabel);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2476309c9b71d614ab97a2f9651b3333
timeCreated: 1487152293
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,253 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;
using System;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIEffect))]
[CanEditMultipleObjects]
public class UIEffectEditor : BaseMeshEffectEditor
{
static readonly GUIContent contentEffectColor = new GUIContent ("Effect Color");
//################################
// Public/Protected Members.
//################################
/// <summary>
/// Draw effect properties.
/// </summary>
public static void DrawEffectProperties(SerializedObject serializedObject, string colorProperty = "m_Color")
{
//================
// Effect material.
//================
var spMaterial = serializedObject.FindProperty("m_EffectMaterial");
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
var spToneMode = serializedObject.FindProperty("m_EffectMode");
EditorGUILayout.PropertyField(spToneMode);
// When tone is enable, show parameters.
if (spToneMode.intValue != (int)EffectMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectFactor"));
EditorGUI.indentLevel--;
}
//================
// Color setting.
//================
var spColorMode = serializedObject.FindProperty("m_ColorMode");
EditorGUILayout.PropertyField(spColorMode);
// When color is enable, show parameters.
//if (spColorMode.intValue != (int)ColorMode.Multiply)
{
EditorGUI.indentLevel++;
SerializedProperty spColor = serializedObject.FindProperty(colorProperty);
if (spColor == null && serializedObject.targetObject is UIEffect) {
spColor = new SerializedObject (serializedObject.targetObjects.Select(x=>(x as UIEffect).targetGraphic).ToArray()).FindProperty(colorProperty);
}
EditorGUI.BeginChangeCheck ();
EditorGUI.showMixedValue = spColor.hasMultipleDifferentValues;
#if UNITY_2018_1_OR_NEWER
spColor.colorValue = EditorGUILayout.ColorField (contentEffectColor, spColor.colorValue, true, false, false);
#else
spColor.colorValue = EditorGUILayout.ColorField (contentEffectColor, spColor.colorValue, true, false, false, null);
#endif
if (EditorGUI.EndChangeCheck ()) {
spColor.serializedObject.ApplyModifiedProperties ();
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ColorFactor"));
EditorGUI.indentLevel--;
}
//================
// Blur setting.
//================
var spBlurMode = serializedObject.FindProperty("m_BlurMode");
EditorGUILayout.PropertyField(spBlurMode);
// When blur is enable, show parameters.
if (spBlurMode.intValue != (int)BlurMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BlurFactor"));
var spAdvancedBlur = serializedObject.FindProperty("m_AdvancedBlur");
if (spAdvancedBlur != null)
{
EditorGUILayout.PropertyField(spAdvancedBlur);
}
EditorGUI.indentLevel--;
}
}
int GetEnum<T>(Material mat)
{
Type type = typeof(T);
string[] names = System.Enum.GetNames (type);
int[] values = System.Enum.GetValues (type) as int[];
int mode = 0;
for(int i=0;i<names.Length;i++)
{
if (mat.IsKeywordEnabled (names [i].ToUpper()))
mode = values [i];
}
return mode;
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
foreach (var d in targets.Cast<UIEffect> ())
{
var mat = d.material;
if (d.isTMPro && mat)
{
var so = new SerializedObject (d);
EffectMode eMode = (EffectMode)GetEnum<EffectMode> (mat);
ColorMode cMode = (ColorMode)GetEnum<ColorMode> (mat);
BlurMode bMode = (BlurMode)GetEnum<BlurMode> (mat);
bool aBlur = mat.IsKeywordEnabled("EX");
if (d.effectMode != eMode || d.colorMode != cMode || d.blurMode != bMode || so.FindProperty ("m_AdvancedBlur").boolValue != aBlur)
{
so.FindProperty ("m_EffectMode").intValue = (int)eMode;
so.FindProperty ("m_ColorMode").intValue = (int)cMode;
so.FindProperty ("m_BlurMode").intValue = (int)bMode;
so.FindProperty ("m_AdvancedBlur").boolValue = aBlur;
so.ApplyModifiedProperties ();
}
}
}
serializedObject.Update();
bool isAnyTMPro = targets.Cast<UIEffect>().Any(x => x.isTMPro);
var c = target as UIEffect;
//================
// Effect material.
//================
var spMaterial = serializedObject.FindProperty("m_EffectMaterial");
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
var spToneMode = serializedObject.FindProperty("m_EffectMode");
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(spToneMode);
// When tone is enable, show parameters.
if (spToneMode.intValue != (int)EffectMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectFactor"));
EditorGUI.indentLevel--;
}
//================
// Color setting.
//================
var spColorMode = serializedObject.FindProperty("m_ColorMode");
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(spColorMode);
// When color is enable, show parameters.
//if (spColorMode.intValue != (int)ColorMode.Multiply)
{
EditorGUI.indentLevel++;
SerializedProperty spColor = serializedObject.FindProperty("m_Color");
if (spColor == null && serializedObject.targetObject is UIEffect) {
spColor = new SerializedObject (serializedObject.targetObjects.Select(x=>(x as UIEffect).targetGraphic).ToArray()).FindProperty(!isAnyTMPro ? "m_Color" : "m_fontColor");
}
EditorGUI.BeginChangeCheck ();
EditorGUI.showMixedValue = spColor.hasMultipleDifferentValues;
#if UNITY_2018_1_OR_NEWER
spColor.colorValue = EditorGUILayout.ColorField (contentEffectColor, spColor.colorValue, true, false, false);
#else
spColor.colorValue = EditorGUILayout.ColorField (contentEffectColor, spColor.colorValue, true, false, false, null);
#endif
if (EditorGUI.EndChangeCheck ()) {
spColor.serializedObject.ApplyModifiedProperties ();
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ColorFactor"));
EditorGUI.indentLevel--;
}
//================
// Blur setting.
//================
var spBlurMode = serializedObject.FindProperty("m_BlurMode");
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(spBlurMode);
// When blur is enable, show parameters.
if (spBlurMode.intValue != (int)BlurMode.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BlurFactor"));
var spAdvancedBlur = serializedObject.FindProperty("m_AdvancedBlur");
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(spAdvancedBlur);
EditorGUI.indentLevel--;
}
serializedObject.ApplyModifiedProperties();
c.ShowTMProWarning (_shader, _mobileShader, _spriteShader, mat => {});
ShowCanvasChannelsWarning ();
ShowMaterialEditors (c.materials, 1, c.materials.Length - 1);
serializedObject.ApplyModifiedProperties();
}
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable ();
_shader = Shader.Find ("TextMeshPro/Distance Field (UIEffect)");
_mobileShader = Shader.Find ("TextMeshPro/Mobile/Distance Field (UIEffect)");
_spriteShader = Shader.Find ("TextMeshPro/Sprite (UIEffect)");
}
//################################
// Private Members.
//################################
Shader _shader;
Shader _mobileShader;
Shader _spriteShader;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4f7e9f2ce1cb543ca88606769affbe24
timeCreated: 1487152293
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIGradient))]
[CanEditMultipleObjects]
public class UIGradientEditor : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
//================
// Direction.
//================
var spDirection = serializedObject.FindProperty("m_Direction");
EditorGUILayout.PropertyField(spDirection);
//================
// Color.
//================
var spColor1 = serializedObject.FindProperty("m_Color1");
var spColor2 = serializedObject.FindProperty("m_Color2");
var spColor3 = serializedObject.FindProperty("m_Color3");
var spColor4 = serializedObject.FindProperty("m_Color4");
switch ((UIGradient.Direction)spDirection.intValue)
{
case UIGradient.Direction.Horizontal:
EditorGUILayout.PropertyField(spColor1, new GUIContent("Left"));
EditorGUILayout.PropertyField(spColor2, new GUIContent("Right"));
break;
case UIGradient.Direction.Vertical:
EditorGUILayout.PropertyField(spColor1, new GUIContent("Top"));
EditorGUILayout.PropertyField(spColor2, new GUIContent("Bottom"));
break;
case UIGradient.Direction.Angle:
EditorGUILayout.PropertyField(spColor1, new GUIContent("Color 1"));
EditorGUILayout.PropertyField(spColor2, new GUIContent("Color 2"));
break;
case UIGradient.Direction.Diagonal:
Rect r = EditorGUILayout.GetControlRect(false, 34);
r = EditorGUI.PrefixLabel(r, new GUIContent("Diagonal Color"));
float w = r.width / 2;
EditorGUI.PropertyField(new Rect(r.x, r.y, w, 16), spColor3, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x + w, r.y, w, 16), spColor4, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x, r.y + 18, w, 16), spColor1, GUIContent.none);
EditorGUI.PropertyField(new Rect(r.x + w, r.y + 18, w, 16), spColor2, GUIContent.none);
break;
}
//================
// Angle.
//================
if ((int)UIGradient.Direction.Angle <= spDirection.intValue)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Rotation"));
}
//================
// Offset.
//================
if ((int)UIGradient.Direction.Diagonal == spDirection.intValue)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Offset1"), new GUIContent("Vertical Offset"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Offset2"), new GUIContent("Horizontal Offset"));
}
else
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Offset1"), new GUIContent("Offset"));
}
//================
// Advanced options.
//================
EditorGUILayout.Space();
EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
{
//if ((target as UIGradient).targetGraphic is Text)
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_GradientStyle"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ColorSpace"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_IgnoreAspectRatio"));
}
EditorGUI.indentLevel--;
serializedObject.ApplyModifiedProperties();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c28dcc885fbba4a5187a6a1aa5fb1b3b
timeCreated: 1515895646
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,84 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIHsvModifier))]
[CanEditMultipleObjects]
public class UIHsvModifierEditor : BaseMeshEffectEditor
{
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable ();
_spMaterial = serializedObject.FindProperty("m_EffectMaterial");
_spTargetColor = serializedObject.FindProperty("m_TargetColor");
_spRange = serializedObject.FindProperty("m_Range");
_spHue = serializedObject.FindProperty("m_Hue");
_spSaturation = serializedObject.FindProperty("m_Saturation");
_spValue = serializedObject.FindProperty("m_Value");
_shader = Shader.Find ("TextMeshPro/Distance Field (UIHsvModifier)");
_mobileShader = Shader.Find ("TextMeshPro/Mobile/Distance Field (UIHsvModifier)");
_spriteShader = Shader.Find ("TextMeshPro/Sprite (UIHsvModifier)");
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
serializedObject.Update();
//================
// Effect material.
//================
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
EditorGUILayout.PropertyField(_spTargetColor);
EditorGUILayout.PropertyField(_spRange);
EditorGUILayout.PropertyField(_spHue);
EditorGUILayout.PropertyField(_spSaturation);
EditorGUILayout.PropertyField(_spValue);
var c = target as UIHsvModifier;
c.ShowTMProWarning (_shader, _mobileShader, _spriteShader, mat => {});
ShowCanvasChannelsWarning ();
ShowMaterialEditors (c.materials, 1, c.materials.Length - 1);
serializedObject.ApplyModifiedProperties();
}
//################################
// Private Members.
//################################
SerializedProperty _spMaterial;
SerializedProperty _spTargetColor;
SerializedProperty _spRange;
SerializedProperty _spHue;
SerializedProperty _spSaturation;
SerializedProperty _spValue;
Shader _shader;
Shader _mobileShader;
Shader _spriteShader;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f002ba0ac474d487b936bc046dda56b4
timeCreated: 1538806052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,54 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIShadow editor.
/// </summary>
[CustomEditor(typeof(UIShadow))]
[CanEditMultipleObjects]
public class UIShadowEditor : Editor
{
UIEffect uiEffect;
void OnEnable()
{
uiEffect = (target as UIShadow).GetComponent<UIEffect>();
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
serializedObject.Update();
//================
// Shadow setting.
//================
var spShadowMode = serializedObject.FindProperty("m_Style");
EditorGUILayout.PropertyField(spShadowMode);
// When shadow is enable, show parameters.
if (spShadowMode.intValue != (int)ShadowStyle.None)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectDistance"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectColor"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_UseGraphicAlpha"));
if (uiEffect && uiEffect.blurMode != BlurMode.None)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BlurFactor"));
}
EditorGUI.indentLevel--;
}
serializedObject.ApplyModifiedProperties();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6e76e7f628f09af449321b4776123f13
timeCreated: 1487152293
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,135 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UIShiny))]
[CanEditMultipleObjects]
public class UIShinyEditor : BaseMeshEffectEditor
{
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable ();
_spMaterial = serializedObject.FindProperty("m_EffectMaterial");
_spEffectFactor = serializedObject.FindProperty("m_EffectFactor");
_spEffectArea = serializedObject.FindProperty("m_EffectArea");
_spWidth = serializedObject.FindProperty("m_Width");
_spRotation = serializedObject.FindProperty("m_Rotation");
_spSoftness = serializedObject.FindProperty("m_Softness");
_spBrightness = serializedObject.FindProperty("m_Brightness");
_spGloss = serializedObject.FindProperty("m_Gloss");
var player = serializedObject.FindProperty("m_Player");
_spPlay = player.FindPropertyRelative("play");
_spDuration = player.FindPropertyRelative("duration");
_spInitialPlayDelay = player.FindPropertyRelative("initialPlayDelay");
_spLoop = player.FindPropertyRelative("loop");
_spLoopDelay = player.FindPropertyRelative("loopDelay");
_spUpdateMode = player.FindPropertyRelative("updateMode");
_shader = Shader.Find ("TextMeshPro/Distance Field (UIShiny)");
_mobileShader = Shader.Find ("TextMeshPro/Mobile/Distance Field (UIShiny)");
_spriteShader = Shader.Find ("TextMeshPro/Sprite (UIShiny)");
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
serializedObject.Update();
//================
// Effect material.
//================
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
EditorGUILayout.PropertyField(_spEffectFactor);
EditorGUILayout.PropertyField(_spWidth);
EditorGUILayout.PropertyField(_spRotation);
EditorGUILayout.PropertyField(_spSoftness);
EditorGUILayout.PropertyField(_spBrightness);
EditorGUILayout.PropertyField(_spGloss);
//================
// Advanced option.
//================
EditorGUILayout.PropertyField(_spEffectArea);
//================
// Effect player.
//================
EditorGUILayout.PropertyField(_spPlay);
EditorGUILayout.PropertyField(_spDuration);
EditorGUILayout.PropertyField(_spInitialPlayDelay);
EditorGUILayout.PropertyField(_spLoop);
EditorGUILayout.PropertyField(_spLoopDelay);
EditorGUILayout.PropertyField(_spUpdateMode);
// Debug.
using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
{
GUILayout.Label("Debug");
if (GUILayout.Button("Play", "ButtonLeft"))
{
(target as UIShiny).Play();
}
if (GUILayout.Button("Stop", "ButtonRight"))
{
(target as UIShiny).Stop();
}
}
var c = target as UIShiny;
c.ShowTMProWarning (_shader, _mobileShader, _spriteShader, mat => {});
ShowCanvasChannelsWarning ();
ShowMaterialEditors (c.materials, 1, c.materials.Length - 1);
serializedObject.ApplyModifiedProperties();
}
//################################
// Private Members.
//################################
SerializedProperty _spMaterial;
SerializedProperty _spEffectFactor;
SerializedProperty _spWidth;
SerializedProperty _spRotation;
SerializedProperty _spSoftness;
SerializedProperty _spBrightness;
SerializedProperty _spGloss;
SerializedProperty _spEffectArea;
SerializedProperty _spPlay;
SerializedProperty _spLoop;
SerializedProperty _spLoopDelay;
SerializedProperty _spDuration;
SerializedProperty _spInitialPlayDelay;
SerializedProperty _spUpdateMode;
Shader _shader;
Shader _mobileShader;
Shader _spriteShader;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0080e984bad7545cd957d9121e99f988
timeCreated: 1538806052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,190 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;
namespace Assets.Scripts.UI.UIEffect.Editors
{
/// <summary>
/// UIEffect editor.
/// </summary>
[CustomEditor(typeof(UITransitionEffect))]
[CanEditMultipleObjects]
public class UITransitionEffectEditor : BaseMeshEffectEditor
{
static int s_NoiseTexId;
//################################
// Public/Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
_spMaterial = serializedObject.FindProperty("m_EffectMaterial");
_spEffectMode = serializedObject.FindProperty("m_EffectMode");
_spEffectFactor = serializedObject.FindProperty("m_EffectFactor");
_spEffectArea = serializedObject.FindProperty("m_EffectArea");
_spKeepAspectRatio = serializedObject.FindProperty("m_KeepAspectRatio");
_spDissolveWidth = serializedObject.FindProperty("m_DissolveWidth");
_spDissolveSoftness = serializedObject.FindProperty("m_DissolveSoftness");
_spDissolveColor = serializedObject.FindProperty("m_DissolveColor");
_spTransitionTexture = serializedObject.FindProperty("m_TransitionTexture");
var player = serializedObject.FindProperty("m_Player");
_spPlay = player.FindPropertyRelative("play");
_spDuration = player.FindPropertyRelative("duration");
_spInitialPlayDelay = player.FindPropertyRelative("initialPlayDelay");
_spLoop = player.FindPropertyRelative("loop");
_spLoopDelay = player.FindPropertyRelative("loopDelay");
_spUpdateMode = player.FindPropertyRelative("updateMode");
_spPassRayOnHidden = serializedObject.FindProperty("m_PassRayOnHidden");
s_NoiseTexId = Shader.PropertyToID("_NoiseTex");
_shader = Shader.Find("TextMeshPro/Distance Field (UITransition)");
_mobileShader = Shader.Find("TextMeshPro/Mobile/Distance Field (UITransition)");
_spriteShader = Shader.Find("TextMeshPro/Sprite (UITransition)");
}
/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
public override void OnInspectorGUI()
{
foreach (var d in targets.Cast<UITransitionEffect> ())
{
var mat = d.material;
if (d.isTMPro && mat && mat.HasProperty (s_NoiseTexId))
{
Texture noiseTexture = mat.GetTexture (s_NoiseTexId);
UITransitionEffect.EffectMode mode =
mat.IsKeywordEnabled ("CUTOFF") ? UITransitionEffect.EffectMode.Cutoff
: mat.IsKeywordEnabled ("FADE") ? UITransitionEffect.EffectMode.Fade
: mat.IsKeywordEnabled ("DISSOLVE") ? UITransitionEffect.EffectMode.Dissolve
: (UITransitionEffect.EffectMode)0;
if (mode == (UITransitionEffect.EffectMode)0)
{
mode = UITransitionEffect.EffectMode.Cutoff;
mat.EnableKeyword ("CUTOFF");
}
bool hasChanged = d.transitionTexture != noiseTexture || d.effectMode != mode;
if (hasChanged)
{
var so = new SerializedObject (d);
so.FindProperty ("m_TransitionTexture").objectReferenceValue = noiseTexture;
so.FindProperty ("m_EffectMode").intValue = (int)mode;
so.ApplyModifiedProperties ();
}
}
}
serializedObject.Update();
//================
// Effect material.
//================
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(_spMaterial);
EditorGUI.EndDisabledGroup();
//================
// Effect setting.
//================
bool isAnyTMPro = targets.Cast<UITransitionEffect>().Any(x => x.isTMPro);
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(_spEffectMode);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_spEffectFactor);
if (_spEffectMode.intValue == (int)UITransitionEffect.EffectMode.Dissolve)
{
EditorGUILayout.PropertyField(_spDissolveWidth);
EditorGUILayout.PropertyField(_spDissolveSoftness);
EditorGUILayout.PropertyField(_spDissolveColor);
}
EditorGUI.indentLevel--;
//================
// Advanced option.
//================
EditorGUILayout.PropertyField(_spEffectArea);
using (new EditorGUI.DisabledGroupScope(isAnyTMPro))
EditorGUILayout.PropertyField(_spTransitionTexture);
EditorGUILayout.PropertyField(_spKeepAspectRatio);
EditorGUILayout.PropertyField(_spPassRayOnHidden);
//================
// Effect player.
//================
EditorGUILayout.PropertyField(_spPlay);
EditorGUILayout.PropertyField(_spDuration);
EditorGUILayout.PropertyField(_spInitialPlayDelay);
EditorGUILayout.PropertyField(_spLoop);
EditorGUILayout.PropertyField(_spLoopDelay);
EditorGUILayout.PropertyField(_spUpdateMode);
// Debug.
using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
{
GUILayout.Label("Debug");
if (GUILayout.Button("Show", "ButtonLeft"))
{
(target as UITransitionEffect).Show();
}
if (GUILayout.Button("Hide", "ButtonRight"))
{
(target as UITransitionEffect).Hide();
}
}
var current = target as UITransitionEffect;
current.ShowTMProWarning(_shader, _mobileShader, _spriteShader, mat =>
{
if (mat.shader == _spriteShader)
{
mat.shaderKeywords = current.material.shaderKeywords;
mat.SetTexture(s_NoiseTexId, current.material.GetTexture(s_NoiseTexId));
}
});
ShowCanvasChannelsWarning();
ShowMaterialEditors(current.materials, 1, current.materials.Length - 1);
serializedObject.ApplyModifiedProperties();
}
//################################
// Private Members.
//################################
SerializedProperty _spMaterial;
SerializedProperty _spEffectMode;
SerializedProperty _spEffectFactor;
SerializedProperty _spEffectArea;
SerializedProperty _spKeepAspectRatio;
SerializedProperty _spDissolveWidth;
SerializedProperty _spDissolveSoftness;
SerializedProperty _spDissolveColor;
SerializedProperty _spTransitionTexture;
SerializedProperty _spPlay;
SerializedProperty _spLoop;
SerializedProperty _spLoopDelay;
SerializedProperty _spDuration;
SerializedProperty _spInitialPlayDelay;
SerializedProperty _spUpdateMode;
SerializedProperty _spPassRayOnHidden;
Shader _shader;
Shader _mobileShader;
Shader _spriteShader;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 631f363a54c834f1f846f823b31bd321
timeCreated: 1538806067
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7af5e5d189eb4d9479f0a083078f4946
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,238 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 8
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-Dissolve
m_Shader: {fileID: 4800000, guid: e1b48dc831eb147e9886c049033213bf, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NoiseTex
second:
m_Texture: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _ColorMask
second: 15
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UseUIAlphaClip
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
--- !u!21 &21162286589123374
Material:
serializedVersion: 6
m_ObjectHideFlags: 9
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-Dissolve-Fill
m_Shader: {fileID: 4800000, guid: e1b48dc831eb147e9886c049033213bf, type: 3}
m_ShaderKeywords: FILL
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NoiseTex
second:
m_Texture: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _ColorMask
second: 15
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UseUIAlphaClip
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
--- !u!21 &21841578701121694
Material:
serializedVersion: 6
m_ObjectHideFlags: 9
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-Dissolve-Subtract
m_Shader: {fileID: 4800000, guid: e1b48dc831eb147e9886c049033213bf, type: 3}
m_ShaderKeywords: SUBTRACT
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NoiseTex
second:
m_Texture: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _ColorMask
second: 15
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UseUIAlphaClip
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
--- !u!21 &21939717441729078
Material:
serializedVersion: 6
m_ObjectHideFlags: 9
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-Dissolve-Add
m_Shader: {fileID: 4800000, guid: e1b48dc831eb147e9886c049033213bf, type: 3}
m_ShaderKeywords: ADD
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NoiseTex
second:
m_Texture: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _ColorMask
second: 15
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UseUIAlphaClip
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17b17d6effbe14075a3bbdf1fda1f6e1
timeCreated: 1526828325
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,154 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-HSV
m_Shader: {fileID: 4800000, guid: 7fc74090480c84f8b977cfcd55cdfe82, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _BumpScale
second: 1
- first:
name: _ColorMask
second: 15
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DstBlend
second: 0
- first:
name: _GlossMapScale
second: 1
- first:
name: _Glossiness
second: 0.5
- first:
name: _GlossyReflections
second: 1
- first:
name: _Metallic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _SmoothnessTextureChannel
second: 0
- first:
name: _SpecularHighlights
second: 1
- first:
name: _SrcBlend
second: 1
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UVSec
second: 0
- first:
name: _UseUIAlphaClip
second: 0
- first:
name: _ZWrite
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c8243c28075b3431084ded42f46ad567
timeCreated: 1531885800
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: UI-Effect-Shiny
m_Shader: {fileID: 4800000, guid: 20ffe76c2439c403aabdd25bd94bf011, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParamTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _ColorMask
second: 15
- first:
name: _Stencil
second: 0
- first:
name: _StencilComp
second: 8
- first:
name: _StencilOp
second: 0
- first:
name: _StencilReadMask
second: 255
- first:
name: _StencilWriteMask
second: 255
- first:
name: _UseUIAlphaClip
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9dc7e810a87b444ab96919f3215c2fe5
timeCreated: 1523859834
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 77a4cc77ec7394415a18f9e5a4b8083e
timeCreated: 1532512709
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aee96bc531e6eba468ec405e536f515f
timeCreated: 1516545204
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1a1a8e44196ca754a9a7b9cb80e17573
timeCreated: 1516545204
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

@@ -0,0 +1,100 @@
fileFormatVersion: 2
guid: 3e04c247fb2604af186173fce0bc62de
timeCreated: 1524468976
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: 1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 2
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 10
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 256
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 256
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: iPhone
maxTextureSize: 256
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Android
maxTextureSize: 256
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: WebGL
maxTextureSize: 256
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@@ -0,0 +1,100 @@
fileFormatVersion: 2
guid: a74d3d4a498866d44b094d3d3717604d
timeCreated: 1533229728
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 2
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 10
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Android
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: WebGL
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: iPhone
maxTextureSize: 512
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 03d05f9ad08aca246bc6462bb5972549
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,88 @@
Shader "UI/Hidden/UI-Effect-Dissolve"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
_ParamTex ("Parameter Texture", 2D) = "white" {}
[Header(Dissolve)]
_NoiseTex("Noise Texture (A)", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#define DISSOLVE 1
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#pragma shader_feature __ ADD SUBTRACT FILL
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#define UI_DISSOLVE 1
#include "UI-Effect.cginc"
#include "UI-Effect-Sprite.cginc"
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
// Dissolve
color = ApplyTransitionEffect(color, IN.eParam);
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1b48dc831eb147e9886c049033213bf
timeCreated: 1523859834
licenseType: Pro
ShaderImporter:
defaultTextures:
- _MainTex: {instanceID: 0}
- _NoiseTex: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,79 @@
Shader "UI/Hidden/UI-Effect-HSV"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
_ParamTex ("Parameter Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#define UI_HSV_MODIFIER 1
#include "UI-Effect.cginc"
#include "UI-Effect-Sprite.cginc"
fixed4 frag(v2f IN) : COLOR
{
half4 color = tex2D(_MainTex, IN.texcoord);// + _TextureSampleAdd) * IN.color;
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
color = ApplyHsvEffect(color, IN.eParam);
return (color + _TextureSampleAdd) * IN.color;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7fc74090480c84f8b977cfcd55cdfe82
timeCreated: 1531882595
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,82 @@
Shader "UI/Hidden/UI-Effect-Shiny"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
_ParamTex ("Parameter Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#define UI_SHINY 1
#include "UI-Effect.cginc"
#include "UI-Effect-Sprite.cginc"
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
color = ApplyShinyEffect(color, IN.eParam);
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 20ffe76c2439c403aabdd25bd94bf011
timeCreated: 1523859834
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,77 @@
#ifndef UI_EFFECT_SPRITE_INCLUDED
#define UI_EFFECT_SPRITE_INCLUDED
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
sampler2D _MainTex;
float4 _MainTex_TexelSize;
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
#if EX && TMP_SPRITE
float2 uvMask : TEXCOORD2;
#elif EX
float2 uvMask : TEXCOORD1;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
#if UI_DISSOLVE || UI_TRANSITION
half3 eParam : TEXCOORD2;
#elif UI_SHINY
half2 eParam : TEXCOORD2;
#else
half eParam : TEXCOORD2;
#endif
#if EX
half4 uvMask : TEXCOORD3;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
#if UI_EFFECT
OUT.texcoord = UnpackToVec2(IN.texcoord.x) * 2 - 0.5;
#else
OUT.texcoord = UnpackToVec2(IN.texcoord.x);
#endif
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
OUT.color = IN.color * _Color;
#if UI_DISSOLVE || UI_TRANSITION
OUT.eParam = UnpackToVec3(IN.texcoord.y);
#elif UI_SHINY
OUT.eParam = UnpackToVec2(IN.texcoord.y);
#else
OUT.eParam = IN.texcoord.y;
#endif
#if EX
OUT.uvMask = half4(UnpackToVec2(IN.uvMask.x), UnpackToVec2(IN.uvMask.y));
#endif
return OUT;
}
#endif // UI_EFFECT_SPRITE_INCLUDED
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: dd60a36b172cf49e2b82258a68799ce3
timeCreated: 1487915863
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,87 @@
Shader "UI/Hidden/UI-Effect-Transition"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
[Header(Transition)]
_NoiseTex ("Transition Texture (A)", 2D) = "white" {}
_ParamTex ("Parameter Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#define REVERSE 1
#define ADD 1
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#pragma shader_feature __ FADE CUTOFF DISSOLVE
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#define UI_TRANSITION 1
#include "UI-Effect.cginc"
#include "UI-Effect-Sprite.cginc"
fixed4 frag(v2f IN) : SV_Target
{
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
color = ApplyTransitionEffect(color, IN.eParam) * IN.color;
#if UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 85ad24dd0759947ddb117625e108d49c
timeCreated: 1548078121
licenseType: Pro
ShaderImporter:
defaultTextures:
- _MainTex: {instanceID: 0}
- _NoiseTex: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
- _ParamTex: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,309 @@
#ifndef UI_EFFECT_INCLUDED
#define UI_EFFECT_INCLUDED
sampler2D _NoiseTex;
sampler2D _ParamTex;
#if GRAYSCALE | SEPIA | NEGA | PIXEL | MONO | CUTOFF | HUE
#define UI_TONE
#endif
#if ADD | SUBTRACT | FILL
#define UI_COLOR
#endif
#if FASTBLUR | MEDIUMBLUR | DETAILBLUR
#define UI_BLUR
#endif
// Unpack float to low-precision [0-1] fixed4.
fixed4 UnpackToVec4(float value)
{
const int PACKER_STEP = 64;
const int PRECISION = PACKER_STEP - 1;
fixed4 unpacked;
unpacked.x = (value % PACKER_STEP) / PRECISION;
value = floor(value / PACKER_STEP);
unpacked.y = (value % PACKER_STEP) / PRECISION;
value = floor(value / PACKER_STEP);
unpacked.z = (value % PACKER_STEP) / PRECISION;
value = floor(value / PACKER_STEP);
unpacked.w = (value % PACKER_STEP) / PRECISION;
return unpacked;
}
// Unpack float to low-precision [0-1] fixed3.
fixed3 UnpackToVec3(float value)
{
const int PACKER_STEP = 256;
const int PRECISION = PACKER_STEP - 1;
fixed3 unpacked;
unpacked.x = (value % (PACKER_STEP)) / (PACKER_STEP - 1);
value = floor(value / (PACKER_STEP));
unpacked.y = (value % PACKER_STEP) / (PACKER_STEP - 1);
value = floor(value / PACKER_STEP);
unpacked.z = (value % PACKER_STEP) / (PACKER_STEP - 1);
return unpacked;
}
// Unpack float to low-precision [0-1] half2.
half2 UnpackToVec2(float value)
{
const int PACKER_STEP = 4096;
const int PRECISION = PACKER_STEP - 1;
half2 unpacked;
unpacked.x = (value % (PACKER_STEP)) / (PACKER_STEP - 1);
value = floor(value / (PACKER_STEP));
unpacked.y = (value % PACKER_STEP) / (PACKER_STEP - 1);
return unpacked;
}
// Sample texture with blurring.
// * Fast: Sample texture with 3x3 kernel.
// * Medium: Sample texture with 5x5 kernel.
// * Detail: Sample texture with 7x7 kernel.
fixed4 Tex2DBlurring (sampler2D tex, half2 texcood, half2 blur, half4 mask)
{
#if FASTBLUR && EX
const int KERNEL_SIZE = 5;
const float KERNEL_[5] = { 0.2486, 0.7046, 1.0, 0.7046, 0.2486};
#elif MEDIUMBLUR && EX
const int KERNEL_SIZE = 9;
const float KERNEL_[9] = { 0.0438, 0.1719, 0.4566, 0.8204, 1.0, 0.8204, 0.4566, 0.1719, 0.0438};
#elif DETAILBLUR && EX
const int KERNEL_SIZE = 13;
const float KERNEL_[13] = { 0.0438, 0.1138, 0.2486, 0.4566, 0.7046, 0.9141, 1.0, 0.9141, 0.7046, 0.4566, 0.2486, 0.1138, 0.0438};
#elif FASTBLUR
const int KERNEL_SIZE = 3;
const float KERNEL_[3] = { 0.4566, 1.0, 0.4566};
#elif MEDIUMBLUR
const int KERNEL_SIZE = 5;
const float KERNEL_[5] = { 0.2486, 0.7046, 1.0, 0.7046, 0.2486};
#elif DETAILBLUR
const int KERNEL_SIZE = 7;
const float KERNEL_[7] = { 0.1719, 0.4566, 0.8204, 1.0, 0.8204, 0.4566, 0.1719};
#else
const int KERNEL_SIZE = 1;
const float KERNEL_[1] = { 1.0 };
#endif
float4 o = 0;
float sum = 0;
float2 shift = 0;
for(int x = 0; x < KERNEL_SIZE; x++)
{
shift.x = blur.x * (float(x) - KERNEL_SIZE/2);
for(int y = 0; y < KERNEL_SIZE; y++)
{
shift.y = blur.y * (float(y) - KERNEL_SIZE/2);
float2 uv = texcood + shift;
float weight = KERNEL_[x] * KERNEL_[y];
sum += weight;
#if EX
fixed masked = min(mask.x <= uv.x, uv.x <= mask.z) * min(mask.y <= uv.y, uv.y <= mask.w);
o += lerp(fixed4(0.5, 0.5, 0.5, 0), tex2D(tex, uv), masked) * weight;
#else
o += tex2D(tex, uv) * weight;
#endif
}
}
return o / sum;
}
// Sample texture with blurring.
// * Fast: Sample texture with 3x3 kernel.
// * Medium: Sample texture with 5x5 kernel.
// * Detail: Sample texture with 7x7 kernel.
fixed4 Tex2DBlurring (sampler2D tex, half2 texcood, half2 blur)
{
return Tex2DBlurring(tex, texcood, blur, half4(0,0,1,1));
}
// Sample texture with blurring.
// * Fast: Sample texture with 3x1 kernel.
// * Medium: Sample texture with 5x1 kernel.
// * Detail: Sample texture with 7x1 kernel.
fixed4 Tex2DBlurring1D (sampler2D tex, half2 uv, half2 blur)
{
#if FASTBLUR
const int KERNEL_SIZE = 3;
#elif MEDIUMBLUR
const int KERNEL_SIZE = 5;
#elif DETAILBLUR
const int KERNEL_SIZE = 7;
#else
const int KERNEL_SIZE = 1;
#endif
float4 o = 0;
float sum = 0;
float weight;
half2 texcood;
for(int i = -KERNEL_SIZE/2; i <= KERNEL_SIZE/2; i++)
{
texcood = uv;
texcood.x += blur.x * i;
texcood.y += blur.y * i;
weight = 1.0/(abs(i)+2);
o += tex2D(tex, texcood)*weight;
sum += weight;
}
return o / sum;
}
fixed3 shift_hue(fixed3 RGB, half VSU, half VSW)
{
fixed3 result;
result.x = (0.299 + 0.701*VSU + 0.168*VSW)*RGB.x
+ (0.587 - 0.587*VSU + 0.330*VSW)*RGB.y
+ (0.114 - 0.114*VSU - 0.497*VSW)*RGB.z;
result.y = (0.299 - 0.299*VSU - 0.328*VSW)*RGB.x
+ (0.587 + 0.413*VSU + 0.035*VSW)*RGB.y
+ (0.114 - 0.114*VSU + 0.292*VSW)*RGB.z;
result.z = (0.299 - 0.3*VSU + 1.25*VSW)*RGB.x
+ (0.587 - 0.588*VSU - 1.05*VSW)*RGB.y
+ (0.114 + 0.886*VSU - 0.203*VSW)*RGB.z;
return result;
}
// Apply tone effect.
fixed4 ApplyToneEffect(fixed4 color, fixed factor)
{
#ifdef GRAYSCALE
color.rgb = lerp(color.rgb, Luminance(color.rgb), factor);
#elif SEPIA
color.rgb = lerp(color.rgb, Luminance(color.rgb) * half3(1.07, 0.74, 0.43), factor);
#elif NEGA
color.rgb = lerp(color.rgb, 1 - color.rgb, factor);
#endif
return color;
}
// Apply color effect.
fixed4 ApplyColorEffect(half4 color, half4 factor)
{
#if FILL
color.rgb = lerp(color.rgb, factor.rgb, factor.a);
#elif ADD
color.rgb += factor.rgb * factor.a;
#elif SUBTRACT
color.rgb -= factor.rgb * factor.a;
#else
color.rgb = lerp(color.rgb, color.rgb * factor.rgb, factor.a);
#endif
#if CUTOFF
color.a = factor.a;
#endif
return color;
}
// Apply transition effect.
fixed4 ApplyTransitionEffect(half4 color, half3 transParam)
{
fixed4 param = tex2D(_ParamTex, float2(0.25, transParam.z));
float alpha = tex2D(_NoiseTex, transParam.xy).a;
#if REVERSE
fixed effectFactor = 1 - param.x;
#else
fixed effectFactor = param.x;
#endif
#if FADE
color.a *= saturate(alpha + (1 - effectFactor * 2));
#elif CUTOFF
color.a *= step(0.001, color.a * alpha - effectFactor);
#elif DISSOLVE
fixed width = param.y/4;
fixed softness = param.z;
fixed3 dissolveColor = tex2D(_ParamTex, float2(0.75, transParam.z)).rgb;
float factor = alpha - effectFactor * ( 1 + width ) + width;
fixed edgeLerp = step(factor, color.a) * saturate((width - factor)*16/ softness);
color = ApplyColorEffect(color, fixed4(dissolveColor, edgeLerp));
color.a *= saturate((factor)*32/ softness);
#endif
return color;
}
// Apply shiny effect.
half4 ApplyShinyEffect(half4 color, half2 shinyParam)
{
fixed nomalizedPos = shinyParam.x;
fixed4 param1 = tex2D(_ParamTex, float2(0.25, shinyParam.y));
fixed4 param2 = tex2D(_ParamTex, float2(0.75, shinyParam.y));
half location = param1.x * 2 - 0.5;
fixed width = param1.y;
fixed soft = param1.z;
fixed brightness = param1.w;
fixed gloss = param2.x;
half normalized = 1 - saturate(abs((nomalizedPos - location) / width));
half shinePower = smoothstep(0, soft*2, normalized);
half3 reflectColor = lerp(1, color.rgb * 10, gloss);
color.rgb += color.a * (shinePower / 2) * brightness * reflectColor;
return color;
}
half3 RgbToHsv(half3 c) {
half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g));
half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r));
half d = q.x - min(q.w, q.y);
half e = 1.0e-10;
return half3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
half3 HsvToRgb(half3 c) {
c = half3(c.x, clamp(c.yz, 0.0, 1.0));
half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
// Apply Hsv effect.
half4 ApplyHsvEffect(half4 color, half param)
{
fixed4 param1 = tex2D(_ParamTex, float2(0.25, param));
fixed4 param2 = tex2D(_ParamTex, float2(0.75, param));
fixed3 targetHsv = param1.rgb;
fixed3 targetRange = param1.w;
fixed3 hsvShift = param2.xyz - 0.5;
half3 hsv = RgbToHsv(color.rgb);
half3 range = abs(hsv - targetHsv);
half diff = max(max(min(1-range.x, range.x), min(1-range.y, range.y)/10), min(1-range.z, range.z)/10);
fixed masked = step(diff, targetRange);
color.rgb = HsvToRgb(hsv + hsvShift * masked);
return color;
}
#endif // UI_EFFECT_INCLUDED
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7467061e9f5514f2c80e30817ee2458b
timeCreated: 1487915863
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,113 @@
Shader "UI/Hidden/UI-Effect"
{
Properties
{
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
_ParamTex ("Parameter Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Blend SrcAlpha OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#if !defined(SHADER_API_D3D11_9X) && !defined(SHADER_API_D3D9)
#pragma target 2.0
#else
#pragma target 3.0
#endif
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#pragma shader_feature __ GRAYSCALE SEPIA NEGA PIXEL
#pragma shader_feature __ ADD SUBTRACT FILL
#pragma shader_feature __ FASTBLUR MEDIUMBLUR DETAILBLUR
#pragma shader_feature __ EX
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#define UI_EFFECT 1
#include "UI-Effect.cginc"
#include "UI-Effect-Sprite.cginc"
fixed4 frag(v2f IN) : SV_Target
{
fixed4 param = tex2D(_ParamTex, float2(0.5, IN.eParam));
fixed effectFactor = param.x;
fixed colorFactor = param.y;
fixed blurFactor = param.z;
#if PIXEL
half2 pixelSize = max(2, (1-effectFactor*0.95) * _MainTex_TexelSize.zw);
IN.texcoord = round(IN.texcoord * pixelSize) / pixelSize;
#endif
#if defined(UI_BLUR) && EX
half4 color = (Tex2DBlurring(_MainTex, IN.texcoord, blurFactor * _MainTex_TexelSize.xy * 2, IN.uvMask) + _TextureSampleAdd);
#elif defined(UI_BLUR)
half4 color = (Tex2DBlurring(_MainTex, IN.texcoord, blurFactor * _MainTex_TexelSize.xy * 2) + _TextureSampleAdd);
#else
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
#endif
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#if UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
#if defined (UI_TONE)
color = ApplyToneEffect(color, effectFactor);
#endif
color = ApplyColorEffect(color, fixed4(IN.color.rgb, colorFactor));
color.a *= IN.color.a;
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b868e81d0156245e08c8646b4fb68d7a
timeCreated: 1482973535
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
Shader "UI/Hidden/UI-EffectCapture"
{
Properties
{
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {}
}
SubShader
{
ZTest Always
Cull Off
ZWrite Off
Fog{ Mode off }
Pass
{
Name "Effect-Base"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma shader_feature __ GRAYSCALE SEPIA NEGA PIXEL
#pragma shader_feature __ ADD SUBTRACT FILL
#include "UnityCG.cginc"
#include "UI-Effect.cginc"
sampler2D _MainTex;
float4 _MainTex_TexelSize;
half4 _EffectFactor;
fixed4 _ColorFactor;
v2f_img vert(appdata_img v)
{
v2f_img o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
#if UNITY_UV_STARTS_AT_TOP
o.uv.y = 1 - o.uv.y;
#endif
return o;
}
fixed4 frag(v2f_img IN) : SV_Target
{
half effectFactor = _EffectFactor.x;
fixed4 colorFactor = _ColorFactor;
#if PIXEL
half2 pixelScale = max(2, (1 - effectFactor) * _MainTex_TexelSize.zw);
IN.uv = round(IN.uv * pixelScale) / pixelScale;
#endif
half4 color = tex2D(_MainTex, IN.uv);
#if defined (UI_TONE)
color = ApplyToneEffect(color, effectFactor);
#endif
#if defined (UI_COLOR)
color = ApplyColorEffect(color, colorFactor);
#endif
color.a = 1;
return color;
}
ENDCG
}
Pass
{
Name "Effect-Blur"
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag_blur
#pragma target 2.0
#pragma shader_feature __ FASTBLUR MEDIUMBLUR DETAILBLUR
#include "UnityCG.cginc"
#include "UI-Effect.cginc"
sampler2D _MainTex;
float4 _MainTex_TexelSize;
half4 _EffectFactor;
fixed4 frag_blur(v2f_img IN) : SV_Target
{
half2 blurFactor = _EffectFactor.xy;
half4 color = Tex2DBlurring1D(_MainTex, IN.uv, blurFactor * _MainTex_TexelSize.xy * 2);
color.a = 1;
return color;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7a6f925a07c3c5846a1c782eaaeb7087
timeCreated: 1482973535
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+432
View File
@@ -0,0 +1,432 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// Dissolve effect for uGUI.
/// </summary>
[AddComponentMenu("UI/UIEffect/UIDissolve", 3)]
public class UIDissolve : UIEffectBase
{
//################################
// Constant or Static Members.
//################################
public const string shaderName = "UI/Hidden/UI-Effect-Dissolve";
static readonly ParameterTexture _ptex = new ParameterTexture(8, 128, "_ParamTex");
//################################
// Serialize Members.
//################################
[Tooltip("Current location[0-1] for dissolve effect. 0 is not dissolved, 1 is completely dissolved.")]
[FormerlySerializedAs("m_Location")]
[SerializeField] [Range(0, 1)] float m_EffectFactor = 0.5f;
[Tooltip("Edge width.")]
[SerializeField] [Range(0, 1)] float m_Width = 0.5f;
[Tooltip("Edge softness.")]
[SerializeField] [Range(0, 1)] float m_Softness = 0.5f;
[Tooltip("Edge color.")]
[SerializeField] [ColorUsage(false)] Color m_Color = new Color(0.0f, 0.25f, 1.0f);
[Tooltip("Edge color effect mode.")]
[SerializeField] ColorMode m_ColorMode = ColorMode.Add;
[Tooltip("Noise texture for dissolving (single channel texture).")]
[SerializeField] Texture m_NoiseTexture;
[Header("Advanced Option")]
[Tooltip("The area for effect.")]
[SerializeField] protected EffectArea m_EffectArea;
[Tooltip("Keep effect aspect ratio.")]
[SerializeField] bool m_KeepAspectRatio;
[Header("Effect Player")]
[SerializeField] EffectPlayer m_Player;
[Tooltip("Reverse the dissolve effect.")]
[FormerlySerializedAs("m_ReverseAnimation")]
[SerializeField] bool m_Reverse = false;
#pragma warning disable 0414
[Obsolete][HideInInspector]
[SerializeField][Range(0.1f, 10)] float m_Duration = 1;
[Obsolete][HideInInspector]
[SerializeField] AnimatorUpdateMode m_UpdateMode = AnimatorUpdateMode.Normal;
#pragma warning restore 0414
//################################
// Public Members.
//################################
/// <summary>
/// Effect factor between 0(start) and 1(end).
/// </summary>
[System.Obsolete("Use effectFactor instead (UnityUpgradable) -> effectFactor")]
public float location
{
get { return m_EffectFactor; }
set
{
value = Mathf.Clamp(value, 0, 1);
if (!Mathf.Approximately(m_EffectFactor, value))
{
m_EffectFactor = value;
SetDirty();
}
}
}
/// <summary>
/// Effect factor between 0(start) and 1(end).
/// </summary>
public float effectFactor
{
get { return m_EffectFactor; }
set
{
value = Mathf.Clamp(value, 0, 1);
if (!Mathf.Approximately(m_EffectFactor, value))
{
m_EffectFactor = value;
SetDirty();
}
}
}
/// <summary>
/// Edge width.
/// </summary>
public float width
{
get { return m_Width; }
set
{
value = Mathf.Clamp(value, 0, 1);
if (!Mathf.Approximately(m_Width, value))
{
m_Width = value;
SetDirty();
}
}
}
/// <summary>
/// Edge softness.
/// </summary>
public float softness
{
get { return m_Softness; }
set
{
value = Mathf.Clamp(value, 0, 1);
if (!Mathf.Approximately(m_Softness, value))
{
m_Softness = value;
SetDirty();
}
}
}
/// <summary>
/// Edge color.
/// </summary>
public Color color
{
get { return m_Color; }
set
{
if (m_Color != value)
{
m_Color = value;
SetDirty();
}
}
}
/// <summary>
/// Noise texture.
/// </summary>
public Texture noiseTexture
{
get { return m_NoiseTexture ?? material.GetTexture("_NoiseTex"); }
set
{
if (m_NoiseTexture != value)
{
m_NoiseTexture = value;
if (graphic)
{
ModifyMaterial();
}
}
}
}
/// <summary>
/// The area for effect.
/// </summary>
public EffectArea effectArea
{
get { return m_EffectArea; }
set
{
if (m_EffectArea != value)
{
m_EffectArea = value;
SetVerticesDirty();
}
}
}
/// <summary>
/// Keep aspect ratio.
/// </summary>
public bool keepAspectRatio
{
get { return m_KeepAspectRatio; }
set
{
if (m_KeepAspectRatio != value)
{
m_KeepAspectRatio = value;
SetVerticesDirty ();
}
}
}
/// <summary>
/// Color effect mode.
/// </summary>
public ColorMode colorMode { get { return m_ColorMode; } }
/// <summary>
/// Play effect on enable.
/// </summary>
[System.Obsolete("Use Play/Stop method instead")]
public bool play { get { return _player.play; } set { _player.play = value; } }
/// <summary>
/// Play effect loop.
/// </summary>
[System.Obsolete]
public bool loop { get { return _player.loop; } set { _player.loop = value; } }
/// <summary>
/// The duration for playing effect.
/// </summary>
public float duration { get { return _player.duration; } set { _player.duration = Mathf.Max(value, 0.1f); } }
/// <summary>
/// Delay on loop effect.
/// </summary>
[System.Obsolete]
public float loopDelay { get { return _player.loopDelay; } set { _player.loopDelay = Mathf.Max(value, 0); } }
/// <summary>
/// Update mode for playing effect.
/// </summary>
public AnimatorUpdateMode updateMode { get { return _player.updateMode; } set { _player.updateMode = value; } }
/// <summary>
/// Reverse the dissolve effect.
/// </summary>
public bool reverse { get { return m_Reverse; } set { m_Reverse = value; } }
/// <summary>
/// Gets the parameter texture.
/// </summary>
public override ParameterTexture ptex { get { return _ptex; } }
/// <summary>
/// Modifies the material.
/// </summary>
public override void ModifyMaterial()
{
if (isTMPro)
{
return;
}
ulong hash = (m_NoiseTexture ? (uint)m_NoiseTexture.GetInstanceID() : 0) + ((ulong)1 << 32) + ((ulong)m_ColorMode << 36);
if (_materialCache != null && (_materialCache.hash != hash || !isActiveAndEnabled || !m_EffectMaterial))
{
MaterialCache.Unregister(_materialCache);
_materialCache = null;
}
if (!isActiveAndEnabled || !m_EffectMaterial)
{
material = null;
}
else if (!m_NoiseTexture)
{
material = m_EffectMaterial;
}
else if (_materialCache != null && _materialCache.hash == hash)
{
material = _materialCache.material;
}
else
{
_materialCache = MaterialCache.Register(hash, m_NoiseTexture, () =>
{
var mat = new Material(m_EffectMaterial);
mat.name += "_" + m_NoiseTexture.name;
mat.SetTexture("_NoiseTex", m_NoiseTexture);
return mat;
});
material = _materialCache.material;
}
}
/// <summary>
/// Modifies the mesh.
/// </summary>
public override void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled)
return;
bool isText = isTMPro || graphic is Text;
float normalizedIndex = ptex.GetNormalizedIndex(this);
// rect.
var tex = noiseTexture;
var aspectRatio = m_KeepAspectRatio && tex ? ((float)tex.width) / tex.height : -1;
Rect rect = m_EffectArea.GetEffectArea(vh, rectTransform.rect, aspectRatio);
// Calculate vertex position.
UIVertex vertex = default(UIVertex);
float x, y;
int count = vh.currentVertCount;
for (int i = 0; i < count; i++)
{
vh.PopulateUIVertex(ref vertex, i);
m_EffectArea.GetPositionFactor (i, rect, vertex.position, isText, isTMPro, out x, out y);
vertex.uv0 = new Vector2(
Packer.ToFloat(vertex.uv0.x, vertex.uv0.y),
Packer.ToFloat(x, y, normalizedIndex)
);
// if(!isTMPro)
// {
// vertex.uv0 = new Vector2(
// Packer.ToFloat(vertex.uv0.x, vertex.uv0.y),
// Packer.ToFloat(x, y, normalizedIndex)
// );
// }
// #if UNITY_5_6_OR_NEWER
// else
// {
// vertex.uv2 = new Vector2 (
// Packer.ToFloat (x, y, normalizedIndex),
// 0
// );
// }
// #endif
vh.SetUIVertex(vertex, i);
}
}
protected override void SetDirty()
{
foreach(var m in materials)
{
ptex.RegisterMaterial (m);
}
ptex.SetData(this, 0, m_EffectFactor); // param1.x : location
ptex.SetData(this, 1, m_Width); // param1.y : width
ptex.SetData(this, 2, m_Softness); // param1.z : softness
ptex.SetData(this, 4, m_Color.r); // param2.x : red
ptex.SetData(this, 5, m_Color.g); // param2.y : green
ptex.SetData(this, 6, m_Color.b); // param2.z : blue
}
/// <summary>
/// Play effect.
/// </summary>
public void Play(bool reset = true)
{
_player.Play(reset);
}
/// <summary>
/// Stop effect.
/// </summary>
public void Stop(bool reset = true)
{
_player.Stop(reset);
}
//################################
// Protected Members.
//################################
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
_player.OnEnable((f) =>
{
effectFactor = m_Reverse ? 1f - f : f;
});
}
protected override void OnDisable()
{
base.OnDisable ();
MaterialCache.Unregister(_materialCache);
_materialCache = null;
_player.OnDisable();
}
#if UNITY_EDITOR
/// <summary>
/// Gets the material.
/// </summary>
/// <returns>The material.</returns>
protected override Material GetMaterial()
{
if (isTMPro)
{
return null;
}
return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_ColorMode);
}
#pragma warning disable 0612
protected override void UpgradeIfNeeded()
{
// Upgrade for v3.0.0
if (IsShouldUpgrade(300))
{
_player.play = false;
_player.duration = m_Duration;
_player.loop = false;
_player.loopDelay = 1;
_player.updateMode = m_UpdateMode;
}
}
#pragma warning restore 0612
#endif
//################################
// Private Members.
//################################
MaterialCache _materialCache = null;
EffectPlayer _player{ get { return m_Player ?? (m_Player = new EffectPlayer()); } }
}
}
@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: ce76b7a490bd74f34a2f2752641aea24
timeCreated: 1538866738
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- m_EffectMaterial: {instanceID: 0}
- m_PtexMaterial: {instanceID: 0}
- m_NoiseTexture: {fileID: 2800000, guid: 3e04c247fb2604af186173fce0bc62de, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+488
View File
@@ -0,0 +1,488 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
#if UNITY_EDITOR
using System.IO;
using System.Linq;
using UnityEditor;
#endif
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// UIEffect.
/// </summary>
[ExecuteInEditMode]
[RequireComponent(typeof(Graphic))]
[DisallowMultipleComponent]
[AddComponentMenu("UI/UIEffect/UIEffect", 1)]
public class UIEffect : UIEffectBase
{
//################################
// Constant or Static Members.
//################################
public const string shaderName = "UI/Hidden/UI-Effect";
static readonly ParameterTexture _ptex = new ParameterTexture(4, 1024, "_ParamTex");
//################################
// Serialize Members.
//################################
[FormerlySerializedAs("m_ToneLevel")]
[Tooltip("Effect factor between 0(no effect) and 1(complete effect).")]
[SerializeField][Range(0, 1)] float m_EffectFactor = 1;
[Tooltip("Color effect factor between 0(no effect) and 1(complete effect).")]
[SerializeField][Range(0, 1)] float m_ColorFactor = 1;
[FormerlySerializedAs("m_Blur")]
[Tooltip("How far is the blurring from the graphic.")]
[SerializeField][Range(0, 1)] float m_BlurFactor = 1;
[FormerlySerializedAs("m_ToneMode")]
[Tooltip("Effect mode")]
[SerializeField] EffectMode m_EffectMode = EffectMode.None;
[Tooltip("Color effect mode")]
[SerializeField] ColorMode m_ColorMode = ColorMode.Multiply;
[Tooltip("Blur effect mode")]
[SerializeField] BlurMode m_BlurMode = BlurMode.None;
[Tooltip("Advanced blurring remove common artifacts in the blur effect for uGUI.")]
[SerializeField] bool m_AdvancedBlur = false;
#pragma warning disable 0414
[Obsolete][HideInInspector]
[SerializeField][Range(0, 1)] float m_ShadowBlur = 1;
[Obsolete][HideInInspector]
[SerializeField] ShadowStyle m_ShadowStyle;
[Obsolete][HideInInspector]
[SerializeField] Color m_ShadowColor = Color.black;
[Obsolete][HideInInspector]
[SerializeField] Vector2 m_EffectDistance = new Vector2(1f, -1f);
[Obsolete][HideInInspector]
[SerializeField] bool m_UseGraphicAlpha = true;
[Obsolete][HideInInspector]
[SerializeField] Color m_EffectColor = Color.white;
[Obsolete][HideInInspector]
[SerializeField] List<UIShadow.AdditionalShadow> m_AdditionalShadows = new List<UIShadow.AdditionalShadow>();
#pragma warning restore 0414
public enum BlurEx
{
None = 0,
Ex = 1,
}
//################################
// Public Members.
//################################
#if UNITY_2017_1_OR_NEWER
public override AdditionalCanvasShaderChannels requiredChannels
{
get
{
if (advancedBlur)
{
return isTMPro
? AdditionalCanvasShaderChannels.TexCoord1 | AdditionalCanvasShaderChannels.TexCoord2
: AdditionalCanvasShaderChannels.TexCoord1;
}
return AdditionalCanvasShaderChannels.None;
}
}
#endif
/// <summary>
/// Effect factor between 0(no effect) and 1(complete effect).
/// </summary>
[System.Obsolete("Use effectFactor instead (UnityUpgradable) -> effectFactor")]
public float toneLevel
{
get { return m_EffectFactor; }
set
{
m_EffectFactor = Mathf.Clamp(value, 0, 1);
SetDirty();
}
}
/// <summary>
/// Effect factor between 0(no effect) and 1(complete effect).
/// </summary>
public float effectFactor
{
get { return m_EffectFactor; }
set
{
m_EffectFactor = Mathf.Clamp(value, 0, 1);
SetDirty();
}
}
/// <summary>
/// Color effect factor between 0(no effect) and 1(complete effect).
/// </summary>
public float colorFactor
{
get { return m_ColorFactor; }
set
{
m_ColorFactor = Mathf.Clamp(value, 0, 1);
SetDirty();
}
}
/// <summary>
/// How far is the blurring from the graphic.
/// </summary>
[System.Obsolete("Use blurFactor instead (UnityUpgradable) -> blurFactor")]
public float blur
{
get { return m_BlurFactor; }
set
{
m_BlurFactor = Mathf.Clamp(value, 0, 1);
SetDirty();
}
}
/// <summary>
/// How far is the blurring from the graphic.
/// </summary>
[System.Obsolete("Use effectFactor instead (UnityUpgradable) -> effectFactor")]
public float blurFactor
{
get { return m_BlurFactor; }
set
{
m_BlurFactor = Mathf.Clamp(value, 0, 1);
SetDirty();
}
}
/// <summary>
/// Effect mode(readonly).
/// </summary>
[System.Obsolete("Use effectMode instead (UnityUpgradable) -> effectMode")]
public EffectMode toneMode { get { return m_EffectMode; } }
/// <summary>
/// Effect mode(readonly).
/// </summary>
public EffectMode effectMode { get { return m_EffectMode; } }
/// <summary>
/// Color effect mode(readonly).
/// </summary>
public ColorMode colorMode { get { return m_ColorMode; } }
/// <summary>
/// Blur effect mode(readonly).
/// </summary>
public BlurMode blurMode { get { return m_BlurMode; } }
/// <summary>
/// Color for the color effect.
/// </summary>
public Color effectColor
{
get { return graphic.color; }
set
{
graphic.color = value;
SetDirty();
}
}
/// <summary>
/// Gets the parameter texture.
/// </summary>
public override ParameterTexture ptex { get { return _ptex; } }
/// <summary>
/// Advanced blurring remove common artifacts in the blur effect for uGUI.
/// </summary>
public bool advancedBlur { get { return isTMPro ? (material && material.IsKeywordEnabled("EX")) : m_AdvancedBlur; } }
/// <summary>
/// Modifies the mesh.
/// </summary>
public override void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled)
{
return;
}
float normalizedIndex = ptex.GetNormalizedIndex(this);
if (m_BlurMode != BlurMode.None && advancedBlur)
{
vh.GetUIVertexStream(tempVerts);
vh.Clear();
var count = tempVerts.Count;
// Bundle
int bundleSize = (targetGraphic is Text || isTMPro) ? 6 : count;
Rect posBounds = default(Rect);
Rect uvBounds = default(Rect);
Vector3 size = default(Vector3);
Vector3 tPos = default(Vector3);
Vector3 tUV = default(Vector3);
float expand = (float)blurMode * 6 * 2;
for (int i = 0; i < count; i += bundleSize)
{
// min/max for bundled-quad
GetBounds(tempVerts, i, bundleSize, ref posBounds, ref uvBounds, true);
// Pack uv mask.
Vector2 uvMask = new Vector2(Packer.ToFloat(uvBounds.xMin, uvBounds.yMin), Packer.ToFloat(uvBounds.xMax, uvBounds.yMax));
// Quad
for (int j = 0; j < bundleSize; j += 6)
{
Vector3 cornerPos1 = tempVerts[i + j + 1].position;
Vector3 cornerPos2 = tempVerts[i + j + 4].position;
// Is outer quad?
bool hasOuterEdge = (bundleSize == 6)
|| !posBounds.Contains(cornerPos1)
|| !posBounds.Contains(cornerPos2);
if (hasOuterEdge)
{
Vector3 cornerUv1 = tempVerts[i + j + 1].uv0;
Vector3 cornerUv2 = tempVerts[i + j + 4].uv0;
Vector3 centerPos = (cornerPos1 + cornerPos2) / 2;
Vector3 centerUV = (cornerUv1 + cornerUv2) / 2;
size = (cornerPos1 - cornerPos2);
size.x = 1 + expand / Mathf.Abs(size.x);
size.y = 1 + expand / Mathf.Abs(size.y);
size.z = 1 + expand / Mathf.Abs(size.z);
tPos = centerPos - Vector3.Scale(size, centerPos);
tUV = centerUV - Vector3.Scale(size, centerUV);
}
// Vertex
for (int k = 0; k < 6; k++)
{
UIVertex vt = tempVerts[i + j + k];
Vector3 pos = vt.position;
Vector2 uv0 = vt.uv0;
if (hasOuterEdge && (pos.x < posBounds.xMin || posBounds.xMax < pos.x))
{
pos.x = pos.x * size.x + tPos.x;
uv0.x = uv0.x * size.x + tUV.x;
}
if (hasOuterEdge && (pos.y < posBounds.yMin || posBounds.yMax < pos.y))
{
pos.y = pos.y * size.y + tPos.y;
uv0.y = uv0.y * size.y + tUV.y;
}
vt.uv0 = new Vector2(Packer.ToFloat((uv0.x + 0.5f) / 2f, (uv0.y + 0.5f) / 2f), normalizedIndex);
vt.position = pos;
if (isTMPro)
{
#if UNITY_2017_1_OR_NEWER
vt.uv2 = uvMask;
#endif
}
else
{
vt.uv1 = uvMask;
}
tempVerts[i + j + k] = vt;
}
}
}
vh.AddUIVertexTriangleStream(tempVerts);
tempVerts.Clear();
}
else
{
int count = vh.currentVertCount;
UIVertex vt = default(UIVertex);
for (int i = 0; i < count; i++)
{
vh.PopulateUIVertex(ref vt, i);
Vector2 uv0 = vt.uv0;
vt.uv0 = new Vector2(
Packer.ToFloat((uv0.x + 0.5f) / 2f, (uv0.y + 0.5f) / 2f),
normalizedIndex
);
vh.SetUIVertex(vt, i);
}
}
}
protected override void SetDirty()
{
foreach (var m in materials)
{
ptex.RegisterMaterial (m);
}
ptex.SetData(this, 0, m_EffectFactor); // param.x : effect factor
ptex.SetData(this, 1, m_ColorFactor); // param.y : color factor
ptex.SetData(this, 2, m_BlurFactor); // param.z : blur factor
}
#if UNITY_EDITOR
/// <summary>
/// Gets the material.
/// </summary>
/// <returns>The material.</returns>
protected override Material GetMaterial()
{
if (isTMPro)
{
return null;
}
return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_EffectMode, m_ColorMode, m_BlurMode, m_AdvancedBlur ? BlurEx.Ex : BlurEx.None);
}
#pragma warning disable 0612
protected override void UpgradeIfNeeded()
{
// Upgrade for v3.0.0
if (IsShouldUpgrade(300))
{
if (m_ColorMode != ColorMode.Multiply)
{
Color col = targetGraphic.color;
col.r = m_EffectColor.r;
col.g = m_EffectColor.g;
col.b = m_EffectColor.b;
targetGraphic.color = col;
m_ColorFactor = m_EffectColor.a;
}
if (m_ShadowStyle != ShadowStyle.None || m_AdditionalShadows.Any(x => x.style != ShadowStyle.None))
{
if (m_ShadowStyle != ShadowStyle.None)
{
var shadow = gameObject.GetComponent<UIShadow>() ?? gameObject.AddComponent<UIShadow>();
shadow.style = m_ShadowStyle;
shadow.effectDistance = m_EffectDistance;
shadow.effectColor = m_ShadowColor;
shadow.useGraphicAlpha = m_UseGraphicAlpha;
shadow.blurFactor = m_ShadowBlur;
}
foreach (var s in m_AdditionalShadows)
{
if (s.style == ShadowStyle.None)
{
continue;
}
var shadow = gameObject.AddComponent<UIShadow>();
shadow.style = s.style;
shadow.effectDistance = s.effectDistance;
shadow.effectColor = s.effectColor;
shadow.useGraphicAlpha = s.useGraphicAlpha;
shadow.blurFactor = s.blur;
}
m_ShadowStyle = ShadowStyle.None;
m_AdditionalShadows = null;
if (m_EffectMode == EffectMode.None && m_ColorMode == ColorMode.Multiply && m_BlurMode == BlurMode.None)
{
DestroyImmediate(this, true);
}
}
int tone = (int)m_EffectMode;
const int Mono = 5;
const int Cutoff = 6;
const int Hue = 7;
if (tone == Hue)
{
var go = gameObject;
var hue = m_EffectFactor;
DestroyImmediate(this, true);
var hsv = go.GetComponent<UIHsvModifier>() ?? go.AddComponent<UIHsvModifier>();
hsv.hue = hue;
hsv.range = 1;
}
// Cutoff/Mono
if (tone == Cutoff || tone == Mono)
{
var go = gameObject;
var factor = m_EffectFactor;
var transitionMode = tone == Cutoff
? UITransitionEffect.EffectMode.Cutoff
: UITransitionEffect.EffectMode.Fade;
DestroyImmediate(this, true);
var trans = go.GetComponent<UITransitionEffect>() ?? go.AddComponent<UITransitionEffect>();
trans.effectFactor = factor;
var sp = new SerializedObject(trans).FindProperty("m_EffectMode");
sp.intValue = (int)transitionMode;
sp.serializedObject.ApplyModifiedProperties();
}
}
}
#pragma warning restore 0612
#endif
//################################
// Private Members.
//################################
static void GetBounds(List<UIVertex> verts, int start, int count, ref Rect posBounds, ref Rect uvBounds, bool global)
{
Vector2 minPos = new Vector2(float.MaxValue, float.MaxValue);
Vector2 maxPos = new Vector2(float.MinValue, float.MinValue);
Vector2 minUV = new Vector2(float.MaxValue, float.MaxValue);
Vector2 maxUV = new Vector2(float.MinValue, float.MinValue);
for (int i = start; i < start + count; i++)
{
UIVertex vt = verts[i];
Vector2 uv = vt.uv0;
Vector3 pos = vt.position;
// Left-Bottom
if (minPos.x >= pos.x && minPos.y >= pos.y)
{
minPos = pos;
}
// Right-Top
else if (maxPos.x <= pos.x && maxPos.y <= pos.y)
{
maxPos = pos;
}
// Left-Bottom
if (minUV.x >= uv.x && minUV.y >= uv.y)
{
minUV = uv;
}
// Right-Top
else if (maxUV.x <= uv.x && maxUV.y <= uv.y)
{
maxUV = uv;
}
}
// Shrink coordinate for detect edge
posBounds.Set(minPos.x + 0.001f, minPos.y + 0.001f, maxPos.x - minPos.x - 0.002f, maxPos.y - minPos.y - 0.002f);
uvBounds.Set(minUV.x, minUV.y, maxUV.x - minUV.x, maxUV.y - minUV.y);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f8b2ed11d675446c5a49da1ea296d490
timeCreated: 1485321967
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,552 @@
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.Rendering;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// UIEffectCapturedImage
/// </summary>
[AddComponentMenu("UI/UIEffect/UIEffectCapturedImage", 200)]
public class UIEffectCapturedImage : RawImage
#if UNITY_EDITOR
, ISerializationCallbackReceiver
#endif
{
//################################
// Constant or Static Members.
//################################
public const string shaderName = "UI/Hidden/UI-EffectCapture";
/// <summary>
/// Desampling rate.
/// </summary>
public enum DesamplingRate
{
None = 0,
x1 = 1,
x2 = 2,
x4 = 4,
x8 = 8,
}
//################################
// Serialize Members.
//################################
[Tooltip("Effect factor between 0(no effect) and 1(complete effect).")]
[FormerlySerializedAs("m_ToneLevel")]
[SerializeField][Range(0, 1)] float m_EffectFactor = 1;
[Tooltip("Color effect factor between 0(no effect) and 1(complete effect).")]
[SerializeField][Range(0, 1)] float m_ColorFactor = 1;
[Tooltip("How far is the blurring from the graphic.")]
[FormerlySerializedAs("m_Blur")]
[SerializeField][Range(0, 1)] float m_BlurFactor = 1;
[Tooltip("Effect mode.")]
[FormerlySerializedAs("m_ToneMode")]
[SerializeField] EffectMode m_EffectMode = EffectMode.None;
[Tooltip("Color effect mode.")]
[SerializeField] ColorMode m_ColorMode = ColorMode.Multiply;
[Tooltip("Blur effect mode.")]
[SerializeField] BlurMode m_BlurMode = BlurMode.DetailBlur;
[Tooltip("Color for the color effect.")]
[SerializeField] Color m_EffectColor = Color.white;
[Tooltip("Desampling rate of the generated RenderTexture.")]
[SerializeField] DesamplingRate m_DesamplingRate = DesamplingRate.x1;
[Tooltip("Desampling rate of reduction buffer to apply effect.")]
[SerializeField] DesamplingRate m_ReductionRate = DesamplingRate.x1;
[Tooltip("FilterMode for capturing.")]
[SerializeField] FilterMode m_FilterMode = FilterMode.Bilinear;
[Tooltip("Effect material.")]
[SerializeField] Material m_EffectMaterial = null;
[Tooltip("Blur iterations.")]
[FormerlySerializedAs("m_Iterations")]
[SerializeField][Range(1, 8)] int m_BlurIterations = 3;
[Tooltip("Fits graphic size to screen on captured.")]
[FormerlySerializedAs("m_KeepCanvasSize")]
[SerializeField] bool m_FitToScreen = true;
[Tooltip("Capture automatically on enable.")]
[SerializeField] bool m_CaptureOnEnable = false;
//################################
// Public Members.
//################################
/// <summary>
/// Effect factor between 0(no effect) and 1(complete effect).
/// </summary>
[System.Obsolete("Use effectFactor instead (UnityUpgradable) -> effectFactor")]
public float toneLevel { get { return m_EffectFactor; } set { m_EffectFactor = Mathf.Clamp(value, 0, 1); } }
/// <summary>
/// Effect factor between 0(no effect) and 1(complete effect).
/// </summary>
public float effectFactor { get { return m_EffectFactor; } set { m_EffectFactor = Mathf.Clamp(value, 0, 1); } }
/// <summary>
/// Color effect factor between 0(no effect) and 1(complete effect).
/// </summary>
public float colorFactor { get { return m_ColorFactor; } set { m_ColorFactor = Mathf.Clamp(value, 0, 1); } }
/// <summary>
/// How far is the blurring from the graphic.
/// </summary>
[System.Obsolete("Use blurFactor instead (UnityUpgradable) -> blurFactor")]
public float blur { get { return m_BlurFactor; } set { m_BlurFactor = Mathf.Clamp(value, 0, 4); } }
/// <summary>
/// How far is the blurring from the graphic.
/// </summary>
public float blurFactor { get { return m_BlurFactor; } set { m_BlurFactor = Mathf.Clamp(value, 0, 4); } }
/// <summary>
/// Tone effect mode.
/// </summary>
[System.Obsolete("Use effectMode instead (UnityUpgradable) -> effectMode")]
public EffectMode toneMode { get { return m_EffectMode; } }
/// <summary>
/// Effect mode.
/// </summary>
public EffectMode effectMode { get { return m_EffectMode; } }
/// <summary>
/// Color effect mode.
/// </summary>
public ColorMode colorMode { get { return m_ColorMode; } }
/// <summary>
/// Blur effect mode.
/// </summary>
public BlurMode blurMode { get { return m_BlurMode; } }
/// <summary>
/// Color for the color effect.
/// </summary>
public Color effectColor { get { return m_EffectColor; } set { m_EffectColor = value; } }
/// <summary>
/// Effect material.
/// </summary>
public virtual Material effectMaterial { get { return m_EffectMaterial; } }
/// <summary>
/// Desampling rate of the generated RenderTexture.
/// </summary>
public DesamplingRate desamplingRate { get { return m_DesamplingRate; } set { m_DesamplingRate = value; } }
/// <summary>
/// Desampling rate of reduction buffer to apply effect.
/// </summary>
public DesamplingRate reductionRate { get { return m_ReductionRate; } set { m_ReductionRate = value; } }
/// <summary>
/// FilterMode for capturing.
/// </summary>
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
/// <summary>
/// Captured texture.
/// </summary>
public RenderTexture capturedTexture { get { return _rt; } }
/// <summary>
/// Blur iterations.
/// </summary>
[System.Obsolete("Use blurIterations instead (UnityUpgradable) -> blurIterations")]
public int iterations { get { return m_BlurIterations; } set { m_BlurIterations = value; } }
/// <summary>
/// Blur iterations.
/// </summary>
public int blurIterations { get { return m_BlurIterations; } set { m_BlurIterations = value; } }
/// <summary>
/// Fits graphic size to screen.
/// </summary>
[System.Obsolete("Use fitToScreen instead (UnityUpgradable) -> fitToScreen")]
public bool keepCanvasSize { get { return m_FitToScreen; } set { m_FitToScreen = value; } }
/// <summary>
/// Fits graphic size to screen on captured.
/// </summary>
public bool fitToScreen { get { return m_FitToScreen; } set { m_FitToScreen = value; } }
/// <summary>
/// Target RenderTexture to capture.
/// </summary>
[System.Obsolete]
public RenderTexture targetTexture { get { return null; } set { } }
/// <summary>
/// Capture automatically on enable.
/// </summary>
public bool captureOnEnable { get { return m_CaptureOnEnable; } set { m_CaptureOnEnable = value; } }
/// <summary>
/// This function is called when the object becomes enabled and active.
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
if (m_CaptureOnEnable && Application.isPlaying)
{
Capture();
}
}
protected override void OnDisable()
{
base.OnDisable();
if (m_CaptureOnEnable && Application.isPlaying)
{
_Release(false);
texture = null;
}
}
/// <summary>
/// This function is called when the MonoBehaviour will be destroyed.
/// </summary>
protected override void OnDestroy()
{
Release();
base.OnDestroy();
}
/// <summary>
/// Callback function when a UI element needs to generate vertices.
/// </summary>
protected override void OnPopulateMesh(VertexHelper vh)
{
// When not displaying, clear vertex.
if (texture == null || color.a < 1 / 255f || canvasRenderer.GetAlpha() < 1 / 255f)
{
vh.Clear();
}
else
{
base.OnPopulateMesh(vh);
int count = vh.currentVertCount;
UIVertex vt = default(UIVertex);
Color c = color;
for (int i = 0; i < count; i++)
{
vh.PopulateUIVertex(ref vt, i);
vt.color = c;
vh.SetUIVertex(vt, i);
}
}
}
/// <summary>
/// Gets the size of the desampling.
/// </summary>
public void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = int.Parse(res[0]);
h = int.Parse(res[1]);
}
else
#endif
{
w = Screen.width;
h = Screen.height;
}
if (rate == DesamplingRate.None)
return;
float aspect = (float)w / h;
if (w < h)
{
h = Mathf.ClosestPowerOfTwo(h / (int)rate);
w = Mathf.CeilToInt(h * aspect);
}
else
{
w = Mathf.ClosestPowerOfTwo(w / (int)rate);
h = Mathf.CeilToInt(w / aspect);
}
}
/// <summary>
/// Capture rendering result.
/// </summary>
public void Capture()
{
// Fit to screen.
var rootCanvas = canvas.rootCanvas;
if (m_FitToScreen)
{
var rootTransform = rootCanvas.transform as RectTransform;
var size = rootTransform.rect.size;
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
rectTransform.position = rootTransform.position;
}
// Cache some ids.
if (s_CopyId == 0)
{
s_CopyId = Shader.PropertyToID("_UIEffectCapturedImage_ScreenCopyId");
s_EffectId1 = Shader.PropertyToID("_UIEffectCapturedImage_EffectId1");
s_EffectId2 = Shader.PropertyToID("_UIEffectCapturedImage_EffectId2");
s_EffectFactorId = Shader.PropertyToID("_EffectFactor");
s_ColorFactorId = Shader.PropertyToID("_ColorFactor");
s_CommandBuffer = new CommandBuffer();
}
// If size of result RT has changed, release it.
int w, h;
GetDesamplingSize(m_DesamplingRate, out w, out h);
if (_rt && (_rt.width != w || _rt.height != h))
{
_Release(ref _rt);
}
// Generate RT for result.
if (_rt == null)
{
_rt = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
_rt.filterMode = m_FilterMode;
_rt.useMipMap = false;
_rt.wrapMode = TextureWrapMode.Clamp;
_rtId = new RenderTargetIdentifier(_rt);
}
SetupCommandBuffer();
}
void SetupCommandBuffer()
{
// Material for effect.
Material mat = m_EffectMaterial;
if (s_CommandBuffer == null)
{
s_CommandBuffer = new CommandBuffer();
}
// [1] Capture from back buffer (back buffer -> copied screen).
int w, h;
GetDesamplingSize(DesamplingRate.None, out w, out h);
s_CommandBuffer.GetTemporaryRT(s_CopyId, w, h, 0, m_FilterMode);
#if UNITY_EDITOR
s_CommandBuffer.Blit(Resources.FindObjectsOfTypeAll<RenderTexture>().FirstOrDefault(x => x.name == "GameView RT"), s_CopyId);
#else
s_CommandBuffer.Blit(BuiltinRenderTextureType.BindableTexture, s_CopyId);
#endif
// Set properties for effect.
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(m_EffectFactor, 0));
s_CommandBuffer.SetGlobalVector(s_ColorFactorId, new Vector4(m_EffectColor.r, m_EffectColor.g, m_EffectColor.b, m_EffectColor.a));
// [2] Apply base effect with reduction buffer (copied screen -> effect1).
GetDesamplingSize(m_ReductionRate, out w, out h);
s_CommandBuffer.GetTemporaryRT(s_EffectId1, w, h, 0, m_FilterMode);
s_CommandBuffer.Blit(s_CopyId, s_EffectId1, mat, 0);
s_CommandBuffer.ReleaseTemporaryRT(s_CopyId);
// Iterate blurring operation.
if (m_BlurMode != BlurMode.None)
{
s_CommandBuffer.GetTemporaryRT(s_EffectId2, w, h, 0, m_FilterMode);
for (int i = 0; i < m_BlurIterations; i++)
{
// [3] Apply blurring with reduction buffer (effect1 -> effect2, or effect2 -> effect1).
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(m_BlurFactor, 0));
s_CommandBuffer.Blit(s_EffectId1, s_EffectId2, mat, 1);
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(0, m_BlurFactor));
s_CommandBuffer.Blit(s_EffectId2, s_EffectId1, mat, 1);
}
s_CommandBuffer.ReleaseTemporaryRT(s_EffectId2);
}
// [4] Copy to result RT.
s_CommandBuffer.Blit(s_EffectId1, _rtId);
s_CommandBuffer.ReleaseTemporaryRT(s_EffectId1);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
Graphics.ExecuteCommandBuffer(s_CommandBuffer);
UpdateTexture();
return;
}
#endif
// Execute command buffer.
canvas.rootCanvas.GetComponent<CanvasScaler> ().StartCoroutine (_CoUpdateTextureOnNextFrame ());
}
/// <summary>
/// Release captured image.
/// </summary>
public void Release()
{
_Release(true);
texture = null;
_SetDirty();
}
#if UNITY_EDITOR
protected override void Reset()
{
// Set parameters as 'Medium'.
m_BlurIterations = 3;
m_FilterMode = FilterMode.Bilinear;
m_DesamplingRate = DesamplingRate.x1;
m_ReductionRate = DesamplingRate.x1;
base.Reset();
}
/// <summary>
/// Raises the before serialize event.
/// </summary>
public void OnBeforeSerialize()
{
}
/// <summary>
/// Raises the after deserialize event.
/// </summary>
public void OnAfterDeserialize()
{
UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(true);
}
/// <summary>
/// Raises the validate event.
/// </summary>
protected override void OnValidate()
{
base.OnValidate();
UnityEditor.EditorApplication.delayCall += () => UpdateMaterial(false);
}
/// <summary>
/// Updates the material.
/// </summary>
/// <param name="ignoreInPlayMode">If set to <c>true</c> ignore in play mode.</param>
protected void UpdateMaterial(bool ignoreInPlayMode)
{
if (!this || ignoreInPlayMode && Application.isPlaying)
{
return;
}
var mat = MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName), m_EffectMode, m_ColorMode, m_BlurMode);
if (m_EffectMaterial != mat)
{
material = null;
m_EffectMaterial = mat;
_SetDirty();
}
}
#endif
//################################
// Private Members.
//################################
RenderTexture _rt;
RenderTargetIdentifier _rtId;
static int s_CopyId;
static int s_EffectId1;
static int s_EffectId2;
static int s_EffectFactorId;
static int s_ColorFactorId;
static CommandBuffer s_CommandBuffer;
/// <summary>
/// Release genarated objects.
/// </summary>
/// <param name="releaseRT">If set to <c>true</c> release cached RenderTexture.</param>
void _Release(bool releaseRT)
{
if (releaseRT)
{
texture = null;
_Release(ref _rt);
}
if (s_CommandBuffer != null)
{
s_CommandBuffer.Clear();
if (releaseRT)
{
s_CommandBuffer.Release();
s_CommandBuffer = null;
}
}
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
void _SetDirty()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
void _Release(ref RenderTexture obj)
{
if (obj)
{
obj.Release();
RenderTexture.ReleaseTemporary (obj);
obj = null;
}
}
/// <summary>
/// Set texture on next frame.
/// </summary>
IEnumerator _CoUpdateTextureOnNextFrame()
{
yield return new WaitForEndOfFrame();
UpdateTexture();
}
void UpdateTexture()
{
#if !UNITY_EDITOR
// Execute command buffer.
Graphics.ExecuteCommandBuffer (s_CommandBuffer);
#endif
_Release(false);
texture = capturedTexture;
_SetDirty();
}
}
}
@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: e96dacbf1b116f64da658fbad66839e2
timeCreated: 1513158591
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- m_Material: {instanceID: 0}
- m_Texture: {instanceID: 0}
- m_Shader: {fileID: 4800000, guid: c7bb8dee750384818a922a942cd437f9, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
//[RequireComponent(typeof(Graphic))]
[DisallowMultipleComponent]
[AddComponentMenu("UI/MeshEffectForTextMeshPro/UIFlip", 102)]
public class UIFlip : BaseMeshEffect
{
//################################
// Serialize Members.
//################################
[Tooltip("Flip horizontally.")]
[SerializeField] private bool m_Horizontal = false;
[Tooltip("Flip vertically.")]
[SerializeField] private bool m_Veritical = false;
//################################
// Public Members.
//################################
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Assets.Scripts.UI.UIEffect.UIFlip"/> should be flipped horizontally.
/// </summary>
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
public bool horizontal { get { return this.m_Horizontal; } set { this.m_Horizontal = value; SetVerticesDirty (); } }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Assets.Scripts.UI.UIEffect.UIFlip"/> should be flipped vertically.
/// </summary>
/// <value><c>true</c> if be flipped horizontally; otherwise, <c>false</c>.</value>
public bool vertical { get { return this.m_Veritical; } set { this.m_Veritical = value; SetVerticesDirty (); } }
/// <summary>
/// Call used to modify mesh.
/// </summary>
/// <param name="vh">VertexHelper.</param>
public override void ModifyMesh(VertexHelper vh)
{
RectTransform rt = graphic.rectTransform;
UIVertex vt = default(UIVertex);
Vector3 pos;
Vector2 center = rt.rect.center;
for (int i = 0; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vt, i);
pos = vt.position;
vt.position = new Vector3(
m_Horizontal ? -pos.x : pos.x,
m_Veritical ? -pos.y : pos.y
);
vh.SetUIVertex(vt, i);
}
}
}
}
+12
View File
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9bb4e59514e90489d985e9a17c838085
timeCreated: 1525607243
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+7 -7
View File
@@ -8,7 +8,7 @@ namespace Assets.Scripts.UI.UIEffect
/// </summary>
[DisallowMultipleComponent]
[AddComponentMenu("UI/MeshEffectForTextMeshPro/UIGradient", 101)]
public class UIGradient : Assets.Scripts.UI.UIEffect.Common.BaseMeshEffect
public class UIGradient : BaseMeshEffect
{
//################################
// Constant or Static Members.
@@ -56,13 +56,13 @@ namespace Assets.Scripts.UI.UIEffect
[SerializeField] Color m_Color4 = Color.white;
[Tooltip("Gradient rotation.")]
[SerializeField] [Range(-180, 180)] float m_Rotation;
[SerializeField][Range(-180, 180)] float m_Rotation;
[Tooltip("Gradient offset for Horizontal, Vertical or Angle.")]
[SerializeField] [Range(-1, 1)] float m_Offset1;
[SerializeField][Range(-1, 1)] float m_Offset1;
[Tooltip("Gradient offset for Diagonal.")]
[SerializeField] [Range(-1, 1)] float m_Offset2;
[SerializeField][Range(-1, 1)] float m_Offset2;
[Tooltip("Gradient style for Text.")]
[SerializeField] GradientStyle m_GradientStyle;
@@ -310,7 +310,7 @@ namespace Assets.Scripts.UI.UIEffect
// Calculate vertex color.
Color color;
Vector2 nomalizedPos;
Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix.
Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y); // Get local matrix.
for (int i = 0; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vertex, i);
@@ -370,11 +370,11 @@ namespace Assets.Scripts.UI.UIEffect
m01 = -sin / rect.height;
m02 = dx * cos - dy * sin + center;
m10 = sin / rect.width;
m11 = cos / rect.height;
m11 = cos / rect.height;
m12 = dx * sin + dy * cos + center;
}
public static Vector2 operator *(Matrix2x3 m, Vector2 v)
public static Vector2 operator*(Matrix2x3 m, Vector2 v)
{
return new Vector2(
(m.m00 * v.x) + (m.m01 * v.y) + m.m02,
+194
View File
@@ -0,0 +1,194 @@
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// HSV Modifier.
/// </summary>
[AddComponentMenu("UI/UIEffect/UIHsvModifier", 4)]
public class UIHsvModifier : UIEffectBase
{
//################################
// Constant or Static Members.
//################################
public const string shaderName = "UI/Hidden/UI-Effect-HSV";
static readonly ParameterTexture _ptex = new ParameterTexture(7, 128, "_ParamTex");
//################################
// Serialize Members.
//################################
[Header("Target")]
[Tooltip("Target color to affect hsv shift.")]
[SerializeField] [ColorUsage(false)] Color m_TargetColor = Color.red;
[Tooltip("Color range to affect hsv shift [0 ~ 1].")]
[SerializeField] [Range(0, 1)] float m_Range = 0.1f;
[Header("Adjustment")]
[Tooltip("Hue shift [-0.5 ~ 0.5].")]
[SerializeField] [Range(-0.5f, 0.5f)] float m_Hue;
[Tooltip("Saturation shift [-0.5 ~ 0.5].")]
[SerializeField] [Range(-0.5f, 0.5f)] float m_Saturation;
[Tooltip("Value shift [-0.5 ~ 0.5].")]
[SerializeField] [Range(-0.5f, 0.5f)] float m_Value;
//################################
// Public Members.
//################################
/// <summary>
/// Target color to affect hsv shift.
/// </summary>
public Color targetColor
{
get { return m_TargetColor; }
set
{
if (m_TargetColor != value)
{
m_TargetColor = value;
SetDirty();
}
}
}
/// <summary>
/// Color range to affect hsv shift [0 ~ 1].
/// </summary>
public float range
{
get { return m_Range; }
set
{
value = Mathf.Clamp(value, 0, 1);
if (!Mathf.Approximately(m_Range, value))
{
m_Range = value;
SetDirty();
}
}
}
/// <summary>
/// Saturation shift [-0.5 ~ 0.5].
/// </summary>
public float saturation
{
get { return m_Saturation; }
set
{
value = Mathf.Clamp(value, -0.5f, 0.5f);
if (!Mathf.Approximately(m_Saturation, value))
{
m_Saturation = value;
SetDirty();
}
}
}
/// <summary>
/// Value shift [-0.5 ~ 0.5].
/// </summary>
public float value
{
get { return m_Value; }
set
{
value = Mathf.Clamp(value, -0.5f, 0.5f);
if (!Mathf.Approximately(m_Value, value))
{
m_Value = value;
SetDirty();
}
}
}
/// <summary>
/// Hue shift [-0.5 ~ 0.5].
/// </summary>
public float hue
{
get { return m_Hue; }
set
{
value = Mathf.Clamp(value, -0.5f, 0.5f);
if (!Mathf.Approximately(m_Hue, value))
{
m_Hue = value;
SetDirty();
}
}
}
/// <summary>
/// Gets the parameter texture.
/// </summary>
public override ParameterTexture ptex { get { return _ptex; } }
#if UNITY_EDITOR
protected override Material GetMaterial()
{
if (isTMPro)
{
return null;
}
return MaterialResolver.GetOrGenerateMaterialVariant(Shader.Find(shaderName));
}
#endif
/// <summary>
/// Modifies the mesh.
/// </summary>
public override void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled)
return;
float normalizedIndex = ptex.GetNormalizedIndex(this);
UIVertex vertex = default(UIVertex);
int count = vh.currentVertCount;
for (int i = 0; i < count; i++)
{
vh.PopulateUIVertex(ref vertex, i);
vertex.uv0 = new Vector2(
Packer.ToFloat(vertex.uv0.x, vertex.uv0.y),
normalizedIndex
);
vh.SetUIVertex(vertex, i);
}
}
protected override void SetDirty()
{
float h, s, v;
Color.RGBToHSV(m_TargetColor, out h, out s, out v);
foreach (var m in materials)
{
ptex.RegisterMaterial (m);
}
ptex.SetData(this, 0, h); // param1.x : target hue
ptex.SetData(this, 1, s); // param1.y : target saturation
ptex.SetData(this, 2, v); // param1.z : target value
ptex.SetData(this, 3, m_Range); // param1.w : target range
ptex.SetData(this, 4, m_Hue + 0.5f); // param2.x : hue shift
ptex.SetData(this, 5, m_Saturation + 0.5f); // param2.y : saturation shift
ptex.SetData(this, 6, m_Value + 0.5f); // param2.z : value shift
}
//################################
// Private Members.
//################################
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: efe700dddcd8341ff8607ac2c827b4b5
timeCreated: 1523859834
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+461
View File
@@ -0,0 +1,461 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
#if UNITY_EDITOR
using System.IO;
using System.Linq;
using UnityEditor;
#endif
namespace Assets.Scripts.UI.UIEffect
{
/// <summary>
/// UIEffect.
/// </summary>
[RequireComponent(typeof(Graphic))]
[AddComponentMenu("UI/UIEffect/UIShadow", 100)]
public class UIShadow : BaseMeshEffect, IParameterTexture
#if UNITY_EDITOR
, ISerializationCallbackReceiver
#endif
{
/// <summary>
/// Additional shadow.
/// </summary>
[System.Obsolete]
[System.Serializable]
public class AdditionalShadow
{
/// <summary>
/// How far is the blurring shadow from the graphic.
/// </summary>
[FormerlySerializedAs("shadowBlur")]
[Range(0, 1)] public float blur = 0.25f;
/// <summary>
/// Shadow effect mode.
/// </summary>
[FormerlySerializedAs("shadowMode")]
public ShadowStyle style = ShadowStyle.Shadow;
/// <summary>
/// Color for the shadow effect.
/// </summary>
[FormerlySerializedAs("shadowColor")]
public Color effectColor = Color.black;
/// <summary>
/// How far is the shadow from the graphic.
/// </summary>
public Vector2 effectDistance = new Vector2(1f, -1f);
/// <summary>
/// Should the shadow inherit the alpha from the graphic?
/// </summary>
public bool useGraphicAlpha = true;
}
//################################
// Serialize Members.
//################################
[Tooltip("How far is the blurring shadow from the graphic.")]
[FormerlySerializedAs("m_Blur")]
[SerializeField][Range(0, 1)] float m_BlurFactor = 1;
[Tooltip("Shadow effect style.")]
[SerializeField] ShadowStyle m_Style = ShadowStyle.Shadow;
#pragma warning disable 0414
[HideInInspector][System.Obsolete]
[SerializeField] List<AdditionalShadow> m_AdditionalShadows = new List<AdditionalShadow>();
#pragma warning restore 0414
[SerializeField]
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
[SerializeField]
private Vector2 m_EffectDistance = new Vector2 (1f, -1f);
[SerializeField]
private bool m_UseGraphicAlpha = true;
private const float kMaxEffectDistance = 600f;
public Color effectColor
{
get { return m_EffectColor; }
set
{
m_EffectColor = value;
if (graphic != null)
graphic.SetVerticesDirty ();
}
}
public Vector2 effectDistance
{
get { return m_EffectDistance; }
set
{
if (value.x > kMaxEffectDistance)
value.x = kMaxEffectDistance;
if (value.x < -kMaxEffectDistance)
value.x = -kMaxEffectDistance;
if (value.y > kMaxEffectDistance)
value.y = kMaxEffectDistance;
if (value.y < -kMaxEffectDistance)
value.y = -kMaxEffectDistance;
if (m_EffectDistance == value)
return;
m_EffectDistance = value;
if (graphic != null)
graphic.SetVerticesDirty ();
}
}
public bool useGraphicAlpha
{
get { return m_UseGraphicAlpha; }
set
{
m_UseGraphicAlpha = value;
if (graphic != null)
graphic.SetVerticesDirty ();
}
}
//################################
// Public Members.
//################################
/// <summary>
/// How far is the blurring shadow from the graphic.
/// </summary>
[System.Obsolete("Use blurFactor instead (UnityUpgradable) -> blurFactor")]
public float blur
{
get { return m_BlurFactor; }
set
{
m_BlurFactor = Mathf.Clamp(value, 0, 2);
_SetDirty();
}
}
/// <summary>
/// How far is the blurring shadow from the graphic.
/// </summary>
public float blurFactor
{
get { return m_BlurFactor; }
set
{
m_BlurFactor = Mathf.Clamp(value, 0, 2);
_SetDirty();
}
}
/// <summary>
/// Shadow effect style.
/// </summary>
public ShadowStyle style
{
get { return m_Style; }
set
{
m_Style = value;
_SetDirty();
}
}
/// <summary>
/// Gets or sets the parameter index.
/// </summary>
public int parameterIndex { get; set; }
/// <summary>
/// Gets the parameter texture.
/// </summary>
public ParameterTexture ptex{ get; private set; }
int _graphicVertexCount;
static readonly List<UIShadow> tmpShadows = new List<UIShadow>();
protected override void OnEnable()
{
base.OnEnable();
_uiEffect = GetComponent<UIEffect>();
if (_uiEffect)
{
ptex = _uiEffect.ptex;
ptex.Register(this);
}
#if TMP_PRESENT
if (isTMPro)
{
textMeshPro.onCullStateChanged.AddListener (OnCullStateChanged);
}
#endif
}
protected override void OnDisable()
{
base.OnDisable();
_uiEffect = null;
if (ptex != null)
{
ptex.Unregister(this);
ptex = null;
}
}
#if UNITY_EDITOR
protected override void OnValidate ()
{
effectDistance = m_EffectDistance;
base.OnValidate ();
}
#endif
#if TMP_PRESENT
protected void OnCullStateChanged (bool state)
{
SetVerticesDirty ();
}
Vector2 res;
protected override void LateUpdate ()
{
if (res.x != Screen.width || res.y != Screen.height)
{
res.x = Screen.width;
res.y = Screen.height;
SetVerticesDirty ();
}
if (textMeshPro && transform.hasChanged)
{
transform.hasChanged = false;
}
base.LateUpdate ();
}
#endif
/// <summary>
/// Modifies the mesh.
/// </summary>
public override void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled || vh.currentVertCount <= 0 || m_Style == ShadowStyle.None)
{
return;
}
vh.GetUIVertexStream(s_Verts);
GetComponents<UIShadow>(tmpShadows);
foreach (var s in tmpShadows)
{
if (s.isActiveAndEnabled)
{
if (s == this)
{
foreach (var s2 in tmpShadows)
{
s2._graphicVertexCount = s_Verts.Count;
}
}
break;
}
}
tmpShadows.Clear();
//================================
// Append shadow vertices.
//================================
{
_uiEffect = _uiEffect ?? GetComponent<UIEffect>();
var start = s_Verts.Count - _graphicVertexCount;
var end = s_Verts.Count;
if (ptex != null && _uiEffect && _uiEffect.isActiveAndEnabled)
{
ptex.SetData(this, 0, _uiEffect.effectFactor); // param.x : effect factor
ptex.SetData(this, 1, 255); // param.y : color factor
ptex.SetData(this, 2, m_BlurFactor); // param.z : blur factor
}
_ApplyShadow(s_Verts, effectColor, ref start, ref end, effectDistance, style, useGraphicAlpha);
}
vh.Clear();
vh.AddUIVertexTriangleStream(s_Verts);
s_Verts.Clear();
}
UIEffect _uiEffect;
//################################
// Private Members.
//################################
static readonly List<UIVertex> s_Verts = new List<UIVertex>(4096);
/// <summary>
/// Append shadow vertices.
/// * It is similar to Shadow component implementation.
/// </summary>
void _ApplyShadow(List<UIVertex> verts, Color color, ref int start, ref int end, Vector2 effectDistance, ShadowStyle style, bool useGraphicAlpha)
{
if (style == ShadowStyle.None || color.a <= 0)
return;
// Append Shadow.
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, effectDistance.y, useGraphicAlpha);
// Append Shadow3.
if (ShadowStyle.Shadow3 == style)
{
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, 0, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, effectDistance.y, useGraphicAlpha);
}
// Append Outline.
else if (ShadowStyle.Outline == style)
{
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, -effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, -effectDistance.y, useGraphicAlpha);
}
// Append Outline8.
else if (ShadowStyle.Outline8 == style)
{
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, -effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, -effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, -effectDistance.x, 0, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, -effectDistance.y, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, effectDistance.x, 0, useGraphicAlpha);
_ApplyShadowZeroAlloc(s_Verts, color, ref start, ref end, 0, effectDistance.y, useGraphicAlpha);
}
}
/// <summary>
/// Append shadow vertices.
/// * It is similar to Shadow component implementation.
/// </summary>
void _ApplyShadowZeroAlloc(List<UIVertex> verts, Color color, ref int start, ref int end, float x, float y, bool useGraphicAlpha)
{
// Check list capacity.
int count = end - start;
var neededCapacity = verts.Count + count;
if (verts.Capacity < neededCapacity)
verts.Capacity *= 2;
float normalizedIndex = ptex != null && _uiEffect && _uiEffect.isActiveAndEnabled
? ptex.GetNormalizedIndex(this)
: -1;
// Add
UIVertex vt = default(UIVertex);
for (int i = 0; i < count; i++)
{
verts.Add(vt);
}
// Move
for (int i = verts.Count - 1; count <= i; i--)
{
verts[i] = verts[i - count];
}
// Append shadow vertices to the front of list.
// * The original vertex is pushed backward.
for (int i = 0; i < count; ++i)
{
vt = verts[i + start + count];
Vector3 v = vt.position;
vt.position.Set(v.x + x, v.y + y, v.z);
Color vertColor = effectColor;
vertColor.a = useGraphicAlpha ? color.a * vt.color.a / 255 : color.a;
vt.color = vertColor;
// Set UIEffect prameters
if (0 <= normalizedIndex)
{
vt.uv0 = new Vector2(
vt.uv0.x,
normalizedIndex
);
}
verts[i] = vt;
}
// Update next shadow offset.
start = end;
end = verts.Count;
}
/// <summary>
/// Mark the UIEffect as dirty.
/// </summary>
void _SetDirty()
{
if (graphic)
graphic.SetVerticesDirty();
}
#if UNITY_EDITOR
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
EditorApplication.delayCall += UpgradeIfNeeded;
}
#pragma warning disable 0612
void UpgradeIfNeeded()
{
if (0 < m_AdditionalShadows.Count)
{
foreach (var s in m_AdditionalShadows)
{
if (s.style == ShadowStyle.None)
{
continue;
}
var shadow = gameObject.AddComponent<UIShadow>();
shadow.style = s.style;
shadow.effectDistance = s.effectDistance;
shadow.effectColor = s.effectColor;
shadow.useGraphicAlpha = s.useGraphicAlpha;
shadow.blurFactor = s.blur;
}
m_AdditionalShadows = null;
}
}
#pragma warning restore 0612
#endif
}
}
Loaded 100 of 130 files, more files were not shown because too many files have changed in this diff. Show more