浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
MingWai
8 年前
当前提交
bdfd3b5f
共有 8 个文件被更改,包括 217 次插入 和 22 次删除
-
2MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
26MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs.meta
-
136MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
class SamplerAssetControlPresenter : GraphControlPresenter |
|||
{ |
|||
private string[] m_TextureTypeNames; |
|||
private string[] textureTypeNames |
|||
{ |
|||
get |
|||
{ |
|||
if (m_TextureTypeNames == null) |
|||
m_TextureTypeNames = Enum.GetNames(typeof(TextureType)); |
|||
return m_TextureTypeNames; |
|||
} |
|||
} |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var tNode = node as UnityEngine.MaterialGraph.SamplerAssetNode; |
|||
if (tNode == null) |
|||
return; |
|||
|
|||
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState); |
|||
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture; |
|||
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup); |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class SamplerAssetNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<SamplerAssetControlPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ec47786947b3100438fbe355a2a23000 |
|||
timeCreated: 1495754404 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Texture/Sampler Asset")] |
|||
public class SamplerAssetNode : PropertyNode |
|||
{ |
|||
|
|||
protected const string kOutputSlotRGBAName = "Sampler2D"; |
|||
|
|||
public const int OutputID = 0; |
|||
|
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return false; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture defaultTexture {get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
|
|||
|
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public SamplerAssetNode() |
|||
{ |
|||
name = "SamplerAsset"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(OutputID, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { OutputID }; } |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture; } } |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bc508c398f312644bb3c00c6ad160133 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
撰写
预览
正在加载...
取消
保存
Reference in new issue