You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.9 KiB
100 lines
2.9 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
#if UNITY_EDITOR
|
||
|
using UnityEditor;
|
||
|
#endif
|
||
|
|
||
|
public partial class UIdSystem : MonoBehaviour
|
||
|
{
|
||
|
[Serializable]
|
||
|
private class ComponentIdPair
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Component component;
|
||
|
[SerializeField]
|
||
|
private ulong id;
|
||
|
|
||
|
public ComponentIdPair(Component component, ulong id)
|
||
|
{
|
||
|
this.component = component;
|
||
|
this.id = id;
|
||
|
}
|
||
|
|
||
|
public Component Component
|
||
|
{
|
||
|
get { return component; }
|
||
|
set { component = value; }
|
||
|
}
|
||
|
|
||
|
public ulong Id
|
||
|
{
|
||
|
get { return id; }
|
||
|
set { id = value; }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#if UNITY_EDITOR
|
||
|
[CustomPropertyDrawer(typeof(ComponentIdPair))]
|
||
|
public class ComponentIdPairDrawer : PropertyDrawer
|
||
|
{
|
||
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||
|
{
|
||
|
return EditorGUIUtility.singleLineHeight;
|
||
|
}
|
||
|
|
||
|
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
|
||
|
{
|
||
|
SerializedProperty objectProperty = property.FindPropertyRelative("component");
|
||
|
SerializedProperty idProperty = property.FindPropertyRelative("id");
|
||
|
UnityEngine.Object objectValue = objectProperty.objectReferenceValue;
|
||
|
|
||
|
bool isGameObject = false;
|
||
|
bool isUIdSystemComponent = false;
|
||
|
|
||
|
if (objectValue != null)
|
||
|
{
|
||
|
Type objectType = objectValue.GetType();
|
||
|
isGameObject = objectType.IsAssignableFrom(typeof(GameObject));
|
||
|
isUIdSystemComponent = objectType.IsAssignableFrom(typeof(UIdSystem));
|
||
|
}
|
||
|
|
||
|
// 开始绘制属性
|
||
|
EditorGUI.BeginProperty(rect, label, property);
|
||
|
|
||
|
rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);
|
||
|
|
||
|
int indent = EditorGUI.indentLevel;
|
||
|
EditorGUI.indentLevel = 0; // 不缩进
|
||
|
|
||
|
// 计算位置和大小
|
||
|
Rect objectRect, idRect;
|
||
|
|
||
|
objectRect = new Rect(rect.x, rect.y, 160f, rect.height);
|
||
|
|
||
|
if (isGameObject)
|
||
|
idRect = new Rect(rect.x + 165f, rect.y, rect.width - 165f, rect.height);
|
||
|
else
|
||
|
idRect = new Rect(rect.x + 165f, rect.y, rect.width - 190f, rect.height);
|
||
|
|
||
|
Color oldColor = GUI.color;
|
||
|
GUI.color = Color.green;
|
||
|
|
||
|
// 不允许编辑
|
||
|
GUI.enabled = false;
|
||
|
|
||
|
EditorGUI.PropertyField(objectRect, objectProperty, GUIContent.none);
|
||
|
EditorGUI.PropertyField(idRect, idProperty, GUIContent.none);
|
||
|
|
||
|
GUI.color = oldColor;
|
||
|
GUI.enabled = true;
|
||
|
|
||
|
EditorGUI.indentLevel = indent;
|
||
|
|
||
|
EditorGUI.EndProperty();
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
}
|