浏览代码

Added New toolbar code as Partial in a separate file

/refactor-2021-2-sceneview-toolbar
Thomas ICHÉ 4 年前
当前提交
cdac4847
共有 3 个文件被更改,包括 301 次插入239 次删除
  1. 241
      Editor/SceneViewToolbar/SceneViewToolbar.cs
  2. 288
      Editor/SceneViewToolbar/SceneViewToolbar.Overlays.cs
  3. 11
      Editor/SceneViewToolbar/SceneViewToolbar.Overlays.cs.meta

241
Editor/SceneViewToolbar/SceneViewToolbar.cs


namespace GameplayIngredients.Editor
{
public static class SceneViewToolbar
public static partial class SceneViewToolbar
#if UNITY_2021_2_OR_NEWER
[Overlay(typeof(SceneView), "Gameplay Ingredients", true)]
public class IngredientsToolbarOverlay : ToolbarOverlay
{
const string prefix = "IngredientsToolbarOverlay.";
public IngredientsToolbarOverlay() : base(PlayFromHereButton.id, LinkGameViewButton.id, PointOfViewButton.id, CommentsButton.id, CheckResolveButton.id) { }
protected override Layout supportedLayouts => Layout.HorizontalToolbar | Layout.VerticalToolbar;
#region PLAY FROM HERE
[EditorToolbarElement(id)]
public class PlayFromHereButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "PlayFromHereButton";
public EditorWindow containerWindow { get; set; }
public PlayFromHereButton() : base()
{
this.SetEnabled(PlayFromHere.IsReady);
icon = EditorApplication.isPlaying ? Contents.playFromHere_Stop : Contents.playFromHere;
tooltip = "Play from Here";
clicked += OnClick;
EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged;
}
private void EditorApplication_playModeStateChanged(PlayModeStateChange obj)
{
if (obj == PlayModeStateChange.EnteredPlayMode)
icon = Contents.playFromHere_Stop;
else if (obj == PlayModeStateChange.EnteredEditMode)
icon = Contents.playFromHere;
}
public void OnClick()
{
if (!EditorApplication.isPlaying)
PlayFromHere.Play(containerWindow as SceneView);
else
EditorApplication.isPlaying = false;
}
}
#endregion
#region LINK GAME VIEW
[EditorToolbarElement(id)]
public class LinkGameViewButton : EditorToolbarDropdownToggle, IAccessContainerWindow
{
public override bool value {
get => base.value;
set
{
base.value = value;
OnValueChanged(value);
}
}
public const string id = prefix + "LinkGameViewButton";
public EditorWindow containerWindow { get; set; }
static List<LinkGameViewButton> buttons = new List<LinkGameViewButton>();
public LinkGameViewButton()
{
tooltip = "Link Game View";
dropdownClicked += OnClick;
SetValueWithoutNotify(LinkGameView.Active && LinkGameView.LockedSceneView == containerWindow as SceneView);
buttons.Add(this);
UpdateIcon();
}
~LinkGameViewButton()
{
if (LinkGameView.LockedSceneView == containerWindow as SceneView)
{
LinkGameView.LockedSceneView = null;
LinkGameView.Active = false;
}
buttons.Remove(this);
}
public void UpdateIcon()
{
if(LinkGameView.CinemachineActive)
icon = Contents.linkGameViewCM;
else
{
icon = (LinkGameView.Active && LinkGameView.LockedSceneView == containerWindow as SceneView) ? Contents.linkGameViewActive : Contents.linkGameView;
}
}
public void OnClick()
{
var m = new GenericMenu();
m.AddItem(new GUIContent("Link Camera"), LinkGameView.LockedSceneView == containerWindow as SceneView,
() => {
LinkGameView.CinemachineActive = false;
value = true;
UpdateIcon();
});
m.AddItem(new GUIContent("Cinemachine Preview"), LinkGameView.CinemachineActive,
() => {
LinkGameView.CinemachineActive = true;
value = true;
UpdateIcon();
});
m.DropDown(worldBound);
}
void OnValueChanged(bool newValue)
{
LinkGameView.Active = newValue;
if(LinkGameView.CinemachineActive && newValue == false)
LinkGameView.CinemachineActive = false;
else if(newValue && !LinkGameView.CinemachineActive)
LinkGameView.LockedSceneView = containerWindow as SceneView;
else
LinkGameView.LockedSceneView = null;
UpdateIcon();
foreach (var button in buttons)
{
if(LinkGameView.CinemachineActive)
{
button.SetValueWithoutNotify(true);
}
else if(button.containerWindow != containerWindow)
{
button.SetValueWithoutNotify(false);
}
button.UpdateIcon();
}
}
}
#endregion
#region POINT OF VIEW
[EditorToolbarElement(id)]
public class PointOfViewButton : EditorToolbarDropdown, IAccessContainerWindow
{
public const string id = prefix + "PointOfViewButton";
public EditorWindow containerWindow { get; set; }
public PointOfViewButton()
{
icon = Contents.pointOfView;
tooltip = "Point of View";
clicked += OnClick;
}
public void OnClick()
{
}
}
#endregion
#region COMMENTS
[EditorToolbarElement(id)]
public class CommentsButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "CommentsButton";
public EditorWindow containerWindow { get; set; }
public CommentsButton()
{
icon = Contents.commentsWindow;
tooltip = "Open Comments Window";
clicked += OnClick;
}
public void OnClick()
{
CommentsWindow.Open();
}
}
#endregion
#region CHECK/RESOLVE
[EditorToolbarElement(id)]
public class CheckResolveButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "CheckResolveButton";
public EditorWindow containerWindow { get; set; }
public CheckResolveButton()
{
icon = Contents.checkWindow;
tooltip = "Open Check/Resolve Window";
clicked += OnClick;
}
public void OnClick()
{
CheckWindow.OpenWindow();
}
}
#endregion
static class Contents
{
public static Texture2D playFromHere;
public static Texture2D playFromHere_Stop;
public static Texture2D pointOfView;
public static Texture2D linkGameView;
public static Texture2D linkGameViewActive;
public static Texture2D linkGameViewCM;
public static Texture2D checkWindow;
public static Texture2D commentsWindow;
static Contents()
{
playFromHere = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/PlayFromHere.png") as Texture2D;
playFromHere_Stop = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/PlayFromHere_Stop.png") as Texture2D;
pointOfView = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/POV.png") as Texture2D;
linkGameView = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/Camera.png") as Texture2D;
linkGameViewActive = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CameraActive.png") as Texture2D;
linkGameViewCM = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CameraCM.png") as Texture2D;
checkWindow = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CheckResolve.png") as Texture2D;
commentsWindow = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/Comments.png") as Texture2D;
}
}
}
#else
#if !UNITY_2021_2_OR_NEWER
public delegate void SceneViewToolbarDelegate(SceneView sceneView);
public static event SceneViewToolbarDelegate OnSceneViewToolbarGUI;

288
Editor/SceneViewToolbar/SceneViewToolbar.Overlays.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using GameplayIngredients.Comments.Editor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using UnityEngine.UIElements;
namespace GameplayIngredients.Editor
{
public static partial class SceneViewToolbar
{
#if UNITY_2021_2_OR_NEWER
[Overlay(typeof(SceneView), "Gameplay Ingredients", true)]
public class IngredientsToolbarOverlay : ToolbarOverlay
{
const string prefix = "IngredientsToolbarOverlay.";
public IngredientsToolbarOverlay() : base(
PlayFromHereButton.id,
LinkGameViewButton.id,
PointOfViewButton.id,
CommentsButton.id,
CheckResolveButton.id,
IngredientExplorerButton.id
) { }
protected override Layout supportedLayouts => Layout.HorizontalToolbar | Layout.VerticalToolbar;
#region PLAY FROM HERE
[EditorToolbarElement(id)]
public class PlayFromHereButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "PlayFromHereButton";
public EditorWindow containerWindow { get; set; }
public PlayFromHereButton() : base()
{
this.SetEnabled(PlayFromHere.IsReady);
icon = EditorApplication.isPlaying ? Contents.playFromHere_Stop : Contents.playFromHere;
tooltip = "Play from Here";
clicked += OnClick;
EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged;
}
private void EditorApplication_playModeStateChanged(PlayModeStateChange obj)
{
if (obj == PlayModeStateChange.EnteredPlayMode)
icon = Contents.playFromHere_Stop;
else if (obj == PlayModeStateChange.EnteredEditMode)
icon = Contents.playFromHere;
}
public void OnClick()
{
if (!EditorApplication.isPlaying)
PlayFromHere.Play(containerWindow as SceneView);
else
EditorApplication.isPlaying = false;
}
}
#endregion
#region LINK GAME VIEW
[EditorToolbarElement(id)]
public class LinkGameViewButton : EditorToolbarDropdownToggle, IAccessContainerWindow
{
public override bool value
{
get => base.value;
set
{
base.value = value;
OnValueChanged(value);
}
}
public const string id = prefix + "LinkGameViewButton";
public EditorWindow containerWindow { get; set; }
static List<LinkGameViewButton> buttons = new List<LinkGameViewButton>();
public LinkGameViewButton()
{
tooltip = "Link Game View";
dropdownClicked += OnClick;
SetValueWithoutNotify(LinkGameView.Active && LinkGameView.LockedSceneView == containerWindow as SceneView);
buttons.Add(this);
UpdateIcon();
}
~LinkGameViewButton()
{
if (LinkGameView.LockedSceneView == containerWindow as SceneView)
{
LinkGameView.LockedSceneView = null;
LinkGameView.Active = false;
}
buttons.Remove(this);
}
public void UpdateIcon()
{
if (LinkGameView.CinemachineActive)
icon = Contents.linkGameViewCM;
else
{
icon = (LinkGameView.Active && LinkGameView.LockedSceneView == containerWindow as SceneView) ? Contents.linkGameViewActive : Contents.linkGameView;
}
}
public void OnClick()
{
var m = new GenericMenu();
m.AddItem(new GUIContent("Link Camera"), LinkGameView.LockedSceneView == containerWindow as SceneView,
() => {
LinkGameView.CinemachineActive = false;
value = true;
UpdateIcon();
});
m.AddItem(new GUIContent("Cinemachine Preview"), LinkGameView.CinemachineActive,
() => {
LinkGameView.CinemachineActive = true;
value = true;
UpdateIcon();
});
m.DropDown(worldBound);
}
void OnValueChanged(bool newValue)
{
LinkGameView.Active = newValue;
if (LinkGameView.CinemachineActive && newValue == false)
LinkGameView.CinemachineActive = false;
else if (newValue && !LinkGameView.CinemachineActive)
LinkGameView.LockedSceneView = containerWindow as SceneView;
else
LinkGameView.LockedSceneView = null;
UpdateIcon();
foreach (var button in buttons)
{
if (LinkGameView.CinemachineActive)
{
button.SetValueWithoutNotify(true);
}
else if (button.containerWindow != containerWindow)
{
button.SetValueWithoutNotify(false);
}
button.UpdateIcon();
}
}
}
#endregion
#region POINT OF VIEW
[EditorToolbarElement(id)]
public class PointOfViewButton : EditorToolbarDropdown, IAccessContainerWindow
{
public const string id = prefix + "PointOfViewButton";
public EditorWindow containerWindow { get; set; }
public PointOfViewButton()
{
icon = Contents.pointOfView;
tooltip = "Point of View";
clicked += OnClick;
}
public void OnClick()
{
SceneViewPOV.ShowPopup(worldBound, containerWindow as SceneView);
}
}
#endregion
#region COMMENTS
[EditorToolbarElement(id)]
public class CommentsButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "CommentsButton";
public EditorWindow containerWindow { get; set; }
public CommentsButton()
{
icon = Contents.commentsWindow;
tooltip = "Open Comments Window";
clicked += OnClick;
}
public void OnClick()
{
CommentsWindow.Open();
}
}
#endregion
#region CHECK/RESOLVE
[EditorToolbarElement(id)]
public class CheckResolveButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "CheckResolveButton";
public EditorWindow containerWindow { get; set; }
public CheckResolveButton()
{
icon = Contents.checkWindow;
tooltip = "Open Check/Resolve Window";
clicked += OnClick;
}
public void OnClick()
{
CheckWindow.OpenWindow();
}
}
#endregion
#region INGREDIENT EXPLORER
[EditorToolbarElement(id)]
public class IngredientExplorerButton : EditorToolbarButton, IAccessContainerWindow
{
public const string id = prefix + "IngredientExplorerButton";
public EditorWindow containerWindow { get; set; }
public IngredientExplorerButton()
{
icon = Contents.ingredientsExplorer;
tooltip = "Open Ingredients Explorer";
clicked += OnClick;
}
public void OnClick()
{
IngredientsExplorerWindow.OpenWindow();
}
}
#endregion
static class Contents
{
public static Texture2D playFromHere;
public static Texture2D playFromHere_Stop;
public static Texture2D pointOfView;
public static Texture2D linkGameView;
public static Texture2D linkGameViewActive;
public static Texture2D linkGameViewCM;
public static Texture2D checkWindow;
public static Texture2D commentsWindow;
public static Texture2D ingredientsExplorer;
static Contents()
{
playFromHere = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/PlayFromHere.png") as Texture2D;
playFromHere_Stop = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/PlayFromHere_Stop.png") as Texture2D;
pointOfView = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/POV.png") as Texture2D;
linkGameView = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/Camera.png") as Texture2D;
linkGameViewActive = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CameraActive.png") as Texture2D;
linkGameViewCM = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CameraCM.png") as Texture2D;
checkWindow = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/CheckResolve.png") as Texture2D;
commentsWindow = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/SceneViewToolbar/Comments.png") as Texture2D;
ingredientsExplorer = EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/Misc/ic-callable.png") as Texture2D;
}
}
}
#endif
}
}

11
Editor/SceneViewToolbar/SceneViewToolbar.Overlays.cs.meta


fileFormatVersion: 2
guid: c55c9d2a68d570945b9dccea2290b061
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存