您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
117 行
4.0 KiB
117 行
4.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace MetaCity.BundleKit.Editor
|
|
{
|
|
[Serializable]
|
|
public class SpawnPositionData
|
|
{
|
|
[SerializeField] private Vector3 mPosition;
|
|
[SerializeField] private Vector3 mEulerAngle;
|
|
}
|
|
|
|
public class SpawnPositionConfig : ScriptableObject
|
|
{
|
|
[SerializeField]
|
|
private SpawnPositionData[] mSpawnPoints;
|
|
}
|
|
|
|
[CustomPropertyDrawer(typeof(SpawnPositionData))]
|
|
public class SpawnPositionEditor : UnityEditor.PropertyDrawer
|
|
{
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
return 36 + 20;
|
|
}
|
|
|
|
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;
|
|
EditorGUI.MultiFloatField(position, s_XYZLabels, s_Vector3Floats);
|
|
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("mPosition");
|
|
var angleProperty = property.FindPropertyRelative("mEulerAngle");
|
|
|
|
var boxSize = 36 + 10;
|
|
|
|
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, "");
|
|
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 (Object dragged_object in DragAndDrop.objectReferences)
|
|
{
|
|
if (dragged_object is GameObject dragged_gameObject)
|
|
{
|
|
var transform = dragged_gameObject.GetComponent<Transform>();
|
|
if (transform is not null)
|
|
{
|
|
positionProperty.vector3Value = transform.position;
|
|
angleProperty.vector3Value = transform.rotation.eulerAngles;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
EditorGUIUtility.labelWidth = 50;
|
|
rect.width -= (boxSize + 5);
|
|
rect.height = 18f;
|
|
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;
|
|
}
|
|
}
|
|
}
|