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.

69 lines
1.7 KiB

  1. using UnityEngine;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace AmplifyShaderEditor
  5. {
  6. [Serializable]
  7. public class TemplateOptionsDefinesContainer
  8. {
  9. [SerializeField]
  10. private List<PropertyDataCollector> m_definesList = new List<PropertyDataCollector>();
  11. [NonSerialized]
  12. private Dictionary<string, PropertyDataCollector> m_definesDict = new Dictionary<string, PropertyDataCollector>();
  13. void Refresh()
  14. {
  15. if( m_definesDict.Count != m_definesList.Count )
  16. {
  17. m_definesDict.Clear();
  18. for( int i = 0; i < m_definesList.Count; i++ )
  19. {
  20. m_definesDict.Add( m_definesList[ i ].PropertyName, m_definesList[ i ] );
  21. }
  22. }
  23. }
  24. public void RemoveTemporaries()
  25. {
  26. List<PropertyDataCollector> temporaries = m_definesList.FindAll( ( x ) => ( x.NodeId == 1 ) );
  27. for( int i = 0; i < temporaries.Count; i++ )
  28. {
  29. m_definesList.Remove( temporaries[ i ] );
  30. m_definesDict.Remove( temporaries[ i ].PropertyName );
  31. }
  32. }
  33. public void AddDefine( string define , bool temporary )
  34. {
  35. Refresh();
  36. if( !m_definesDict.ContainsKey( define ) )
  37. {
  38. int nodeId = temporary ? 1 : 0;
  39. PropertyDataCollector data = new PropertyDataCollector( nodeId, define );
  40. m_definesDict.Add( define, data );
  41. m_definesList.Add( data );
  42. }
  43. }
  44. public void RemoveDefine( string define )
  45. {
  46. Refresh();
  47. if( m_definesDict.ContainsKey( define ) )
  48. {
  49. m_definesList.Remove( m_definesDict[define] );
  50. m_definesDict.Remove( define );
  51. }
  52. }
  53. public void Destroy()
  54. {
  55. m_definesDict.Clear();
  56. m_definesDict = null;
  57. m_definesList.Clear();
  58. m_definesList = null;
  59. }
  60. public List<PropertyDataCollector> DefinesList { get { return m_definesList; } }
  61. }
  62. }