GitHub 上的工程多如繁星腰池,有些好的倉庫,但凡不經(jīng)意間錯(cuò)過了就很難找回壤追,故稍作采擷磕道,希望能幫助到有心人。
本文集以一個(gè)小的功能點(diǎn)為單位行文行冰,也便于拾取罷溺蕉!
簡(jiǎn)介:
筆者今天推薦的倉庫叫 SetProperty 。
A PropertyAttribute/PropertyDrawer combination that allows for properties in Unity - 通過屬性聲明 + 屬性繪制 功能將屬性擁有的特性移植到 Inspector 的字段輸入體驗(yàn)上悼做。
功能:
Unity allows you to serialize private fields with [SerializeField]. Use the new [SetProperty] attribute to have a public property set every time the field is modified in Unity's inspector.
通過在字段之上聲明:[SetProperty("指定的屬性")]
屬性疯特,可以在 Inspector 輸入框每次輸入完成之后進(jìn)行斷言和修正(屬性特性)。
演示:
通過指明 屬性的 名稱肛走,即能在Inspector 輸入框輸入時(shí)對(duì)輸入的值進(jìn)行必要的修正漓雅。
[SerializeField, SetProperty("Number")]
private float number;
public float Number
{
get
{
return number;
}
private set
{
number = Mathf.Clamp01(value);
}
}
演示內(nèi)容:
1.演示將數(shù)值限制在0-1
2.演示將輸入的小寫字母轉(zhuǎn)大寫
3.演示枚舉
4.演示 類中類/非Mono類
鏈接
結(jié)語:
這個(gè)組件提供了一個(gè)非常不錯(cuò)的:字段斷言,修正和Inspector調(diào)方法做API測(cè)試的解決方案(亦即將屬性特性搬上了Inspector)朽色。雖然它的實(shí)現(xiàn)僅僅一個(gè)反射而已邻吞,達(dá)到的效果卻是非常入人意中啊。
本文集持續(xù)更新ing