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.

495 lines
18 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using UnityEngine.Networking;
  7. using System.Collections;
  8. namespace AmplifyShaderEditor
  9. {
  10. public class ASEStartScreen : EditorWindow
  11. {
  12. [MenuItem( "Window/Amplify Shader Editor/Start Screen", false, 1999 )]
  13. public static void Init()
  14. {
  15. ASEStartScreen window = (ASEStartScreen)GetWindow( typeof( ASEStartScreen ), true, "Amplify Shader Editor Start Screen" );
  16. window.minSize = new Vector2( 650, 500 );
  17. window.maxSize = new Vector2( 650, 500 );
  18. window.Show();
  19. }
  20. private static readonly string ChangeLogGUID = "580cccd3e608b7f4cac35ea46d62d429";
  21. private static readonly string ResourcesGUID = "c0a0a980c9ba86345bc15411db88d34f";
  22. private static readonly string BuiltInGUID = "e00e6f90ab8233e46a41c5e33917c642";
  23. private static readonly string UniversalGUID = "a9d68dd8913f05d4d9ce75e7b40c6044";
  24. private static readonly string HighDefinitionGUID = "d1c0b77896049554fa4b635531caf741";
  25. private static readonly string OLDHighDefinitionGUID = "dff05fea7446d7b4e9029bfab77455d2";
  26. private static readonly string LightWeightGUID = "6ecbfd0a046659943a69328c98ff0442";
  27. private static readonly string OLDLightWeightGUID = "f7c4e22642de60d448f4e4809190f7b1";
  28. private static readonly string IconGUID = "2c6536772776dd84f872779990273bfc";
  29. public static readonly string ChangelogURL = "http://amplify.pt/Banner/ASEchangelog.json";
  30. private static readonly string ManualURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual";
  31. private static readonly string BasicURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Basics";
  32. private static readonly string BeginnerURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Tutorials#Official_-_Beginner_Series";
  33. private static readonly string NodesURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Nodes";
  34. private static readonly string SRPURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Scriptable_Rendering_Pipeline";
  35. private static readonly string FunctionsURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Manual#Shader_Functions";
  36. private static readonly string TemplatesURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Templates";
  37. private static readonly string APIURL = "http://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/API";
  38. private static readonly string DiscordURL = "https://discordapp.com/invite/EdrVAP5";
  39. private static readonly string ForumURL = "https://forum.unity.com/threads/best-tool-asset-store-award-amplify-shader-editor-node-based-shader-creation-tool.430959/";
  40. private static readonly string SiteURL = "http://amplify.pt/download/";
  41. private static readonly string StoreURL = "https://assetstore.unity.com/packages/tools/visual-scripting/amplify-shader-editor-68570";
  42. private static readonly GUIContent SamplesTitle = new GUIContent( "Shader Samples", "Import samples according to you project rendering pipeline" );
  43. private static readonly GUIContent ResourcesTitle = new GUIContent( "Learning Resources", "Check the online wiki for various topics about how to use ASE with node examples and explanations" );
  44. private static readonly GUIContent CommunityTitle = new GUIContent( "Community", "Need help? Reach us through our discord server or the offitial support Unity forum" );
  45. private static readonly GUIContent UpdateTitle = new GUIContent( "Latest Update", "Check the lastest additions, improvements and bug fixes done to ASE" );
  46. private static readonly GUIContent ASETitle = new GUIContent( "Amplify Shader Editor", "Are you using the latest version? Now you know" );
  47. private static readonly string DownArrow = "\u25BC";
  48. #if UNITY_2019_3_OR_NEWER
  49. private int DownButtonSize = 22;
  50. #else
  51. private int DownButtonSize = 21;
  52. #endif
  53. Vector2 m_scrollPosition = Vector2.zero;
  54. Preferences.ShowOption m_startup = Preferences.ShowOption.Never;
  55. bool m_showLWRP = false;
  56. bool m_showHDRP = false;
  57. [NonSerialized]
  58. Texture packageIcon = null;
  59. [NonSerialized]
  60. Texture textIcon = null;
  61. [NonSerialized]
  62. Texture webIcon = null;
  63. GUIContent HDRPbutton = null;
  64. GUIContent HDRPOLDbutton = null;
  65. GUIContent URPbutton = null;
  66. GUIContent LWRPbutton = null;
  67. GUIContent LWRPOLDbutton = null;
  68. GUIContent BuiltInbutton = null;
  69. GUIContent Manualbutton = null;
  70. GUIContent Basicbutton = null;
  71. GUIContent Beginnerbutton = null;
  72. GUIContent Nodesbutton = null;
  73. GUIContent SRPusebutton = null;
  74. GUIContent Functionsbutton = null;
  75. GUIContent Templatesbutton = null;
  76. GUIContent APIbutton = null;
  77. GUIContent DiscordButton = null;
  78. GUIContent ForumButton = null;
  79. GUIContent ASEIcon = null;
  80. RenderTexture rt;
  81. [NonSerialized]
  82. GUIStyle m_buttonStyle = null;
  83. [NonSerialized]
  84. GUIStyle m_buttonLeftStyle = null;
  85. [NonSerialized]
  86. GUIStyle m_buttonRightStyle = null;
  87. [NonSerialized]
  88. GUIStyle m_minibuttonStyle = null;
  89. [NonSerialized]
  90. GUIStyle m_labelStyle = null;
  91. [NonSerialized]
  92. GUIStyle m_linkStyle = null;
  93. private ChangeLogInfo m_changeLog;
  94. private bool m_infoDownloaded = false;
  95. private string m_newVersion = string.Empty;
  96. private void OnEnable()
  97. {
  98. rt = new RenderTexture( 16, 16, 0 );
  99. rt.Create();
  100. m_startup = (Preferences.ShowOption)EditorPrefs.GetInt( Preferences.PrefStartUp, 0 );
  101. if( textIcon == null )
  102. {
  103. Texture icon = EditorGUIUtility.IconContent( "TextAsset Icon" ).image;
  104. var cache = RenderTexture.active;
  105. RenderTexture.active = rt;
  106. Graphics.Blit( icon, rt );
  107. RenderTexture.active = cache;
  108. textIcon = rt;
  109. Manualbutton = new GUIContent( " Manual", textIcon );
  110. Basicbutton = new GUIContent( " Basic use tutorials", textIcon );
  111. Beginnerbutton = new GUIContent( " Beginner Series", textIcon );
  112. Nodesbutton = new GUIContent( " Node List", textIcon );
  113. SRPusebutton = new GUIContent( " SRP HD/URP/LW use", textIcon );
  114. Functionsbutton = new GUIContent( " Shader Functions", textIcon );
  115. Templatesbutton = new GUIContent( " Shader Templates", textIcon );
  116. APIbutton = new GUIContent( " Node API", textIcon );
  117. }
  118. if( packageIcon == null )
  119. {
  120. packageIcon = EditorGUIUtility.IconContent( "BuildSettings.Editor.Small" ).image;
  121. HDRPbutton = new GUIContent( " HDRP Samples", packageIcon );
  122. HDRPOLDbutton = new GUIContent( " HDRP Samples 6.X.X", packageIcon );
  123. URPbutton = new GUIContent( " URP Samples", packageIcon );
  124. LWRPbutton = new GUIContent( " LWRP Samples 6.X.X", packageIcon );
  125. LWRPOLDbutton = new GUIContent( " LWRP Samples 3.X.X", packageIcon );
  126. BuiltInbutton = new GUIContent( " Built-In Samples", packageIcon );
  127. }
  128. if( webIcon == null )
  129. {
  130. webIcon = EditorGUIUtility.IconContent( "BuildSettings.Web.Small" ).image;
  131. DiscordButton = new GUIContent( " Discord", webIcon );
  132. ForumButton = new GUIContent( " Unity Forum", webIcon );
  133. }
  134. if( m_changeLog == null )
  135. {
  136. var changelog = AssetDatabase.LoadAssetAtPath<TextAsset>( AssetDatabase.GUIDToAssetPath( ChangeLogGUID ) );
  137. string lastUpdate = string.Empty;
  138. if(changelog != null )
  139. {
  140. lastUpdate = changelog.text.Substring( 0, changelog.text.IndexOf( "\nv", 50 ) );// + "\n...";
  141. lastUpdate = lastUpdate.Replace( " *", " \u25CB" );
  142. lastUpdate = lastUpdate.Replace( "* ", "\u2022 " );
  143. }
  144. m_changeLog = new ChangeLogInfo( VersionInfo.FullNumber, lastUpdate );
  145. }
  146. if( ASEIcon == null )
  147. {
  148. ASEIcon = new GUIContent( AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IconGUID ) ) );
  149. }
  150. }
  151. private void OnDisable()
  152. {
  153. if( rt != null )
  154. {
  155. rt.Release();
  156. DestroyImmediate( rt );
  157. }
  158. }
  159. public void OnGUI()
  160. {
  161. if( !m_infoDownloaded )
  162. {
  163. m_infoDownloaded = true;
  164. StartBackgroundTask( StartRequest( ChangelogURL, () =>
  165. {
  166. var temp = ChangeLogInfo.CreateFromJSON( www.downloadHandler.text );
  167. if( temp != null && temp.Version >= m_changeLog.Version )
  168. {
  169. m_changeLog = temp;
  170. }
  171. // improve this later
  172. int major = m_changeLog.Version / 10000;
  173. int minor = ( m_changeLog.Version / 1000 ) - major * 10;
  174. int release = ( m_changeLog.Version / 100 ) - major * 100 - minor * 10;
  175. int revision = ( ( m_changeLog.Version / 10 ) - major * 1000 - minor * 100 - release * 10 ) + ( m_changeLog.Version - major * 10000 - minor * 1000 - release * 100 );
  176. m_newVersion = major + "." + minor + "." + release + "r" + revision;
  177. Repaint();
  178. } ) );
  179. }
  180. if( m_buttonStyle == null )
  181. {
  182. m_buttonStyle = new GUIStyle( GUI.skin.button );
  183. m_buttonStyle.alignment = TextAnchor.MiddleLeft;
  184. }
  185. if( m_buttonLeftStyle == null )
  186. {
  187. m_buttonLeftStyle = new GUIStyle( "ButtonLeft" );
  188. m_buttonLeftStyle.alignment = TextAnchor.MiddleLeft;
  189. m_buttonLeftStyle.margin = m_buttonStyle.margin;
  190. m_buttonLeftStyle.margin.right = 0;
  191. }
  192. if( m_buttonRightStyle == null )
  193. {
  194. m_buttonRightStyle = new GUIStyle( "ButtonRight" );
  195. m_buttonRightStyle.alignment = TextAnchor.MiddleLeft;
  196. m_buttonRightStyle.margin = m_buttonStyle.margin;
  197. m_buttonRightStyle.margin.left = 0;
  198. }
  199. if( m_minibuttonStyle == null )
  200. {
  201. m_minibuttonStyle = new GUIStyle( "MiniButton" );
  202. m_minibuttonStyle.alignment = TextAnchor.MiddleLeft;
  203. m_minibuttonStyle.margin = m_buttonStyle.margin;
  204. m_minibuttonStyle.margin.left = 20;
  205. m_minibuttonStyle.normal.textColor = m_buttonStyle.normal.textColor;
  206. m_minibuttonStyle.hover.textColor = m_buttonStyle.hover.textColor;
  207. }
  208. if( m_labelStyle == null )
  209. {
  210. m_labelStyle = new GUIStyle( "BoldLabel" );
  211. m_labelStyle.margin = new RectOffset( 4, 4, 4, 4 );
  212. m_labelStyle.padding = new RectOffset( 2, 2, 2, 2 );
  213. m_labelStyle.fontSize = 13;
  214. }
  215. if( m_linkStyle == null )
  216. {
  217. var inv = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( "1004d06b4b28f5943abdf2313a22790a" ) ); // find a better solution for transparent buttons
  218. m_linkStyle = new GUIStyle();
  219. m_linkStyle.normal.textColor = new Color( 0.2980392f, 0.4901961f, 1f );
  220. m_linkStyle.hover.textColor = Color.white;
  221. m_linkStyle.active.textColor = Color.grey;
  222. m_linkStyle.margin.top = 3;
  223. m_linkStyle.margin.bottom = 2;
  224. m_linkStyle.hover.background = inv;
  225. m_linkStyle.active.background = inv;
  226. }
  227. EditorGUILayout.BeginHorizontal( GUIStyle.none, GUILayout.ExpandWidth( true ) );
  228. {
  229. // left column
  230. EditorGUILayout.BeginVertical( GUILayout.Width( 175 ) );
  231. {
  232. GUILayout.Label( SamplesTitle, m_labelStyle );
  233. EditorGUILayout.BeginHorizontal();
  234. if( GUILayout.Button( HDRPbutton, m_buttonLeftStyle ) )
  235. ImportSample( HDRPbutton.text, HighDefinitionGUID );
  236. if( GUILayout.Button( DownArrow, m_buttonRightStyle, GUILayout.Width( DownButtonSize ), GUILayout.Height( DownButtonSize ) ) )
  237. {
  238. m_showHDRP = !m_showHDRP;
  239. m_showLWRP = false;
  240. }
  241. EditorGUILayout.EndHorizontal();
  242. if( m_showHDRP )
  243. {
  244. if( GUILayout.Button( HDRPOLDbutton, m_minibuttonStyle ) )
  245. ImportSample( HDRPOLDbutton.text, OLDHighDefinitionGUID );
  246. }
  247. EditorGUILayout.BeginHorizontal();
  248. if( GUILayout.Button( URPbutton, m_buttonLeftStyle ) )
  249. ImportSample( URPbutton.text, UniversalGUID );
  250. if( GUILayout.Button( DownArrow, m_buttonRightStyle, GUILayout.Width( DownButtonSize ), GUILayout.Height( DownButtonSize ) ) )
  251. {
  252. m_showLWRP = !m_showLWRP;
  253. m_showHDRP = false;
  254. }
  255. EditorGUILayout.EndHorizontal();
  256. if( m_showLWRP )
  257. {
  258. EditorGUILayout.BeginVertical();
  259. if( GUILayout.Button( LWRPbutton, m_minibuttonStyle ) )
  260. ImportSample( LWRPbutton.text, LightWeightGUID );
  261. if( GUILayout.Button( LWRPOLDbutton, m_minibuttonStyle ) )
  262. ImportSample( LWRPOLDbutton.text, OLDLightWeightGUID );
  263. EditorGUILayout.EndVertical();
  264. }
  265. if( GUILayout.Button( BuiltInbutton, m_buttonStyle ) )
  266. ImportSample( BuiltInbutton.text, BuiltInGUID );
  267. GUILayout.Space( 10 );
  268. GUILayout.Label( ResourcesTitle, m_labelStyle );
  269. if( GUILayout.Button( Manualbutton, m_buttonStyle ) )
  270. Application.OpenURL( ManualURL );
  271. if( GUILayout.Button( Basicbutton, m_buttonStyle ) )
  272. Application.OpenURL( BasicURL );
  273. if( GUILayout.Button( Beginnerbutton, m_buttonStyle ) )
  274. Application.OpenURL( BeginnerURL );
  275. if( GUILayout.Button( Nodesbutton, m_buttonStyle ) )
  276. Application.OpenURL( NodesURL );
  277. if( GUILayout.Button( SRPusebutton, m_buttonStyle ) )
  278. Application.OpenURL( SRPURL );
  279. if( GUILayout.Button( Functionsbutton, m_buttonStyle ) )
  280. Application.OpenURL( FunctionsURL );
  281. if( GUILayout.Button( Templatesbutton, m_buttonStyle ) )
  282. Application.OpenURL( TemplatesURL );
  283. if( GUILayout.Button( APIbutton, m_buttonStyle ) )
  284. Application.OpenURL( APIURL );
  285. }
  286. EditorGUILayout.EndVertical();
  287. // right column
  288. EditorGUILayout.BeginVertical( GUILayout.Width( 650 - 175 - 9 ), GUILayout.ExpandHeight( true ) );
  289. {
  290. GUILayout.Label( CommunityTitle, m_labelStyle );
  291. EditorGUILayout.BeginHorizontal( GUILayout.ExpandWidth( true ) );
  292. {
  293. if( GUILayout.Button( DiscordButton, GUILayout.ExpandWidth( true ) ) )
  294. {
  295. Application.OpenURL( DiscordURL );
  296. }
  297. if( GUILayout.Button( ForumButton, GUILayout.ExpandWidth( true ) ) )
  298. {
  299. Application.OpenURL( ForumURL );
  300. }
  301. }
  302. EditorGUILayout.EndHorizontal();
  303. GUILayout.Label( UpdateTitle, m_labelStyle );
  304. m_scrollPosition = GUILayout.BeginScrollView( m_scrollPosition, "ProgressBarBack", GUILayout.ExpandHeight( true ), GUILayout.ExpandWidth( true ) );
  305. GUILayout.Label( m_changeLog.LastUpdate, "WordWrappedMiniLabel", GUILayout.ExpandHeight( true ) );
  306. GUILayout.EndScrollView();
  307. EditorGUILayout.BeginHorizontal( GUILayout.ExpandWidth( true ) );
  308. {
  309. EditorGUILayout.BeginVertical();
  310. GUILayout.Label( ASETitle, m_labelStyle );
  311. GUILayout.Label( "Installed Version: " + VersionInfo.StaticToString() );
  312. if( m_changeLog.Version > VersionInfo.FullNumber )
  313. {
  314. var cache = GUI.color;
  315. GUI.color = Color.red;
  316. GUILayout.Label( "New version available: " + m_newVersion, "BoldLabel" );
  317. GUI.color = cache;
  318. }
  319. else
  320. {
  321. var cache = GUI.color;
  322. GUI.color = Color.green;
  323. GUILayout.Label( "You are using the latest version", "BoldLabel" );
  324. GUI.color = cache;
  325. }
  326. EditorGUILayout.BeginHorizontal();
  327. GUILayout.Label( "Download links:" );
  328. if( GUILayout.Button( "Amplify", m_linkStyle ) )
  329. Application.OpenURL( SiteURL );
  330. GUILayout.Label( "-" );
  331. if( GUILayout.Button( "Asset Store", m_linkStyle ) )
  332. Application.OpenURL( StoreURL );
  333. EditorGUILayout.EndHorizontal();
  334. GUILayout.Space( 7 );
  335. EditorGUILayout.EndVertical();
  336. GUILayout.FlexibleSpace();
  337. EditorGUILayout.BeginVertical();
  338. GUILayout.Space( 7 );
  339. GUILayout.Label( ASEIcon );
  340. EditorGUILayout.EndVertical();
  341. }
  342. EditorGUILayout.EndHorizontal();
  343. }
  344. EditorGUILayout.EndVertical();
  345. }
  346. EditorGUILayout.EndHorizontal();
  347. EditorGUILayout.BeginHorizontal( "ProjectBrowserBottomBarBg", GUILayout.ExpandWidth( true ), GUILayout.Height(22) );
  348. {
  349. GUILayout.FlexibleSpace();
  350. EditorGUI.BeginChangeCheck();
  351. var cache = EditorGUIUtility.labelWidth;
  352. EditorGUIUtility.labelWidth = 100;
  353. m_startup = (Preferences.ShowOption)EditorGUILayout.EnumPopup( "Show At Startup", m_startup, GUILayout.Width( 220 ) );
  354. EditorGUIUtility.labelWidth = cache;
  355. if( EditorGUI.EndChangeCheck() )
  356. {
  357. EditorPrefs.SetInt( Preferences.PrefStartUp, (int)m_startup );
  358. }
  359. }
  360. EditorGUILayout.EndHorizontal();
  361. // Find a better way to update link buttons without repainting the window
  362. Repaint();
  363. }
  364. void ImportSample( string pipeline, string guid )
  365. {
  366. if( EditorUtility.DisplayDialog( "Import Sample", "This will import the samples for" + pipeline.Replace( " Samples", "" ) + ", please make sure the pipeline is properly installed and/or selected before importing the samples.\n\nContinue?", "Yes", "No" ) )
  367. {
  368. AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( ResourcesGUID ), false );
  369. AssetDatabase.ImportPackage( AssetDatabase.GUIDToAssetPath( guid ), false );
  370. }
  371. }
  372. UnityWebRequest www;
  373. IEnumerator StartRequest( string url, Action success = null )
  374. {
  375. using( www = UnityWebRequest.Get( url ) )
  376. {
  377. #if UNITY_2017_2_OR_NEWER
  378. yield return www.SendWebRequest();
  379. #else
  380. yield return www.Send();
  381. #endif
  382. while( www.isDone == false )
  383. yield return null;
  384. if( success != null )
  385. success();
  386. }
  387. }
  388. public static void StartBackgroundTask( IEnumerator update, Action end = null )
  389. {
  390. EditorApplication.CallbackFunction closureCallback = null;
  391. closureCallback = () =>
  392. {
  393. try
  394. {
  395. if( update.MoveNext() == false )
  396. {
  397. if( end != null )
  398. end();
  399. EditorApplication.update -= closureCallback;
  400. }
  401. }
  402. catch( Exception ex )
  403. {
  404. if( end != null )
  405. end();
  406. Debug.LogException( ex );
  407. EditorApplication.update -= closureCallback;
  408. }
  409. };
  410. EditorApplication.update += closureCallback;
  411. }
  412. }
  413. [Serializable]
  414. internal class ChangeLogInfo
  415. {
  416. public int Version;
  417. public string LastUpdate;
  418. public static ChangeLogInfo CreateFromJSON( string jsonString )
  419. {
  420. return JsonUtility.FromJson<ChangeLogInfo>( jsonString );
  421. }
  422. public ChangeLogInfo( int version, string lastUpdate )
  423. {
  424. Version = version;
  425. LastUpdate = lastUpdate;
  426. }
  427. }
  428. }