Unity Odin(实现如图所示)(一)

Unity Odin(实现如图所示)(一)

在这里插入图片描述

代码实现

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

public class Test : MonoBehaviour
{
    [BoxGroup("Game State Info")]
    [EnumToggleButtons]
    [OnValueChanged("StateChange")]
    [ShowInInspector]
    public static GameState gameState;
    
    [BoxGroup("Game State Info")]
    [ShowInInspector]
    [OnValueChanged("IndexChange")]
    public static int index;

    [TabGroup("UI")]
    [SceneObjectsOnly,Required]
    [InlineButton("SelectCanvas","Select With Scene")]
    public Canvas startButtons;
    [TabGroup("UI")]
    [SceneObjectsOnly,Required]
    [InlineButton("SelectCanvas","Select With Scene")]
    public Canvas pauseMenu;
    [TabGroup("UI")]
    [SceneObjectsOnly,Required]
    [InlineButton("SelectCanvas","Select With Scene")]
    public Canvas HUD;

    [TabGroup("Music")]
    public AudioSource musicSource;
    
    [Space]
    [ShowInInspector]
    [ValueDropdown("musicList")]
    [TabGroup("Music")]
    [InlineButton("PlayMusic","Play")]
    [InlineButton("StopMusic","Stop")]
    private AudioClip _currMusicClip;
    [TabGroup("Music")]
    [InlineEditor(InlineEditorModes.SmallPreview)]
    public List<AudioClip> musicList;

    [TabGroup("SFX")]
    public AudioSource sfxSource;
    [TabGroup("SFX")]
    public AudioClip music1;
    [TabGroup("SFX")]
    public AudioClip music2;
    [TabGroup("SFX")]
    public AudioClip music3;
    [TabGroup("SFX")]
    public AudioClip music4;

    [TabGroup("Enemies","Enemy Data"),Required]
    [AssetsOnly]
    public GameObject enemyPrefab;
    [Space]
    [TabGroup("Enemies","Enemy Data")]
    public List<EnemyData> enemyList;
    [TabGroup("Enemies","Spawn Point")]
    [SceneObjectsOnly]
    public List<Transform> spawnPointLst;

    [Button(ButtonSizes.Medium)]
    [TabGroup("Enemies","Enemy Data")]
    [GUIColor(0,6f,1f,1f)]
    private void CreateEnemy()
    {
        var go = Instantiate(enemyPrefab);
        go.transform.position = spawnPointLst[Random.Range(0, spawnPointLst.Count)].position;
    }

#if UNITY_EDITOR
    
    //==========Editor===========
    private void StateChange()
    {
        Debug.Log(gameState);
    }

    private void IndexChange()
    {
        Debug.Log(index);
    }

    private void SelectCanvas(Canvas obj)
    {
        if (obj)
            UnityEditor.Selection.activeObject = obj.gameObject;
    }

    private void PlayMusic(AudioClip musicClip)
    {
        if (musicSource == null || musicClip == null) return;
        musicSource.clip = musicClip;
        musicSource.Play();
    }

    private void StopMusic(AudioClip musicClip)
    {
        if (musicSource == null || !musicSource.isPlaying) return;
        musicSource.Stop();
        musicSource.clip = null;
    }
    
#endif

}

public enum GameState
{
    State1,
    State2,
    State3,
    State4,
}

[Serializable]
public class EnemyData
{
    public string name;
    public int age;
    public int damage;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值