많은 스프라이트 배열을 처리하는 스크립트가 있습니다. 그래서 내가 쓴 하나씩 끌어 싶지 않았다 나를 한 번 드래그를 사용하여 여러 스프라이트를 할당하고 드롭 작동하도록 할 수 있습니다 그것을 위해 CustomEditor
: 나는 관리자를 고정inspector에서 여러 스프라이트를 끌어다 놓는 방법
[CustomEditor(typeof(MyMonoBehaviour))]
public class MyMonoBehaviourEditor : Editor
{
Sprite[] sprites;//actually Sprite[,][] but simplified here
Object[] DropAreaGUI()
{
Event evt = Event.current;
Rect drop_area = GUILayoutUtility.GetRect(0.0f, 20.0f, GUILayout.ExpandWidth(true));
GUI.Box(drop_area, "Drop here!");
switch (evt.type)
{
case EventType.DragUpdated:
case EventType.DragPerform:
if (!drop_area.Contains(evt.mousePosition))
return null;
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (evt.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
return DragAndDrop.objectReferences;
}
break;
}
return null;
}
void OnInspectorGUI(){
var drops = DropAreaGUI();
if (drops != null)
{
//the following line gives me error
sprites = drops.Select(x => (x as Sprite)).ToArray();
}
}
}
, 12 개 스프라이트를 선택 프로젝트, 상자로 드래그하고 내가 그들을 놓을 때 그것은 나에게 오류를 제공합니다 ArgumentException: GUILayout: Mismatched LayoutGroup.DragPerform
나는 DragAndDrop.objectReferences
내 A 경우 Texture2D[]
에있는 Object[]
를 반환하고 내가 Sprite[]
에 캐스팅 할 수없는 것으로 나타났습니다. 나는 Sprite.Create
을 시도했지만 내가 가지고 있지 않은 rect와 pivot을 묻습니다.
DragAndDrop이 Texture2D가 아닌 Sprite를 삭제한다는 것을 어떻게 인식합니까?
멋지 네요. 나는이 옵션을 놓친 것 같아서 맞춤형 검사기를 사용하고있었습니다. – Bijan