using UnityEngine; using System; using UnityEditor; namespace MetaCity.BundleKit.Editor { [Serializable] public class PortalData { [SerializeField] private string mPortalName; [SerializeField] private uint mPortalGUID; [SerializeField] private Vector3 spawnPosition; [SerializeField] private Vector3 spwanEulerAngle; } public class PortalConfig : ScriptableObject { [SerializeField] private PortalData[] portals; } [CustomPropertyDrawer(typeof(PortalData))] public class PortalConfigEditor : UnityEditor.PropertyDrawer { public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return 36 + 50; } private static float[] s_Vector3Floats = new float[3]; private static GUIContent[] s_XYZLabels = new GUIContent[3] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), }; private static Vector3 Vector3Field(Rect position, Vector3 value) { s_Vector3Floats[0] = value.x; s_Vector3Floats[1] = value.y; s_Vector3Floats[2] = value.z; EditorGUI.BeginChangeCheck(); position.height = 18f; GUI.enabled=false; EditorGUI.MultiFloatField(position, s_XYZLabels, s_Vector3Floats); GUI.enabled=true; if (EditorGUI.EndChangeCheck()) { value.x = s_Vector3Floats[0]; value.y = s_Vector3Floats[1]; value.z = s_Vector3Floats[2]; } return value; } public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { var positionProperty = property.FindPropertyRelative("spawnPosition"); var angleProperty = property.FindPropertyRelative("spwanEulerAngle"); var nameProperty = property.FindPropertyRelative("mPortalName"); var guidProperty=property.FindPropertyRelative("mPortalGUID"); var boxSize = 36 + 40; Event evt = Event.current; Rect drop_area = new Rect(new Vector2(rect.x, rect.y + 5), new Vector2(boxSize - 5, boxSize - 5)); rect.x += boxSize + 10; GUI.Box (drop_area, "Drag Portal To Here"); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!drop_area.Contains (evt.mousePosition)) return; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag (); foreach (UnityEngine.Object dragged_object in DragAndDrop.objectReferences) { Portal.Portal portal=null; if (dragged_object is GameObject dragged_gameObject) { portal = dragged_gameObject.GetComponent(); } if(dragged_object is Portal.Portal) { portal=dragged_object as Portal.Portal; } if (portal is not null) { positionProperty.vector3Value = portal.SpwanPoint.position; angleProperty.vector3Value = portal.SpwanPoint.rotation.eulerAngles; nameProperty.stringValue=portal.PortalName; guidProperty.intValue= portal.PortalGUID; } } } break; } EditorGUIUtility.labelWidth = 50; rect.width -= (boxSize + 5); rect.height = 18f; EditorGUI.LabelField(rect,"Name"); rect.x += 50; rect.width -= 50; GUI.enabled=false; nameProperty.stringValue = EditorGUI.TextField(rect, nameProperty.stringValue); GUI.enabled=true; rect.x -= 50; rect.width += 50; rect.y += 18 + 5; EditorGUI.LabelField(rect, "ID"); rect.x += 50; rect.width -= 50; GUI.enabled=false; guidProperty.intValue = EditorGUI.IntField(rect, guidProperty.intValue); GUI.enabled=true; rect.x -= 50; rect.width += 50; rect.y += 18 + 5; EditorGUI.LabelField(rect, "Position"); rect.x += 50; rect.width -= 50; positionProperty.vector3Value = Vector3Field(rect, positionProperty.vector3Value); rect.x -= 50; rect.width += 50; rect.y += 18 + 5; EditorGUI.LabelField(rect, "Angle"); rect.x += 50; rect.width -= 50; angleProperty.vector3Value = Vector3Field(rect, angleProperty.vector3Value); rect.width += (boxSize + 5 + 50); rect.y += 18 + 5; } } }