[ ] Unity 3D. 1: |
[MenuItem("Tools/Initialization Project")]
string path //
bool valudate // ( )
int order //
[MenuItem("Tools/Initialization Project", true)]
public static bool Initialization()
{
// ,
return Selection.gameObjects.Length > 0;
}
[MenuItem("Tools/Initialization Project")]
public static void Initialization()
{
//do something...
}
[Range(float min, float max)]
[Header(string title)]
[Space]
[Tooltip(string tip)]
[SerializeField]
[NonSerialized]
[HiddenInInspector]
[ExecuteInEditMode]
[RequireComponent(System.Type type)]
[AddComponentMenu(string path)]
public class IntAttribute : PropertyAttribute
{
private string path = ;
public IntAttribute(string path)
{
this.path = path;
}
}
[CustomPropertyDrawer(typeof(IntAttribute ))]
public class IntAttributeDrawer : PropertyDrawer
{
}
public interface IResource
{
int ID
{
get;
}
string Name
{
get;
}
}
[System.Serializable]
public class Effect : IResource
{
[SerializeField]
private string name = ;
[SerializeField]
private int id = 0;
public int ID
{
get
{
return id;
}
}
public string Name
{
get
{
return name;
}
}
}
public interface IContainer
{
IResource[] Resources
{
get;
}
}
public abstract class ResourcesContainer : MonoBehavior, IContainer
{
public virtual IResource[] Resources
{
get
{
return null;
}
}
}
public class EffectsContainer : ResourcesContainer
{
[SerializeField]
private Effect[] effects = null;
public override IResource[] Resources
{
get
{
return effects;
}
}
}
[CustomPropertyDrawer(typeof(IntAttribute ))]
public class IntAttributeDrawer : PropertyDrawer
{
protected string[] values = null;
protected List idents = null;
protected virtual void Init(SerializedProperty property)
{
if (attribute != null)
{
IntAttribute intAttribute = (IntAttribute)attribute;
// null, , ,
IResource[] resources = Resources.Load(intAttribute.Path).Resources;
values = new string[resources.Length + 1];
idents = new List(resources.Length + 1);
// -1
values[0] = -1: None;
idents.Add(-1);
for (int i = 0; i < resources.Length; i++)
{
values[i+1] = resources[i].ID + : + resources[i].Path;
idents.Add(resources[i].ID);
}
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property == null)
{
return;
}
Init(property);
EditorGUI.BeginProperty(position, label, property);
// Draw label
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
// Don't make child fields be indented
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// Calculate rects
Rect pathRect = new Rect(position.x, position.y, position.width - 6, position.height);
int intValue = property.intValue;
intValue = idents[EditorGUI.Popup(pathRect, Mathf.Max(0, idents.IndexOf(intValue)), Values)];
property.intValue = intValue;
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
ScriptableObject ( Resources/Effects/Container).
.
public class Bullet : MonoBehavior
{
[SerializeField]
[IntAttribute(Effects/Container)]
private int effectId = -1;
}