Peter Bay Bastian
7 年前
当前提交
e7218ad7
共有 15 个文件被更改,包括 61 次插入 和 493 次删除
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardField.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/SliderControl.cs
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MasterPreviewView.uss
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs.meta
-
127MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
190MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PreviewTextureView.cs.meta
-
28MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PreviewTextureView.cs
-
89MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/GraphInspectorView.uss
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/GraphInspectorView.uss.meta
|
|||
fileFormatVersion: 2 |
|||
guid: d80d2409e2484dbea449768bbdd267b9 |
|||
timeCreated: 1502956197 |
|
|||
fileFormatVersion: 2 |
|||
guid: a7487f4dc0fc4cf6a84bde37e66b60cb |
|||
timeCreated: 1507035849 |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Inspector |
|||
{ |
|||
public class GraphInspectorView : VisualElement, IDisposable |
|||
{ |
|||
int m_SelectionHash; |
|||
|
|||
VisualElement m_PropertyItems; |
|||
VisualElement m_LayerItems; |
|||
ObjectField m_PreviewMeshPicker; |
|||
|
|||
PreviewTextureView m_PreviewTextureView; |
|||
|
|||
AbstractMaterialGraph m_Graph; |
|||
PreviewRenderData m_PreviewRenderHandle; |
|||
|
|||
Vector2 m_PreviewScrollPosition; |
|||
|
|||
public Action onUpdateAssetClick { get; set; } |
|||
public Action onShowInProjectClick { get; set; } |
|||
|
|||
public GraphInspectorView(string assetName, PreviewManager previewManager, AbstractMaterialGraph graph) |
|||
{ |
|||
m_Graph = graph; |
|||
|
|||
AddStyleSheetPath("Styles/GraphInspectorView"); |
|||
|
|||
var topContainer = new VisualElement {name = "top"}; |
|||
{ |
|||
var headerContainer = new VisualElement {name = "header"}; |
|||
{ |
|||
var title = new Label(assetName) {name = "title"}; |
|||
title.AddManipulator(new Clickable(() => |
|||
{ |
|||
if (onShowInProjectClick != null) |
|||
onShowInProjectClick(); |
|||
})); |
|||
headerContainer.Add(title); |
|||
headerContainer.Add(new Button(() => |
|||
{ |
|||
if (onUpdateAssetClick != null) |
|||
onUpdateAssetClick(); |
|||
}) { name = "save", text = "Save" }); |
|||
} |
|||
topContainer.Add(headerContainer); |
|||
|
|||
var propertiesContainer = new VisualElement {name = "properties"}; |
|||
{ |
|||
var header = new VisualElement {name = "header"}; |
|||
{ |
|||
var title = new Label("Properties") {name = "title"}; |
|||
header.Add(title); |
|||
|
|||
var addPropertyButton = new Button(OnAddProperty) {text = "Add", name = "addButton"}; |
|||
header.Add(addPropertyButton); |
|||
} |
|||
propertiesContainer.Add(header); |
|||
|
|||
m_PropertyItems = new VisualContainer {name = "items"}; |
|||
propertiesContainer.Add(m_PropertyItems); |
|||
} |
|||
topContainer.Add(propertiesContainer); |
|||
} |
|||
Add(topContainer); |
|||
|
|||
foreach (var property in m_Graph.properties) |
|||
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property)); |
|||
|
|||
Add(new ResizeBorderFrame(this) { name = "resizeBorderFrame" }); |
|||
|
|||
this.AddManipulator(new WindowDraggable()); |
|||
} |
|||
|
|||
void OnAddProperty() |
|||
{ |
|||
var gm = new GenericMenu(); |
|||
gm.AddItem(new GUIContent("Vector1"), false, () => AddProperty(new Vector1ShaderProperty())); |
|||
gm.AddItem(new GUIContent("Vector2"), false, () => AddProperty(new Vector2ShaderProperty())); |
|||
gm.AddItem(new GUIContent("Vector3"), false, () => AddProperty(new Vector3ShaderProperty())); |
|||
gm.AddItem(new GUIContent("Vector4"), false, () => AddProperty(new Vector4ShaderProperty())); |
|||
gm.AddItem(new GUIContent("Color"), false, () => AddProperty(new ColorShaderProperty())); |
|||
gm.AddItem(new GUIContent("HDR Color"), false, () => AddProperty(new ColorShaderProperty() {colorMode = ColorMode.HDR})); |
|||
gm.AddItem(new GUIContent("Boolean"), false, () => AddProperty(new BooleanShaderProperty())); |
|||
gm.AddItem(new GUIContent("Texture"), false, () => AddProperty(new TextureShaderProperty())); |
|||
gm.AddItem(new GUIContent("Cubemap"), false, () => AddProperty(new CubemapShaderProperty())); |
|||
gm.ShowAsContext(); |
|||
} |
|||
|
|||
void AddProperty(IShaderProperty property) |
|||
{ |
|||
m_Graph.owner.RegisterCompleteObjectUndo("Add Property"); |
|||
m_Graph.AddShaderProperty(property); |
|||
} |
|||
|
|||
void OnPreviewChanged() |
|||
{ |
|||
m_PreviewTextureView.image = m_PreviewRenderHandle.texture ?? Texture2D.blackTexture; |
|||
m_PreviewTextureView.Dirty(ChangeType.Repaint); |
|||
} |
|||
|
|||
public void HandleGraphChanges() |
|||
{ |
|||
foreach (var propertyGuid in m_Graph.removedProperties) |
|||
{ |
|||
var propertyView = m_PropertyItems.OfType<ShaderPropertyView>().FirstOrDefault(v => v.property.guid == propertyGuid); if (propertyView != null) |
|||
m_PropertyItems.Remove(propertyView); |
|||
} |
|||
|
|||
foreach (var property in m_Graph.addedProperties) |
|||
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property)); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
if (m_PreviewRenderHandle != null) |
|||
{ |
|||
m_PreviewRenderHandle.onPreviewChanged -= OnPreviewChanged; |
|||
m_PreviewRenderHandle = null; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Inspector |
|||
{ |
|||
public class ShaderPropertyView : VisualElement |
|||
{ |
|||
Action m_ValueAction; |
|||
public AbstractMaterialGraph graph { get; private set; } |
|||
public IShaderProperty property { get; private set; } |
|||
|
|||
public ShaderPropertyView(AbstractMaterialGraph graph, IShaderProperty property) |
|||
{ |
|||
this.graph = graph; |
|||
this.property = property; |
|||
AddStyleSheetPath("Styles/ShaderPropertyView"); |
|||
|
|||
var displayNameField = new TextField { name = "displayName", value = property.displayName }; |
|||
displayNameField.OnValueChanged(OnDisplayNameChanged); |
|||
Add(displayNameField); |
|||
|
|||
m_ValueAction = null; |
|||
if (property is Vector1ShaderProperty) |
|||
m_ValueAction = FloatField; |
|||
else if (property is Vector2ShaderProperty) |
|||
m_ValueAction = Vector2Field; |
|||
else if (property is Vector3ShaderProperty) |
|||
m_ValueAction = Vector3Field; |
|||
else if (property is Vector4ShaderProperty) |
|||
m_ValueAction = Vector4Field; |
|||
else if (property is BooleanShaderProperty) |
|||
m_ValueAction = BooleanField; |
|||
|
|||
if (m_ValueAction != null) |
|||
{ |
|||
Add(new IMGUIContainer(ValueField) { name = "value" }); |
|||
} |
|||
else if (property is ColorShaderProperty) |
|||
{ |
|||
var fProp = (ColorShaderProperty)property; |
|||
ColorField colorField; |
|||
if(fProp.colorMode == ColorMode.HDR) |
|||
colorField = new ColorField { name = "value", value = fProp.value, hdr = true }; |
|||
else |
|||
colorField = new ColorField { name = "value", value = fProp.value }; |
|||
colorField.OnValueChanged(OnColorChanged); |
|||
Add(colorField); |
|||
} |
|||
else if (property is TextureShaderProperty) |
|||
{ |
|||
var fProp = (TextureShaderProperty)property; |
|||
var objectField = new ObjectField { name = "value", objectType = typeof(Texture), value = fProp.value.texture }; |
|||
objectField.OnValueChanged(OnTextureChanged); |
|||
Add(objectField); |
|||
} |
|||
else if (property is CubemapShaderProperty) |
|||
{ |
|||
var fProp = (CubemapShaderProperty)property; |
|||
var objectField = new ObjectField { name = "value", objectType = typeof(Cubemap), value = fProp.value.cubemap }; |
|||
objectField.OnValueChanged(OnCubemapChanged); |
|||
Add(objectField); |
|||
} |
|||
|
|||
Add(new Button(OnClickRemove) { name = "remove", text = "Remove" }); |
|||
} |
|||
|
|||
void OnColorChanged(ChangeEvent<Color> evt) |
|||
{ |
|||
var fProp = (ColorShaderProperty)property; |
|||
if (evt.newValue != fProp.value) |
|||
{ |
|||
fProp.value = evt.newValue; |
|||
NotifyNodes(); |
|||
} |
|||
} |
|||
|
|||
void OnTextureChanged(ChangeEvent<Object> evt) |
|||
{ |
|||
var fProp = (TextureShaderProperty)property; |
|||
var newValue = (Texture)evt.newValue; |
|||
if (newValue != fProp.value.texture) |
|||
{ |
|||
fProp.value.texture = newValue; |
|||
NotifyNodes(); |
|||
} |
|||
} |
|||
|
|||
void OnCubemapChanged(ChangeEvent<Object> evt) |
|||
{ |
|||
var fProp = (CubemapShaderProperty)property; |
|||
var newValue = (Cubemap)evt.newValue; |
|||
if (newValue != fProp.value.cubemap) |
|||
{ |
|||
fProp.value.cubemap = newValue; |
|||
NotifyNodes(); |
|||
} |
|||
} |
|||
|
|||
void OnDisplayNameChanged(ChangeEvent<string> evt) |
|||
{ |
|||
if (evt.newValue != property.displayName) |
|||
{ |
|||
property.displayName = evt.newValue; |
|||
NotifyNodes(); |
|||
} |
|||
} |
|||
|
|||
void OnClickRemove() |
|||
{ |
|||
graph.owner.RegisterCompleteObjectUndo("Remove Property"); |
|||
graph.RemoveShaderProperty(property.guid); |
|||
NotifyNodes(); |
|||
} |
|||
|
|||
void ValueField() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
m_ValueAction(); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
NotifyNodes(); |
|||
} |
|||
|
|||
void NotifyNodes() |
|||
{ |
|||
foreach (var node in graph.GetNodes<PropertyNode>()) |
|||
node.Dirty(ModificationScope.Node); |
|||
} |
|||
|
|||
void FloatField() |
|||
{ |
|||
var fProp = (Vector1ShaderProperty)property; |
|||
fProp.value = EditorGUILayout.FloatField(fProp.value); |
|||
} |
|||
|
|||
void Vector2Field() |
|||
{ |
|||
var fProp = (Vector2ShaderProperty)property; |
|||
fProp.value = EditorGUILayout.Vector2Field("", fProp.value); |
|||
} |
|||
|
|||
void Vector3Field() |
|||
{ |
|||
var fProp = (Vector3ShaderProperty)property; |
|||
fProp.value = EditorGUILayout.Vector3Field("", fProp.value); |
|||
} |
|||
|
|||
void Vector4Field() |
|||
{ |
|||
var fProp = (Vector4ShaderProperty)property; |
|||
fProp.value = EditorGUILayout.Vector4Field("", fProp.value); |
|||
} |
|||
|
|||
/*void IntegerField() |
|||
{ |
|||
var fProp = (IntegerShaderProperty)property; |
|||
fProp.value = EditorGUILayout.IntField(fProp.value); |
|||
} |
|||
|
|||
void SliderField() |
|||
{ |
|||
var fProp = (SliderShaderProperty)property; |
|||
var value = fProp.value; |
|||
|
|||
GUILayoutOption[] sliderOptions = { GUILayout.ExpandWidth(true) }; |
|||
GUILayoutOption[] options = { GUILayout.MaxWidth(30.0f) }; |
|||
value.x = EditorGUILayout.Slider(fProp.value.x, fProp.value.y, fProp.value.z, sliderOptions); |
|||
EditorGUILayout.BeginHorizontal(); |
|||
float previousLabelWidth = EditorGUIUtility.labelWidth; |
|||
EditorGUIUtility.labelWidth = 30f; |
|||
Rect minMaxRect = EditorGUILayout.GetControlRect(new GUILayoutOption[]{ GUILayout.ExpandWidth(true) } ); |
|||
Rect minRect = new Rect(minMaxRect.x, minMaxRect.y, minMaxRect.width / 2, minMaxRect.height); |
|||
Rect maxRect = new Rect(minMaxRect.x + minMaxRect.width / 2, minMaxRect.y, minMaxRect.width / 2, minMaxRect.height); |
|||
value.y = EditorGUI.FloatField(minRect, "Min", fProp.value.y); |
|||
value.z = EditorGUI.FloatField(maxRect, "Max", fProp.value.z); |
|||
EditorGUIUtility.labelWidth = previousLabelWidth; |
|||
EditorGUILayout.EndHorizontal(); |
|||
fProp.value = value; |
|||
}*/ |
|||
|
|||
void BooleanField() |
|||
{ |
|||
var fProp = (BooleanShaderProperty)property; |
|||
fProp.value = EditorGUILayout.Toggle(fProp.value); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 524b1aa8d68043cd81a6514d805eb50d |
|||
timeCreated: 1508917442 |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing |
|||
{ |
|||
public sealed class PreviewTextureView : Image |
|||
{ |
|||
// Texture m_Image;
|
|||
//
|
|||
// public Texture image
|
|||
// {
|
|||
// get { return m_Image; }
|
|||
// set
|
|||
// {
|
|||
// if (value == m_Image)
|
|||
// return;
|
|||
// m_Image = value;
|
|||
// Dirty(ChangeType.Repaint);
|
|||
// }
|
|||
// }
|
|||
|
|||
// public override void DoRepaint()
|
|||
// {
|
|||
// EditorGUI.DrawPreviewTexture(contentRect, image);
|
|||
// }
|
|||
} |
|||
} |
|
|||
GraphInspectorView { |
|||
background-color: rgb(56, 56, 56); |
|||
flex-direction: column; |
|||
justify-content: space-between; |
|||
position-type: absolute; |
|||
position-right: 0; |
|||
position-top: 0; |
|||
width: 400; |
|||
min-width: 300; |
|||
} |
|||
|
|||
GraphInspectorView * { |
|||
font-size: 11; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #header { |
|||
background-color: rgb(64, 64, 64); |
|||
border-color: rgb(79, 79, 79); |
|||
border-bottom-width: 1; |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #header > #title { |
|||
text-color: rgb(180, 180, 180); |
|||
font-style: bold; |
|||
padding-left: 16; |
|||
padding-right: 16; |
|||
padding-top: 10; |
|||
padding-bottom: 10; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #content > #selectionCount { |
|||
text-color: rgb(180, 180, 180); |
|||
padding-left: 16; |
|||
padding-right: 16; |
|||
padding-top: 10; |
|||
padding-bottom: 10; |
|||
} |
|||
|
|||
GraphInspectorView > #bottom { |
|||
margin-bottom: 20; |
|||
} |
|||
|
|||
GraphInspectorView > #bottom > #preview { |
|||
max-height: 400; |
|||
background-color: rgb(79, 79, 79); |
|||
} |
|||
|
|||
GraphInspectorView > #top > #properties { |
|||
border-color: rgb(41, 41, 41); |
|||
border-top-width: 1; |
|||
border-bottom-width: 1; |
|||
border-left-width: 1; |
|||
border-right-width: 1; |
|||
margin-top: 8; |
|||
margin-bottom: 8; |
|||
margin-left: 8; |
|||
margin-right: 8; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #properties > #header { |
|||
border-color: rgb(41, 41, 41); |
|||
border-bottom-width: 1; |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #properties > #header > #title { |
|||
text-color: rgb(180, 180, 180); |
|||
font-style: bold; |
|||
padding-top: 8; |
|||
padding-bottom: 8; |
|||
padding-left: 8; |
|||
padding-right: 8; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #properties > #header > #addButton { |
|||
height: 24; |
|||
margin-top: 0; |
|||
margin-bottom: 0; |
|||
margin-left: 0; |
|||
margin-right: 8; |
|||
} |
|||
|
|||
GraphInspectorView > #top > #properties > #items { |
|||
padding-bottom: 4; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 15ae31264ebcd2b4ebde7b4d0ca5d5f4 |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} |
撰写
预览
正在加载...
取消
保存
Reference in new issue