Odin Inspector 系列教程 --- Progress Bar Attribute(逼格提升利器)

根據(jù)屬性的值繪制水平進(jìn)度條。用它來(lái)顯示計(jì)量表以指示存貨有多少,或以可視方式指示運(yùn)行狀況欄。(逼格滿(mǎn)滿(mǎn))

using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProgressBarAttributeExample : MonoBehaviour
{
    [ProgressBar(0, 100)]
    public int ProgressBar = 50;

    [ProgressBar(-100, 100, r: 1, g: 1, b: 1, Height = 30)]
    public short BigColoredProgressBar = 50;

    [ProgressBar(0, 10, 0, 1, 0, Segmented = true, DrawValueLabel = true)]
    public int SegmentedColoredBar = 5;

    [ProgressBar(0, 100, ColorMember = "GetHealthBarColor")]
    public float DynamicHealthBarColor = 50;
    private Color GetHealthBarColor(float value)
    {
        return Color.Lerp(Color.red, Color.green, Mathf.Pow(value / 100f, 2));
    }

    // 最小和最大屬性也支持帶有$符號(hào)的屬性表達(dá)式.
    [BoxGroup("Dynamic Range")]
    [ProgressBar("Min", "Max")]
    public float DynamicProgressBar = 50;

    [BoxGroup("Dynamic Range")]
    public float Min;

    [BoxGroup("Dynamic Range")]
    public float Max = 100;

    [Range(0, 300)]
    [BoxGroup("Stacked Health"), HideLabel]
    public float StackedHealth = 150;

    [HideLabel, ShowInInspector]
    [ProgressBar(0, 100, ColorMember = "GetStackedHealthColor", BackgroundColorMember = "GetStackHealthBackgroundColor", DrawValueLabel = false)]
    [BoxGroup("Stacked Health")]
    private float StackedHealthProgressBar
    {
        get { return this.StackedHealth % 100.01f; }
    }

    private Color GetStackedHealthColor()
    {
        return
            this.StackedHealth > 200 ? Color.white :
            this.StackedHealth > 100 ? Color.green :
            Color.red;
    }

    private Color GetStackHealthBackgroundColor()
    {
        return
            this.StackedHealth > 200 ? Color.green :
            this.StackedHealth > 100 ? Color.red :
            new Color(0.16f, 0.16f, 0.16f, 1f);
    }
}


更多教程內(nèi)容詳見(jiàn):革命性Unity 編輯器擴(kuò)展工具 --- Odin Inspector 系列教程

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。