浏览代码

Merge branch 'master' into HDMaster

/main
Tim Cooper 7 年前
当前提交
e3bd536c
共有 7 个文件被更改,包括 79 次插入8 次删除
  1. 3
      .gitignore
  2. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/SubGraphNode.cs
  4. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  5. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  6. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/package.json

3
.gitignore


MaterialGraphProject/Packages/*
MaterialGraphProject/GeneratedShader.shader
MaterialGraphProject/UberShader.shader
!MaterialGraphProject/Packages/manifest.json
!MaterialGraphProject/Packages/manifest.json
.npmrc

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;

if (m_Properties.Contains(property))
return;
property.displayName = property.displayName.Trim();
if (m_Properties.Any(p => p.displayName == property.displayName))
{
var regex = new Regex(@"^" + Regex.Escape(property.displayName) + @" \((\d+)\)$");
var existingDuplicateNumbers = m_Properties.Select(p => regex.Match(p.displayName)).Where(m => m.Success).Select(m => int.Parse(m.Groups[1].Value)).Where(n => n > 0).ToList();
var duplicateNumber = 1;
existingDuplicateNumbers.Sort();
if (existingDuplicateNumbers.Any() && existingDuplicateNumbers.First() == 1)
{
duplicateNumber = existingDuplicateNumbers.Last() + 1;
for (var i = 1; i < existingDuplicateNumbers.Count; i++)
{
if (existingDuplicateNumbers[i - 1] != existingDuplicateNumbers[i] - 1)
{
duplicateNumber = existingDuplicateNumbers[i - 1] + 1;
break;
}
}
}
property.displayName = string.Format("{0} ({1})", property.displayName, duplicateNumber);
}
m_Properties.Add(property);
m_AddedProperties.Add(property);

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/SubGraphNode.cs


}
#if UNITY_EDITOR
[ObjectControl("")]
public MaterialSubGraphAsset subGraphAsset
{
get

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


if (prop != null)
{
var materialGraph = (AbstractMaterialGraph)graphObject.graph;
var fromPropertyNode = fromNode as PropertyNode;
var fromProperty = fromPropertyNode != null ? materialGraph.properties.FirstOrDefault(p => p.guid == fromPropertyNode.propertyGuid) : null;
prop.displayName = fromProperty != null ? fromProperty.displayName : fromNode.name;
subGraph.AddShaderProperty(prop);
var propNode = new PropertyNode();
{

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


using UnityEngine.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using Node = UnityEditor.Experimental.UIElements.GraphView.Node;
namespace UnityEditor.ShaderGraph.Drawing
{

AddSlots(node.GetSlots<MaterialSlot>());
expanded = node.drawState.expanded;
RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here
UpdateSlotAttachers();
UpdatePortInputVisibilities();
SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

UpdateTitle();
if (node.hasPreview)
UpdatePreviewExpandedState(node.previewExpanded);
expanded = node.drawState.expanded;
base.expanded = node.drawState.expanded;
// Update slots to match node modification
if (scope == ModificationScope.Topological)
{

outputContainer.Sort((x, y) => slots.IndexOf(x.userData as MaterialSlot) - slots.IndexOf(y.userData as MaterialSlot));
}
UpdateControls();
RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here
UpdateSlotAttachers();
UpdatePortInputVisibilities();
foreach (var control in m_ControlViews)

port.visualClass = slot.concreteValueType.ToClassName();
if (slot.isOutputSlot)
{
}
inputContainer.Add(port);
}
}
void UpdateSlotAttachers()
{
foreach (var port in inputContainer.OfType<Port>())
{
if (!m_Attachers.Any(a => a.target == port))
inputContainer.Add(port);
var portInputView = new PortInputView(slot);
var portInputView = new PortInputView((MaterialSlot)port.userData);
Add(portInputView);
mainContainer.BringToFront();
m_Attachers.Add(new Attacher(portInputView, port, SpriteAlignment.LeftCenter) { distance = -8f });

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs


using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
[ScriptedImporter(1, "shadergraph")]
[ScriptedImporter(1, ShaderGraphImporter.ShaderGraphExtension)]
public const string ShaderGraphExtension = "shadergraph";
private string errorShader = @"
Shader ""Hidden/GraphErrorShader2""
{

return null;
}
}
class ShaderGraphAssetPostProcessor : AssetPostprocessor
{
static void RegisterShaders(string[] paths)
{
foreach (var path in paths)
{
if (!path.EndsWith(ShaderGraphImporter.ShaderGraphExtension, StringComparison.InvariantCultureIgnoreCase))
continue;
var mainObj = AssetDatabase.LoadMainAssetAtPath(path);
if (mainObj is Shader)
ShaderUtil.RegisterShader((Shader)mainObj);
var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
foreach (var obj in objs)
{
if (obj is Shader)
ShaderUtil.RegisterShader((Shader)obj);
}
}
}
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
RegisterShaders(importedAssets);
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/package.json


{
"name": "com.unity.shadergraph",
"description": "Shader Graph",
"version": "0.1.6",
"version": "0.1.7",
"unity": "2018.1",
"dependencies": {
}
正在加载...
取消
保存