123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- using UnityEngine;
- using UnityEngine.Assertions;
- using UnityEditor;
- using UnityEditorInternal;
- using System;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- namespace VoxelImporter
- {
- public class VoxelFrameAnimationListWindow : EditorWindow
- {
- public static VoxelFrameAnimationListWindow instance;
- public VoxelFrameAnimationObject objectTarget { get; private set; }
- public event Action frameIndexChanged;
- public event Action previewCameraModeChanged;
- private GUIStyle guiStyleButton;
- private GUIStyle guiStyleActiveButton;
- private GUIStyle guiStyleNameLabel;
- private static float frameIconSize = 64f;
- private Vector3 scrollPosition;
- public static void Create(VoxelFrameAnimationObject objectTarget)
- {
- if (instance == null)
- {
- instance = CreateInstance<VoxelFrameAnimationListWindow>();
- }
- instance.Initialize(objectTarget);
-
- instance.ShowUtility();
- }
- public static void Destroy()
- {
- if (instance != null)
- {
- instance.Close();
- }
- }
- void OnEnable()
- {
- InternalEditorUtility.RepaintAllViews();
- }
- void OnDisable()
- {
- instance = null;
- InternalEditorUtility.RepaintAllViews();
- }
- void OnDestroy()
- {
- OnDisable();
- }
- void OnSelectionChange()
- {
- var go = Selection.activeGameObject;
- if (go != objectTarget)
- {
- Close();
- }
- }
- private void Initialize(VoxelFrameAnimationObject objectTarget)
- {
- this.objectTarget = objectTarget;
- UpdateTitle();
- }
- void Update()
- {
- if (instance == null)
- {
- Close();
- }
- }
- void OnGUI()
- {
- #region GUIStyle
- if (guiStyleButton == null)
- guiStyleButton = new GUIStyle(GUI.skin.button);
- guiStyleButton.margin = new RectOffset(0, 0, 0, 0);
- guiStyleButton.overflow = new RectOffset(0, 0, 0, 0);
- guiStyleButton.padding = new RectOffset(0, 0, 0, 0);
- if (guiStyleActiveButton == null)
- guiStyleActiveButton = new GUIStyle(GUI.skin.button);
- guiStyleActiveButton.margin = new RectOffset(0, 0, 0, 0);
- guiStyleActiveButton.overflow = new RectOffset(0, 0, 0, 0);
- guiStyleActiveButton.padding = new RectOffset(0, 0, 0, 0);
- guiStyleActiveButton.normal = guiStyleActiveButton.active;
- if (guiStyleNameLabel == null)
- guiStyleNameLabel = new GUIStyle(GUI.skin.label);
- guiStyleNameLabel.alignment = TextAnchor.LowerCenter;
- #endregion
-
- EditorGUILayout.BeginHorizontal();
- {
- #region PreviewCameraMode
- {
- EditorGUI.BeginChangeCheck();
- var edit_previewCameraMode = (VoxelFrameAnimationObject.Edit_CameraMode)EditorGUILayout.EnumPopup(objectTarget.edit_previewCameraMode, GUILayout.Width(64));
- if (EditorGUI.EndChangeCheck())
- {
- Undo.RecordObject(objectTarget, "Camera Mode");
- objectTarget.edit_previewCameraMode = edit_previewCameraMode;
- if (previewCameraModeChanged != null)
- previewCameraModeChanged.Invoke();
- EditorApplication.delayCall += () =>
- {
- InternalEditorUtility.RepaintAllViews();
- };
- }
- }
- #endregion
- EditorGUILayout.Space();
- #region Size
- {
- frameIconSize = EditorGUILayout.Slider(frameIconSize, 32f, 128f);
- }
- #endregion
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.Space();
- scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
- {
- int countX = Math.Max(1, Mathf.FloorToInt(position.width / frameIconSize));
- int countY = Mathf.CeilToInt(objectTarget.frames.Count / (float)countX);
- for (int i = 0; i < countY; i++)
- {
- EditorGUILayout.BeginHorizontal();
- for (int j = 0; j < countX; j++)
- {
- var index = i * countX + j;
- if (index >= objectTarget.frames.Count) break;
- var rect = EditorGUILayout.GetControlRect(false, frameIconSize, guiStyleButton, GUILayout.Width(frameIconSize), GUILayout.Height(frameIconSize));
- if (GUI.Button(rect, objectTarget.frames[index].icon, index != objectTarget.edit_frameIndex ? guiStyleButton : guiStyleActiveButton))
- {
- Undo.RecordObject(objectTarget, "Select Frame");
- objectTarget.edit_frameIndex = index;
- if (frameIndexChanged != null)
- frameIndexChanged.Invoke();
- UpdateTitle();
- InternalEditorUtility.RepaintAllViews();
- }
- GUI.Label(rect, objectTarget.frames[index].name, guiStyleNameLabel);
- }
- EditorGUILayout.EndHorizontal();
- }
- {
- var index = -1;
- var rect = EditorGUILayout.GetControlRect(false, frameIconSize, guiStyleButton, GUILayout.Width(frameIconSize), GUILayout.Height(frameIconSize));
- if (GUI.Button(rect, "", index != objectTarget.edit_frameIndex ? guiStyleButton : guiStyleActiveButton))
- {
- Undo.RecordObject(objectTarget, "Select Frame");
- objectTarget.edit_frameIndex = index;
- if (frameIndexChanged != null)
- frameIndexChanged.Invoke();
- UpdateTitle();
- InternalEditorUtility.RepaintAllViews();
- }
- GUI.Label(rect, "None", guiStyleNameLabel);
- }
- }
- EditorGUILayout.EndScrollView();
- }
- public void FrameIndexChanged()
- {
- UpdateTitle();
- Repaint();
- }
- private void UpdateTitle()
- {
- if (objectTarget.edit_frameEnable)
- {
- var frame = objectTarget.edit_currentFrame;
- instance.titleContent = new GUIContent(string.Format("Frame List ({0}) - ({1} / {2})", frame.name, objectTarget.edit_frameIndex, objectTarget.frames.Count));
- }
- else
- {
- instance.titleContent = new GUIContent("Frame List");
- }
- }
- }
- }
|