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.

692 lines
28 KiB

  1. using UnityEditor;
  2. using UnityEngine;
  3. using System;
  4. namespace AmplifyShaderEditor
  5. {
  6. [Serializable]
  7. public class UndoParentNode : ScriptableObject
  8. {
  9. private const string MessageFormat = "Changing value {0} on node {1}";
  10. [SerializeField]
  11. protected NodeAttributes m_nodeAttribs;
  12. [SerializeField]
  13. protected ParentGraph m_containerGraph;
  14. public void UndoRecordObject( string name )
  15. {
  16. UIUtils.MarkUndoAction();
  17. Undo.RegisterCompleteObjectUndo( UIUtils.CurrentWindow, name );
  18. Undo.RecordObject( this, name );
  19. }
  20. public virtual void RecordObject( string Id )
  21. {
  22. Undo.RecordObject( this, Id );
  23. }
  24. public virtual void RecordObjectOnDestroy( string Id )
  25. {
  26. Undo.RecordObject( this, Id );
  27. }
  28. public string EditorGUILayoutStringField( string name, string value, params GUILayoutOption[] options )
  29. {
  30. string newValue = EditorGUILayout.TextField( name, value, options );
  31. if( !newValue.Equals( value ) )
  32. {
  33. UndoRecordObject( string.Format( MessageFormat, "EditorGUILayoutStringField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  34. }
  35. return newValue;
  36. }
  37. public string EditorGUILayoutTextField( GUIContent label, string text, params GUILayoutOption[] options )
  38. {
  39. string newValue = EditorGUILayout.TextField( label, text, options );
  40. if( !text.Equals( newValue ) )
  41. {
  42. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  43. }
  44. return newValue;
  45. }
  46. public string EditorGUILayoutTextField( string label, string text, params GUILayoutOption[] options )
  47. {
  48. string newValue = EditorGUILayout.TextField( label, text, options );
  49. if( !text.Equals( newValue ) )
  50. {
  51. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  52. }
  53. return newValue;
  54. }
  55. public Enum EditorGUILayoutEnumPopup( GUIContent label, Enum selected, params GUILayoutOption[] options )
  56. {
  57. Enum newValue = EditorGUILayout.EnumPopup( label, selected, options );
  58. if( !newValue.ToString().Equals( selected.ToString() ) )
  59. {
  60. UndoRecordObject( string.Concat( "Changing value ", label, " on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  61. //UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  62. }
  63. return newValue;
  64. }
  65. public Enum EditorGUILayoutEnumPopup( string label, Enum selected, params GUILayoutOption[] options )
  66. {
  67. Enum newValue = EditorGUILayout.EnumPopup( label, selected, options );
  68. if( !newValue.ToString().Equals( selected.ToString() ) )
  69. {
  70. UndoRecordObject( string.Concat( "Changing value ", label, " on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  71. //UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  72. }
  73. return newValue;
  74. }
  75. public Enum EditorGUILayoutEnumPopup( Enum selected, params GUILayoutOption[] options )
  76. {
  77. Enum newValue = EditorGUILayout.EnumPopup( selected, options );
  78. if( !newValue.ToString().Equals( selected.ToString() ) )
  79. {
  80. UndoRecordObject( string.Concat( "Changing value EditorGUILayoutEnumPopup on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  81. //UndoRecordObject(string.Format( MessageFormat, "EditorGUILayoutEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  82. }
  83. return newValue;
  84. }
  85. public int EditorGUILayoutIntPopup( string label, int selectedValue, string[] displayedOptions, int[] optionValues, params GUILayoutOption[] options )
  86. {
  87. int newValue = EditorGUILayout.IntPopup( label, selectedValue, displayedOptions, optionValues, options );
  88. if( newValue != selectedValue )
  89. {
  90. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  91. }
  92. return newValue;
  93. }
  94. public int EditorGUILayoutPopup( string label, int selectedIndex, string[] displayedOptions, GUIStyle style, params GUILayoutOption[] options )
  95. {
  96. int newValue = EditorGUILayout.Popup( label, selectedIndex, displayedOptions, style, options );
  97. if( newValue != selectedIndex )
  98. {
  99. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  100. }
  101. return newValue;
  102. }
  103. public int EditorGUILayoutPopup( GUIContent label, int selectedIndex, GUIContent[] displayedOptions, params GUILayoutOption[] options )
  104. {
  105. int newValue = EditorGUILayout.Popup( label, selectedIndex, displayedOptions, options );
  106. if( newValue != selectedIndex )
  107. {
  108. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  109. }
  110. return newValue;
  111. }
  112. public int EditorGUILayoutPopup( GUIContent label, int selectedIndex, GUIContent[] displayedOptions, GUIStyle style, params GUILayoutOption[] options )
  113. {
  114. int newValue = EditorGUILayout.Popup( label, selectedIndex, displayedOptions, style, options );
  115. if( newValue != selectedIndex )
  116. {
  117. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  118. }
  119. return newValue;
  120. }
  121. public int EditorGUILayoutPopup( int selectedIndex, string[] displayedOptions, params GUILayoutOption[] options )
  122. {
  123. int newValue = EditorGUILayout.Popup( selectedIndex, displayedOptions, options );
  124. if( newValue != selectedIndex )
  125. {
  126. UndoRecordObject( string.Format( MessageFormat, "EditorGUILayoutPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  127. }
  128. return newValue;
  129. }
  130. public int EditorGUILayoutPopup( string label, int selectedIndex, string[] displayedOptions, params GUILayoutOption[] options )
  131. {
  132. int newValue = EditorGUILayout.Popup( label, selectedIndex, displayedOptions, options );
  133. if( newValue != selectedIndex )
  134. {
  135. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  136. }
  137. return newValue;
  138. }
  139. public bool EditorGUILayoutToggle( GUIContent label, bool value, params GUILayoutOption[] options )
  140. {
  141. bool newValue = EditorGUILayout.Toggle( label, value, options );
  142. if( newValue != value )
  143. {
  144. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  145. }
  146. return newValue;
  147. }
  148. public bool EditorGUILayoutToggle( string label, bool value, params GUILayoutOption[] options )
  149. {
  150. bool newValue = EditorGUILayout.Toggle( label, value, options );
  151. if( newValue != value )
  152. {
  153. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  154. }
  155. return newValue;
  156. }
  157. public bool EditorGUILayoutToggle( string label, bool value, GUIStyle style, params GUILayoutOption[] options )
  158. {
  159. bool newValue = EditorGUILayout.Toggle( label, value, style, options );
  160. if( newValue != value )
  161. {
  162. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  163. }
  164. return newValue;
  165. }
  166. public int EditorGUILayoutIntField( int value, params GUILayoutOption[] options )
  167. {
  168. int newValue = EditorGUILayout.IntField( value, options );
  169. if( newValue != value )
  170. {
  171. UndoRecordObject( string.Format( MessageFormat, "EditorGUILayoutIntField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  172. }
  173. return newValue;
  174. }
  175. public int EditorGUILayoutIntField( GUIContent label, int value, params GUILayoutOption[] options )
  176. {
  177. int newValue = EditorGUILayout.IntField( label, value, options );
  178. if( newValue != value )
  179. {
  180. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  181. }
  182. return newValue;
  183. }
  184. public int EditorGUILayoutIntField( string label, int value, params GUILayoutOption[] options )
  185. {
  186. int newValue = EditorGUILayout.IntField( label, value, options );
  187. if( newValue != value )
  188. {
  189. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  190. }
  191. return newValue;
  192. }
  193. public float EditorGUILayoutFloatField( GUIContent label, float value, params GUILayoutOption[] options )
  194. {
  195. float newValue = EditorGUILayout.FloatField( label, value, options );
  196. if( newValue != value )
  197. {
  198. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  199. }
  200. return newValue;
  201. }
  202. public float EditorGUILayoutFloatField( string label, float value, params GUILayoutOption[] options )
  203. {
  204. float newValue = EditorGUILayout.FloatField( label, value, options );
  205. if( newValue != value )
  206. {
  207. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  208. }
  209. return newValue;
  210. }
  211. public float EditorGUILayoutRangedFloatField( string label, float value, float min, float max, params GUILayoutOption[] options )
  212. {
  213. float newValue = Mathf.Clamp( EditorGUILayout.FloatField( label, value, options ), min, max );
  214. if( newValue != value )
  215. {
  216. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  217. }
  218. return newValue;
  219. }
  220. public Color EditorGUILayoutColorField( string label, Color value, params GUILayoutOption[] options )
  221. {
  222. Color newValue = EditorGUILayout.ColorField( label, value, options );
  223. if( newValue != value )
  224. {
  225. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  226. }
  227. return newValue;
  228. }
  229. #if UNITY_2018_1_OR_NEWER
  230. public Color EditorGUILayoutColorField( GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, params GUILayoutOption[] options )
  231. {
  232. Color newValue = EditorGUILayout.ColorField( label, value, showEyedropper, showAlpha, hdr, options );
  233. if( newValue != value )
  234. {
  235. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  236. }
  237. return newValue;
  238. }
  239. #else
  240. public Color EditorGUILayoutColorField( GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig, params GUILayoutOption[] options )
  241. {
  242. Color newValue = EditorGUILayout.ColorField( label, value, showEyedropper, showAlpha, hdr, hdrConfig, options );
  243. if( newValue != value )
  244. {
  245. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  246. }
  247. return newValue;
  248. }
  249. #endif
  250. public float EditorGUILayoutSlider( string label, float value, float leftValue, float rightValue, params GUILayoutOption[] options )
  251. {
  252. float newValue = EditorGUILayout.Slider( label, value, leftValue, rightValue, options );
  253. if( newValue != value )
  254. {
  255. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  256. }
  257. return newValue;
  258. }
  259. public float EditorGUILayoutSlider( GUIContent label, float value, float leftValue, float rightValue, params GUILayoutOption[] options )
  260. {
  261. float newValue = EditorGUILayout.Slider( label, value, leftValue, rightValue, options );
  262. if( newValue != value )
  263. {
  264. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  265. }
  266. return newValue;
  267. }
  268. public UnityEngine.Object EditorGUILayoutObjectField( string label, UnityEngine.Object obj, System.Type objType, bool allowSceneObjects, params GUILayoutOption[] options )
  269. {
  270. UnityEngine.Object newValue = EditorGUILayout.ObjectField( label, obj, objType, allowSceneObjects, options );
  271. if( newValue != obj )
  272. {
  273. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  274. }
  275. return newValue;
  276. }
  277. public Vector2 EditorGUIVector2Field( Rect position, string label, Vector2 value )
  278. {
  279. Vector2 newValue = EditorGUI.Vector2Field( position, label, value );
  280. if( newValue != value )
  281. {
  282. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  283. }
  284. return newValue;
  285. }
  286. public Vector2 EditorGUILayoutVector2Field( string label, Vector2 value, params GUILayoutOption[] options )
  287. {
  288. Vector2 newValue = EditorGUILayout.Vector2Field( label, value, options );
  289. if( newValue != value )
  290. {
  291. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  292. }
  293. return newValue;
  294. }
  295. public Vector3 EditorGUIVector3Field( Rect position, string label, Vector3 value )
  296. {
  297. Vector3 newValue = EditorGUI.Vector3Field( position, label, value );
  298. if( newValue != value )
  299. {
  300. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  301. }
  302. return newValue;
  303. }
  304. public Vector3 EditorGUILayoutVector3Field( string label, Vector3 value, params GUILayoutOption[] options )
  305. {
  306. Vector3 newValue = EditorGUILayout.Vector3Field( label, value, options );
  307. if( newValue != value )
  308. {
  309. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  310. }
  311. return newValue;
  312. }
  313. public Vector4 EditorGUIVector4Field( Rect position, string label, Vector4 value )
  314. {
  315. Vector4 newValue = EditorGUI.Vector4Field( position, label, value );
  316. if( newValue != value )
  317. {
  318. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  319. }
  320. return newValue;
  321. }
  322. public Vector4 EditorGUILayoutVector4Field( string label, Vector4 value, params GUILayoutOption[] options )
  323. {
  324. Vector4 newValue = EditorGUILayout.Vector4Field( label, value, options );
  325. if( newValue != value )
  326. {
  327. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  328. }
  329. return newValue;
  330. }
  331. public int EditorGUILayoutIntSlider( GUIContent label, int value, int leftValue, int rightValue, params GUILayoutOption[] options )
  332. {
  333. int newValue = EditorGUILayout.IntSlider( label, value, leftValue, rightValue, options );
  334. if( newValue != value )
  335. {
  336. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  337. }
  338. return newValue;
  339. }
  340. public int EditorGUILayoutIntSlider( string label, int value, int leftValue, int rightValue, params GUILayoutOption[] options )
  341. {
  342. int newValue = EditorGUILayout.IntSlider( label, value, leftValue, rightValue, options );
  343. if( newValue != value )
  344. {
  345. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  346. }
  347. return newValue;
  348. }
  349. public bool EditorGUILayoutToggleLeft( string label, bool value, params GUILayoutOption[] options )
  350. {
  351. bool newValue = EditorGUILayout.ToggleLeft( label, value, options );
  352. if( newValue != value )
  353. {
  354. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  355. }
  356. return newValue;
  357. }
  358. public bool EditorGUILayoutToggleLeft( GUIContent label, bool value, params GUILayoutOption[] options )
  359. {
  360. bool newValue = EditorGUILayout.ToggleLeft( label, value, options );
  361. if( newValue != value )
  362. {
  363. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  364. }
  365. return newValue;
  366. }
  367. public string EditorGUILayoutTextArea( string text, GUIStyle style, params GUILayoutOption[] options )
  368. {
  369. string newValue = EditorGUILayout.TextArea( text, style, options );
  370. if( !newValue.Equals( text ) )
  371. {
  372. UndoRecordObject( string.Format( MessageFormat, "EditorGUILayoutTextArea", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  373. }
  374. return newValue;
  375. }
  376. public bool EditorGUILayoutFoldout( bool foldout, string content )
  377. {
  378. bool newValue = EditorGUILayout.Foldout( foldout, content );
  379. if( newValue != foldout )
  380. {
  381. UndoRecordObject( string.Format( MessageFormat, "EditorGUILayoutFoldout", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  382. }
  383. return newValue;
  384. }
  385. public bool EditorGUIFoldout( Rect position, bool foldout, string content )
  386. {
  387. bool newValue = EditorGUI.Foldout( position, foldout, content );
  388. if( newValue != foldout )
  389. {
  390. UndoRecordObject( string.Format( MessageFormat, "EditorGUIFoldout", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  391. }
  392. return newValue;
  393. }
  394. public string EditorGUITextField( Rect position, string label, string text )
  395. {
  396. string newValue = EditorGUI.TextField( position, label, text );
  397. if( !newValue.Equals( text ) )
  398. {
  399. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  400. }
  401. return newValue;
  402. }
  403. public string EditorGUITextField( Rect position, string label, string text, [UnityEngine.Internal.DefaultValue( "EditorStyles.textField" )] GUIStyle style )
  404. {
  405. string newValue = EditorGUI.TextField( position, label, text, style );
  406. if( !newValue.Equals( text ) )
  407. {
  408. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  409. }
  410. return newValue;
  411. }
  412. #if UNITY_2018_1_OR_NEWER
  413. public Color EditorGUIColorField( Rect position, GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr )
  414. {
  415. Color newValue = EditorGUI.ColorField( position, label, value, showEyedropper, showAlpha, hdr );
  416. if( newValue != value )
  417. {
  418. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  419. }
  420. return newValue;
  421. }
  422. #else
  423. public Color EditorGUIColorField( Rect position, GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig )
  424. {
  425. Color newValue = EditorGUI.ColorField( position, label, value, showEyedropper, showAlpha, hdr, hdrConfig );
  426. if( newValue != value )
  427. {
  428. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  429. }
  430. return newValue;
  431. }
  432. #endif
  433. public Color EditorGUIColorField( Rect position, string label, Color value )
  434. {
  435. Color newValue = EditorGUI.ColorField( position, label, value );
  436. if( newValue != value )
  437. {
  438. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  439. }
  440. return newValue;
  441. }
  442. public int EditorGUIIntField( Rect position, string label, int value )
  443. {
  444. int newValue = EditorGUI.IntField( position, label, value );
  445. if( newValue != value )
  446. {
  447. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  448. }
  449. return newValue;
  450. }
  451. public int EditorGUIIntField( Rect position, string label, int value, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  452. {
  453. int newValue = EditorGUI.IntField( position, label, value, style );
  454. if( newValue != value )
  455. {
  456. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  457. }
  458. return newValue;
  459. }
  460. public float EditorGUIFloatField( Rect position, string label, float value )
  461. {
  462. float newValue = EditorGUI.FloatField( position, label, value );
  463. if( newValue != value )
  464. {
  465. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  466. }
  467. return newValue;
  468. }
  469. public float EditorGUIFloatField( Rect position, string label, float value, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  470. {
  471. float newValue = EditorGUI.FloatField( position, label, value, style );
  472. if( newValue != value )
  473. {
  474. UndoRecordObject( string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  475. }
  476. return newValue;
  477. }
  478. public float EditorGUIFloatField( Rect position, float value, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  479. {
  480. float newValue = EditorGUI.FloatField( position, value, style );
  481. if( newValue != value )
  482. {
  483. UndoRecordObject( string.Format( MessageFormat, "EditorGUIFloatField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  484. }
  485. return newValue;
  486. }
  487. public float GUIHorizontalSlider( Rect position, float value, float leftValue, float rightValue, GUIStyle slider, GUIStyle thumb )
  488. {
  489. float newValue = GUI.HorizontalSlider( position, value, leftValue, rightValue, slider, thumb );
  490. if( newValue != value )
  491. {
  492. UndoRecordObject( string.Format( MessageFormat, "GUIHorizontalSlider", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  493. }
  494. return newValue;
  495. }
  496. public Enum EditorGUIEnumPopup( Rect position, Enum selected )
  497. {
  498. Enum newValue = EditorGUI.EnumPopup( position, selected );
  499. if( !newValue.ToString().Equals( selected.ToString() ) )
  500. {
  501. UndoRecordObject( string.Concat( "Changing value EditorGUIEnumPopup on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  502. //UndoRecordObject(string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  503. }
  504. return newValue;
  505. }
  506. public Enum EditorGUIEnumPopup( Rect position, Enum selected, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  507. {
  508. Enum newValue = EditorGUI.EnumPopup( position, selected, style );
  509. if( !newValue.ToString().Equals( selected.ToString() ) )
  510. {
  511. UndoRecordObject( string.Concat( "Changing value EditorGUIEnumPopup on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  512. //UndoRecordObject(string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  513. }
  514. return newValue;
  515. }
  516. public int EditorGUIIntPopup( Rect position, int selectedValue, GUIContent[] displayedOptions, int[] optionValues, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  517. {
  518. int newValue = EditorGUI.IntPopup( position, selectedValue, displayedOptions, optionValues, style );
  519. if( newValue != selectedValue )
  520. {
  521. UndoRecordObject( string.Format( MessageFormat, "EditorGUIIntEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  522. }
  523. return newValue;
  524. }
  525. public int EditorGUIPopup( Rect position, string label, int selectedIndex, string[] displayedOptions )
  526. {
  527. int newValue = EditorGUI.Popup( position, label, selectedIndex, displayedOptions );
  528. if( newValue != selectedIndex )
  529. {
  530. UndoRecordObject( string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  531. }
  532. return newValue;
  533. }
  534. public int EditorGUIPopup( Rect position, int selectedIndex, GUIContent[] displayedOptions, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  535. {
  536. int newValue = EditorGUI.Popup( position, selectedIndex, displayedOptions, style );
  537. if( newValue != selectedIndex )
  538. {
  539. UndoRecordObject( string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  540. }
  541. return newValue;
  542. }
  543. public int EditorGUIPopup( Rect position, int selectedIndex, string[] displayedOptions, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  544. {
  545. int newValue = EditorGUI.Popup( position, selectedIndex, displayedOptions, style );
  546. if( newValue != selectedIndex )
  547. {
  548. UndoRecordObject( string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  549. }
  550. return newValue;
  551. }
  552. public UnityEngine.Object EditorGUIObjectField( Rect position, UnityEngine.Object obj, System.Type objType, bool allowSceneObjects )
  553. {
  554. UnityEngine.Object newValue = EditorGUI.ObjectField( position, obj, objType, allowSceneObjects );
  555. if( newValue != obj )
  556. {
  557. UndoRecordObject( string.Format( MessageFormat, "EditorGUIObjectField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  558. }
  559. return newValue;
  560. }
  561. public int EditorGUIIntPopup( Rect position, int selectedValue, string[] displayedOptions, int[] optionValues, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  562. {
  563. int newValue = EditorGUI.IntPopup( position, selectedValue, displayedOptions, optionValues, style );
  564. if( newValue != selectedValue )
  565. {
  566. UndoRecordObject( string.Format( MessageFormat, "EditorGUIIntPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  567. }
  568. return newValue;
  569. }
  570. public bool EditorGUIToggle( Rect position, bool value )
  571. {
  572. bool newValue = EditorGUI.Toggle( position, value );
  573. if( newValue != value )
  574. {
  575. UndoRecordObject( string.Format( MessageFormat, "EditorGUIToggle", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  576. }
  577. return newValue;
  578. }
  579. public bool EditorGUIToggle( Rect position, string text, bool value )
  580. {
  581. bool newValue = EditorGUI.Toggle( position,text, value );
  582. if( newValue != value )
  583. {
  584. UndoRecordObject( string.Format( MessageFormat, "EditorGUIToggle", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  585. }
  586. return newValue;
  587. }
  588. public string GUITextField( Rect position, string text, GUIStyle style )
  589. {
  590. string newValue = GUI.TextField( position, text, style );
  591. if( !newValue.Equals( text ) )
  592. {
  593. UndoRecordObject( string.Format( MessageFormat, "GUITextfield", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  594. }
  595. return newValue;
  596. }
  597. public bool GUILayoutToggle( bool value, string text, GUIStyle style, params GUILayoutOption[] options )
  598. {
  599. bool newValue = GUILayout.Toggle( value, text, style, options );
  600. if( newValue != value )
  601. {
  602. UndoRecordObject( string.Format( MessageFormat, "GUILayoutToggle", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  603. }
  604. return newValue;
  605. }
  606. public bool GUILayoutButton( string text, GUIStyle style, params GUILayoutOption[] options )
  607. {
  608. bool value = GUILayout.Button( text, style, options );
  609. if( value )
  610. {
  611. UndoRecordObject( string.Format( MessageFormat, "GUILayoutButton", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  612. }
  613. return value;
  614. }
  615. /// <summary>
  616. /// It's the graph the node exists in, this is set after node creation and it's not available on CommonInit
  617. /// </summary>
  618. public ParentGraph ContainerGraph
  619. {
  620. get { return m_containerGraph; }
  621. set { m_containerGraph = value; }
  622. }
  623. }
  624. }