您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
107 行
3.0 KiB
107 行
3.0 KiB
using System.Linq;
|
|
using UnityEditor.Graphs;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEditor.MaterialGraph
|
|
{
|
|
public abstract class BaseMaterialGraph : Graph
|
|
{
|
|
private PreviewRenderUtility m_PreviewUtility;
|
|
|
|
public PreviewRenderUtility previewUtility
|
|
{
|
|
get
|
|
{
|
|
if (m_PreviewUtility == null)
|
|
{
|
|
m_PreviewUtility = new PreviewRenderUtility();
|
|
EditorUtility.SetCameraAnimateMaterials(m_PreviewUtility.m_Camera, true);
|
|
}
|
|
|
|
return m_PreviewUtility;
|
|
}
|
|
}
|
|
|
|
public bool requiresRepaint
|
|
{
|
|
get { return isAwake && nodes.Any(x => x is IRequiresTime); }
|
|
}
|
|
|
|
public override void RemoveEdge(Edge e)
|
|
{
|
|
base.RemoveEdge(e);
|
|
RevalidateGraph();
|
|
}
|
|
|
|
public void RemoveEdgeNoRevalidate(Edge e)
|
|
{
|
|
base.RemoveEdge(e);
|
|
}
|
|
|
|
public override Edge Connect(Slot fromSlot, Slot toSlot)
|
|
{
|
|
Slot outputSlot = null;
|
|
Slot inputSlot = null;
|
|
|
|
// output must connect to input
|
|
if (fromSlot.isOutputSlot)
|
|
outputSlot = fromSlot;
|
|
else if (fromSlot.isInputSlot)
|
|
inputSlot = fromSlot;
|
|
|
|
if (toSlot.isOutputSlot)
|
|
outputSlot = toSlot;
|
|
else if (toSlot.isInputSlot)
|
|
inputSlot = toSlot;
|
|
|
|
if (inputSlot == null || outputSlot == null)
|
|
return null;
|
|
|
|
// remove any inputs that exits before adding
|
|
foreach (var edge in inputSlot.edges.ToArray())
|
|
{
|
|
Debug.Log("Removing existing edge:" + edge);
|
|
// call base here as we DO NOT want to
|
|
// do expensive shader regeneration
|
|
base.RemoveEdge(edge);
|
|
}
|
|
|
|
var newEdge = base.Connect(outputSlot, inputSlot);
|
|
|
|
Debug.Log("Connected edge: " + newEdge);
|
|
var toNode = inputSlot.node as BaseMaterialNode;
|
|
var fromNode = outputSlot.node as BaseMaterialNode;
|
|
|
|
if (fromNode == null || toNode == null)
|
|
return newEdge;
|
|
|
|
RevalidateGraph();
|
|
return newEdge;
|
|
}
|
|
|
|
public virtual void RevalidateGraph()
|
|
{
|
|
var bmns = nodes.Where(x => x is BaseMaterialNode).Cast<BaseMaterialNode>().ToList();
|
|
|
|
foreach (var node in bmns)
|
|
node.InvalidateNode();
|
|
|
|
foreach (var node in bmns)
|
|
{
|
|
node.ValidateNode();
|
|
}
|
|
}
|
|
|
|
public override void AddNode(Node node)
|
|
{
|
|
base.AddNode(node);
|
|
AssetDatabase.AddObjectToAsset(node, this);
|
|
RevalidateGraph();
|
|
}
|
|
|
|
protected void AddMasterNodeNoAddToAsset(Node node)
|
|
{
|
|
base.AddNode(node);
|
|
}
|
|
}
|
|
}
|