Unity5의 uGUI에서 문자 그래디언트(Gradient)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[AddComponentMenu("UI/Effects/Gradient")]
public class Gradient : BaseMeshEffect
{
[SerializeField] private Color32 topColor = Color.white;
[SerializeField] private Color32 bottomColor = Color.black;
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive()) {
return;
}
var vertexList = new List<UIVertex>();
vh.GetUIVertexStream(vertexList);
int count = vertexList.Count;
ApplyGradient(vertexList, 0, count);
vh.Clear();
vh.AddUIVertexTriangleStream(vertexList);
}
private void ApplyGradient(List<UIVertex> vertexList, int start, int end)
{
float bottomY = vertexList[0].position.y;
float topY = vertexList[0].position.y;
for (int i = start; i < end; ++i) {
float y = vertexList[i].position.y;
if (y > topY) {
topY = y;
} else if (y < bottomY) {
bottomY = y;
}
}
float uiElementHeight = topY - bottomY;
for (int i = start; i < end; ++i) {
UIVertex uiVertex = vertexList[i];
uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY)/uiElementHeight);
vertexList[i] = uiVertex;
}
}
}
주로 우송의 문장과 그 아래의 회답을 참고하였다.여기서 하나 더 설명하자면 Unity의 uGUI의 특수 효과 처리는 모두 정점에 기초한 것이다. 이것은 글씨체에 음영, 묘사, 점차적인 처리를 전문적으로 쓰는 것이 아니라 정점 처리로 그 효과를 시뮬레이션한 것이다.따라서 글에 음영 (묘사) 과 점차적인 변화가 동시에 있을 때 스크립트의 추가 순서에 주의해야 한다.
먼저 점차적인 스크립트를 추가한 다음에 묘사된 스크립트를 추가해야 한다. 그렇지 않으면 코드 논리에 따라 처리한다. 점차적인 정점 처리는 묘사된 정점 색깔도 모두 수정한다. 즉, 묘사 효과가 없다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.