using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using System;
|
using System.Collections.Generic;
|
|
[DisallowMultipleComponent]
|
[AddComponentMenu("UI/Effects/Reflection")]
|
public class Reflection:BaseMeshEffect {
|
|
[Range(0,30)]
|
[SerializeField]
|
float m_Distance;
|
public float distance {
|
get {
|
return m_Distance;
|
}
|
}
|
|
[Range(0,1)]
|
[SerializeField]
|
float m_HeightScale = 1f;
|
public float heightScale {
|
get {
|
return m_HeightScale;
|
}
|
}
|
|
[Range(0,1)]
|
[SerializeField]
|
float m_Virtualness;
|
public float virtualness {
|
get {
|
return m_Virtualness;
|
}
|
}
|
|
[SerializeField]
|
float m_OffsetX = 0;
|
public float offsetX {
|
get {
|
return m_OffsetX;
|
}
|
}
|
|
|
public override void ModifyMesh(VertexHelper vh) {
|
if(!IsActive() || vh.currentVertCount == 0) {
|
return;
|
}
|
|
var vertexs = new List<UIVertex>();
|
vh.GetUIVertexStream(vertexs);
|
|
var count = vertexs.Count;
|
var edge = UIUtility.GetEdge(vertexs,1);
|
var height = (edge[1] - edge[0]) * heightScale;
|
if(height == 0) {
|
return;
|
}
|
|
var mirrorMinY = (edge[0] - edge[1]) * heightScale + edge[0] - distance;
|
var color = this.graphic.color;
|
var top = color.SetA(1 - virtualness);
|
var bottom = color.SetA(0);
|
|
for(var i = 0;i < count;i++) {
|
var vertex = vertexs[i];
|
vertexs.Add(vertex);
|
var position = vertex.position;
|
position.y = edge[0] - distance + (edge[0] - position.y) * heightScale;
|
position.x += offsetX * (1 - Mathf.Abs((position.y - mirrorMinY) / height));
|
vertex.position = position;
|
|
var colort = Mathf.Abs((position.y - mirrorMinY) / height);
|
vertex.color = Color32.Lerp(bottom,top,colort);
|
vertexs[i + count] = vertex;
|
}
|
|
vh.Clear();
|
vh.AddUIVertexTriangleStream(vertexs);
|
}
|
}
|