浏览代码

Base work with buttons

/refactor-2021-2-sceneview-toolbar
Thomas ICHÉ 3 年前
当前提交
e061afd3
共有 13 个文件被更改,包括 1625 次插入6 次删除
  1. 2
      Editor/CheckWindow/CheckWindow.cs
  2. 200
      Editor/SceneViewToolbar.cs
  3. 8
      Icons/SceneViewToolbar.meta
  4. 1001
      GFX~/Icons/PlayFromHere.afphoto
  5. 6
      Icons/SceneViewToolbar/POV.png
  6. 110
      Icons/SceneViewToolbar/POV.png.meta
  7. 40
      Icons/SceneViewToolbar/PlayFromHere.png
  8. 110
      Icons/SceneViewToolbar/PlayFromHere.png.meta
  9. 44
      Icons/SceneViewToolbar/PlayFromHere_Stop.png
  10. 110
      Icons/SceneViewToolbar/PlayFromHere_Stop.png.meta

2
Editor/CheckWindow/CheckWindow.cs


public class CheckWindow : EditorWindow
{
[MenuItem("Window/Gameplay Ingredients/Check and Resolve", priority = MenuItems.kWindowMenuPriority+30)]
static void OpenWindow()
public static void OpenWindow()
{
GetWindow<CheckWindow>(false);
}

200
Editor/SceneViewToolbar.cs


using System;
using GameplayIngredients.Comments.Editor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using UnityEngine.UIElements;
namespace GameplayIngredients.Editor

#if UNITY_2021_2_OR_NEWER
[Overlay(typeof(SceneView), "Toolbar", true)]
public class IngredientsToolbarOverlay : Overlay
[Overlay(typeof(SceneView), "Gameplay Ingredients", true)]
public class IngredientsToolbarOverlay : ToolbarOverlay
public override VisualElement CreatePanelContent()
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
return new Label("Toto");
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()
{
icon = Contents.linkGameView;
tooltip = "Link Game View";
dropdownClicked += OnClick;
buttons.Add(this);
}
~LinkGameViewButton()
{
if (LinkGameView.LockedSceneView == containerWindow as SceneView)
{
LinkGameView.LockedSceneView = null;
LinkGameView.Active = false;
}
buttons.Remove(this);
}
public void OnClick()
{
}
void OnValueChanged(bool newValue)
{
LinkGameView.Active = newValue;
if (newValue)
LinkGameView.LockedSceneView = containerWindow as SceneView;
else
LinkGameView.LockedSceneView = null;
foreach(var button in buttons)
{
if(button.containerWindow != containerWindow)
{
button.SetValueWithoutNotify(false);
}
}
}
}
#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 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/GUI/Camera16x16.png") as Texture2D;
checkWindow = EditorGUIUtility.IconContent("Valid").image as Texture2D;
commentsWindow = EditorGUIUtility.IconContent("console.infoicon.inactive.sml").image as Texture2D;
}
}
}
#else
public delegate void SceneViewToolbarDelegate(SceneView sceneView);

8
Icons/SceneViewToolbar.meta


fileFormatVersion: 2
guid: 9c9d7cadb27f8af41a443a44648f71e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
GFX~/Icons/PlayFromHere.afphoto
文件差异内容过多而无法显示
查看文件

6
Icons/SceneViewToolbar/POV.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 469 B

110
Icons/SceneViewToolbar/POV.png.meta


fileFormatVersion: 2
guid: fab6d20367ea0aa4d8eb22f3115dd962
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

40
Icons/SceneViewToolbar/PlayFromHere.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 2.2 KiB

110
Icons/SceneViewToolbar/PlayFromHere.png.meta


fileFormatVersion: 2
guid: d2301fdb9aab0ca41ba71f099e43d433
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

44
Icons/SceneViewToolbar/PlayFromHere_Stop.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 2.2 KiB

110
Icons/SceneViewToolbar/PlayFromHere_Stop.png.meta


fileFormatVersion: 2
guid: 5952df0bad81f994baa6965addbf0d4d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存