Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.2 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. namespace AmplifyShaderEditor
  7. {
  8. public enum TemplateCodeSnippetType
  9. {
  10. Toggle
  11. };
  12. public enum TemplateCodeSnippetInfoIdx
  13. {
  14. Name = 0,
  15. Type
  16. };
  17. [Serializable]
  18. public class TemplateCodeSnippetElement
  19. {
  20. public string Id;
  21. public string Snippet;
  22. public TemplateCodeSnippetElement( string id, string snippet )
  23. {
  24. Id = id;
  25. Snippet = snippet;
  26. }
  27. }
  28. [Serializable]
  29. public class TemplateCodeSnippetBase : ScriptableObject
  30. {
  31. [SerializeField]
  32. private string m_nameId;
  33. [SerializeField]
  34. private TemplateCodeSnippetType m_type;
  35. [SerializeField]
  36. private List<TemplateCodeSnippetElement> m_elements = new List<TemplateCodeSnippetElement>();
  37. public void Init( string nameId, TemplateCodeSnippetType type )
  38. {
  39. m_nameId = nameId;
  40. m_type = type;
  41. }
  42. public void AddSnippet( TemplateCodeSnippetElement element )
  43. {
  44. m_elements.Add( element );
  45. }
  46. public void Destroy()
  47. {
  48. for ( int i = 0; i < m_elements.Count; i++ )
  49. {
  50. m_elements[ i ].Snippet = null;
  51. }
  52. m_elements.Clear();
  53. m_elements = null;
  54. }
  55. public virtual void DrawProperties( ParentNode owner ) { }
  56. public virtual bool CheckSnippet() { return true; }
  57. public void InsertSnippet( ref string shaderBody )
  58. {
  59. bool insertSnippet = CheckSnippet();
  60. for ( int i = 0; i < m_elements.Count; i++ )
  61. {
  62. shaderBody = shaderBody.Replace( m_elements[ i ].Id, ( insertSnippet ? m_elements[ i ].Snippet : string.Empty ) );
  63. }
  64. }
  65. public string NameId { get { return m_nameId; } }
  66. public TemplateCodeSnippetType Type { get { return m_type; } }
  67. public List<TemplateCodeSnippetElement> Elements { get { return m_elements; } }
  68. }
  69. [Serializable]
  70. public class TemplateCodeSnippetToggle : TemplateCodeSnippetBase
  71. {
  72. private const string Label = "Activate";
  73. [SerializeField]
  74. private bool m_value = false;
  75. public override bool CheckSnippet()
  76. {
  77. return m_value;
  78. }
  79. public override void DrawProperties( ParentNode owner )
  80. {
  81. m_value = owner.EditorGUILayoutToggle( Label, m_value );
  82. }
  83. }
  84. }