Unity Odin (实现如图所示效果)(四)

Unity Odin (实现如图所示效果)(四)

在这里插入图片描述

代码

using UnityEngine;

public class Test4 : MonoBehaviour
{
    public string characterName;
    public string characterInfo;
    private int _characterAge;
    public Texture2D icon;
    public GameObject prefab;
    public Stats stats;
}
[System.Serializable]
public class Stats
{
    public int s1;
    public int s2;
    public int s3;
    public int s4;
}
using System;
using System.Collections.Generic;
using System.Reflection;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using UnityEngine;

public class CharacterAttributeProcessor<T>:OdinAttributeProcessor<T> where T:Test4
{
    public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member, List<Attribute> attributes)
    {
        attributes.Add(new LabelWidthAttribute(100));
        if (member.Name == "icon")
        {
            attributes.Add(new PropertyOrderAttribute(-1));
            attributes.Add(new HideLabelAttribute());
            attributes.Add(new HorizontalGroupAttribute("base",100));
            attributes.Add(new PreviewFieldAttribute(100,ObjectFieldAlignment.Center));
        }

        if (member.GetReturnType() == typeof(string))
        {
            attributes.Add(new VerticalGroupAttribute("base/right"));
        }

        switch (member.Name)
        {
            case "prefab":
                attributes.Add(new VerticalGroupAttribute("base/right"));
                attributes.Add(new InlineEditorAttribute(InlineEditorModes.LargePreview));
                attributes.Add(new RequiredAttribute());
                break;
            case "_characterAge":
                attributes.Add(new ShowInInspectorAttribute());
                attributes.Add(new VerticalGroupAttribute("base/right"));
                break;
        }
    }
}

public class StatsAttributeProcessor : OdinAttributeProcessor<Stats>
{
    public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member, List<Attribute> attributes)
    {
        attributes.Add(new BoxGroupAttribute("Box"));
        attributes.Add(new RangeAttribute(10,20));
    }

    public override void ProcessSelfAttributes(InspectorProperty property, List<Attribute> attributes)
    {
        attributes.Add(new PropertySpaceAttribute(50));
        attributes.Add(new HideLabelAttribute());
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值