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.

672 lines
27 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 Color EditorGUILayoutColorField( string label, Color value, params GUILayoutOption[] options )
  212. {
  213. Color newValue = EditorGUILayout.ColorField( label, value, options );
  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. #if UNITY_2018_1_OR_NEWER
  221. public Color EditorGUILayoutColorField( GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, params GUILayoutOption[] options )
  222. {
  223. Color newValue = EditorGUILayout.ColorField( label, value, showEyedropper, showAlpha, hdr, options );
  224. if( newValue != value )
  225. {
  226. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  227. }
  228. return newValue;
  229. }
  230. #else
  231. public Color EditorGUILayoutColorField( GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig, params GUILayoutOption[] options )
  232. {
  233. Color newValue = EditorGUILayout.ColorField( label, value, showEyedropper, showAlpha, hdr, hdrConfig, options );
  234. if ( newValue != value )
  235. {
  236. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  237. }
  238. return newValue;
  239. }
  240. #endif
  241. public float EditorGUILayoutSlider( string label, float value, float leftValue, float rightValue, params GUILayoutOption[] options )
  242. {
  243. float newValue = EditorGUILayout.Slider( label, value, leftValue, rightValue, options );
  244. if ( newValue != value )
  245. {
  246. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  247. }
  248. return newValue;
  249. }
  250. public float EditorGUILayoutSlider( GUIContent 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 UnityEngine.Object EditorGUILayoutObjectField( string label, UnityEngine.Object obj, System.Type objType, bool allowSceneObjects, params GUILayoutOption[] options )
  260. {
  261. UnityEngine.Object newValue = EditorGUILayout.ObjectField( label, obj, objType, allowSceneObjects, options );
  262. if ( newValue != obj )
  263. {
  264. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  265. }
  266. return newValue;
  267. }
  268. public Vector2 EditorGUIVector2Field( Rect position, string label, Vector2 value )
  269. {
  270. Vector2 newValue = EditorGUI.Vector2Field( position, label, value );
  271. if( newValue != value )
  272. {
  273. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  274. }
  275. return newValue;
  276. }
  277. public Vector2 EditorGUILayoutVector2Field( string label, Vector2 value, params GUILayoutOption[] options )
  278. {
  279. Vector2 newValue = EditorGUILayout.Vector2Field( label, value, options );
  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 Vector3 EditorGUIVector3Field( Rect position, string label, Vector3 value )
  287. {
  288. Vector3 newValue = EditorGUI.Vector3Field( position, label, value );
  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 EditorGUILayoutVector3Field( string label, Vector3 value, params GUILayoutOption[] options )
  296. {
  297. Vector3 newValue = EditorGUILayout.Vector3Field( label, value, options );
  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 Vector4 EditorGUIVector4Field( Rect position, string label, Vector4 value )
  305. {
  306. Vector4 newValue = EditorGUI.Vector4Field( position, label, value );
  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 EditorGUILayoutVector4Field( string label, Vector4 value, params GUILayoutOption[] options )
  314. {
  315. Vector4 newValue = EditorGUILayout.Vector4Field( label, value, options );
  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 int EditorGUILayoutIntSlider( GUIContent label, int value, int leftValue, int rightValue, params GUILayoutOption[] options )
  323. {
  324. int newValue = EditorGUILayout.IntSlider( label, value, leftValue, rightValue, 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( string 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 bool EditorGUILayoutToggleLeft( string label, bool value, params GUILayoutOption[] options )
  341. {
  342. bool newValue = EditorGUILayout.ToggleLeft( label, value, 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( GUIContent 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 string EditorGUILayoutTextArea( string text, GUIStyle style, params GUILayoutOption[] options )
  359. {
  360. string newValue = EditorGUILayout.TextArea( text, style, options );
  361. if ( !newValue.Equals( text ) )
  362. {
  363. UndoRecordObject(string.Format( MessageFormat, "EditorGUILayoutTextArea", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  364. }
  365. return newValue;
  366. }
  367. public bool EditorGUILayoutFoldout( bool foldout, string content )
  368. {
  369. bool newValue = EditorGUILayout.Foldout( foldout, content );
  370. if ( newValue != foldout )
  371. {
  372. UndoRecordObject(string.Format( MessageFormat, "EditorGUILayoutFoldout", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  373. }
  374. return newValue;
  375. }
  376. public bool EditorGUIFoldout( Rect position, bool foldout, string content )
  377. {
  378. bool newValue = EditorGUI.Foldout( position, foldout, content );
  379. if( newValue != foldout )
  380. {
  381. UndoRecordObject(string.Format( MessageFormat, "EditorGUIFoldout", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  382. }
  383. return newValue;
  384. }
  385. public string EditorGUITextField( Rect position, string label, string text )
  386. {
  387. string newValue = EditorGUI.TextField( position, label, text );
  388. if( !newValue.Equals( text ) )
  389. {
  390. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  391. }
  392. return newValue;
  393. }
  394. public string EditorGUITextField( Rect position, string label, string text, [UnityEngine.Internal.DefaultValue( "EditorStyles.textField" )] GUIStyle style )
  395. {
  396. string newValue = EditorGUI.TextField( position, label, text, style );
  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. #if UNITY_2018_1_OR_NEWER
  404. public Color EditorGUIColorField( Rect position, GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr )
  405. {
  406. Color newValue = EditorGUI.ColorField( position, label, value, showEyedropper, showAlpha, hdr );
  407. if( newValue != value )
  408. {
  409. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  410. }
  411. return newValue;
  412. }
  413. #else
  414. public Color EditorGUIColorField( Rect position, GUIContent label, Color value, bool showEyedropper, bool showAlpha, bool hdr, ColorPickerHDRConfig hdrConfig )
  415. {
  416. Color newValue = EditorGUI.ColorField( position, label, value, showEyedropper, showAlpha, hdr, hdrConfig );
  417. if ( newValue != value )
  418. {
  419. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  420. }
  421. return newValue;
  422. }
  423. #endif
  424. public Color EditorGUIColorField( Rect position, string label, Color value )
  425. {
  426. Color newValue = EditorGUI.ColorField( position, label, value );
  427. if( newValue != value )
  428. {
  429. UndoRecordObject(string.Format( MessageFormat, label, ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  430. }
  431. return newValue;
  432. }
  433. public int EditorGUIIntField( Rect position, string label, int value )
  434. {
  435. int newValue = EditorGUI.IntField( 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, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  443. {
  444. int newValue = EditorGUI.IntField( position, label, value, style );
  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 float EditorGUIFloatField( Rect position, string label, float value )
  452. {
  453. float newValue = EditorGUI.FloatField( position, label, value );
  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, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  461. {
  462. float newValue = EditorGUI.FloatField( position, label, value, style );
  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, float value, [UnityEngine.Internal.DefaultValue( "EditorStyles.numberField" )] GUIStyle style )
  470. {
  471. float newValue = EditorGUI.FloatField( position, value, style );
  472. if ( newValue != value )
  473. {
  474. UndoRecordObject(string.Format( MessageFormat, "EditorGUIFloatField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  475. }
  476. return newValue;
  477. }
  478. public float GUIHorizontalSlider( Rect position, float value, float leftValue, float rightValue, GUIStyle slider, GUIStyle thumb )
  479. {
  480. float newValue = GUI.HorizontalSlider( position, value, leftValue, rightValue, slider, thumb );
  481. if( newValue != value )
  482. {
  483. UndoRecordObject(string.Format( MessageFormat, "GUIHorizontalSlider", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  484. }
  485. return newValue;
  486. }
  487. public Enum EditorGUIEnumPopup( Rect position, Enum selected )
  488. {
  489. Enum newValue = EditorGUI.EnumPopup( position, selected );
  490. if( !newValue.ToString().Equals( selected.ToString() ) )
  491. {
  492. UndoRecordObject(string.Concat( "Changing value EditorGUIEnumPopup on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  493. //UndoRecordObject(string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  494. }
  495. return newValue;
  496. }
  497. public Enum EditorGUIEnumPopup( Rect position, Enum selected, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  498. {
  499. Enum newValue = EditorGUI.EnumPopup( position, selected, style );
  500. if ( !newValue.ToString().Equals( selected.ToString() ) )
  501. {
  502. UndoRecordObject(string.Concat( "Changing value EditorGUIEnumPopup on node ", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  503. //UndoRecordObject(string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  504. }
  505. return newValue;
  506. }
  507. public int EditorGUIIntPopup( Rect position, int selectedValue, GUIContent[] displayedOptions, int[] optionValues, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  508. {
  509. int newValue = EditorGUI.IntPopup( position, selectedValue, displayedOptions, optionValues, style );
  510. if ( newValue != selectedValue )
  511. {
  512. UndoRecordObject(string.Format( MessageFormat, "EditorGUIIntEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  513. }
  514. return newValue;
  515. }
  516. public int EditorGUIPopup( Rect position, string label, int selectedIndex, string[] displayedOptions)
  517. {
  518. int newValue = EditorGUI.Popup( position, label, selectedIndex, displayedOptions );
  519. if( newValue != selectedIndex )
  520. {
  521. UndoRecordObject(string.Format( MessageFormat, "EditorGUIEnumPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  522. }
  523. return newValue;
  524. }
  525. public int EditorGUIPopup( Rect position, int selectedIndex, GUIContent[] displayedOptions, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  526. {
  527. int newValue = EditorGUI.Popup( position, selectedIndex, displayedOptions, style );
  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, string[] 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 UnityEngine.Object EditorGUIObjectField( Rect position, UnityEngine.Object obj, System.Type objType, bool allowSceneObjects )
  544. {
  545. UnityEngine.Object newValue = EditorGUI.ObjectField( position, obj, objType, allowSceneObjects );
  546. if ( newValue != obj )
  547. {
  548. UndoRecordObject(string.Format( MessageFormat, "EditorGUIObjectField", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  549. }
  550. return newValue;
  551. }
  552. public int EditorGUIIntPopup( Rect position, int selectedValue, string[] displayedOptions, int[] optionValues, [UnityEngine.Internal.DefaultValue( "EditorStyles.popup" )] GUIStyle style )
  553. {
  554. int newValue = EditorGUI.IntPopup( position, selectedValue, displayedOptions, optionValues, style );
  555. if ( newValue != selectedValue )
  556. {
  557. UndoRecordObject(string.Format( MessageFormat, "EditorGUIIntPopup", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  558. }
  559. return newValue;
  560. }
  561. public bool EditorGUIToggle( Rect position, bool value )
  562. {
  563. bool newValue = EditorGUI.Toggle( position, value );
  564. if ( newValue != value )
  565. {
  566. UndoRecordObject(string.Format( MessageFormat, "EditorGUIToggle", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  567. }
  568. return newValue;
  569. }
  570. public string GUITextField( Rect position, string text, GUIStyle style )
  571. {
  572. string newValue = GUI.TextField( position, text, style );
  573. if ( !newValue.Equals( text ) )
  574. {
  575. UndoRecordObject(string.Format( MessageFormat, "GUITextfield", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  576. }
  577. return newValue;
  578. }
  579. public bool GUILayoutToggle( bool value, string text, GUIStyle style, params GUILayoutOption[] options )
  580. {
  581. bool newValue = GUILayout.Toggle( value, text, style, options );
  582. if ( newValue != value )
  583. {
  584. UndoRecordObject(string.Format( MessageFormat, "GUILayoutToggle", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  585. }
  586. return newValue;
  587. }
  588. public bool GUILayoutButton( string text, GUIStyle style, params GUILayoutOption[] options )
  589. {
  590. bool value = GUILayout.Button( text, style, options );
  591. if ( value )
  592. {
  593. UndoRecordObject(string.Format( MessageFormat, "GUILayoutButton", ( ( m_nodeAttribs != null ) ? m_nodeAttribs.Name : GetType().ToString() ) ) );
  594. }
  595. return value;
  596. }
  597. /// <summary>
  598. /// It's the graph the node exists in, this is set after node creation and it's not available on CommonInit
  599. /// </summary>
  600. public ParentGraph ContainerGraph
  601. {
  602. get { return m_containerGraph; }
  603. set { m_containerGraph = value; }
  604. }
  605. }
  606. }