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.

108 lines
3.4 KiB

using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace uc
{
[CanEditMultipleObjects, CustomEditor(typeof(MoviePlayerCanvas), false)]
public class MoviePlayerCanvasEditor : ActivityBaseEditor
{
SerializedProperty m_LoopProperty;
GUIContent m_LoopLabel;
SerializedProperty m_FilenamesProperty;
ReorderableList m_FilenamesList;
MoviePlayerCanvas canvas;
protected override void OnEnable()
{
base.OnEnable();
canvas = target as MoviePlayerCanvas;
m_LoopProperty = serializedObject.FindProperty("loop");
m_LoopLabel = new GUIContent("Loop", "loop movie");
m_FilenamesProperty = serializedObject.FindProperty("filenames");
m_FilenamesList = new ReorderableList(serializedObject, m_FilenamesProperty, true, true, true, true);
m_FilenamesList.drawHeaderCallback = rect =>
{
EditorGUI.LabelField(rect, "Movie Filenames");
};
m_FilenamesList.drawElementCallback = (rect, index, active, focused) =>
{
#if true
SerializedProperty prefab = m_FilenamesProperty.GetArrayElementAtIndex(index);
DShowClip go = (DShowClip)prefab.objectReferenceValue;
GUIContent label;
if (go == null)
{
label = new GUIContent("Empty", "Drag a GameObject here");
}
else
{
label = new GUIContent(go.name);
}
float shrink = 0.2f;
rect.y += rect.height * shrink * 0.4f;
rect.height *= (1.0f - shrink);
var newGameObject = (DShowClip)EditorGUI.ObjectField(rect, label, go, typeof(DShowClip), true);
if (newGameObject == null)
{
canvas.filenames[index] = null;
EditorUtility.SetDirty(target);
return;
}
if (canvas.filenames[index] != newGameObject)
{
canvas.filenames[index] = newGameObject;
EditorUtility.SetDirty(target);
}
#else
SerializedProperty prefab = m_FilenamesProperty.GetArrayElementAtIndex(index);
string go = prefab.stringValue;
float shrink = 0.2f;
rect.y += rect.height * shrink * 0.4f;
rect.height *= (1.0f - shrink);
go = EditorGUI.TextField(rect, go);
if (string.IsNullOrEmpty(go))
{
canvas.filenames[index] = "";
EditorUtility.SetDirty(target);
return;
}
if (canvas.filenames[index] != go)
{
canvas.filenames[index] = go;
EditorUtility.SetDirty(target);
}
#endif
};
}
public override void OnInspectorGUI()
{
EditorGUILayout.Space();
serializedObject.Update();
EditorGUILayout.PropertyField(m_LoopProperty, m_LoopLabel);
EditorGUILayout.Space();
m_FilenamesList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
DrawEventInspectorGUI();
}
}
}