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.

91 lines
3.1 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. using System;
  6. using UnityEngine;
  7. namespace AmplifyShaderEditor
  8. {
  9. [Serializable]
  10. public class ShaderLibrary : EditorWindow
  11. {
  12. private const string SHADER_LIB_FILE = "/AmplifyShaderEditor/Resources/ShaderLibrary/ShaderLibrary.txt";
  13. private bool m_init = false;
  14. private Vector2 m_scrollPos = new Vector2();
  15. [SerializeField]
  16. private List<string> m_shaders = new List<string>();
  17. void Init()
  18. {
  19. m_init = true;
  20. string list = IOUtils.LoadTextFileFromDisk( Application.dataPath + SHADER_LIB_FILE );
  21. if ( String.IsNullOrEmpty( list ) )
  22. return;
  23. string[] listArr = list.Split( IOUtils.FIELD_SEPARATOR );
  24. for ( int i = 0; i < listArr.Length; i++ )
  25. {
  26. m_shaders.Add( listArr[ i ] );
  27. }
  28. UIUtils.MainSkin.customStyles[ 10 ].active.background = Texture2D.whiteTexture;
  29. UIUtils.MainSkin.customStyles[ 6 ].fixedHeight = UIUtils.MainSkin.customStyles[ 6 ].normal.background.height;
  30. UIUtils.MainSkin.customStyles[ 6 ].fixedWidth = UIUtils.MainSkin.customStyles[ 6 ].normal.background.width;
  31. UIUtils.MainSkin.customStyles[ 7 ].fixedHeight = UIUtils.MainSkin.customStyles[ 7 ].normal.background.height;
  32. UIUtils.MainSkin.customStyles[ 7 ].fixedWidth = UIUtils.MainSkin.customStyles[ 7 ].normal.background.width;
  33. UIUtils.MainSkin.customStyles[ 8 ].fixedHeight = UIUtils.MainSkin.customStyles[ 8 ].normal.background.height;
  34. UIUtils.MainSkin.customStyles[ 8 ].fixedWidth = UIUtils.MainSkin.customStyles[ 8 ].normal.background.width;
  35. UIUtils.MainSkin.customStyles[ 9 ].fixedHeight = UIUtils.MainSkin.customStyles[ 9 ].normal.background.height;
  36. UIUtils.MainSkin.customStyles[ 9 ].fixedWidth = UIUtils.MainSkin.customStyles[ 9 ].normal.background.width;
  37. }
  38. void OnGUI()
  39. {
  40. if ( !m_init )
  41. {
  42. Init();
  43. }
  44. Rect availableArea = position;
  45. availableArea.y = 100f;
  46. availableArea.x = 0.05f * availableArea.width;
  47. availableArea.height *= 0.5f;
  48. availableArea.width *= 0.9f;
  49. EditorGUILayout.BeginVertical();
  50. {
  51. EditorGUILayout.LabelField( "Shader Library", UIUtils.MainSkin.customStyles[ 5 ] );
  52. GUILayout.Space( 10 );
  53. EditorGUILayout.BeginHorizontal();
  54. {
  55. GUILayout.Space( 0.05f * position.width );
  56. GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 8 ] );
  57. GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 9 ] );
  58. GUILayout.Space( 0.8f*position.width );
  59. GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 7 ] );
  60. GUILayout.Button( string.Empty, UIUtils.MainSkin.customStyles[ 6 ] );
  61. }
  62. EditorGUILayout.EndHorizontal();
  63. GUILayout.BeginArea( availableArea );
  64. m_scrollPos = EditorGUILayout.BeginScrollView( m_scrollPos, UIUtils.MainSkin.box );
  65. {
  66. for ( int i = 0; i < m_shaders.Count; i++ )
  67. {
  68. GUILayout.Button( m_shaders[ i ], UIUtils.MainSkin.customStyles[ 10 ] );
  69. }
  70. }
  71. EditorGUILayout.EndScrollView();
  72. GUILayout.EndArea();
  73. }
  74. EditorGUILayout.EndVertical();
  75. }
  76. }
  77. }