浏览代码

Merge pull request #283 from Unity-Technologies/fix-trunk-compatibility

Fix trunk compatibility
/main
GitHub 7 年前
当前提交
dba26376
共有 16 个文件被更改,包括 169 次插入92 次删除
  1. 37
      com.unity.shadergraph/Editor/Data/Graphs/SerializableCubemap.cs
  2. 37
      com.unity.shadergraph/Editor/Data/Graphs/SerializableMesh.cs
  3. 38
      com.unity.shadergraph/Editor/Data/Graphs/SerializableTexture.cs
  4. 2
      com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs
  5. 2
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs
  6. 3
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs
  7. 2
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs
  8. 2
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs
  9. 2
      com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  10. 46
      com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
  11. 9
      com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs
  12. 16
      com.unity.shadergraph/Editor/Drawing/Views/ShaderPort.cs
  13. 33
      com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs
  14. 3
      com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs.meta
  15. 12
      com.unity.shadergraph/Editor/Util/GraphTypeMapper.cs.meta
  16. 17
      com.unity.shadergraph/Editor/Util/GraphTypeMapper.cs

37
com.unity.shadergraph/Editor/Data/Graphs/SerializableCubemap.cs


public class SerializableCubemap
{
[SerializeField]
private string m_SerializedCubemap;
string m_SerializedCubemap;
[SerializeField]
string m_Guid;
[NonSerialized]
Cubemap m_Cubemap;
private class CubemapHelper
class CubemapHelper
{
public Cubemap cubemap;
}

get
{
if (string.IsNullOrEmpty(m_SerializedCubemap))
return null;
if (!string.IsNullOrEmpty(m_SerializedCubemap))
{
var textureHelper = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, textureHelper);
m_SerializedCubemap = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.cubemap));
m_Cubemap = textureHelper.cubemap;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Cubemap == null)
{
m_Cubemap = AssetDatabase.LoadAssetAtPath<Cubemap>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
return cube.cubemap;
return m_Cubemap;
if(cubemap == value)
return;
var cubemapHelper = new CubemapHelper();
cubemapHelper.cubemap = value;
m_SerializedCubemap = EditorJsonUtility.ToJson(cubemapHelper, true);
m_SerializedCubemap = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Cubemap = value;
}
}
}

37
com.unity.shadergraph/Editor/Data/Graphs/SerializableMesh.cs


public class SerializableMesh
{
[SerializeField]
private string m_SerializedMesh;
string m_SerializedMesh;
[SerializeField]
string m_Guid;
[NonSerialized]
Mesh m_Mesh;
private class MeshHelper
class MeshHelper
{
public Mesh mesh;
}

get
{
if (string.IsNullOrEmpty(m_SerializedMesh))
return null;
if (!string.IsNullOrEmpty(m_SerializedMesh))
{
var textureHelper = new MeshHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedMesh, textureHelper);
m_SerializedMesh = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.mesh));
m_Mesh = textureHelper.mesh;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Mesh == null)
{
m_Mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
var meshHelper = new MeshHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedMesh, meshHelper);
return meshHelper.mesh;
return m_Mesh;
if (mesh == value)
return;
var meshHelper = new MeshHelper();
meshHelper.mesh = value;
m_SerializedMesh = EditorJsonUtility.ToJson(meshHelper, true);
m_SerializedMesh = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Mesh = value;
}
}
}

38
com.unity.shadergraph/Editor/Data/Graphs/SerializableTexture.cs


public class SerializableTexture
{
[SerializeField]
private string m_SerializedTexture;
string m_SerializedTexture;
[SerializeField]
string m_Guid;
[NonSerialized]
Texture m_Texture;
private class TextureHelper
class TextureHelper
{
public Texture texture;
}

get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
if (!string.IsNullOrEmpty(m_SerializedTexture))
{
var textureHelper = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, textureHelper);
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.texture));
m_Texture = textureHelper.texture;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Texture == null)
{
m_Texture = AssetDatabase.LoadAssetAtPath<Texture>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
return m_Texture;
if (texture == value)
return;
var textureHelper = new TextureHelper();
textureHelper.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(textureHelper, true);
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_Texture = value;
}
}
}

2
com.unity.shadergraph/Editor/Drawing/Blackboard/Blackboard.cs


#if UNITY_2018_1
using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;

}
}
}
#endif

2
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardField.cs


#if UNITY_2018_1
using System;
using System.Collections.Generic;
using System.Linq;

}
}
}
#endif

3
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;

if (create)
{
field.RenameGo();
field.OpenTextEditor();
row.expanded = true;
m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
m_Graph.AddShaderProperty(property);

2
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardRow.cs


#if UNITY_2018_1
using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;

}
}
}
#endif

2
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardSection.cs


#if UNITY_2018_1
using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;

}
}
}
#endif

2
com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs


using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
#if UNITY_2018_1
using GeometryChangedEvent = UnityEngine.Experimental.UIElements.PostLayoutEvent;
#else
using GeometryChangedEvent = UnityEngine.Experimental.UIElements.GeometryChangedEvent;
#endif
namespace UnityEditor.ShaderGraph.Drawing

46
com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs


if (selection.OfType<MaterialNodeView>().Count() == 1 && selection.OfType<MaterialNodeView>().First().node is SubGraphNode)
{
evt.menu.AppendSeparator();
evt.menu.AppendAction("Open Sub Graph", OpenSubGraph, ContextualMenu.MenuAction.AlwaysEnabled);
evt.menu.AppendAction("Open Sub Graph", OpenSubGraph, ContextualMenu.MenuAction.StatusFlags.Normal);
}
}
else if (evt.target is BlackboardField)

if (evt.target is MaterialGraphView)
{
evt.menu.AppendAction("Collapse Previews", CollapsePreviews, ContextualMenu.MenuAction.AlwaysEnabled);
evt.menu.AppendAction("Expand Previews", ExpandPreviews, ContextualMenu.MenuAction.AlwaysEnabled);
evt.menu.AppendAction("Collapse Previews", CollapsePreviews, ContextualMenu.MenuAction.StatusFlags.Normal);
evt.menu.AppendAction("Expand Previews", ExpandPreviews, ContextualMenu.MenuAction.StatusFlags.Normal);
void CollapsePreviews(EventBase evt)
void CollapsePreviews()
{
graph.owner.RegisterCompleteObjectUndo("Collapse Previews");
foreach (AbstractMaterialNode node in graph.GetNodes<AbstractMaterialNode>())

}
void ExpandPreviews(EventBase evt)
void ExpandPreviews()
{
graph.owner.RegisterCompleteObjectUndo("Expand Previews");
foreach (AbstractMaterialNode node in graph.GetNodes<AbstractMaterialNode>())

}
void SeeDocumentation(EventBase evt)
void SeeDocumentation()
{
var node = selection.OfType<MaterialNodeView>().First().node;
if (node.documentationURL != null)

void OpenSubGraph(EventBase evt)
void OpenSubGraph()
{
SubGraphNode subgraphNode = selection.OfType<MaterialNodeView>().First().node as SubGraphNode;

ContextualMenu.MenuAction.StatusFlags SeeDocumentationStatus(EventBase eventBase)
ContextualMenu.MenuAction.StatusFlags SeeDocumentationStatus()
{
if (selection.OfType<MaterialNodeView>().First().node.documentationURL == null)
return ContextualMenu.MenuAction.StatusFlags.Disabled;

ContextualMenu.MenuAction.StatusFlags ConvertToPropertyStatus(EventBase eventBase)
ContextualMenu.MenuAction.StatusFlags ConvertToPropertyStatus()
{
if (selection.OfType<MaterialNodeView>().Any(v => v.node != null))
{

return ContextualMenu.MenuAction.StatusFlags.Hidden;
}
void ConvertToProperty(EventBase eventBase)
void ConvertToProperty()
{
var selectedNodeViews = selection.OfType<MaterialNodeView>().Select(x => x.node).ToList();
foreach (var node in selectedNodeViews)

}
}
ContextualMenu.MenuAction.StatusFlags ConvertToInlineNodeStatus(EventBase eventBase)
ContextualMenu.MenuAction.StatusFlags ConvertToInlineNodeStatus()
{
if (selection.OfType<MaterialNodeView>().Any(v => v.node != null))
{

return ContextualMenu.MenuAction.StatusFlags.Hidden;
}
void ConvertToInlineNode(EventBase eventBase)
void ConvertToInlineNode()
{
var selectedNodeViews = selection.OfType<MaterialNodeView>()
.Select(x => x.node)

((AbstractMaterialGraph)propNode.owner).ReplacePropertyNodeWithConcreteNode(propNode);
}
ContextualMenu.MenuAction.StatusFlags ConvertToSubgraphStatus(EventBase eventBase)
ContextualMenu.MenuAction.StatusFlags ConvertToSubgraphStatus()
void ConvertToSubgraph(EventBase eventBase)
void ConvertToSubgraph()
{
onConvertToSubgraphClick();
}

return selection.OfType<BlackboardField>().Any();
}
#if UNITY_2018_1
public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
{
return EventPropagation.Continue;

{
return EventPropagation.Continue;
}
#else
public bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
{
return true;
}
public bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
{
return true;
}
bool IDropTarget.DragExited()
{
return true;
}
#endif
}
public static class GraphViewExtensions

9
com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs


public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
if (evt.target is Node)
evt.menu.AppendAction("Copy shader", ConvertToShader, ConvertToShaderStatus);
evt.menu.AppendAction("Copy shader", ConvertToShader, node.hasPreview ? ContextualMenu.MenuAction.StatusFlags.Normal : ContextualMenu.MenuAction.StatusFlags.Hidden);
ContextualMenu.MenuAction.StatusFlags ConvertToShaderStatus(EventBase eventBase)
{
return node.hasPreview ? ContextualMenu.MenuAction.StatusFlags.Normal : ContextualMenu.MenuAction.StatusFlags.Hidden;
}
void ConvertToShader(EventBase eventBase)
void ConvertToShader()
{
List<PropertyCollector.TextureInfo> textureInfo;
var masterNode = node as IMasterNode;

16
com.unity.shadergraph/Editor/Drawing/Views/ShaderPort.cs


{
sealed class ShaderPort : Port
{
#if UNITY_2018_1
: base(portOrientation, portDirection, type) { AddStyleSheetPath("Styles/ShaderPort"); }
: base(portOrientation, portDirection, type)
#else
ShaderPort(Orientation portOrientation, Direction portDirection, Capacity portCapacity, Type type)
: base(portOrientation, portDirection, portCapacity, type)
#endif
{
AddStyleSheetPath("Styles/ShaderPort");
}
var port = new ShaderPort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, null)
var port = new ShaderPort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output,
#if !UNITY_2018_1
slot.isInputSlot ? Capacity.Single : Capacity.Multi,
#endif
null)
{
m_EdgeConnector = new EdgeConnector<Edge>(connectorListener),
};

33
com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
#if UNITY_2018_1
using UnityEditor.Experimental.UIElements.GraphView;
#endif
namespace UnityEditor.ShaderGraph.Drawing
{
static class CompatibilityExtensions
{
#if UNITY_2018_1
public static void OpenTextEditor(this BlackboardField field)
{
field.RenameGo();
}
#endif
public static void AppendAction(this ContextualMenu contextualMenu, string actionName, Action action, Func<ContextualMenu.MenuAction.StatusFlags> actionStatusCallback)
{
Debug.Assert(action != null);
Debug.Assert(actionStatusCallback != null);
contextualMenu.AppendAction(actionName, e => action(), e => actionStatusCallback());
}
public static void AppendAction(this ContextualMenu contextualMenu, string actionName, Action action, ContextualMenu.MenuAction.StatusFlags statusFlags)
{
Debug.Assert(action != null);
contextualMenu.AppendAction(actionName, e => action(), e => statusFlags);
}
}
}

3
com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs.meta


fileFormatVersion: 2
guid: 7c1717b624ad45ccbb3fa6bec28af711
timeCreated: 1519741123

12
com.unity.shadergraph/Editor/Util/GraphTypeMapper.cs.meta


fileFormatVersion: 2
guid: efaba3c359b73408c9888998f9a4c87d
timeCreated: 1482407708
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
com.unity.shadergraph/Editor/Util/GraphTypeMapper.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
namespace UnityEditor.Graphing.Util
{
public class GraphTypeMapper : BaseTypeFactory<INode, GraphElement>
{
public GraphTypeMapper(Type fallbackType) : base(fallbackType)
{
}
protected override GraphElement InternalCreate(Type valueType)
{
return (GraphElement)Activator.CreateInstance(valueType);
}
}
}
正在加载...
取消
保存