Thomas ICHÉ
6 年前
当前提交
9508871d
共有 20 个文件被更改,包括 940 次插入 和 203 次删除
-
7com.unity.vfx-toolbox/Workbench/Editor/Tools/FlowMapPainter.cs
-
9com.unity.vfx-toolbox/Workbench/Editor/Tools/NoiseGenerator.cs
-
7com.unity.vfx-toolbox/Workbench/Editor/Tools/ProgressionMapGenerator.cs
-
138com.unity.vfx-toolbox/Workbench/Editor/Workbench.cs
-
2com.unity.vfx-toolbox/Workbench/Editor/WorkbenchBehaviourFactory.cs
-
2com.unity.vfx-toolbox/Workbench/Editor/WorkbenchInspector.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchToolBase.cs
-
8com.unity.vfx-toolbox/ImageSequencer/Editor/Public.meta
-
8com.unity.vfx-toolbox/Workbench/Editor/Canvas.meta
-
8com.unity.vfx-toolbox/Workbench/Editor/Canvas/Shaders.meta
-
69com.unity.vfx-toolbox/Workbench/Editor/Canvas/Shaders/WorkbenchImageCanvas.shader
-
9com.unity.vfx-toolbox/Workbench/Editor/Canvas/Shaders/WorkbenchImageCanvas.shader.meta
-
26com.unity.vfx-toolbox/Workbench/Editor/Canvas/WorkbenchCanvasBase.cs
-
11com.unity.vfx-toolbox/Workbench/Editor/Canvas/WorkbenchCanvasBase.cs.meta
-
747com.unity.vfx-toolbox/Workbench/Editor/Canvas/WorkbenchImageCanvas.cs
-
11com.unity.vfx-toolbox/Workbench/Editor/Canvas/WorkbenchImageCanvas.cs.meta
-
57com.unity.vfx-toolbox/Workbench/Editor/WorkbenchImageCanvas.cs
-
12com.unity.vfx-toolbox/Workbench/Editor/WorkbenchImageCanvas.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 587f081463041004ca4b2a3454fe1840 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7256165afe6f7f34e8e3fb7d1eaa63a7 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b7bc216727c26b943b6d5d6e7943ed7d |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/VFXToolbox/Workbench/WorkbenchImageCanvas" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", 2D) = "white" {} |
|||
_RGBAMask("RGBAMask", Color) = (1.0,1.0,1.0,1.0) |
|||
_MipMap("MipMap", float) = 0.0 |
|||
} |
|||
SubShader |
|||
{ |
|||
// No culling or depth |
|||
Cull Off ZWrite Off ZTest Always |
|||
|
|||
Pass |
|||
{ |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
float4 vertex : SV_POSITION; |
|||
}; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.uv; |
|||
return o; |
|||
} |
|||
|
|||
sampler2D _MainTex; |
|||
float4 _RGBAMask; |
|||
float _MipMap; |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
fixed4 col = tex2Dlod(_MainTex, float4(i.uv,0.0f,_MipMap)); |
|||
|
|||
if(_RGBAMask.r + _RGBAMask.g + _RGBAMask.b == 0.0f) |
|||
{ |
|||
// As we preview alpha, we need to linearize |
|||
float a = GammaToLinearSpaceExact(col.a); |
|||
col = float4(a,a,a,1.0f); |
|||
} |
|||
else |
|||
{ |
|||
if(_RGBAMask.a == 0.0f) |
|||
{ |
|||
col.a = 1.0f; |
|||
} |
|||
col.rgb *= _RGBAMask.rgb; |
|||
} |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9d1550a098ac7834a802df7aed0b256b |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.VFXToolbox; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public abstract class WorkbenchCanvasBase |
|||
{ |
|||
protected Workbench m_Window; |
|||
|
|||
public WorkbenchCanvasBase(Workbench window) |
|||
{ |
|||
m_Window = window; |
|||
} |
|||
|
|||
public abstract void Invalidate(bool needRedraw); |
|||
|
|||
public abstract void OnGUI(Rect displayRect, WorkbenchToolBase currentTool); |
|||
|
|||
public abstract void OnToolbarGUI(); |
|||
|
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 1e25faf9e67e10347939f347b8996361 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class WorkbenchImageCanvas : WorkbenchCanvasBase |
|||
{ |
|||
private Rect m_DisplayRect; |
|||
|
|||
public bool maskR |
|||
{ |
|||
get { return m_Material.GetColor("_RGBAMask").r == 1.0f; } |
|||
set |
|||
{ |
|||
Color c = m_Material.GetColor("_RGBAMask"); |
|||
if (value) c.r = 1.0f; else c.r = 0.0f; |
|||
m_Material.SetColor("_RGBAMask", c); |
|||
Invalidate(true); |
|||
} |
|||
} |
|||
|
|||
public bool maskG |
|||
{ |
|||
get { return m_Material.GetColor("_RGBAMask").g == 1.0f; } |
|||
set |
|||
{ |
|||
Color c = m_Material.GetColor("_RGBAMask"); |
|||
if (value) c.g = 1.0f; else c.g = 0.0f; |
|||
m_Material.SetColor("_RGBAMask", c); |
|||
Invalidate(true); |
|||
} |
|||
} |
|||
|
|||
public bool maskB |
|||
{ |
|||
get { return m_Material.GetColor("_RGBAMask").b == 1.0f; } |
|||
set |
|||
{ |
|||
Color c = m_Material.GetColor("_RGBAMask"); |
|||
if (value) c.b = 1.0f; else c.b = 0.0f; |
|||
m_Material.SetColor("_RGBAMask", c); |
|||
Invalidate(true); |
|||
} |
|||
|
|||
} |
|||
|
|||
public bool maskA |
|||
{ |
|||
get { return m_Material.GetColor("_RGBAMask").a == 1.0f; } |
|||
set |
|||
{ |
|||
Color c = m_Material.GetColor("_RGBAMask"); |
|||
if (value) c.a = 1.0f; else c.a = 0.0f; |
|||
m_Material.SetColor("_RGBAMask", c); |
|||
Invalidate(true); |
|||
} |
|||
} |
|||
|
|||
public bool filter |
|||
{ |
|||
get { return m_bFilter; } |
|||
set |
|||
{ |
|||
if (m_bFilter != value) |
|||
{ |
|||
m_bFilter = value; |
|||
InvalidateRenderTarget(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public int mipMap |
|||
{ |
|||
get |
|||
{ |
|||
return m_MipMap; |
|||
} |
|||
set |
|||
{ |
|||
if (m_MipMap != value) |
|||
{ |
|||
m_MipMap = value; |
|||
m_Material.SetFloat("_MipMap", (float)value); |
|||
InvalidateRenderTarget(); |
|||
} |
|||
else |
|||
{ |
|||
m_MipMap = value; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public int mipMapCount |
|||
{ |
|||
get { return GetMipMapCount(); } |
|||
} |
|||
|
|||
public bool showGrid |
|||
{ |
|||
get |
|||
{ |
|||
return m_bShowGrid; |
|||
} |
|||
set |
|||
{ |
|||
m_bShowGrid = value; |
|||
} |
|||
} |
|||
|
|||
public float BackgroundBrightness |
|||
{ |
|||
get |
|||
{ |
|||
return m_bgBrightness; |
|||
} |
|||
set |
|||
{ |
|||
SetBGBrightness(value); |
|||
} |
|||
} |
|||
|
|||
public Styles styles |
|||
{ |
|||
get |
|||
{ |
|||
if (m_Styles == null) |
|||
m_Styles = new Styles(this); |
|||
return m_Styles; |
|||
} |
|||
} |
|||
|
|||
public float zoom |
|||
{ |
|||
get |
|||
{ |
|||
return m_Zoom; |
|||
} |
|||
set |
|||
{ |
|||
m_Zoom = value; |
|||
Invalidate(false); |
|||
} |
|||
} |
|||
|
|||
private Vector2 m_CameraPosition = Vector2.zero; |
|||
private float m_Zoom = 1.0f; |
|||
private bool m_DragPreview = false; |
|||
private bool m_ZoomPreview = false; |
|||
private Vector2 m_ZoomPreviewCenter; |
|||
private Vector2 m_PreviousMousePosition; |
|||
|
|||
private Styles m_Styles; |
|||
|
|||
private Vector2 m_ZoomMinMax = new Vector2(0.2f, 10.0f); |
|||
private bool m_bFilter = true; |
|||
private int m_MipMap = 0; |
|||
private bool m_bShowGrid = true; |
|||
|
|||
private Shader m_Shader; |
|||
private Material m_Material; |
|||
private RenderTexture m_RenderTexture; |
|||
|
|||
private bool m_IsDirtyRenderTarget; |
|||
private bool m_bNeedRedraw; |
|||
private float m_bgBrightness = -1.0f; |
|||
|
|||
public Texture texture |
|||
{ |
|||
get { return GetTexture(); } |
|||
set { SetTexture(value); } |
|||
} |
|||
private Texture m_Texture; |
|||
|
|||
public CanvasGUIDelegate onCanvasGUI; |
|||
public delegate void CanvasGUIDelegate(); |
|||
|
|||
public WorkbenchImageCanvas(Workbench window, string shaderName = "Packages/com.unity.vfx-toolbox/Workbench/Editor/Canvas/Shaders/WorkbenchImageCanvas.shader") |
|||
:base(window) |
|||
{ |
|||
m_IsDirtyRenderTarget = true; |
|||
m_bNeedRedraw = true; |
|||
m_Shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderName); |
|||
m_Material = new Material(m_Shader) { hideFlags = HideFlags.DontSave }; |
|||
m_RenderTexture = RenderTexture.GetTemporary(1, 1, 0); |
|||
} |
|||
|
|||
public override void Invalidate(bool needRedraw) |
|||
{ |
|||
m_bNeedRedraw = m_bNeedRedraw | needRedraw; |
|||
m_Window.Invalidate(); |
|||
} |
|||
|
|||
protected Texture GetTexture() |
|||
{ |
|||
return m_Texture; |
|||
} |
|||
|
|||
protected void SetTexture(Texture tex) |
|||
{ |
|||
m_Texture = tex; |
|||
Invalidate(true); |
|||
} |
|||
|
|||
protected virtual int GetMipMapCount() |
|||
{ |
|||
if (texture != null) |
|||
{ |
|||
if (texture is Texture2D) |
|||
{ |
|||
return (texture as Texture2D).mipmapCount; |
|||
} |
|||
else |
|||
return 0; |
|||
} |
|||
else |
|||
return 0; |
|||
} |
|||
|
|||
public void InvalidateRenderTarget() |
|||
{ |
|||
m_IsDirtyRenderTarget = true; |
|||
} |
|||
|
|||
private void UpdateRenderTarget() |
|||
{ |
|||
int width = Mathf.Max(1, texture.width / (int)Mathf.Pow(2, (mipMap))); |
|||
int height = Mathf.Max(1, texture.height / (int)Mathf.Pow(2, (mipMap))); |
|||
|
|||
if (m_RenderTexture.width != width || m_RenderTexture.height != height) |
|||
{ |
|||
RenderTexture.ReleaseTemporary(m_RenderTexture); |
|||
m_RenderTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGBHalf); |
|||
} |
|||
|
|||
if (filter) |
|||
m_RenderTexture.filterMode = FilterMode.Bilinear; |
|||
else |
|||
m_RenderTexture.filterMode = FilterMode.Point; |
|||
|
|||
m_IsDirtyRenderTarget = false; |
|||
Invalidate(true); |
|||
} |
|||
|
|||
public void Recenter(bool Refit) |
|||
{ |
|||
m_CameraPosition = Vector2.zero; |
|||
if (Refit) |
|||
{ |
|||
float hZoom = (m_DisplayRect.height - 70) / texture.height; |
|||
float wZoom = (m_DisplayRect.width - 70) / texture.width; |
|||
|
|||
m_Zoom = Mathf.Min(hZoom, wZoom); |
|||
} |
|||
else |
|||
{ |
|||
m_Zoom = 1.0f; |
|||
} |
|||
} |
|||
|
|||
private void Zoom(float ZoomDelta, Vector2 zoomCenter) |
|||
{ |
|||
Vector2 centerPos = -new Vector2(zoomCenter.x - m_DisplayRect.width / 2, zoomCenter.y - m_DisplayRect.height / 2) - m_CameraPosition; |
|||
|
|||
float prevZoom = m_Zoom; |
|||
|
|||
m_Zoom -= ZoomDelta; |
|||
if (m_Zoom < m_ZoomMinMax.x) |
|||
m_Zoom = m_ZoomMinMax.x; |
|||
else if (m_Zoom > m_ZoomMinMax.y) |
|||
m_Zoom = m_ZoomMinMax.y; |
|||
else |
|||
{ |
|||
m_CameraPosition += centerPos - ((m_Zoom / prevZoom) * centerPos); |
|||
} |
|||
} |
|||
|
|||
protected virtual void HandleKeyboardEvents() |
|||
{ |
|||
if (Event.current.type == EventType.KeyDown) |
|||
{ |
|||
switch (Event.current.keyCode) |
|||
{ |
|||
// Viewport Toggles
|
|||
case KeyCode.F: |
|||
Recenter(!Event.current.shift); |
|||
break; |
|||
case KeyCode.G: |
|||
showGrid = !showGrid; |
|||
break; |
|||
case KeyCode.J: |
|||
filter = !filter; |
|||
Invalidate(true); |
|||
break; |
|||
// Brightness Control
|
|||
case KeyCode.V: |
|||
BrightnessDown(0.1f); |
|||
break; |
|||
case KeyCode.B: |
|||
ResetBrightness(); |
|||
break; |
|||
case KeyCode.N: |
|||
BrightnessUp(0.1f); |
|||
break; |
|||
default: |
|||
return; // Return without using event.
|
|||
} |
|||
Invalidate(false); |
|||
Event.current.Use(); |
|||
} |
|||
} |
|||
|
|||
private void DrawCurrentTexture() |
|||
{ |
|||
Rect rect = new Rect(0, 0, m_DisplayRect.width, m_DisplayRect.height); |
|||
|
|||
// Pan : use Middle Mouse button or Alt+Click
|
|||
if (Event.current.type == EventType.MouseDown && (Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt))) |
|||
{ |
|||
m_DragPreview = true; |
|||
} |
|||
|
|||
if ((Event.current.rawType == EventType.MouseUp || Event.current.rawType == EventType.DragExited) && (Event.current.button == 2 || Event.current.button == 0)) |
|||
{ |
|||
m_DragPreview = false; |
|||
Invalidate(false); |
|||
} |
|||
|
|||
if ((!m_DragPreview && Event.current.alt) || m_DragPreview) |
|||
{ |
|||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Pan); |
|||
Invalidate(false); |
|||
} |
|||
|
|||
if (m_DragPreview && Event.current.type == EventType.MouseDrag) |
|||
{ |
|||
m_CameraPosition -= Event.current.delta; |
|||
Invalidate(false); |
|||
} |
|||
|
|||
// Zoom : using MouseWheel
|
|||
if (Event.current.type == EventType.ScrollWheel && rect.Contains(Event.current.mousePosition)) |
|||
{ |
|||
// Delta negative when zooming In, Positive when zooming out
|
|||
Zoom(Event.current.delta.y * 0.05f, Event.current.mousePosition); |
|||
Invalidate(false); |
|||
} |
|||
|
|||
|
|||
// Zoom : using Alt + RightClick
|
|||
if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && Event.current.alt) |
|||
{ |
|||
m_ZoomPreview = true; |
|||
m_ZoomPreviewCenter = Event.current.mousePosition; |
|||
m_PreviousMousePosition = m_ZoomPreviewCenter; |
|||
} |
|||
|
|||
if (Event.current.rawType == EventType.MouseUp && Event.current.button == 1) |
|||
{ |
|||
m_ZoomPreview = false; |
|||
} |
|||
|
|||
if (m_ZoomPreview) |
|||
{ |
|||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Zoom); |
|||
Vector2 mouseDelta = Event.current.mousePosition - m_PreviousMousePosition; |
|||
Zoom((mouseDelta.x + mouseDelta.y) * -0.002f, m_ZoomPreviewCenter); |
|||
Invalidate(false); |
|||
m_PreviousMousePosition = Event.current.mousePosition; |
|||
} |
|||
|
|||
// Draw Texture
|
|||
if (Event.current.type == EventType.Repaint) |
|||
{ |
|||
GUI.DrawTexture |
|||
( |
|||
new Rect( |
|||
(rect.width / 2) - m_CameraPosition.x - (texture.width * m_Zoom * 0.5f), |
|||
(rect.height / 2) - m_CameraPosition.y - (texture.height * m_Zoom * 0.5f), |
|||
texture.width * m_Zoom, |
|||
texture.height * m_Zoom |
|||
), |
|||
m_RenderTexture, |
|||
ScaleMode.ScaleToFit |
|||
); |
|||
} |
|||
} |
|||
|
|||
public Vector2 CanvasToScreen(Vector2 Position) |
|||
{ |
|||
return new Vector2( |
|||
(m_DisplayRect.width / 2) - m_CameraPosition.x - (Position.x * m_Zoom), |
|||
(m_DisplayRect.height / 2) - m_CameraPosition.y - (Position.y * m_Zoom) |
|||
); |
|||
} |
|||
|
|||
protected virtual void DrawGrid() |
|||
{ |
|||
Vector2 src, dst; |
|||
if (BackgroundBrightness < 0.5f) |
|||
Handles.color = new Color(1.0f, 1.0f, 1.0f, 0.33333f); |
|||
else |
|||
Handles.color = new Color(0.0f, 0.0f, 0.0f, 0.66666f); |
|||
|
|||
src = CanvasToScreen(new Vector2(-texture.width / 2, -texture.height / 2)); |
|||
dst = CanvasToScreen(new Vector2(texture.width / 2, texture.height / 2)); |
|||
|
|||
Handles.DrawLine(new Vector2(src.x, src.y), new Vector2(dst.x, src.y)); |
|||
Handles.DrawLine(new Vector2(dst.x, src.y), new Vector2(dst.x, dst.y)); |
|||
Handles.DrawLine(new Vector2(dst.x, dst.y), new Vector2(src.x, dst.y)); |
|||
Handles.DrawLine(new Vector2(src.x, dst.y), new Vector2(src.x, src.y)); |
|||
|
|||
Handles.color = Color.white; |
|||
} |
|||
|
|||
private void BlitIntoRenderTarget() |
|||
{ |
|||
// Backup GUI RenderTarget
|
|||
var oldrendertarget = RenderTexture.active; |
|||
|
|||
Graphics.Blit(texture, m_RenderTexture, m_Material); |
|||
|
|||
// Restore GUI RenderTarget
|
|||
RenderTexture.active = oldrendertarget; |
|||
} |
|||
|
|||
public override void OnToolbarGUI() |
|||
{ |
|||
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) |
|||
{ |
|||
bool prev; |
|||
|
|||
bool bMaskR = maskR; |
|||
bool bMaskG = maskG; |
|||
bool bMaskB = maskB; |
|||
bool bMaskA = maskA; |
|||
bool bMaskRGB = bMaskR && bMaskG && bMaskB; |
|||
|
|||
bMaskRGB = GUILayout.Toggle(bMaskRGB, styles.iconRGB, EditorStyles.toolbarButton); |
|||
|
|||
if (bMaskRGB != (bMaskR && bMaskG && bMaskB)) |
|||
{ |
|||
bMaskR = bMaskG = bMaskB = bMaskRGB; |
|||
|
|||
maskR = bMaskR; |
|||
maskG = bMaskG; |
|||
maskB = bMaskB; |
|||
|
|||
} |
|||
|
|||
prev = bMaskR; |
|||
bMaskR = GUILayout.Toggle(bMaskR, VFXToolboxGUIUtility.Get("R"), styles.MaskRToggle); |
|||
|
|||
if (bMaskR != prev) |
|||
maskR = bMaskR; |
|||
|
|||
prev = bMaskG; |
|||
bMaskG = GUILayout.Toggle(bMaskG, VFXToolboxGUIUtility.Get("G"), styles.MaskGToggle); |
|||
if (bMaskG != prev) |
|||
maskG = bMaskG; |
|||
|
|||
prev = bMaskB; |
|||
bMaskB = GUILayout.Toggle(bMaskB, VFXToolboxGUIUtility.Get("B"), styles.MaskBToggle); |
|||
if (bMaskB != prev) |
|||
maskB = bMaskB; |
|||
|
|||
prev = bMaskA; |
|||
bMaskA = GUILayout.Toggle(bMaskA, VFXToolboxGUIUtility.Get("A"), styles.MaskAToggle); |
|||
if (bMaskA != prev) |
|||
maskA = bMaskA; |
|||
|
|||
|
|||
GUILayout.Space(20); |
|||
{ |
|||
Rect brightnessRect = GUILayoutUtility.GetRect(160, 24); |
|||
GUI.Box(brightnessRect, GUIContent.none, EditorStyles.toolbarButton); |
|||
GUI.Label(new RectOffset(4, 0, 0, 0).Remove(brightnessRect), VFXToolboxGUIUtility.GetTextAndIcon("Background|Sets the Background Brightness", "CheckerFloor"), EditorStyles.miniLabel); |
|||
|
|||
float newBrightness = GUI.HorizontalSlider(new RectOffset(82, 4, 0, 0).Remove(brightnessRect), BackgroundBrightness, 0.0f, 1.0f); |
|||
if (BackgroundBrightness != newBrightness) |
|||
BackgroundBrightness = newBrightness; |
|||
} |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
} |
|||
} |
|||
|
|||
public override void OnGUI(Rect displayRect, WorkbenchToolBase currentTool = null) |
|||
{ |
|||
m_DisplayRect = displayRect; |
|||
|
|||
if (m_bgBrightness < 0.0f) |
|||
{ |
|||
ResetBrightness(); |
|||
} |
|||
|
|||
// Focus taken when clicked in viewport
|
|||
if (Event.current.type == EventType.MouseDown && m_DisplayRect.Contains(Event.current.mousePosition)) |
|||
{ |
|||
GUI.FocusControl(""); |
|||
} |
|||
|
|||
if (texture != null && Event.current.type == EventType.Repaint) |
|||
{ |
|||
if (m_IsDirtyRenderTarget) |
|||
UpdateRenderTarget(); |
|||
|
|||
if (m_bNeedRedraw) |
|||
{ |
|||
BlitIntoRenderTarget(); |
|||
m_bNeedRedraw = false; |
|||
} |
|||
} |
|||
|
|||
GUI.BeginGroup(m_DisplayRect); |
|||
Rect LocalRect = new Rect(Vector2.zero, m_DisplayRect.size); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
#endif
|
|||
GUI.DrawTextureWithTexCoords(LocalRect, BackgroundTexture, new Rect(0, 0, m_DisplayRect.width / 64, m_DisplayRect.height / 64)); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
//GL.sRGBWrite = false;
|
|||
#endif
|
|||
if (texture != null) |
|||
{ |
|||
HandleKeyboardEvents(); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
#endif
|
|||
DrawCurrentTexture(); |
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
//GL.sRGBWrite = false;
|
|||
#endif
|
|||
|
|||
if (showGrid) DrawGrid(); |
|||
if (onCanvasGUI != null) |
|||
onCanvasGUI(); |
|||
} |
|||
else |
|||
GUI.Label(LocalRect, VFXToolboxGUIUtility.Get("No Texture"), EditorStyles.centeredGreyMiniLabel); |
|||
|
|||
#if !UNITY_2018_2_OR_NEWER
|
|||
//GL.sRGBWrite = false;
|
|||
#endif
|
|||
|
|||
GUI.EndGroup(); |
|||
|
|||
if (currentTool != null) |
|||
{ |
|||
using (new GUI.ClipScope(displayRect)) |
|||
{ |
|||
if (currentTool.OnCanvasGUI(this)) |
|||
Invalidate(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
#region BRIGHTNESS CONTROLS
|
|||
|
|||
public Texture2D BackgroundTexture { get { return m_BackgroundTexture; } } |
|||
private Texture2D m_BackgroundTexture; |
|||
|
|||
public void SetBGBrightness(float value) |
|||
{ |
|||
m_bgBrightness = value; |
|||
m_BackgroundTexture = Styles.GetBGTexture(value); |
|||
} |
|||
|
|||
public void ResetBrightness() |
|||
{ |
|||
if (EditorGUIUtility.isProSkin) |
|||
BackgroundBrightness = 0.2f; |
|||
else |
|||
BackgroundBrightness = 0.4f; |
|||
} |
|||
|
|||
public void BrightnessUp(float value) |
|||
{ |
|||
BackgroundBrightness = Mathf.Min(BackgroundBrightness + value, 1.0f); |
|||
} |
|||
|
|||
public void BrightnessDown(float value) |
|||
{ |
|||
BackgroundBrightness = Mathf.Max(0.0f, BackgroundBrightness - value); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region STYLES
|
|||
|
|||
public class Styles |
|||
{ |
|||
public GUIStyle miniLabel |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_ViewportMiniLabel : m_ViewportMiniLabelDark; } |
|||
} |
|||
|
|||
public GUIStyle miniLabelRight |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_ViewportMiniLabelRight : m_ViewportMiniLabelRightDark; } |
|||
} |
|||
|
|||
public GUIStyle miniLabelCenter |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_ViewportMiniLabelCenter : m_ViewportMiniLabelCenterDark; } |
|||
} |
|||
|
|||
public GUIStyle label |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_ViewportLabel : m_ViewportLabelDark; } |
|||
} |
|||
|
|||
public GUIStyle largeLabel |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_ViewportLargeLabel : m_ViewportLargeLabelDark; } |
|||
} |
|||
|
|||
public Color backgroundPanelColor |
|||
{ |
|||
get { return m_Canvas.BackgroundBrightness < 0.5f ? m_BackgroundPanelColor : m_BackgroundPanelColorDark; } |
|||
} |
|||
|
|||
public Color red { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(1, 0, 0, 1) : new Color(0.7f, 0, 0, 1); } } |
|||
public Color green { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(0, 1, 0, 1) : new Color(0, 0.5f, 0, 1); } } |
|||
public Color blue { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(0, 0, 1, 1) : new Color(0, 0, 0.5f, 1); } } |
|||
public Color white { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(1, 1, 1, 1) : new Color(0, 0, 0, 1); } } |
|||
public Color black { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(0, 0, 0, 1) : new Color(1, 1, 1, 1); } } |
|||
public Color yellow { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(1.0f, 0.8f, 0.25f) : new Color(0.5f, 0.4f, 0.1f); } } |
|||
public Color cyan { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(0.25f, 0.8f, 1.0f) : new Color(0.1f, 0.4f, 0.5f); } } |
|||
public Color fadewhite { get { return m_Canvas.BackgroundBrightness < 0.5f ? new Color(1, 1, 1, 0.25f) : new Color(0, 0, 0, 0.25f); } } |
|||
|
|||
private GUIStyle m_ViewportMiniLabel; |
|||
private GUIStyle m_ViewportMiniLabelDark; |
|||
private GUIStyle m_ViewportMiniLabelRight; |
|||
private GUIStyle m_ViewportMiniLabelRightDark; |
|||
private GUIStyle m_ViewportMiniLabelCenter; |
|||
private GUIStyle m_ViewportMiniLabelCenterDark; |
|||
private GUIStyle m_ViewportLabel; |
|||
private GUIStyle m_ViewportLabelDark; |
|||
private GUIStyle m_ViewportLargeLabel; |
|||
private GUIStyle m_ViewportLargeLabelDark; |
|||
|
|||
private WorkbenchImageCanvas m_Canvas; |
|||
|
|||
private Color m_BackgroundPanelColor; |
|||
private Color m_BackgroundPanelColorDark; |
|||
|
|||
public readonly GUIContent iconRGB = EditorGUIUtility.IconContent("PreTextureRGB", "Toggle RGB/Alpha only"); |
|||
public readonly GUIContent iconMipMapUp = EditorGUIUtility.IconContent("PreTextureMipMapLow", "Go one MipMap up (smaller size)"); |
|||
public readonly GUIContent iconMipMapDown = EditorGUIUtility.IconContent("PreTextureMipMapHigh", "Go one MipMap down (higher size)"); |
|||
|
|||
public GUIStyle MaskRToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskRTogglePro; else return m_MaskRToggle; } } |
|||
public GUIStyle MaskGToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskGTogglePro; else return m_MaskGToggle; } } |
|||
public GUIStyle MaskBToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskBTogglePro; else return m_MaskBToggle; } } |
|||
public GUIStyle MaskAToggle { get { if (EditorGUIUtility.isProSkin) return m_MaskATogglePro; else return m_MaskAToggle; } } |
|||
|
|||
private GUIStyle m_MaskRToggle; |
|||
private GUIStyle m_MaskRTogglePro; |
|||
private GUIStyle m_MaskGToggle; |
|||
private GUIStyle m_MaskGTogglePro; |
|||
private GUIStyle m_MaskBToggle; |
|||
private GUIStyle m_MaskBTogglePro; |
|||
private GUIStyle m_MaskAToggle; |
|||
private GUIStyle m_MaskATogglePro; |
|||
|
|||
|
|||
public Styles(WorkbenchImageCanvas canvas) |
|||
{ |
|||
m_Canvas = canvas; |
|||
|
|||
m_ViewportMiniLabel = new GUIStyle(EditorStyles.miniLabel); |
|||
m_ViewportMiniLabel.normal.textColor = Color.white; |
|||
m_ViewportMiniLabelDark = new GUIStyle(EditorStyles.miniLabel); |
|||
m_ViewportMiniLabelDark.normal.textColor = Color.black; |
|||
|
|||
m_ViewportMiniLabelRight = new GUIStyle(m_ViewportMiniLabel); |
|||
m_ViewportMiniLabelRight.alignment = TextAnchor.MiddleRight; |
|||
m_ViewportMiniLabelRightDark = new GUIStyle(m_ViewportMiniLabelDark); |
|||
m_ViewportMiniLabelRightDark.alignment = TextAnchor.MiddleRight; |
|||
|
|||
m_ViewportMiniLabelCenter = new GUIStyle(m_ViewportMiniLabel); |
|||
m_ViewportMiniLabelCenter.alignment = TextAnchor.MiddleCenter; |
|||
m_ViewportMiniLabelCenterDark = new GUIStyle(m_ViewportMiniLabelDark); |
|||
m_ViewportMiniLabelCenterDark.alignment = TextAnchor.MiddleCenter; |
|||
|
|||
m_ViewportLabel = new GUIStyle(EditorStyles.largeLabel); |
|||
m_ViewportLabel.normal.textColor = Color.white; |
|||
|
|||
m_ViewportLabelDark = new GUIStyle(EditorStyles.largeLabel); |
|||
m_ViewportLabelDark.normal.textColor = Color.black; |
|||
|
|||
m_ViewportLargeLabel = new GUIStyle(EditorStyles.largeLabel); |
|||
m_ViewportLargeLabel.fontSize = 24; |
|||
m_ViewportLargeLabel.normal.textColor = Color.white; |
|||
|
|||
m_ViewportLargeLabelDark = new GUIStyle(EditorStyles.largeLabel); |
|||
m_ViewportLargeLabelDark.fontSize = 24; |
|||
m_ViewportLargeLabelDark.normal.textColor = Color.black; |
|||
|
|||
m_BackgroundPanelColor = new Color(0.02f, 0.02f, 0.02f, 0.85f); |
|||
m_BackgroundPanelColorDark = new Color(0.25f, 0.25f, 0.25f, 0.85f); |
|||
|
|||
m_MaskRToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskGToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskBToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskAToggle = new GUIStyle(EditorStyles.toolbarButton); |
|||
|
|||
m_MaskRToggle.onNormal.textColor = new Color(1.0f, 0.0f, 0.0f); |
|||
m_MaskGToggle.onNormal.textColor = new Color(0.0f, 0.6f, 0.2f); |
|||
m_MaskBToggle.onNormal.textColor = new Color(0.0f, 0.2f, 1.0f); |
|||
m_MaskAToggle.onNormal.textColor = new Color(0.5f, 0.5f, 0.5f); |
|||
|
|||
m_MaskRTogglePro = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskGTogglePro = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskBTogglePro = new GUIStyle(EditorStyles.toolbarButton); |
|||
m_MaskATogglePro = new GUIStyle(EditorStyles.toolbarButton); |
|||
|
|||
m_MaskRTogglePro.onNormal.textColor = new Color(2.0f, 0.3f, 0.3f); |
|||
m_MaskGTogglePro.onNormal.textColor = new Color(0.5f, 2.0f, 0.1f); |
|||
m_MaskBTogglePro.onNormal.textColor = new Color(0.2f, 0.6f, 2.0f); |
|||
m_MaskATogglePro.onNormal.textColor = new Color(2.0f, 2.0f, 2.0f); |
|||
} |
|||
|
|||
public static Texture2D GetBGTexture(float brightness) |
|||
{ |
|||
Texture2D out_tex = new Texture2D(2, 2) { hideFlags = HideFlags.DontSave }; |
|||
Color[] bgcolors = new Color[4]; |
|||
brightness *= 0.95f; |
|||
bgcolors[0] = new Color(brightness + 0.05f, brightness + 0.05f, brightness + 0.05f); |
|||
bgcolors[1] = new Color(brightness, brightness, brightness); |
|||
bgcolors[2] = new Color(brightness, brightness, brightness); |
|||
bgcolors[3] = new Color(brightness + 0.05f, brightness + 0.05f, brightness + 0.05f); |
|||
out_tex.SetPixels(bgcolors); |
|||
out_tex.wrapMode = TextureWrapMode.Repeat; |
|||
out_tex.filterMode = FilterMode.Point; |
|||
out_tex.Apply(); |
|||
return out_tex; |
|||
} |
|||
|
|||
|
|||
} |
|||
#endregion
|
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3f89a6a9c959fc741a4d92258ca28947 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.VFXToolbox; |
|||
|
|||
namespace UnityEditor.VFXToolbox.Workbench |
|||
{ |
|||
public class WorkbenchImageCanvas : VFXToolboxCanvas |
|||
{ |
|||
private Texture m_Texture; |
|||
private Workbench m_Editor; |
|||
|
|||
public WorkbenchImageCanvas(Rect displayRect, Workbench editorWindow) |
|||
: base (displayRect) |
|||
{ |
|||
m_Editor = editorWindow; |
|||
} |
|||
|
|||
public override void Invalidate(bool needRedraw) |
|||
{ |
|||
base.Invalidate(needRedraw); |
|||
m_Editor.Invalidate(); |
|||
} |
|||
|
|||
protected override Texture GetTexture() |
|||
{ |
|||
return m_Texture; |
|||
} |
|||
|
|||
protected override void SetTexture(Texture tex) |
|||
{ |
|||
m_Texture = tex; |
|||
Invalidate(true); |
|||
} |
|||
|
|||
public override void OnGUI() |
|||
{ |
|||
texture = null; |
|||
base.OnGUI(); |
|||
} |
|||
|
|||
public void OnGUI(WorkbenchToolBase currentTool) |
|||
{ |
|||
base.OnGUI(); |
|||
|
|||
if (currentTool != null) |
|||
{ |
|||
using (new GUI.ClipScope(displayRect)) |
|||
{ |
|||
if (currentTool.OnCanvasGUI(this)) |
|||
Invalidate(false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 76685ef3ce4edb44d9fd3677d2c01cff |
|||
timeCreated: 1475500629 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue