157 lines
5.8 KiB
C#
157 lines
5.8 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
namespace Klak.Hap
|
|
{
|
|
[CanEditMultipleObjects]
|
|
[CustomEditor(typeof(HapPlayer))]
|
|
sealed class HapPlayerEditor : Editor
|
|
{
|
|
SerializedProperty _filePath;
|
|
SerializedProperty _pathMode;
|
|
SerializedProperty _time;
|
|
SerializedProperty _speed;
|
|
SerializedProperty _loop;
|
|
SerializedProperty _targetTexture;
|
|
SerializedProperty _flipHorizontal;
|
|
SerializedProperty _flipVertical;
|
|
|
|
static class Labels
|
|
{
|
|
public static readonly GUIContent Property = new GUIContent("Property");
|
|
public static readonly GUIContent Select = new GUIContent("Select");
|
|
}
|
|
|
|
string _sourceInfo;
|
|
|
|
void ShowSourceInfo(HapPlayer player)
|
|
{
|
|
if (!player.enabled || !player.gameObject.activeInHierarchy) return;
|
|
|
|
if (!player.isValid)
|
|
{
|
|
EditorGUILayout.HelpBox(
|
|
"Failed to open file. " +
|
|
"Please specify a valid HAP-encoded .mov file.",
|
|
MessageType.Warning
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (_sourceInfo == null)
|
|
_sourceInfo = string.Format(
|
|
"Codec: {0}\n" +
|
|
"Frame dimensions: {1} x {2}\n" +
|
|
"Stream duration: {3:0.00}\n" +
|
|
"Frame rate: {4:0.00}",
|
|
player.codecType,
|
|
player.frameWidth, player.frameHeight,
|
|
player.streamDuration,
|
|
player.frameCount / player.streamDuration
|
|
);
|
|
|
|
EditorGUILayout.HelpBox(_sourceInfo, MessageType.None);
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
_filePath = serializedObject.FindProperty("_filePath");
|
|
_pathMode = serializedObject.FindProperty("_pathMode");
|
|
_time = serializedObject.FindProperty("_time");
|
|
_speed = serializedObject.FindProperty("_speed");
|
|
_loop = serializedObject.FindProperty("_loop");
|
|
_targetTexture = serializedObject.FindProperty("_targetTexture");
|
|
_flipHorizontal = serializedObject.FindProperty("_flipHorizontal");
|
|
_flipVertical = serializedObject.FindProperty("_flipVertical");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
var reload = false;
|
|
|
|
serializedObject.Update();
|
|
|
|
// Source infomation
|
|
if (!_filePath.hasMultipleDifferentValues &&
|
|
!_pathMode.hasMultipleDifferentValues &&
|
|
!string.IsNullOrEmpty(_filePath.stringValue))
|
|
{
|
|
ShowSourceInfo((HapPlayer)target);
|
|
}
|
|
|
|
// Source file (드래그 앤 드롭 + 파일 브라우저)
|
|
EditorGUILayout.BeginHorizontal();
|
|
EditorGUI.BeginChangeCheck();
|
|
EditorGUILayout.DelayedTextField(_filePath);
|
|
if (GUILayout.Button("파일 선택", GUILayout.Width(80)))
|
|
{
|
|
string path = EditorUtility.OpenFilePanel("HAP MOV 파일 선택", Application.dataPath, "mov");
|
|
if (!string.IsNullOrEmpty(path))
|
|
{
|
|
string streamingPath = Application.streamingAssetsPath;
|
|
if (path.StartsWith(streamingPath))
|
|
path = path.Substring(streamingPath.Length + 1);
|
|
_filePath.stringValue = path;
|
|
}
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
if (EditorGUI.EndChangeCheck()) reload = true;
|
|
|
|
// 드래그 앤 드롭 지원
|
|
Rect dropRect = GUILayoutUtility.GetLastRect();
|
|
if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
|
|
{
|
|
if (dropRect.Contains(Event.current.mousePosition))
|
|
{
|
|
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
|
if (Event.current.type == EventType.DragPerform)
|
|
{
|
|
DragAndDrop.AcceptDrag();
|
|
foreach (var dragged in DragAndDrop.paths)
|
|
{
|
|
if (dragged.ToLower().EndsWith(".mov"))
|
|
{
|
|
string path = dragged;
|
|
string streamingPath = Application.streamingAssetsPath;
|
|
if (path.StartsWith(streamingPath))
|
|
path = path.Substring(streamingPath.Length + 1);
|
|
_filePath.stringValue = path;
|
|
GUI.FocusControl(null);
|
|
reload = true;
|
|
break;
|
|
}
|
|
}
|
|
Event.current.Use();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Playback control
|
|
EditorGUILayout.PropertyField(_time);
|
|
EditorGUILayout.PropertyField(_speed);
|
|
EditorGUILayout.PropertyField(_loop);
|
|
|
|
// Flip options
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField("Flip Options", EditorStyles.boldLabel);
|
|
EditorGUILayout.PropertyField(_flipHorizontal, new GUIContent("Flip Horizontal"));
|
|
EditorGUILayout.PropertyField(_flipVertical, new GUIContent("Flip Vertical"));
|
|
|
|
// Target texture
|
|
EditorGUILayout.PropertyField(_targetTexture);
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
if (reload)
|
|
{
|
|
foreach (HapPlayer hp in targets)
|
|
{
|
|
hp.SendMessage("OnDestroy");
|
|
hp.SendMessage("LateUpdate");
|
|
}
|
|
_sourceInfo = null;
|
|
}
|
|
}
|
|
}
|
|
}
|