initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.Graphing
|
||||
{
|
||||
[Serializable]
|
||||
class Edge : IEdge, IComparable<Edge>
|
||||
{
|
||||
[SerializeField]
|
||||
private SlotReference m_OutputSlot;
|
||||
[SerializeField]
|
||||
private SlotReference m_InputSlot;
|
||||
|
||||
public Edge()
|
||||
{ }
|
||||
|
||||
public Edge(SlotReference outputSlot, SlotReference inputSlot)
|
||||
{
|
||||
m_OutputSlot = outputSlot;
|
||||
m_InputSlot = inputSlot;
|
||||
}
|
||||
|
||||
public SlotReference outputSlot
|
||||
{
|
||||
get { return m_OutputSlot; }
|
||||
}
|
||||
|
||||
public SlotReference inputSlot
|
||||
{
|
||||
get { return m_InputSlot; }
|
||||
}
|
||||
|
||||
protected bool Equals(Edge other)
|
||||
{
|
||||
return Equals(m_OutputSlot, other.m_OutputSlot) && Equals(m_InputSlot, other.m_InputSlot);
|
||||
}
|
||||
|
||||
public bool Equals(IEdge other)
|
||||
{
|
||||
return Equals(other as object);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((Edge)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// Can't make fields readonly due to Unity serialization
|
||||
return (m_OutputSlot.GetHashCode() * 397) ^ m_InputSlot.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo(Edge other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return 0;
|
||||
if (ReferenceEquals(null, other)) return 1;
|
||||
var outputSlotComparison = m_OutputSlot.CompareTo(other.m_OutputSlot);
|
||||
if (outputSlotComparison != 0) return outputSlotComparison;
|
||||
return m_InputSlot.CompareTo(other.m_InputSlot);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d35a1ba1f2dabea42ab1fc3d040eec81
|
||||
timeCreated: 1464264925
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,160 @@
|
|||
using System;
|
||||
using UnityEditor.Graphs;
|
||||
using UnityEditor.ShaderGraph;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.Graphing
|
||||
{
|
||||
class HandleUndoRedoAction : IGraphDataAction
|
||||
{
|
||||
void HandleGraphUndoRedo(GraphData graphData)
|
||||
{
|
||||
AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out HandleUndoRedoAction");
|
||||
AssertHelpers.IsNotNull(newGraphData, "NewGraphData is null while carrying out HandleUndoRedoAction");
|
||||
graphData?.ReplaceWith(newGraphData);
|
||||
}
|
||||
|
||||
public Action<GraphData> modifyGraphDataAction => HandleGraphUndoRedo;
|
||||
|
||||
public GraphData newGraphData { get; set; }
|
||||
}
|
||||
|
||||
class GraphObject : ScriptableObject, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
SerializationHelper.JSONSerializedElement m_SerializedGraph;
|
||||
|
||||
[SerializeField]
|
||||
int m_SerializedVersion;
|
||||
|
||||
[SerializeField]
|
||||
bool m_IsDirty;
|
||||
|
||||
[SerializeField]
|
||||
bool m_IsSubGraph;
|
||||
|
||||
[SerializeField]
|
||||
string m_AssetGuid;
|
||||
|
||||
internal string AssetGuid
|
||||
{
|
||||
get => m_AssetGuid;
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
GraphData m_Graph;
|
||||
|
||||
[NonSerialized]
|
||||
int m_DeserializedVersion;
|
||||
|
||||
public DataStore<GraphData> graphDataStore
|
||||
{
|
||||
get => m_DataStore;
|
||||
private set
|
||||
{
|
||||
if (m_DataStore != value && value != null)
|
||||
m_DataStore = value;
|
||||
}
|
||||
}
|
||||
|
||||
DataStore<GraphData> m_DataStore;
|
||||
|
||||
public GraphData graph
|
||||
{
|
||||
get { return m_Graph; }
|
||||
set
|
||||
{
|
||||
if (m_Graph != null)
|
||||
m_Graph.owner = null;
|
||||
m_Graph = value;
|
||||
graphDataStore = new DataStore<GraphData>(ReduceGraphDataAction, m_Graph);
|
||||
if (m_Graph != null)
|
||||
m_Graph.owner = this;
|
||||
}
|
||||
}
|
||||
|
||||
// this value stores whether an undo operation has been registered (which indicates a change has been made to the graph)
|
||||
// and is used to trigger the MaterialGraphEditWindow to update it's title
|
||||
public bool isDirty
|
||||
{
|
||||
get { return m_IsDirty; }
|
||||
set { m_IsDirty = value; }
|
||||
}
|
||||
|
||||
public virtual void RegisterCompleteObjectUndo(string actionName)
|
||||
{
|
||||
Undo.RegisterCompleteObjectUndo(this, actionName);
|
||||
m_SerializedVersion++;
|
||||
m_DeserializedVersion++;
|
||||
m_IsDirty = true;
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
var json = MultiJson.Serialize(graph);
|
||||
m_SerializedGraph = new SerializationHelper.JSONSerializedElement { JSONnodeData = json };
|
||||
m_IsSubGraph = graph.isSubGraph;
|
||||
m_AssetGuid = graph.assetGuid;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool wasUndoRedoPerformed => m_DeserializedVersion != m_SerializedVersion;
|
||||
|
||||
public void HandleUndoRedo()
|
||||
{
|
||||
Debug.Assert(wasUndoRedoPerformed);
|
||||
var deserializedGraph = DeserializeGraph();
|
||||
|
||||
var handleUndoRedoAction = new HandleUndoRedoAction();
|
||||
handleUndoRedoAction.newGraphData = deserializedGraph;
|
||||
graphDataStore.Dispatch(handleUndoRedoAction);
|
||||
}
|
||||
|
||||
GraphData DeserializeGraph()
|
||||
{
|
||||
var json = m_SerializedGraph.JSONnodeData;
|
||||
var deserializedGraph = new GraphData { isSubGraph = m_IsSubGraph, assetGuid = m_AssetGuid };
|
||||
MultiJson.Deserialize(deserializedGraph, json);
|
||||
m_DeserializedVersion = m_SerializedVersion;
|
||||
m_SerializedGraph = default;
|
||||
return deserializedGraph;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
graph.OnEnable();
|
||||
graph.ValidateGraph();
|
||||
}
|
||||
}
|
||||
|
||||
// This is a very simple reducer, all it does is take the action and apply it to the graph data, which causes some mutation in state
|
||||
// This isn't strictly redux anymore but its needed given that our state tree is quite large and we don't want to be creating copies of it everywhere by unboxing
|
||||
void ReduceGraphDataAction(GraphData initialState, IGraphDataAction graphDataAction)
|
||||
{
|
||||
graphDataAction.modifyGraphDataAction(initialState);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (graph == null && m_SerializedGraph.JSONnodeData != null)
|
||||
{
|
||||
graph = DeserializeGraph();
|
||||
}
|
||||
Validate();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
graph?.OnDisable();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 463ff292c8554dc18fb52fb725707a21
|
||||
timeCreated: 1508144011
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
class HasDependenciesAttribute : Attribute
|
||||
{
|
||||
public HasDependenciesAttribute(Type minimalType)
|
||||
{
|
||||
this.minimalType = minimalType;
|
||||
}
|
||||
|
||||
public Type minimalType { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f1daf78dc4be7634f9d1b8a5115e8730
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
interface IHasDependencies
|
||||
{
|
||||
void GetSourceAssetDependencies(AssetCollection assetCollection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e66d88e09e6cd6648944e3ee0e997f62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5721d495a5354c4a96da57b12f43adb
|
||||
timeCreated: 1464264925
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
namespace UnityEditor.Graphing
|
||||
{
|
||||
enum SlotType
|
||||
{
|
||||
Input,
|
||||
Output
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c465ac18d51260d41999717f8c47770f
|
||||
timeCreated: 1464264925
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue