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 --- .../Editor/Templates/TemplateCodeSnippetBase.cs | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateCodeSnippetBase.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateCodeSnippetBase.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateCodeSnippetBase.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateCodeSnippetBase.cs new file mode 100644 index 00000000..ea717e62 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Templates/TemplateCodeSnippetBase.cs @@ -0,0 +1,102 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using System; +using UnityEngine; +using System.Collections.Generic; + +namespace AmplifyShaderEditor +{ + public enum TemplateCodeSnippetType + { + Toggle + }; + + + public enum TemplateCodeSnippetInfoIdx + { + Name = 0, + Type + }; + + [Serializable] + public class TemplateCodeSnippetElement + { + public string Id; + public string Snippet; + public TemplateCodeSnippetElement( string id, string snippet ) + { + Id = id; + Snippet = snippet; + } + } + + [Serializable] + public class TemplateCodeSnippetBase : ScriptableObject + { + [SerializeField] + private string m_nameId; + + [SerializeField] + private TemplateCodeSnippetType m_type; + + [SerializeField] + private List m_elements = new List(); + + public void Init( string nameId, TemplateCodeSnippetType type ) + { + m_nameId = nameId; + m_type = type; + } + + public void AddSnippet( TemplateCodeSnippetElement element ) + { + m_elements.Add( element ); + } + + public void Destroy() + { + for ( int i = 0; i < m_elements.Count; i++ ) + { + m_elements[ i ].Snippet = null; + } + m_elements.Clear(); + m_elements = null; + } + + public virtual void DrawProperties( ParentNode owner ) { } + public virtual bool CheckSnippet() { return true; } + + public void InsertSnippet( ref string shaderBody ) + { + bool insertSnippet = CheckSnippet(); + for ( int i = 0; i < m_elements.Count; i++ ) + { + shaderBody = shaderBody.Replace( m_elements[ i ].Id, ( insertSnippet ? m_elements[ i ].Snippet : string.Empty ) ); + } + } + public string NameId { get { return m_nameId; } } + public TemplateCodeSnippetType Type { get { return m_type; } } + public List Elements { get { return m_elements; } } + } + + [Serializable] + public class TemplateCodeSnippetToggle : TemplateCodeSnippetBase + { + private const string Label = "Activate"; + [SerializeField] + private bool m_value = false; + + + public override bool CheckSnippet() + { + return m_value; + } + + public override void DrawProperties( ParentNode owner ) + { + m_value = owner.EditorGUILayoutToggle( Label, m_value ); + } + } + +} -- cgit v1.1-26-g67d0