summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-23 13:08:43 +0800
committerchai <chaifix@163.com>2020-10-23 13:08:43 +0800
commitb82da95b5181ac8bbae38efb13e950d5e88a4caa (patch)
tree48a6f3269276484bbc7cfc95f0651f40a2176aa1 /Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs
parent917e9e0b320775634dc2e710f7deac74fd0822f0 (diff)
*移动amplify shader editor到third party目录
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs')
-rw-r--r--Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs107
1 files changed, 107 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs
new file mode 100644
index 00000000..e1de14b2
--- /dev/null
+++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateShaderModelModule.cs
@@ -0,0 +1,107 @@
+// Amplify Shader Editor - Visual Shader Editing Tool
+// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
+
+using System;
+using UnityEngine;
+using UnityEditor;
+
+namespace AmplifyShaderEditor
+{
+ [Serializable]
+ public sealed class TemplateShaderModelModule : TemplateModuleParent
+ {
+ private const string ShaderModelStr = "Shader Model";
+ private const string ShaderModelFormatStr = "#pragma target ";
+ private const string ShaderModelEncapsulateFormatStr = "CGINCLUDE\n#pragma target {0}\nENDCG";
+
+ [SerializeField]
+ private int m_shaderModelIdx = 2;
+
+ [SerializeField]
+ private bool m_encapsulateOnCGInlude = false;
+
+ public TemplateShaderModelModule() : base("Shader Model"){ }
+
+ public override void Draw( UndoParentNode owner, bool style = true )
+ {
+ EditorGUI.BeginChangeCheck();
+ m_shaderModelIdx = owner.EditorGUILayoutPopup( ShaderModelStr, m_shaderModelIdx, TemplateHelperFunctions.AvailableShaderModels );
+ if( EditorGUI.EndChangeCheck() )
+ {
+ m_isDirty = true;
+ }
+ }
+
+ public void CopyFrom( TemplateShaderModelModule other , bool allData )
+ {
+ if( allData )
+ {
+ m_independentModule = other.IndependentModule;
+ m_encapsulateOnCGInlude = other.EncapsulateOnCGInlude;
+ }
+
+ m_shaderModelIdx = other.CurrentShaderModelIdx;
+ }
+
+ public override void ReadFromString( ref uint index, ref string[] nodeParams )
+ {
+ bool validDataOnMeta = m_validData;
+ if( UIUtils.CurrentShaderVersion() > TemplatesManager.MPShaderVersion )
+ {
+ validDataOnMeta = Convert.ToBoolean( nodeParams[ index++ ] );
+ }
+
+ if( validDataOnMeta )
+ m_shaderModelIdx = Convert.ToInt32( nodeParams[ index++ ] );
+ }
+
+ public override void WriteToString( ref string nodeInfo )
+ {
+ IOUtils.AddFieldValueToString( ref nodeInfo, m_validData );
+ if( m_validData )
+ IOUtils.AddFieldValueToString( ref nodeInfo, m_shaderModelIdx );
+ }
+
+ public override string GenerateShaderData( bool isSubShader )
+ {
+ if( m_encapsulateOnCGInlude )
+ {
+ return string.Format( ShaderModelEncapsulateFormatStr, TemplateHelperFunctions.AvailableShaderModels[ m_shaderModelIdx ] );
+ }
+ else
+ {
+ return ShaderModelFormatStr + TemplateHelperFunctions.AvailableShaderModels[ m_shaderModelIdx ];
+ }
+ }
+
+ public void ConfigureFromTemplateData( TemplateShaderModelData data )
+ {
+ bool newValidData = ( data.DataCheck == TemplateDataCheck.Valid );
+
+ if( newValidData && m_validData != newValidData )
+ {
+ m_independentModule = data.IndependentModule;
+
+ if( TemplateHelperFunctions.ShaderModelToArrayIdx.ContainsKey( data.Value ) )
+ {
+ m_shaderModelIdx = TemplateHelperFunctions.ShaderModelToArrayIdx[ data.Value ];
+ }
+ m_encapsulateOnCGInlude = data.Encapsulate;
+ }
+
+ m_validData = newValidData;
+ }
+
+ public int CurrentShaderModelIdx { get { return m_shaderModelIdx; } }
+ public string CurrentShaderModel { get { return TemplateHelperFunctions.AvailableShaderModels[ m_shaderModelIdx ]; } }
+ public bool EncapsulateOnCGInlude { get { return m_encapsulateOnCGInlude; } }
+ public int InterpolatorAmount
+ {
+ get
+ {
+ return TemplateHelperFunctions.AvailableInterpolators[ TemplateHelperFunctions.AvailableShaderModels[ m_shaderModelIdx ] ];
+ }
+ }
+
+ }
+}