Thomas ICHÉ
5 年前
当前提交
bbb9b1a4
共有 15 个文件被更改,包括 863 次插入 和 33 次删除
-
6Editor/EditorSceneSetup/EditorSceneSetup.cs
-
3Editor/GameplayIngredients-Editor.asmdef
-
63Editor/WelcomeScreen/WelcomeScreen.cs
-
8Editor/Discover.meta
-
8Runtime/Discover.meta
-
54Editor/Discover/DiscoverAsset.cs
-
11Editor/Discover/DiscoverAsset.cs.meta
-
174Editor/Discover/DiscoverEditor.cs
-
11Editor/Discover/DiscoverEditor.cs.meta
-
489Editor/Discover/DiscoverWindow.cs
-
11Editor/Discover/DiscoverWindow.cs.meta
-
47Runtime/Discover/Discover.cs
-
11Runtime/Discover/Discover.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 1654aa6a98f49614c87efd8f50c2785c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e65b0a4c26482dd4795cef781a110a1e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
public class DiscoverAsset : ScriptableObject |
|||
{ |
|||
[MenuItem("Assets/Create/Discover Asset", priority = 202)] |
|||
static void Create() |
|||
{ |
|||
AssetFactory.CreateAssetInProjectWindow<DiscoverAsset>(null, "New DiscoverAsset"); |
|||
} |
|||
|
|||
[Header("General Properties")] |
|||
public string WindowTitle = "Discover"; |
|||
public Texture2D HeaderTexture; |
|||
|
|||
[Tooltip("Width of the Window, in pixels")] |
|||
public int WindowWidth = 640; |
|||
[Tooltip("Height of the Window, in pixels")] |
|||
public int WindowHeight = 520; |
|||
[Tooltip("Width of the Discover List, in pixels")] |
|||
public int DiscoverListWidth = 180; |
|||
|
|||
[Header("Show At Startup")] |
|||
public bool EnableShowAtStartup = true; |
|||
[Tooltip("The name of the preference for auto showing at startup, will be ")] |
|||
public string PreferenceName = "Discover"; |
|||
|
|||
[Header("Content")] |
|||
public string Title = "Welcome!"; |
|||
[Multiline] |
|||
public string Description = "This is a sample body for your discover window."; |
|||
[Header("Scenes")] |
|||
public DiscoverSceneInfo[] Scenes; |
|||
|
|||
[Header("Debug")] |
|||
public bool Debug = false; |
|||
} |
|||
|
|||
[System.Serializable] |
|||
public struct DiscoverSceneInfo |
|||
{ |
|||
public string Title; |
|||
[Multiline] |
|||
public string Description; |
|||
public EditorSceneSetup SceneSetup; |
|||
public SceneAsset SingleScene; |
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 99c49654b9bada340bfd165d70dc8296 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.Experimental.VFX; |
|||
using UnityEngine.Timeline; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomEditor(typeof(Discover))] |
|||
public class DiscoverEditor : UnityEditor.Editor |
|||
{ |
|||
const string kEditPreferenceName = "GameplayIngredients.DiscoverEditor.Editing"; |
|||
|
|||
static bool editing |
|||
{ |
|||
get { return EditorPrefs.GetBool(kEditPreferenceName, false); } |
|||
set { if (value != editing) EditorPrefs.SetBool(kEditPreferenceName, value); } |
|||
} |
|||
|
|||
Discover m_Discover; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
m_Discover = serializedObject.targetObject as Discover; |
|||
if (m_Discover.transform.hideFlags != HideFlags.HideInInspector) |
|||
m_Discover.transform.hideFlags = HideFlags.HideInInspector; |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.FlexibleSpace(); |
|||
editing = GUILayout.Toggle(editing, "Edit", EditorStyles.miniButton, GUILayout.Width(48)); |
|||
} |
|||
|
|||
if (editing) |
|||
DrawDefaultInspector(); |
|||
else |
|||
DrawDiscoverContentGUI(m_Discover); |
|||
} |
|||
|
|||
|
|||
public static void DrawDiscoverContentGUI(Discover discover) |
|||
{ |
|||
|
|||
GUILayout.Label(discover.Category, DiscoverWindow.Styles.subHeader); |
|||
GUILayout.Label(discover.Name, DiscoverWindow.Styles.header); |
|||
|
|||
using (new GUILayout.VerticalScope(DiscoverWindow.Styles.indent)) |
|||
{ |
|||
if (discover.Description != null && discover.Description != string.Empty) |
|||
{ |
|||
GUILayout.Label(discover.Description, DiscoverWindow.Styles.body); |
|||
} |
|||
|
|||
GUILayout.Space(8); |
|||
|
|||
foreach (var section in discover.Sections) |
|||
{ |
|||
SectionGUI(section); |
|||
GUILayout.Space(16); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static void SectionGUI(DiscoverSection section) |
|||
{ |
|||
using (new DiscoverWindow.GroupLabelScope(section.SectionName)) |
|||
{ |
|||
using (new GUILayout.VerticalScope(DiscoverWindow.Styles.slightIndent)) |
|||
{ |
|||
GUILayout.Label(section.SectionContent, DiscoverWindow.Styles.body); |
|||
|
|||
if (section.Actions != null && section.Actions.Length > 0) |
|||
{ |
|||
GUILayout.Space(8); |
|||
|
|||
using (new GUILayout.VerticalScope(GUI.skin.box)) |
|||
{ |
|||
foreach (var action in section.Actions) |
|||
{ |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.Label(action.Description); |
|||
GUILayout.FlexibleSpace(); |
|||
using (new GUILayout.HorizontalScope(GUILayout.MinWidth(160))) |
|||
{ |
|||
ActionButtonGUI(action.Target); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void ActionButtonGUI(UnityEngine.Object target) |
|||
{ |
|||
Type t = target.GetType(); |
|||
|
|||
if (t == typeof(GameObject)) |
|||
{ |
|||
GameObject go = target as GameObject; |
|||
|
|||
if (GUILayout.Button(" Select ", DiscoverWindow.Styles.buttonLeft)) |
|||
{ |
|||
Selection.activeObject = go; |
|||
} |
|||
|
|||
if(PrefabUtility.GetPrefabAssetType(go) == PrefabAssetType.NotAPrefab) |
|||
{ |
|||
if (GUILayout.Button(" Go to ", DiscoverWindow.Styles.buttonRight)) |
|||
{ |
|||
|
|||
Selection.activeObject = go; |
|||
SceneView.lastActiveSceneView.FrameSelected(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (GUILayout.Button(" Open ", DiscoverWindow.Styles.buttonRight)) |
|||
{ |
|||
AssetDatabase.OpenAsset(go); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
else if (t == typeof(VisualEffectAsset)) |
|||
{ |
|||
if (GUILayout.Button("Open VFX Graph")) |
|||
{ |
|||
VisualEffectAsset graph = target as VisualEffectAsset; |
|||
AssetDatabase.OpenAsset(graph); |
|||
} |
|||
} |
|||
else if (t == typeof(Animation)) |
|||
{ |
|||
if (GUILayout.Button("Open Animation")) |
|||
{ |
|||
Animation animation = target as Animation; |
|||
AssetDatabase.OpenAsset(animation); |
|||
} |
|||
} |
|||
else if (t == typeof(TimelineAsset)) |
|||
{ |
|||
if (GUILayout.Button("Open Timeline")) |
|||
{ |
|||
TimelineAsset timeline = target as TimelineAsset; |
|||
AssetDatabase.OpenAsset(timeline); |
|||
} |
|||
} |
|||
else if (t == typeof(Shader)) |
|||
{ |
|||
if (GUILayout.Button("Open Shader")) |
|||
{ |
|||
Shader shader = target as Shader; |
|||
AssetDatabase.OpenAsset(shader); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (GUILayout.Button("Select")) |
|||
{ |
|||
Selection.activeObject = target; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: b1c258c43239c974080376d0bf372421 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
using UnityEngine.Experimental.VFX; |
|||
using UnityEngine.SceneManagement; |
|||
using UnityEditor; |
|||
using UnityEditor.SceneManagement; |
|||
using UnityEngine.Timeline; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
public class DiscoverWindow : EditorWindow |
|||
{ |
|||
static List<DiscoverAsset> s_StartupDiscoverAssets; |
|||
|
|||
static bool GetShowOnStartup(string name) |
|||
{ |
|||
return EditorPrefs.GetBool($"{name}.ShowAtStartup", true); |
|||
} |
|||
|
|||
static void SetShowOnStartup(string name, bool value) |
|||
{ |
|||
if (value != GetShowOnStartup(name)) EditorPrefs.SetBool($"{name}.ShowAtStartup", value); |
|||
} |
|||
|
|||
|
|||
[InitializeOnLoadMethod] |
|||
static void InitShowAtStartup() |
|||
{ |
|||
string[] guids = AssetDatabase.FindAssets("t:DiscoverAsset"); |
|||
foreach(var guid in guids) |
|||
{ |
|||
DiscoverAsset asset = AssetDatabase.LoadAssetAtPath<DiscoverAsset>(AssetDatabase.GUIDToAssetPath(guid)); |
|||
if(asset.EnableShowAtStartup) |
|||
{ |
|||
if (s_StartupDiscoverAssets == null) |
|||
s_StartupDiscoverAssets = new List<DiscoverAsset>(); |
|||
|
|||
s_StartupDiscoverAssets.Add(asset); |
|||
} |
|||
} |
|||
|
|||
if(s_StartupDiscoverAssets != null && s_StartupDiscoverAssets.Count > 0) |
|||
EditorApplication.update += ShowAtStartup; |
|||
} |
|||
|
|||
static void ShowAtStartup() |
|||
{ |
|||
if (!Application.isPlaying && s_StartupDiscoverAssets != null) |
|||
{ |
|||
foreach(var discoverAsset in s_StartupDiscoverAssets) |
|||
{ |
|||
if(GetShowOnStartup(discoverAsset.PreferenceName)) |
|||
ShowDiscoverWindow(discoverAsset); |
|||
} |
|||
} |
|||
EditorApplication.update -= ShowAtStartup; |
|||
} |
|||
|
|||
public static void ShowDiscoverWindow(DiscoverAsset discoverAsset) |
|||
{ |
|||
if(discoverAsset != null) |
|||
{ |
|||
var window = GetWindow<DiscoverWindow>(true); |
|||
window.SetDiscoverAsset(discoverAsset); |
|||
} |
|||
else |
|||
{ |
|||
Debug.LogError("Could not open Discover Window : discoverAsset is null"); |
|||
} |
|||
} |
|||
|
|||
Texture2D header; |
|||
DiscoverAsset discoverAsset; |
|||
bool forceGlobal; |
|||
|
|||
void SetDiscoverAsset(DiscoverAsset discover) |
|||
{ |
|||
discoverAsset = discover; |
|||
titleContent = new GUIContent(discoverAsset.WindowTitle); |
|||
minSize = new Vector2(discoverAsset.WindowWidth, discoverAsset.WindowHeight); |
|||
maxSize = new Vector2(discoverAsset.WindowWidth, discoverAsset.WindowHeight); |
|||
} |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
UpdateDiscoverObjects(); |
|||
EditorSceneManager.newSceneCreated += UpdateDiscoverObjectsOnCreate; |
|||
EditorSceneManager.sceneOpened += UpdateDiscoverObjectsOnLoad; |
|||
EditorSceneSetup.onSetupLoaded += UpdateDiscoverObjectsOnLoadSetup; |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
EditorSceneManager.newSceneCreated -= UpdateDiscoverObjectsOnCreate; |
|||
EditorSceneManager.sceneOpened -= UpdateDiscoverObjectsOnLoad; |
|||
EditorSceneSetup.onSetupLoaded -= UpdateDiscoverObjectsOnLoadSetup; |
|||
} |
|||
|
|||
Dictionary<string, List<Discover>> discoverObjects = null; |
|||
|
|||
void UpdateDiscoverObjectsOnLoadSetup(EditorSceneSetup setup) |
|||
{ |
|||
forceGlobal = false; |
|||
UpdateDiscoverObjects(); |
|||
} |
|||
|
|||
void UpdateDiscoverObjectsOnCreate(Scene scene, NewSceneSetup setup, NewSceneMode mode) |
|||
{ |
|||
forceGlobal = false; |
|||
UpdateDiscoverObjects(); |
|||
} |
|||
|
|||
void UpdateDiscoverObjectsOnLoad(Scene s, OpenSceneMode s2) |
|||
{ |
|||
forceGlobal = false; |
|||
UpdateDiscoverObjects(); |
|||
} |
|||
|
|||
void UpdateDiscoverObjects(bool clear = false) |
|||
{ |
|||
if (discoverObjects == null) |
|||
discoverObjects = new Dictionary<string, List<Discover>>(); |
|||
|
|||
if (clear) |
|||
discoverObjects.Clear(); |
|||
|
|||
Discover[] newOnes = FindObjectsOfType<Discover>(); |
|||
|
|||
// Add new ones
|
|||
foreach (var item in newOnes) |
|||
{ |
|||
if (!discoverObjects.ContainsKey(item.Category)) |
|||
{ |
|||
discoverObjects.Add(item.Category, new List<Discover>()); |
|||
} |
|||
|
|||
if (!discoverObjects[item.Category].Contains(item)) |
|||
{ |
|||
discoverObjects[item.Category].Add(item); |
|||
} |
|||
} |
|||
|
|||
// Cleanup Empty Entries
|
|||
Dictionary<string, List<Discover>> cleanedUpLists = new Dictionary<string, List<Discover>>(); |
|||
|
|||
foreach (var categoryKvp in discoverObjects) |
|||
{ |
|||
cleanedUpLists.Add(categoryKvp.Key, categoryKvp.Value.Where((o) => o != null).ToList()); |
|||
} |
|||
foreach (var categoryKvp in cleanedUpLists) |
|||
{ |
|||
discoverObjects[categoryKvp.Key] = categoryKvp.Value; |
|||
} |
|||
|
|||
// Cleanup Empty Categories
|
|||
List<string> toDelete = new List<string>(); |
|||
foreach (var categoryKvp in discoverObjects) |
|||
{ |
|||
if (categoryKvp.Value == null || categoryKvp.Value.Count == 0) |
|||
toDelete.Add(categoryKvp.Key); |
|||
} |
|||
foreach (var category in toDelete) |
|||
{ |
|||
discoverObjects.Remove(category); |
|||
} |
|||
|
|||
// Finally, sort items in each category
|
|||
foreach (var categoryKvp in discoverObjects) |
|||
{ |
|||
discoverObjects[categoryKvp.Key].Sort((a, b) => { return Comparer<int>.Default.Compare(a.Priority, b.Priority); }); |
|||
} |
|||
|
|||
// Ensure something is selected is possible
|
|||
if (selectedDiscover == null && discoverObjects != null && discoverObjects.Count > 0) |
|||
{ |
|||
selectedDiscover = discoverObjects.First().Value.First(); |
|||
} |
|||
Repaint(); |
|||
} |
|||
|
|||
private void OnGUI() |
|||
{ |
|||
// Draw Header Image
|
|||
if (discoverAsset.HeaderTexture != null) |
|||
{ |
|||
if (header == null || header != discoverAsset.HeaderTexture) |
|||
header = discoverAsset.HeaderTexture; |
|||
|
|||
Rect headerRect = GUILayoutUtility.GetRect(header.width, header.height); |
|||
GUI.DrawTexture(headerRect, header); |
|||
} |
|||
else |
|||
{ |
|||
Rect headerRect = GUILayoutUtility.GetRect(discoverAsset.WindowWidth, 80); |
|||
EditorGUI.DrawRect(headerRect, new Color(0,0,0,0.2f)); |
|||
headerRect.xMin += 16; |
|||
headerRect.yMin += 16; |
|||
GUI.Label(headerRect, discoverAsset.WindowTitle, Styles.header); |
|||
} |
|||
|
|||
bool hasContent = discoverObjects != null && discoverObjects.Count > 0; |
|||
|
|||
// Draw Navigation
|
|||
using (new GUILayout.AreaScope(new Rect(discoverAsset.WindowWidth - 168, 8, 160, 20))) |
|||
{ |
|||
using (new GUILayout.HorizontalScope(Styles.tabContainer)) |
|||
{ |
|||
bool value = forceGlobal; |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = GUILayout.Toggle(forceGlobal, "Levels", Styles.buttonLeft); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
forceGlobal = true; |
|||
} |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
value = GUILayout.Toggle(!forceGlobal, "Discover", Styles.buttonRight); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
forceGlobal = false; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
// Draw Content
|
|||
if (!hasContent || forceGlobal) |
|||
GlobalContentGUI(); |
|||
else |
|||
SceneContentGUI(); |
|||
|
|||
// Draw Footer
|
|||
Rect line = GUILayoutUtility.GetRect(discoverAsset.WindowWidth, 1); |
|||
EditorGUI.DrawRect(line, Color.black); |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
if(discoverAsset.EnableShowAtStartup) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
bool showOnStartup = GUILayout.Toggle(GetShowOnStartup(discoverAsset.PreferenceName), " Show this window on startup"); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
SetShowOnStartup(discoverAsset.PreferenceName, showOnStartup); |
|||
} |
|||
} |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
|
|||
if(discoverAsset.Debug) |
|||
{ |
|||
if (GUILayout.Button("Select DiscoverAsset")) |
|||
Selection.activeObject = discoverAsset; |
|||
|
|||
if (GUILayout.Button("Reload")) |
|||
UpdateDiscoverObjects(true); |
|||
} |
|||
|
|||
if (GUILayout.Button("Close")) |
|||
{ |
|||
Close(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void GlobalContentGUI() |
|||
{ |
|||
using (new GUILayout.VerticalScope(Styles.indent)) |
|||
{ |
|||
GUILayout.Label(discoverAsset.Title, Styles.header); |
|||
using (new GUILayout.VerticalScope(Styles.indent)) |
|||
{ |
|||
GUILayout.Label(discoverAsset.Description, Styles.body); |
|||
|
|||
if(discoverAsset.Scenes != null) |
|||
{ |
|||
foreach (var map in discoverAsset.Scenes) |
|||
{ |
|||
using (new GroupLabelScope(map.Title)) |
|||
{ |
|||
GUILayout.Label(map.Description, Styles.body); |
|||
|
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
GUILayout.FlexibleSpace(); |
|||
|
|||
if (map.SceneSetup != null && GUILayout.Button($"Open {map.SceneSetup.name}")) |
|||
{ |
|||
LoadSceneSetup(map.SceneSetup); |
|||
} |
|||
else if(map.SingleScene != null && GUILayout.Button($"Open {map.SingleScene.name}")) |
|||
{ |
|||
LoadSingleScene(map.SingleScene); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
GUILayout.FlexibleSpace(); |
|||
} |
|||
|
|||
Discover selectedDiscover; |
|||
Vector2 listScroll; |
|||
Vector2 contentScroll; |
|||
|
|||
void SceneContentGUI() |
|||
{ |
|||
using (new GUILayout.HorizontalScope()) |
|||
{ |
|||
using (new GUILayout.VerticalScope()) |
|||
{ |
|||
listScroll = GUILayout.BeginScrollView(listScroll, GUI.skin.box, GUILayout.Width(discoverAsset.DiscoverListWidth)); |
|||
using (new GUILayout.VerticalScope(GUILayout.ExpandHeight(true))) |
|||
{ |
|||
foreach (var category in discoverObjects.Keys.OrderBy((x) => x.ToString())) |
|||
{ |
|||
GUILayout.Label(category, EditorStyles.boldLabel); |
|||
|
|||
foreach (var item in discoverObjects[category]) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
bool value = GUILayout.Toggle(item == selectedDiscover, item.Name, Styles.listItem); |
|||
|
|||
if (value) |
|||
{ |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
if(discoverAsset.Debug) |
|||
Selection.activeObject = item; |
|||
|
|||
if (SceneView.lastActiveSceneView != null && item.AlignViewToTransform) |
|||
{ |
|||
SceneView.lastActiveSceneView.AlignViewToObject(item.transform); |
|||
} |
|||
} |
|||
|
|||
selectedDiscover = item; |
|||
Rect r = GUILayoutUtility.GetLastRect(); |
|||
int c = EditorGUIUtility.isProSkin ? 1 : 0; |
|||
EditorGUI.DrawRect(r, new Color(c, c, c, 0.1f)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
} |
|||
GUILayout.EndScrollView(); |
|||
} |
|||
GUILayout.Space(4); |
|||
|
|||
using (new GUILayout.VerticalScope(GUILayout.Width(440))) |
|||
{ |
|||
contentScroll = GUILayout.BeginScrollView(contentScroll); |
|||
GUILayout.Space(8); |
|||
|
|||
DiscoverEditor.DrawDiscoverContentGUI(selectedDiscover); |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
GUILayout.EndScrollView(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void LoadSceneSetup(EditorSceneSetup setup) |
|||
{ |
|||
try |
|||
{ |
|||
EditorUtility.DisplayProgressBar("Discover", $"Opening {setup.name}...", 0.9f); |
|||
forceGlobal = false; |
|||
EditorSceneSetup.RestoreSetup(setup); |
|||
} |
|||
catch |
|||
{ |
|||
Debug.LogError($"Could not load EditorSceneSetup : {setup.name}"); |
|||
} |
|||
finally |
|||
{ |
|||
EditorUtility.ClearProgressBar(); |
|||
UpdateDiscoverObjects(); |
|||
} |
|||
} |
|||
|
|||
void LoadSingleScene(SceneAsset scene) |
|||
{ |
|||
try |
|||
{ |
|||
EditorUtility.DisplayProgressBar("Discover", $"Opening {scene.name}...", 0.9f); |
|||
forceGlobal = false; |
|||
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(scene), OpenSceneMode.Single); |
|||
} |
|||
catch |
|||
{ |
|||
Debug.LogError($"Could not load Scene : {scene.name}"); |
|||
} |
|||
finally |
|||
{ |
|||
EditorUtility.ClearProgressBar(); |
|||
UpdateDiscoverObjects(); |
|||
} |
|||
} |
|||
|
|||
public class GroupLabelScope : GUILayout.VerticalScope |
|||
{ |
|||
public GroupLabelScope(string name) : base(Styles.box) |
|||
{ |
|||
if(!string.IsNullOrWhiteSpace(name)) |
|||
{ |
|||
GUIContent n = new GUIContent(name); |
|||
Rect r = GUILayoutUtility.GetRect(n, Styles.boxHeader, GUILayout.ExpandWidth(true)); |
|||
GUI.Label(r, n, Styles.boxHeader); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public static class Styles |
|||
{ |
|||
public static GUIStyle indent; |
|||
public static GUIStyle slightIndent; |
|||
|
|||
public static GUIStyle header; |
|||
public static GUIStyle subHeader; |
|||
public static GUIStyle body; |
|||
|
|||
public static GUIStyle box; |
|||
public static GUIStyle boxHeader; |
|||
|
|||
public static GUIStyle listItem; |
|||
|
|||
public static GUIStyle buttonLeft; |
|||
public static GUIStyle buttonMid; |
|||
public static GUIStyle buttonRight; |
|||
|
|||
public static GUIStyle tabContainer; |
|||
|
|||
static Styles() |
|||
{ |
|||
header = new GUIStyle(EditorStyles.wordWrappedLabel); |
|||
header.fontSize = 24; |
|||
header.padding = new RectOffset(0, 0, -4, -4); |
|||
header.richText = true; |
|||
|
|||
subHeader = new GUIStyle(EditorStyles.wordWrappedLabel); |
|||
subHeader.fontSize = 11; |
|||
subHeader.fontStyle = FontStyle.Italic; |
|||
|
|||
body = new GUIStyle(EditorStyles.wordWrappedLabel); |
|||
body.fontSize = 11; |
|||
body.richText = true; |
|||
|
|||
indent = new GUIStyle(); |
|||
indent.padding = new RectOffset(12, 12, 12, 12); |
|||
|
|||
slightIndent = new GUIStyle(); |
|||
slightIndent.padding = new RectOffset(6, 6, 0, 6); |
|||
|
|||
box = new GUIStyle(EditorStyles.helpBox); |
|||
|
|||
boxHeader = new GUIStyle(GUI.skin.box); |
|||
boxHeader.normal.textColor = GUI.skin.label.normal.textColor; |
|||
boxHeader.fixedHeight = 20; |
|||
boxHeader.fontSize = 11; |
|||
boxHeader.fontStyle = FontStyle.Bold; |
|||
boxHeader.alignment = TextAnchor.UpperLeft; |
|||
boxHeader.margin = new RectOffset(0, 0, 0, 6); |
|||
|
|||
listItem = new GUIStyle(EditorStyles.label); |
|||
listItem.padding = new RectOffset(12, 0, 2, 2); |
|||
|
|||
buttonLeft = new GUIStyle(EditorStyles.miniButtonLeft); |
|||
buttonLeft.fontSize = 11; |
|||
buttonMid = new GUIStyle(EditorStyles.miniButtonMid); |
|||
buttonMid.fontSize = 11; |
|||
buttonRight = new GUIStyle(EditorStyles.miniButtonRight); |
|||
buttonRight.fontSize = 11; |
|||
|
|||
tabContainer = new GUIStyle(EditorStyles.miniButton); |
|||
tabContainer.padding = new RectOffset(4, 4, 0, 0); |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6206e16563e844a4f897a8cc92efc86a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class Discover : MonoBehaviour |
|||
{ |
|||
public string Name = "Discover"; |
|||
public string Category = "Category"; |
|||
public bool AlignViewToTransform = false; |
|||
[Multiline] |
|||
public string Description = "Some Description of the Component\n\nCan be set as multiple lines."; |
|||
public int Priority = 0; |
|||
public DiscoverSection[] Sections; |
|||
|
|||
#if UNITY_EDITOR
|
|||
[UnityEditor.MenuItem("GameObject/GameplayIngredients/Discover", priority=10)] |
|||
static void CreateObject() |
|||
{ |
|||
GameObject selected = UnityEditor.Selection.activeGameObject; |
|||
|
|||
var go = new GameObject("Discover"); |
|||
if (selected != null) |
|||
{ |
|||
go.transform.parent = selected.transform; |
|||
go.transform.position = selected.transform.position; |
|||
} |
|||
go.AddComponent<Discover>(); |
|||
UnityEditor.Selection.activeGameObject = go; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
[System.Serializable] |
|||
public struct DiscoverSection |
|||
{ |
|||
public string SectionName; |
|||
[Multiline] |
|||
public string SectionContent; |
|||
public SectionAction[] Actions; |
|||
} |
|||
|
|||
[System.Serializable] |
|||
public struct SectionAction |
|||
{ |
|||
public string Description; |
|||
public Object Target; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a952ff0a6afde7c4b95d55801086887e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue