BlackboardFieldPropertyView.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. using System;
  2. using System.Linq;
  3. using System.Globalization;
  4. using UnityEditor.Graphing;
  5. using UnityEditor.Graphing.Util;
  6. using UnityEngine;
  7. using UnityEditor.UIElements;
  8. using UnityEngine.UIElements;
  9. using Toggle = UnityEngine.UIElements.Toggle;
  10. using UnityEditor.Experimental.GraphView;
  11. using UnityEditor.ShaderGraph.Internal;
  12. namespace UnityEditor.ShaderGraph.Drawing
  13. {
  14. class BlackboardFieldPropertyView : BlackboardFieldView
  15. {
  16. public BlackboardFieldPropertyView(BlackboardField blackboardField, GraphData graph, ShaderInput input)
  17. : base (blackboardField, graph, input)
  18. {
  19. }
  20. public override void BuildCustomFields(ShaderInput input)
  21. {
  22. AbstractShaderProperty property = input as AbstractShaderProperty;
  23. if(property == null)
  24. return;
  25. switch(input)
  26. {
  27. case Vector1ShaderProperty vector1Property:
  28. BuildVector1PropertyField(vector1Property);
  29. break;
  30. case Vector2ShaderProperty vector2Property:
  31. BuildVector2PropertyField(vector2Property);
  32. break;
  33. case Vector3ShaderProperty vector3Property:
  34. BuildVector3PropertyField(vector3Property);
  35. break;
  36. case Vector4ShaderProperty vector4Property:
  37. BuildVector4PropertyField(vector4Property);
  38. break;
  39. case ColorShaderProperty colorProperty:
  40. BuildColorPropertyField(colorProperty);
  41. break;
  42. case Texture2DShaderProperty texture2DProperty:
  43. BuildTexture2DPropertyField(texture2DProperty);
  44. break;
  45. case Texture2DArrayShaderProperty texture2DArrayProperty:
  46. BuildTexture2DArrayPropertyField(texture2DArrayProperty);
  47. break;
  48. case Texture3DShaderProperty texture3DProperty:
  49. BuildTexture3DPropertyField(texture3DProperty);
  50. break;
  51. case CubemapShaderProperty cubemapProperty:
  52. BuildCubemapPropertyField(cubemapProperty);
  53. break;
  54. case BooleanShaderProperty booleanProperty:
  55. BuildBooleanPropertyField(booleanProperty);
  56. break;
  57. case Matrix2ShaderProperty matrix2Property:
  58. BuildMatrix2PropertyField(matrix2Property);
  59. break;
  60. case Matrix3ShaderProperty matrix3Property:
  61. BuildMatrix3PropertyField(matrix3Property);
  62. break;
  63. case Matrix4ShaderProperty matrix4Property:
  64. BuildMatrix4PropertyField(matrix4Property);
  65. break;
  66. case SamplerStateShaderProperty samplerStateProperty:
  67. BuildSamplerStatePropertyField(samplerStateProperty);
  68. break;
  69. case GradientShaderProperty gradientProperty:
  70. BuildGradientPropertyField(gradientProperty);
  71. break;
  72. default:
  73. throw new ArgumentOutOfRangeException();
  74. }
  75. // Precision
  76. var precisionField = new EnumField((Enum)property.precision);
  77. precisionField.RegisterValueChangedCallback(evt =>
  78. {
  79. graph.owner.RegisterCompleteObjectUndo("Change Precision");
  80. if (property.precision == (Precision)evt.newValue)
  81. return;
  82. property.precision = (Precision)evt.newValue;
  83. graph.ValidateGraph();
  84. precisionField.MarkDirtyRepaint();
  85. DirtyNodes();
  86. });
  87. AddRow("Precision", precisionField);
  88. if (property.isGpuInstanceable)
  89. {
  90. Toggle gpuInstancedToogle = new Toggle { value = property.gpuInstanced };
  91. gpuInstancedToogle.OnToggleChanged(evt =>
  92. {
  93. graph.owner.RegisterCompleteObjectUndo("Change Hybrid Instanced Toggle");
  94. property.gpuInstanced = evt.newValue;
  95. DirtyNodes(ModificationScope.Graph);
  96. });
  97. AddRow("Hybrid Instanced (experimental)", gpuInstancedToogle);
  98. }
  99. }
  100. void BuildVector1PropertyField(Vector1ShaderProperty property)
  101. {
  102. switch (property.floatType)
  103. {
  104. case FloatType.Slider:
  105. {
  106. float min = Mathf.Min(property.value, property.rangeValues.x);
  107. float max = Mathf.Max(property.value, property.rangeValues.y);
  108. property.rangeValues = new Vector2(min, max);
  109. var defaultField = new FloatField { value = property.value };
  110. var minField = new FloatField { value = property.rangeValues.x };
  111. var maxField = new FloatField { value = property.rangeValues.y };
  112. defaultField.RegisterValueChangedCallback(evt =>
  113. {
  114. property.value = (float)evt.newValue;
  115. this.MarkDirtyRepaint();
  116. });
  117. defaultField.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
  118. {
  119. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  120. float minValue = Mathf.Min(property.value, property.rangeValues.x);
  121. float maxValue = Mathf.Max(property.value, property.rangeValues.y);
  122. property.rangeValues = new Vector2(minValue, maxValue);
  123. minField.value = minValue;
  124. maxField.value = maxValue;
  125. DirtyNodes();
  126. });
  127. minField.RegisterValueChangedCallback(evt =>
  128. {
  129. graph.owner.RegisterCompleteObjectUndo("Change Range Property Minimum");
  130. property.rangeValues = new Vector2((float)evt.newValue, property.rangeValues.y);
  131. DirtyNodes();
  132. });
  133. minField.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
  134. {
  135. property.value = Mathf.Max(Mathf.Min(property.value, property.rangeValues.y), property.rangeValues.x);
  136. defaultField.value = property.value;
  137. DirtyNodes();
  138. });
  139. maxField.RegisterValueChangedCallback(evt =>
  140. {
  141. graph.owner.RegisterCompleteObjectUndo("Change Range Property Maximum");
  142. property.rangeValues = new Vector2(property.rangeValues.x, (float)evt.newValue);
  143. DirtyNodes();
  144. });
  145. maxField.Q("unity-text-input").RegisterCallback<FocusOutEvent>(evt =>
  146. {
  147. property.value = Mathf.Max(Mathf.Min(property.value, property.rangeValues.y), property.rangeValues.x);
  148. defaultField.value = property.value;
  149. DirtyNodes();
  150. });
  151. AddRow("Default", defaultField);
  152. AddRow("Min", minField);
  153. AddRow("Max", maxField);
  154. }
  155. break;
  156. case FloatType.Integer:
  157. {
  158. property.value = (int)property.value;
  159. var defaultField = new IntegerField { value = (int)property.value };
  160. defaultField.RegisterValueChangedCallback(evt =>
  161. {
  162. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  163. property.value = (int)evt.newValue;
  164. DirtyNodes();
  165. });
  166. AddRow("Default", defaultField);
  167. }
  168. break;
  169. default:
  170. {
  171. var defaultField = new FloatField { value = property.value };
  172. defaultField.RegisterValueChangedCallback(evt =>
  173. {
  174. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  175. property.value = (float)evt.newValue;
  176. DirtyNodes();
  177. });
  178. AddRow("Default", defaultField);
  179. }
  180. break;
  181. }
  182. if(!graph.isSubGraph)
  183. {
  184. var modeField = new EnumField(property.floatType);
  185. modeField.RegisterValueChangedCallback(evt =>
  186. {
  187. graph.owner.RegisterCompleteObjectUndo("Change Vector1 Mode");
  188. property.floatType = (FloatType)evt.newValue;
  189. Rebuild();
  190. });
  191. AddRow("Mode", modeField);
  192. }
  193. }
  194. void BuildVector2PropertyField(Vector2ShaderProperty property)
  195. {
  196. var field = new Vector2Field { value = property.value };
  197. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  198. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  199. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  200. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  201. // Called after KeyDownEvent
  202. field.RegisterValueChangedCallback(evt =>
  203. {
  204. // Only true when setting value via FieldMouseDragger
  205. // Undo recorded once per dragger release
  206. if (undoGroup == -1)
  207. graph.owner.RegisterCompleteObjectUndo("Change property value");
  208. property.value = evt.newValue;
  209. DirtyNodes();
  210. });
  211. AddRow("Default", field);
  212. }
  213. void BuildVector3PropertyField(Vector3ShaderProperty property)
  214. {
  215. var field = new Vector3Field { value = property.value };
  216. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  217. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  218. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  219. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  220. field.Q("unity-z-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  221. field.Q("unity-z-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  222. // Called after KeyDownEvent
  223. field.RegisterValueChangedCallback(evt =>
  224. {
  225. // Only true when setting value via FieldMouseDragger
  226. // Undo recorded once per dragger release
  227. if (undoGroup == -1)
  228. graph.owner.RegisterCompleteObjectUndo("Change property value");
  229. property.value = evt.newValue;
  230. DirtyNodes();
  231. });
  232. AddRow("Default", field);
  233. }
  234. void BuildVector4PropertyField(Vector4ShaderProperty property)
  235. {
  236. var field = new Vector4Field { value = property.value };
  237. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  238. field.Q("unity-x-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  239. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  240. field.Q("unity-y-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  241. field.Q("unity-z-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  242. field.Q("unity-z-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  243. field.Q("unity-w-input").Q("unity-text-input").RegisterCallback<KeyDownEvent>(keyDownCallback);
  244. field.Q("unity-w-input").Q("unity-text-input").RegisterCallback<FocusOutEvent>(focusOutCallback);
  245. // Called after KeyDownEvent
  246. field.RegisterValueChangedCallback(evt =>
  247. {
  248. // Only true when setting value via FieldMouseDragger
  249. // Undo recorded once per dragger release
  250. if (undoGroup == -1)
  251. graph.owner.RegisterCompleteObjectUndo("Change property value");
  252. property.value = evt.newValue;
  253. DirtyNodes();
  254. });
  255. AddRow("Default", field);
  256. }
  257. void BuildColorPropertyField(ColorShaderProperty property)
  258. {
  259. var colorField = new ColorField { value = property.value, showEyeDropper = false, hdr = property.colorMode == ColorMode.HDR };
  260. colorField.RegisterValueChangedCallback(evt =>
  261. {
  262. graph.owner.RegisterCompleteObjectUndo("Change property value");
  263. property.value = evt.newValue;
  264. DirtyNodes();
  265. });
  266. AddRow("Default", colorField);
  267. if(!graph.isSubGraph)
  268. {
  269. var colorModeField = new EnumField((Enum)property.colorMode);
  270. colorModeField.RegisterValueChangedCallback(evt =>
  271. {
  272. graph.owner.RegisterCompleteObjectUndo("Change Color Mode");
  273. if (property.colorMode == (ColorMode)evt.newValue)
  274. return;
  275. property.colorMode = (ColorMode)evt.newValue;
  276. colorField.hdr = property.colorMode == ColorMode.HDR;
  277. colorField.MarkDirtyRepaint();
  278. DirtyNodes();
  279. });
  280. AddRow("Mode", colorModeField);
  281. }
  282. }
  283. void BuildTexture2DPropertyField(Texture2DShaderProperty property)
  284. {
  285. var field = new ObjectField { value = property.value.texture, objectType = typeof(Texture) };
  286. field.RegisterValueChangedCallback(evt =>
  287. {
  288. graph.owner.RegisterCompleteObjectUndo("Change property value");
  289. property.value.texture = (Texture)evt.newValue;
  290. DirtyNodes();
  291. });
  292. AddRow("Default", field);
  293. var defaultMode = (Enum)Texture2DShaderProperty.DefaultType.Grey;
  294. var textureMode = property.generatePropertyBlock ? (Enum)property.defaultType : defaultMode;
  295. var defaultModeField = new EnumField(textureMode);
  296. defaultModeField.RegisterValueChangedCallback(evt =>
  297. {
  298. graph.owner.RegisterCompleteObjectUndo("Change Texture Mode");
  299. if (property.defaultType == (Texture2DShaderProperty.DefaultType)evt.newValue)
  300. return;
  301. property.defaultType = (Texture2DShaderProperty.DefaultType)evt.newValue;
  302. DirtyNodes(ModificationScope.Graph);
  303. });
  304. AddRow("Mode", defaultModeField, !graph.isSubGraph && property.generatePropertyBlock);
  305. }
  306. void BuildTexture2DArrayPropertyField(Texture2DArrayShaderProperty property)
  307. {
  308. var field = new ObjectField { value = property.value.textureArray, objectType = typeof(Texture2DArray) };
  309. field.RegisterValueChangedCallback(evt =>
  310. {
  311. graph.owner.RegisterCompleteObjectUndo("Change property value");
  312. property.value.textureArray = (Texture2DArray)evt.newValue;
  313. DirtyNodes();
  314. });
  315. AddRow("Default", field);
  316. }
  317. void BuildTexture3DPropertyField(Texture3DShaderProperty property)
  318. {
  319. var field = new ObjectField { value = property.value.texture, objectType = typeof(Texture3D) };
  320. field.RegisterValueChangedCallback(evt =>
  321. {
  322. graph.owner.RegisterCompleteObjectUndo("Change property value");
  323. property.value.texture = (Texture3D)evt.newValue;
  324. DirtyNodes();
  325. });
  326. AddRow("Default", field);
  327. }
  328. void BuildCubemapPropertyField(CubemapShaderProperty property)
  329. {
  330. var field = new ObjectField { value = property.value.cubemap, objectType = typeof(Cubemap) };
  331. field.RegisterValueChangedCallback(evt =>
  332. {
  333. graph.owner.RegisterCompleteObjectUndo("Change property value");
  334. property.value.cubemap = (Cubemap)evt.newValue;
  335. DirtyNodes();
  336. });
  337. AddRow("Default", field);
  338. }
  339. void BuildBooleanPropertyField(BooleanShaderProperty property)
  340. {
  341. var field = new Toggle() { value = property.value };
  342. field.OnToggleChanged(evt =>
  343. {
  344. graph.owner.RegisterCompleteObjectUndo("Change property value");
  345. property.value = evt.newValue;
  346. DirtyNodes();
  347. });
  348. AddRow("Default", field);
  349. }
  350. void BuildMatrix2PropertyField(Matrix2ShaderProperty property)
  351. {
  352. var row0Field = new Vector2Field { value = property.value.GetRow(0) };
  353. row0Field.RegisterValueChangedCallback(evt =>
  354. {
  355. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  356. Vector2 row1 = property.value.GetRow(1);
  357. property.value = new Matrix4x4()
  358. {
  359. m00 = evt.newValue.x,
  360. m01 = evt.newValue.y,
  361. m02 = 0,
  362. m03 = 0,
  363. m10 = row1.x,
  364. m11 = row1.y,
  365. m12 = 0,
  366. m13 = 0,
  367. m20 = 0,
  368. m21 = 0,
  369. m22 = 0,
  370. m23 = 0,
  371. m30 = 0,
  372. m31 = 0,
  373. m32 = 0,
  374. m33 = 0,
  375. };
  376. DirtyNodes();
  377. });
  378. AddRow("Default", row0Field);
  379. var row1Field = new Vector2Field { value = property.value.GetRow(1) };
  380. row1Field.RegisterValueChangedCallback(evt =>
  381. {
  382. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  383. Vector2 row0 = property.value.GetRow(0);
  384. property.value = new Matrix4x4()
  385. {
  386. m00 = row0.x,
  387. m01 = row0.y,
  388. m02 = 0,
  389. m03 = 0,
  390. m10 = evt.newValue.x,
  391. m11 = evt.newValue.y,
  392. m12 = 0,
  393. m13 = 0,
  394. m20 = 0,
  395. m21 = 0,
  396. m22 = 0,
  397. m23 = 0,
  398. m30 = 0,
  399. m31 = 0,
  400. m32 = 0,
  401. m33 = 0,
  402. };
  403. DirtyNodes();
  404. });
  405. AddRow("", row1Field);
  406. }
  407. void BuildMatrix3PropertyField(Matrix3ShaderProperty property)
  408. {
  409. var row0Field = new Vector3Field { value = property.value.GetRow(0) };
  410. row0Field.RegisterValueChangedCallback(evt =>
  411. {
  412. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  413. Vector3 row1 = property.value.GetRow(1);
  414. Vector3 row2 = property.value.GetRow(2);
  415. property.value = new Matrix4x4()
  416. {
  417. m00 = evt.newValue.x,
  418. m01 = evt.newValue.y,
  419. m02 = evt.newValue.z,
  420. m03 = 0,
  421. m10 = row1.x,
  422. m11 = row1.y,
  423. m12 = row1.z,
  424. m13 = 0,
  425. m20 = row2.x,
  426. m21 = row2.y,
  427. m22 = row2.z,
  428. m23 = 0,
  429. m30 = 0,
  430. m31 = 0,
  431. m32 = 0,
  432. m33 = 0,
  433. };
  434. DirtyNodes();
  435. });
  436. AddRow("Default", row0Field);
  437. var row1Field = new Vector3Field { value = property.value.GetRow(1) };
  438. row1Field.RegisterValueChangedCallback(evt =>
  439. {
  440. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  441. Vector3 row0 = property.value.GetRow(0);
  442. Vector3 row2 = property.value.GetRow(2);
  443. property.value = new Matrix4x4()
  444. {
  445. m00 = row0.x,
  446. m01 = row0.y,
  447. m02 = row0.z,
  448. m03 = 0,
  449. m10 = evt.newValue.x,
  450. m11 = evt.newValue.y,
  451. m12 = evt.newValue.z,
  452. m13 = 0,
  453. m20 = row2.x,
  454. m21 = row2.y,
  455. m22 = row2.z,
  456. m23 = 0,
  457. m30 = 0,
  458. m31 = 0,
  459. m32 = 0,
  460. m33 = 0,
  461. };
  462. DirtyNodes();
  463. });
  464. AddRow("", row1Field);
  465. var row2Field = new Vector3Field { value = property.value.GetRow(2) };
  466. row2Field.RegisterValueChangedCallback(evt =>
  467. {
  468. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  469. Vector3 row0 = property.value.GetRow(0);
  470. Vector3 row1 = property.value.GetRow(1);
  471. property.value = new Matrix4x4()
  472. {
  473. m00 = row0.x,
  474. m01 = row0.y,
  475. m02 = row0.z,
  476. m03 = 0,
  477. m10 = row1.x,
  478. m11 = row1.y,
  479. m12 = row1.z,
  480. m13 = 0,
  481. m20 = evt.newValue.x,
  482. m21 = evt.newValue.y,
  483. m22 = evt.newValue.z,
  484. m23 = 0,
  485. m30 = 0,
  486. m31 = 0,
  487. m32 = 0,
  488. m33 = 0,
  489. };
  490. DirtyNodes();
  491. });
  492. AddRow("", row2Field);
  493. }
  494. void BuildMatrix4PropertyField(Matrix4ShaderProperty property)
  495. {
  496. var row0Field = new Vector4Field { value = property.value.GetRow(0) };
  497. row0Field.RegisterValueChangedCallback(evt =>
  498. {
  499. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  500. Vector4 row1 = property.value.GetRow(1);
  501. Vector4 row2 = property.value.GetRow(2);
  502. Vector4 row3 = property.value.GetRow(3);
  503. property.value = new Matrix4x4()
  504. {
  505. m00 = evt.newValue.x,
  506. m01 = evt.newValue.y,
  507. m02 = evt.newValue.z,
  508. m03 = evt.newValue.w,
  509. m10 = row1.x,
  510. m11 = row1.y,
  511. m12 = row1.z,
  512. m13 = row1.w,
  513. m20 = row2.x,
  514. m21 = row2.y,
  515. m22 = row2.z,
  516. m23 = row2.w,
  517. m30 = row3.x,
  518. m31 = row3.y,
  519. m32 = row3.z,
  520. m33 = row3.w,
  521. };
  522. DirtyNodes();
  523. });
  524. AddRow("Default", row0Field);
  525. var row1Field = new Vector4Field { value = property.value.GetRow(1) };
  526. row1Field.RegisterValueChangedCallback(evt =>
  527. {
  528. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  529. Vector4 row0 = property.value.GetRow(0);
  530. Vector4 row2 = property.value.GetRow(2);
  531. Vector4 row3 = property.value.GetRow(3);
  532. property.value = new Matrix4x4()
  533. {
  534. m00 = row0.x,
  535. m01 = row0.y,
  536. m02 = row0.z,
  537. m03 = row0.w,
  538. m10 = evt.newValue.x,
  539. m11 = evt.newValue.y,
  540. m12 = evt.newValue.z,
  541. m13 = evt.newValue.w,
  542. m20 = row2.x,
  543. m21 = row2.y,
  544. m22 = row2.z,
  545. m23 = row2.w,
  546. m30 = row3.x,
  547. m31 = row3.y,
  548. m32 = row3.z,
  549. m33 = row3.w,
  550. };
  551. DirtyNodes();
  552. });
  553. AddRow("", row1Field);
  554. var row2Field = new Vector4Field { value = property.value.GetRow(2) };
  555. row2Field.RegisterValueChangedCallback(evt =>
  556. {
  557. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  558. Vector4 row0 = property.value.GetRow(0);
  559. Vector4 row1 = property.value.GetRow(1);
  560. Vector4 row3 = property.value.GetRow(3);
  561. property.value = new Matrix4x4()
  562. {
  563. m00 = row0.x,
  564. m01 = row0.y,
  565. m02 = row0.z,
  566. m03 = row0.w,
  567. m10 = row1.x,
  568. m11 = row1.y,
  569. m12 = row1.z,
  570. m13 = row1.w,
  571. m20 = evt.newValue.x,
  572. m21 = evt.newValue.y,
  573. m22 = evt.newValue.z,
  574. m23 = evt.newValue.w,
  575. m30 = row3.x,
  576. m31 = row3.y,
  577. m32 = row3.z,
  578. m33 = row3.w,
  579. };
  580. DirtyNodes();
  581. });
  582. AddRow("", row2Field);
  583. var row3Field = new Vector4Field { value = property.value.GetRow(3) };
  584. row3Field.RegisterValueChangedCallback(evt =>
  585. {
  586. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  587. Vector4 row0 = property.value.GetRow(0);
  588. Vector4 row1 = property.value.GetRow(1);
  589. Vector4 row2 = property.value.GetRow(2);
  590. property.value = new Matrix4x4()
  591. {
  592. m00 = row0.x,
  593. m01 = row0.y,
  594. m02 = row0.z,
  595. m03 = row0.w,
  596. m10 = row1.x,
  597. m11 = row1.y,
  598. m12 = row1.z,
  599. m13 = row1.w,
  600. m20 = row2.x,
  601. m21 = row2.y,
  602. m22 = row2.z,
  603. m23 = row2.w,
  604. m30 = evt.newValue.x,
  605. m31 = evt.newValue.y,
  606. m32 = evt.newValue.z,
  607. m33 = evt.newValue.w,
  608. };
  609. DirtyNodes();
  610. });
  611. AddRow("", row3Field);
  612. }
  613. void BuildSamplerStatePropertyField(SamplerStateShaderProperty property)
  614. {
  615. var filterField = new EnumField(property.value.filter);
  616. filterField.RegisterValueChangedCallback(evt =>
  617. {
  618. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  619. TextureSamplerState state = property.value;
  620. state.filter = (TextureSamplerState.FilterMode)evt.newValue;
  621. property.value = state;
  622. Rebuild();
  623. DirtyNodes(ModificationScope.Graph);
  624. });
  625. AddRow("Filter", filterField);
  626. var wrapField = new EnumField(property.value.wrap);
  627. wrapField.RegisterValueChangedCallback(evt =>
  628. {
  629. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  630. TextureSamplerState state = property.value;
  631. state.wrap = (TextureSamplerState.WrapMode)evt.newValue;
  632. property.value = state;
  633. Rebuild();
  634. DirtyNodes(ModificationScope.Graph);
  635. });
  636. AddRow("Wrap", wrapField);
  637. }
  638. void BuildGradientPropertyField(GradientShaderProperty property)
  639. {
  640. var field = new GradientField { value = property.value };
  641. field.RegisterValueChangedCallback(evt =>
  642. {
  643. graph.owner.RegisterCompleteObjectUndo("Change Property Value");
  644. property.value = evt.newValue;
  645. DirtyNodes();
  646. });
  647. AddRow("Default", field);
  648. }
  649. public override void DirtyNodes(ModificationScope modificationScope = ModificationScope.Node)
  650. {
  651. var colorManager = GetFirstAncestorOfType<GraphEditorView>().colorManager;
  652. var nodes = GetFirstAncestorOfType<GraphEditorView>().graphView.Query<MaterialNodeView>().ToList();
  653. colorManager.SetNodesDirty(nodes);
  654. colorManager.UpdateNodeViews(nodes);
  655. foreach (var node in graph.GetNodes<PropertyNode>())
  656. {
  657. node.Dirty(modificationScope);
  658. }
  659. }
  660. }
  661. }