using System; using System.Collections; using UMotionEditor.API; using UnityEditor; using UnityEngine; [InitializeOnLoad] public class UMotionQuickOpenEditor : Editor { #if UNITY_EDITOR public static ScriptableObject uProject; public static GameObject character; public static GUIStyle style; static UMotionQuickOpenEditor() { #if UNITY_2018 SceneView.onSceneGUIDelegate -= OnScene; SceneView.onSceneGUIDelegate += OnScene; #elif UNITY_2019_1_OR_NEWER SceneView.duringSceneGui -= OnScene; SceneView.duringSceneGui += OnScene; #endif } public static void OnScene(SceneView sceneView) { Handles.BeginGUI(); float width = 260; float height = 90; var rect = new Rect(Screen.width - width - 10f, Screen.height - height * 1.5f, width, height); bool validation = Validation(); if (validation) { if (style == null) { style = new GUIStyle(EditorStyles.whiteLabel); style.fontSize = 12; style.alignment = TextAnchor.UpperCenter; style.fontStyle = FontStyle.Bold; style.wordWrap = true; } GUILayout.BeginArea(rect); GUILayout.BeginVertical("window"); GUILayout.Space(-14); GUILayout.Label("uMotion QuickOpen Extension", style); GUILayout.BeginHorizontal(); GUILayout.Label("uProject", GUILayout.Width(width * 0.25f)); GUILayout.FlexibleSpace(); uProject = EditorGUILayout.ObjectField(GUIContent.none, uProject, typeof(ScriptableObject), true, GUILayout.Width(width * 0.7f)) as ScriptableObject; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Character", GUILayout.Width(width * 0.25f)); GUILayout.FlexibleSpace(); character = EditorGUILayout.ObjectField(GUIContent.none, character, typeof(GameObject), true, GUILayout.Width(width * 0.7f)) as GameObject; GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Space(4); if (GUILayout.Button("Quick Open", EditorStyles.miniButton)) { OpenMyUMotionInstance(); } GUILayout.EndVertical(); GUILayout.EndArea(); } Handles.EndGUI(); } private static bool Validation() { return ClipEditor.IsWindowOpened && !ClipEditor.IsProjectLoaded; } private static void OpenMyUMotionInstance() { ClipEditor.OpenWindow(); ClipEditor.LoadProject(AssetDatabase.GetAssetPath(uProject)); if (ClipEditor.IsProjectLoaded) { PoseEditor.SetAnimatedGameObject(character); } } #endif }