Property Attribute를 사용하여 Tag의string을 읽을 수 있도록 편집기 확장
TagAttribute.cs
using UnityEngine;
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditorInternal;
#endif
class TagAttribute : PropertyAttribute{}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(TagAttribute))]
public class TagEditor : PropertyDrawer
{
//tagのList
List<string> AllTags
{
get
{
return InternalEditorUtility.tags.ToList();
}
}
//ドロップダウンメニューの作成
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var list = AllTags;
var selectedIndex = list.FindIndex(item => item.Equals(property.stringValue));
if (selectedIndex == -1)
{
selectedIndex = list.FindIndex(item => item.Equals(list[0]));
}
selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, list.ToArray());
property.stringValue = list[selectedIndex];
}
}
#endif
지난번에 보도된 Getter를 바꿨을 뿐입니다.설치할 때 아래의string형 필드를 참조하십시오.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
[SerializeField, TagAttribute]
string Tags;
}
기본'tag'외에 추가'tag'도 표시됩니다.
Reference
이 문제에 관하여(Property Attribute를 사용하여 Tag의string을 읽을 수 있도록 편집기 확장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/keel/items/6178a1d7c1a025d1677d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)