UndoParentNode.cs 28 KB

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