浏览代码

Fixes for DiscoverWindow

/main
Thomas ICHÉ 5 年前
当前提交
e89d79d4
共有 3 个文件被更改,包括 128 次插入66 次删除
  1. 26
      Editor/Discover/DiscoverEditor.cs
  2. 167
      Editor/Discover/DiscoverWindow.cs
  3. 1
      Runtime/Discover/Discover.cs

26
Editor/Discover/DiscoverEditor.cs


DrawDiscoverContentGUI(m_Discover);
}
if(!string.IsNullOrEmpty(discover.Category))
GUILayout.Label(discover.Category, DiscoverWindow.Styles.subHeader);
GUILayout.Label(discover.Category, DiscoverWindow.Styles.subHeader);
GUILayout.Label(discover.Name, DiscoverWindow.Styles.header);
using (new GUILayout.VerticalScope(DiscoverWindow.Styles.indent))

{
GUILayout.Label(action.Description);
GUILayout.FlexibleSpace();
using (new GUILayout.HorizontalScope(GUILayout.MinWidth(160)))
using (new GUILayout.HorizontalScope(GUILayout.MinWidth(160), GUILayout.Height(22)))
{
ActionButtonGUI(action.Target);
}

static void ActionButtonGUI(UnityEngine.Object target)
{
if (target == null)
{
EditorGUI.BeginDisabledGroup(true);
GUILayout.Button("(No Object)");
EditorGUI.EndDisabledGroup();
return;
}
Type t = target.GetType();
if (t == typeof(GameObject))

AssetDatabase.OpenAsset(go);
}
}
}
else if (t == typeof(Discover))
{
if (GUILayout.Button("Discover"))
{
var discover = target as Discover;
Selection.activeGameObject = discover.gameObject;
DiscoverWindow.SelectDiscover(discover);
}
}
else if (t == typeof(VisualEffectAsset))
{

167
Editor/Discover/DiscoverWindow.cs


if (value != GetShowOnStartup(name)) EditorPrefs.SetBool($"{name}.ShowAtStartup", value);
}
public static void SelectDiscover(Discover discover)
{
foreach(var window in s_Windows)
{
foreach(var categoryKvp in window.discoverObjects)
{
if (categoryKvp.Value.Contains(discover))
{
window.SetSelectedDiscover(discover);
break;
}
}
}
}
public static void Reload()
{
EditorApplication.update -= ShowAtStartup;

static void InitShowAtStartup()
{
string[] guids = AssetDatabase.FindAssets("t:DiscoverAsset");
foreach(var guid in guids)
foreach (var guid in guids)
if(asset.EnableShowAtStartup)
if (asset.EnableShowAtStartup)
{
if (s_StartupDiscoverAssets == null)
s_StartupDiscoverAssets = new List<DiscoverAsset>();

}
if(s_StartupDiscoverAssets != null && s_StartupDiscoverAssets.Count > 0)
if (s_StartupDiscoverAssets != null && s_StartupDiscoverAssets.Count > 0)
EditorApplication.update += ShowAtStartup;
}

{
foreach(var discoverAsset in s_StartupDiscoverAssets)
foreach (var discoverAsset in s_StartupDiscoverAssets)
if(GetShowOnStartup(discoverAsset.PreferenceName))
if (GetShowOnStartup(discoverAsset.PreferenceName))
ShowDiscoverWindow(discoverAsset);
}
}

static List<DiscoverWindow> s_Windows;
if(discoverAsset != null)
if (discoverAsset != null)
{
var window = GetWindow<DiscoverWindow>(true);
window.SetDiscoverAsset(discoverAsset);

}
}
public DiscoverAsset discoverAsset { get; private set; }
DiscoverAsset discoverAsset;
bool forceGlobal;
void SetDiscoverAsset(DiscoverAsset discover)

EditorSceneManager.newSceneCreated += UpdateDiscoverObjectsOnCreate;
EditorSceneManager.sceneOpened += UpdateDiscoverObjectsOnLoad;
EditorSceneSetup.onSetupLoaded += UpdateDiscoverObjectsOnLoadSetup;
if (s_Windows == null)
s_Windows = new List<DiscoverWindow>();
if(!s_Windows.Contains(this))
s_Windows.Add(this);
}
private void OnDisable()

EditorSceneSetup.onSetupLoaded -= UpdateDiscoverObjectsOnLoadSetup;
if (s_Windows.Contains(this))
s_Windows.Remove(this);
}
Dictionary<string, List<Discover>> discoverObjects = null;

}
// Ensure something is selected is possible
if (selectedDiscover == null) // Try Fetching a default
{
foreach (var categoryKvp in discoverObjects)
{
selectedDiscover = categoryKvp.Value.FirstOrDefault(o => o.DefaultSelected == true);
if (selectedDiscover != null)
break;
}
}
Repaint();
}

{
foreach (var category in discoverObjects.Keys.OrderBy((x) => x.ToString()))
{
GUILayout.Label(category, EditorStyles.boldLabel);
if(!string.IsNullOrEmpty(category))
GUILayout.Label(category, EditorStyles.boldLabel);
foreach (var item in discoverObjects[category])
{

if (discoverAsset.Debug)
Selection.activeObject = item;
if (SceneView.lastActiveSceneView != null && item.AlignViewToTransform)
{
SceneView.lastActiveSceneView.AlignViewToObject(item.transform);
}
}
if (selectedDiscover.ObjectsToToggle != null)
{
// Reverse Toggle previous GameObjects state
foreach (var go in selectedDiscover.ObjectsToToggle)
{
if (go.GameObject == null)
continue;
switch (go.State)
{
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Disable:
go.GameObject.SetActive(true);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Enable:
go.GameObject.SetActive(false);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Toggle:
go.GameObject.SetActive(go.GameObject.activeSelf);
break;
}
}
}
// Set the new item
selectedDiscover = item;
if (selectedDiscover.ObjectsToToggle != null)
{
// Toggle Next GameObjects State
foreach (var go in selectedDiscover.ObjectsToToggle)
{
if (go.GameObject == null)
continue;
switch (go.State)
{
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Disable:
go.GameObject.SetActive(false);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Enable:
go.GameObject.SetActive(true);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Toggle:
go.GameObject.SetActive(go.GameObject.activeSelf);
break;
}
}
SetSelectedDiscover(item);
}
}

GUILayout.EndScrollView();
}
}
}
void SetSelectedDiscover(Discover newSelection)
{
if (SceneView.lastActiveSceneView != null && newSelection.AlignViewToTransform)
{
SceneView.lastActiveSceneView.AlignViewToObject(newSelection.transform);
}
if (selectedDiscover.ObjectsToToggle != null)
{
// Reverse Toggle previous GameObjects state
foreach (var go in selectedDiscover.ObjectsToToggle)
{
if (go.GameObject == null)
continue;
switch (go.State)
{
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Disable:
go.GameObject.SetActive(true);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Enable:
go.GameObject.SetActive(false);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Toggle:
go.GameObject.SetActive(go.GameObject.activeSelf);
break;
}
}
}
// Set the new item
selectedDiscover = newSelection;
if (selectedDiscover.ObjectsToToggle != null)
{
// Toggle Next GameObjects State
foreach (var go in selectedDiscover.ObjectsToToggle)
{
if (go.GameObject == null)
continue;
switch (go.State)
{
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Disable:
go.GameObject.SetActive(false);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Enable:
go.GameObject.SetActive(true);
break;
case Actions.ToggleGameObjectAction.GameObjectToggle.GameObjectToggleState.Toggle:
go.GameObject.SetActive(go.GameObject.activeSelf);
break;
}
}
}
contentScroll = Vector2.zero;
}
void LoadSceneSetup(EditorSceneSetup setup)

1
Runtime/Discover/Discover.cs


{
public string Name = "Discover";
public string Category = "Category";
public bool DefaultSelected = false;
public bool AlignViewToTransform = false;
public GameObjectToggle[] ObjectsToToggle;

正在加载...
取消
保存