unity 如何實現ugui 圖片和字型顏色漸變
話不多說,直接程式碼
using System.Collections;
using System.Collections.Generic;using UnityEngine;
using UnityEngine.UI;
public class TextColorExt : BaseMeshEffect {
private enum Direction
{
Vertical,
Horizontal,
}
[SerializeField]
private Direction mDirection = Direction.Vertical;
[SerializeField]
private Color color = Color.white;
[SerializeField]
private bool isMid = true;
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive())
return;
if (vh.currentVertCount == 0)
return;
if (isMid) {
List<UIVertex> vlist = new List<UIVertex> ();
for (int i = 0; i < vh.currentVertCount; i+=4) {
UIVertex ver0 = new UIVertex();
UIVertex ver1 = new UIVertex();
UIVertex ver3 = new UIVertex();
UIVertex ver4 = new UIVertex();
vh.PopulateUIVertex (ref ver0, i + 0);
vh.PopulateUIVertex (ref ver1, i + 1);
vh.PopulateUIVertex (ref ver3, i + 2);
vh.PopulateUIVertex (ref ver4, i + 3);
UIVertex ver2 = new UIVertex();
ver2.position = (ver1.position + ver3.position) / 2;
ver2.uv0 = (ver1.uv0 + ver3.uv0) / 2;
ver2.color = color;
ver2.normal = ver0.normal;
ver2.tangent = ver0.tangent;
UIVertex ver5 = new UIVertex();
ver5.position = (ver0.position + ver4.position) / 2;
ver5.uv0 = (ver0.uv0 + ver4.uv0) / 2;
ver5.color = color;
ver5.normal = ver0.normal;
ver5.tangent = ver0.tangent;
vlist.Add (ver0);
vlist.Add (ver1);
vlist.Add (ver2);
vlist.Add (ver3);
vlist.Add (ver4);
vlist.Add (ver5);
}
List<int> tlist = new List<int> ();
for (int i = 0; i < vlist.Count; i += 6) {
tlist.Add (i + 0);
tlist.Add (i + 1);
tlist.Add (i + 2);
tlist.Add (i + 0);
tlist.Add (i + 2);
tlist.Add (i + 5);
tlist.Add (i + 2);
tlist.Add (i + 3);
tlist.Add (i + 4);
tlist.Add (i + 2);
tlist.Add (i + 4);
tlist.Add (i + 5);
}
vh.Clear ();
vh.AddUIVertexStream (vlist, tlist);
} else {
List<UIVertex> vlist = new List<UIVertex>();
vh.GetUIVertexStream(vlist);
if (vlist == null || vlist.Count == 0)
return;
Color startColr = vlist [0].color;
float leftX = vlist[0].position.x;
float rightX = vlist[0].position.x;
float bottomY = vlist[0].position.y;
float topY = vlist[0].position.y;
for (int i = 1; i < vlist.Count; i++) {
float y = vlist[i].position.y;
if (y > topY) {
topY = y;
} else if (y < bottomY) {
bottomY = y;
}
float x = vlist[i].position.x;
if (x > rightX) {
rightX = x;
} else if (x < leftX) {
leftX = x;
}
}
for (int i = 0; i < vlist.Count; i++) {
UIVertex ver = vlist[i];
float t = 0f;
if (mDirection == Direction.Vertical) {
t = (ver.position.y - bottomY) / (topY - bottomY);
} else {
t = (ver.position.x - leftX) / (rightX - leftX);
}
ver.color = Color.Lerp (startColr, color, t);
vlist[i] = ver;
}
vh.Clear();
vh.AddUIVertexTriangleStream(vlist);
}
}
}
實現結果如下
相關推薦
unity 如何實現ugui 圖片和字型顏色漸變
話不多說,直接程式碼using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class TextColorExt : Bas
關於Unity中UGUI圖片Image實現仿視頻播放窗口的四角縮放功能
重置 assert clas () strong unity 操作 寬度 腳本 應用方法:將下面腳本掛載在需要實現四角縮放功能的UI圖片上即可. 自定義拖拽精度(與邊界距離多少內觸發)m_validityWidth. 1 /********************
用QT實現字型顏色漸變效果——模擬彩色混光鍵盤
paint.h #ifndef PAINT_H #define PAINT_H #include <QWidget> #include <QtWidgets> class Paint : public QWidget { Q_OBJECT
CSS 實現背景色漸變和文字顏色漸變
1. 背景色漸變 A . linear-gradient:用線性漸變建立影象。 語法:<linear-gradient> = linear-gradient([ [ <angle> | to <side-or-corner
實現listview條目點選後改變item背景顏色和字型顏色並保留
先上效果圖。 其實實現是很簡單的在item的佈局中設定背景顏色選擇器,當item被選中時就會改變背景顏色 字型顏色在listview的adapter這種進行設定,定義標記記錄當前被點選的item
字型顏色漸變和邊框漸變的一個方法
.test {position: relative;margin: auto;height: 80px;width: 200px;border-radius: 40px;background-color: #fff;&:before {content: '';background: linear-gr
Unity實現UGUI中按鈕的單機、右擊和中鍵點選的判定
直接上程式碼吧,把這個程式碼繫結到Unity的相應Button上即可實現。 public class RightClick : MonoBehaviour, IPointerClickHandler
Button點選背景和字型顏色改變的實現方法
Button 點選背景顏色改變 Android Studio 中如何設定Button點選背景顏色改變 具體方法: 2. button 中字型顏色點選改變
TextMeshPro 字型顏色漸變和富文字
字型顏色漸變做法: 1. Project 目錄右鍵建立ColorGradient資源放在Resource目錄,設定字型上下漸變顏色 2. 獲取元件後: if (!m_txtHeroNameText.enableVertexGradient)
Qt中使用Qss修改邊框寬度,字型顏色,修改選擇時背景色和字型顏色
以Dialog為例 setStyleSheet("QDialog {border: 1px solid #CCCCCC;}"); 以LineEdit為例 setStyleSheet("color:white"); 以日曆為例 setStyleSheet(
CSS3j背景漸變,字型顏色漸變,以及相容IE寫法
一、背景漸變 #grad { background: linear-gradient(red, blue); } 漸變路徑預設是從上到下,也可以指定路徑: 從左到右 #grad { background: linear-gradient(to right, red , blu
Excel轉Html(十)--POI處理HSSFWorkbook與XSSFWorkbook解析表項的邊框和字型顏色區別
1、增加HSSFWorkbook老Excel支援 2、注意:HSSFWorkbook與XSSFWorkbook解析表項的邊框和字型顏色區別 邊框和字型顏色,需要在HSSFPalette中獲取, HSSFPalette customPalette = wb.getCustomPalet
ios 狀態列statusBar的背景顏色和字型顏色設定
假如我想讓狀態列顏色設定成紅色,字型仍為黑色,可以在需要顯示的那一頁進行如下設定:(最好寫在viewWillAppear裡面) //設定狀態列顏色 - (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *
Android簡單實現本地圖片和視訊選擇器功能
哈嘍,大家好,好久不見了,很久沒有更新 Android 方面的技術文章了,最近在忙公司的 AR 類的新產品,其中涉及到本地圖片和視訊的選擇和上傳功能。至於為什麼不用系統提供的圖片和視訊選擇器,原因你懂的,系統提供的選擇器只能通過 Intent 方式去獲取,這意味
Unity-實現UGUI閃爍效果
沒什麼特殊點,直接一套程式碼 using UnityEngine; using System.Collections; using UnityEngine.UI; public class ShanShuoAnim : MonoBehaviour { priv
改變背景和字型顏色
<!DOCTYPE html> <html> <head> <title>第二題</title>
關於螢幕適配 有不同解析度的圖片 和 字型大小
首先 新建兩個資料夾 一個是大解析度的格式 一個是小的 例如:values-720x1080 和 values-480x800 //新建出來的 資料夾在哪找? //就能發現你的資料夾 //然後兩個不同的解析度 每一個解析度裡都有一個xml檔案,這裡展示一個字型大小的檔案 大解析度
Ext.Net 1.x_Ext.Net_修改grid行或者列的背景顏色和字型顏色
修改某一列的背景顏色和字型顏色 css程式碼 .x-grid-back-red { background: #FF0000; //修改背景顏色 color:#000000; //修改字型顏色 } JS程式碼 { header : '分成型
UISegmentedControl-更改背景色和字型顏色
UISegmentedControl在很多的地方都會用到,但是每次修改的時候都不盡人意 比如說 UISegmentedControl有個tintColor屬性 segmentedControl.tintColor = [UIColorredColor]; 結果是
如何修改狀態列Statusbar(SystemUI)圖示和字型顏色
前言 由於公司專案的歡迎頁是白色的,,修改狀態列顏色後,導致狀態列的白色字型完全被覆蓋了,聯想到之前在QQ、UC等一些app上都見到過狀態列的字型是深色的,想著,,必定有解決的方案。於是,有了本篇blog。 參考 下面是我在網上找到的兩篇文章 解決方