From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs new file mode 100644 index 00000000..6dd1b8d3 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Vertex/ObjectScaleNode.cs @@ -0,0 +1,75 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using System; +using UnityEngine; +using UnityEditor; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Object Scale", "Vertex Data", "Object Scale extracted directly from its transform matrix" )] + public class ObjectScaleNode : ParentNode + { + private const string RotationIndependentScaleStr = "Rotation Independent Scale"; + + [SerializeField] + private bool m_rotationIndependentScale = false; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" ); + m_drawPreviewAsSphere = true; + m_previewShaderGUID = "5540033c6c52f51468938c1a42bd2730"; + m_textLabelWidth = 180; + UpdateMaterialPass(); + m_autoWrapProperties = true; + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_rotationIndependentScale = EditorGUILayoutToggle( RotationIndependentScaleStr, m_rotationIndependentScale ); + if( EditorGUI.EndChangeCheck() ) + { + UpdateMaterialPass(); + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string objectScale = m_rotationIndependentScale ? GeneratorUtils.GenerateRotationIndependentObjectScale( ref dataCollector, UniqueId ): + GeneratorUtils.GenerateObjectScale( ref dataCollector, UniqueId ); + + return GetOutputVectorItem( 0, outputId, objectScale ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 17402 ) + { + m_rotationIndependentScale = false; + } + else + { + m_rotationIndependentScale = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + UpdateMaterialPass(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_rotationIndependentScale ); + } + + void UpdateMaterialPass() + { + m_previewMaterialPassId = m_rotationIndependentScale ? 1 : 0; + PreviewIsDirty = true; + } + + } +} -- cgit v1.1-26-g67d0