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
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;
}