美文网首页
Odin Inspector 系列教程 --- On Value

Odin Inspector 系列教程 --- On Value

作者: su9257_海澜 | 来源:发表于2019-10-09 09:59 被阅读0次

On Value Changed Attribute:处理属性和字段,并且只要通过检查器更改了值,就会调用指定的函数。

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

public class OnValueChangedAttributeExample : MonoBehaviour
{

    [ShowInInspector]
    [EnumPaging, OnValueChanged("SetCurrentTool")]
    [InfoBox("更改此属性将更改Unity编辑器中当前选择的工具.")]
    private UnityEditor.Tool sceneTool;

    private void SetCurrentTool()
    {
        UnityEditor.Tools.current = this.sceneTool;
        Debug.Log($"更改为:{UnityEditor.Tools.current}");
    }

    [OnValueChanged("CreateMaterial")]
    public Shader Shader;

    [ReadOnly, InlineEditor(InlineEditorModes.LargePreview)]
    public Material Material;

    private void CreateMaterial()
    {
        if (this.Material != null)
        {
            Material.DestroyImmediate(this.Material);
        }

        if (this.Shader != null)
        {
            this.Material = new Material(this.Shader);
        }
    }
}


更多教程内容详见:革命性Unity 编辑器扩展工具 --- Odin Inspector 系列教程

相关文章

网友评论

      本文标题:Odin Inspector 系列教程 --- On Value

      本文链接:https://www.haomeiwen.com/subject/jmxipctx.html