浏览代码

Scene View Toolbar Preferences (#38)

* Scene View Toolbar Preferences

* Handle Correct disable of features upon visibility change.
/main
GitHub 4 年前
当前提交
d7cc2b12
共有 2 个文件被更改,包括 180 次插入63 次删除
  1. 1
      CHANGELOG.md
  2. 242
      Editor/SceneViewToolbar.cs

1
CHANGELOG.md


* Added abstract `PingableEditor` class for MonoBehaviours that can be Pinged to stand out in the inspector.
* Added Help items in Menu, Added HelpURL class attributes
* Feature: Scene Comments
* Added preferences to control visibility of buttons in Additional Scene View Toolbar
## 2020.2.2

242
Editor/SceneViewToolbar.cs


private static void OnSceneGUI(SceneView sceneView)
{
if (!Preferences.showToolbar)
return;
var r = new Rect(Vector2.zero, new Vector2(sceneView.position.width,24));
Handles.BeginGUI();
using (new GUILayout.AreaScope(r))

if(PlayFromHere.IsReady)
if(Preferences.showPlayFromHere)
bool play = GUILayout.Toggle(EditorApplication.isPlaying, Contents.playFromHere, EditorStyles.toolbarButton);
using(new EditorGUI.DisabledGroupScope(!PlayFromHere.IsReady))
{
bool play = GUILayout.Toggle(EditorApplication.isPlaying, Contents.playFromHere, EditorStyles.toolbarButton);
if (GUI.changed)
{
if (play)
PlayFromHere.Play(sceneView);
else
EditorApplication.isPlaying = false;
}
if(GUI.changed)
{
if (play)
PlayFromHere.Play(sceneView);
else
EditorApplication.isPlaying = false;
Color backup = GUI.color;
if(Preferences.showLinkGameView)
{
bool isLinked = LinkGameView.Active;
bool isLocked = LinkGameView.LockedSceneView == sceneView;
Color backup = GUI.color;
bool isLinked = LinkGameView.Active;
bool isLocked = LinkGameView.LockedSceneView == sceneView;
if(isLinked && isLocked)
{
GUI.color = Styles.lockedLinkColor * 2;
}
else if (isLinked && LinkGameView.CinemachineActive)
{
GUI.color = Styles.cineColor * 2;
}
isLinked = GUILayout.Toggle(isLinked, LinkGameView.CinemachineActive? Contents.linkGameViewCinemachine: Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));
if (GUI.changed)
{
if(Event.current.shift)
if (isLinked && isLocked)
if (!LinkGameView.Active)
LinkGameView.Active = true;
LinkGameView.CinemachineActive = !LinkGameView.CinemachineActive;
GUI.color = Styles.lockedLinkColor * 2;
else
else if (isLinked && LinkGameView.CinemachineActive)
LinkGameView.Active = isLinked;
LinkGameView.CinemachineActive = false;
GUI.color = Styles.cineColor * 2;
}
isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);
isLinked = GUILayout.Toggle(isLinked, LinkGameView.CinemachineActive ? Contents.linkGameViewCinemachine : Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));
if (GUI.changed)
{
if (isLocked)
if (GUI.changed)
LinkGameView.CinemachineActive = false;
LinkGameView.LockedSceneView = sceneView;
if (Event.current.shift)
{
if (!LinkGameView.Active)
LinkGameView.Active = true;
LinkGameView.CinemachineActive = !LinkGameView.CinemachineActive;
}
else
{
LinkGameView.Active = isLinked;
LinkGameView.CinemachineActive = false;
}
else
isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);
if (GUI.changed)
LinkGameView.LockedSceneView = null;
if (isLocked)
{
LinkGameView.CinemachineActive = false;
LinkGameView.LockedSceneView = sceneView;
}
else
{
LinkGameView.LockedSceneView = null;
}
}
GUI.color = backup;
GUI.color = backup;
GUILayout.Space(16);
}
// SceneViewPOV
GUILayout.Space(16);
if(GUILayout.Button("POV", EditorStyles.toolbarDropDown))
if(Preferences.showPOV)
Rect btnrect = GUILayoutUtility.GetLastRect();
btnrect.yMax += 17;
SceneViewPOV.ShowPopup(btnrect, sceneView);
if (GUILayout.Button("POV", EditorStyles.toolbarDropDown))
{
Rect btnrect = GUILayoutUtility.GetLastRect();
btnrect.yMax += 17;
SceneViewPOV.ShowPopup(btnrect, sceneView);
}
GUILayout.Space(16);
// Check Window
GUILayout.Space(16);
if (GUILayout.Button(Contents.checkWindow, EditorStyles.toolbarButton))
if(Preferences.showCheck)
EditorWindow.GetWindow<CheckWindow>();
if (GUILayout.Button(Contents.checkWindow, EditorStyles.toolbarButton))
{
EditorWindow.GetWindow<CheckWindow>();
}
GUILayout.Space(16);
// Comments Window
GUILayout.Space(16);
if (GUILayout.Button(Contents.commentsWindow, EditorStyles.toolbarButton))
if(Preferences.showComments)
CommentsWindow.Open();
if (GUILayout.Button(Contents.commentsWindow, EditorStyles.toolbarButton))
{
CommentsWindow.Open();
}
if (GUILayout.Button(Contents.addComment, EditorStyles.toolbarButton))
{
SceneCommentEditor.CreateComment();
}
if (GUILayout.Button(Contents.addComment, EditorStyles.toolbarButton))
if(Preferences.showCustom)
SceneCommentEditor.CreateComment();
// Custom Callback here
if (OnSceneViewToolbarGUI != null)
OnSceneViewToolbarGUI.Invoke(sceneView);
// Custom Code here
if (OnSceneViewToolbarGUI != null)
OnSceneViewToolbarGUI.Invoke(sceneView);
GUILayout.FlexibleSpace();
// Saving Space not to overlap view controls

GUI.color = color;
GUI.Label(r, text);
GUI.color = Color.white;
}
static class Preferences
{
// Public Getters
public static bool showToolbar => Get(kShowToolbar);
public static bool showPlayFromHere => Get(kShowPlayFromHere);
public static bool showLinkGameView => Get(kShowLinkGameView);
public static bool showPOV => Get(kShowPOV);
public static bool showCheck => Get(kShowCheck);
public static bool showComments => Get(kShowComments);
public static bool showCustom => Get(kShowCustom);
const string kShowToolbar = "showToolbar";
const string kShowPlayFromHere = "showPlayFromHere";
const string kShowLinkGameView = "showLinkGameView";
const string kShowPOV = "showPOV";
const string kShowCheck = "showCheck";
const string kShowComments = "showComments";
const string kShowCustom = "showCustom";
const string kPrefPrefix = "GameplayIngredients.SceneViewToolbar";
static readonly Dictionary<string, bool> defaults = new Dictionary<string, bool>
{
{ kShowToolbar , true },
{ kShowPlayFromHere , true },
{ kShowLinkGameView , true },
{ kShowPOV , true },
{ kShowCheck , true },
{ kShowComments , true },
{ kShowCustom , true },
};
static bool Default(string name)
{
if (defaults.ContainsKey(name))
return defaults[name];
else
return false;
}
static bool Get(string name)
{
return EditorPrefs.GetBool($"{kPrefPrefix}.{name}", Default(name));
}
static void Set(string name, bool value)
{
EditorPrefs.SetBool($"{kPrefPrefix}.{name}", value);
}
[SettingsProvider]
public static SettingsProvider GetPreferences()
{
static void OnToggleAll(bool toggle)
{
OnToggleLinkGameView(toggle);
}
static void OnToggleLinkGameView(bool toggle)
{
if (!toggle)
LinkGameView.Active = false;
}
static void PreferenceItem(string label, string name, Action<bool> onToggle = null)
{
EditorGUI.BeginChangeCheck();
bool val = EditorGUILayout.Toggle(label, Get(name));
if (EditorGUI.EndChangeCheck())
{
Set(name, val);
onToggle?.Invoke(val);
SceneView.RepaintAll();
}
};
return new SettingsProvider("Preferences/Gameplay Ingredients/Scene View", SettingsScope.User)
{
label = "Scene View",
guiHandler = (searchContext) =>
{
PreferenceItem("Show Toolbar", "showToolbar", OnToggleAll);
using (new EditorGUI.IndentLevelScope(1))
{
PreferenceItem("Play From Here", kShowPlayFromHere);
PreferenceItem("Link Game View", kShowLinkGameView, OnToggleLinkGameView);
PreferenceItem("Point of View", kShowPOV);
PreferenceItem("Check Window", kShowCheck);
PreferenceItem("Comments Window", kShowComments);
PreferenceItem("Custom Toolbar Items", kShowCustom);
}
}
};
}
}
static class Contents

正在加载...
取消
保存