TC_SelectItemGUI.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections;
  5. namespace TerrainComposer2
  6. {
  7. static public class TC_SelectItemGUI
  8. {
  9. // static public FilterGroupNode parent;
  10. static public void DrawSplatCustomPreview(TC_SelectItem selectItem, Rect rect)
  11. {
  12. // selectItem.CalcSplatCustomTotal();
  13. GUI.color = Color.black;
  14. EditorGUI.DrawPreviewTexture(rect, Texture2D.whiteTexture);
  15. for (int i = 0; i < selectItem.splatCustomValues.Length; i++)
  16. {
  17. GUI.color = new Color(1, 1, 1, (selectItem.splatCustomValues[i] / selectItem.splatCustomTotal) * 1.5f);
  18. EditorGUI.DrawPreviewTexture(rect, TC_Settings.instance.masterTerrain.terrainData.splatPrototypes[i].texture);
  19. }
  20. GUI.color = Color.white;
  21. }
  22. static public void Draw(TC_SelectItemGroup selectItemGroup, float activeMulti, int index, bool nodeFoldout, ref Vector2 pos, Color color)
  23. {
  24. TC_SelectItem selectItem = selectItemGroup.itemList[index];
  25. Undo.RecordObject(selectItem, selectItem.name);
  26. Rect rectPreview;
  27. bool isCulled = false;
  28. if (selectItem.outputId == TC.colorOutput)
  29. {
  30. if (selectItem.texColor != null && selectItem.parentItem.itemList.Count == 1) rectPreview = TD.DrawNode(selectItem, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, false, false);
  31. else rectPreview = TD.DrawNode(selectItem, pos, color, selectItem.color, ref isCulled, activeMulti, nodeFoldout, false, false);
  32. }
  33. else rectPreview = TD.DrawNode(selectItem, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, false, !selectItem.splatCustom);
  34. if (isCulled || !nodeFoldout) return;
  35. if (TC_Settings.instance.hasMasterTerrain)
  36. {
  37. Vector2 sliderPos = TD.GetPositionScaled(new Vector2(pos.x + 10.5f, pos.y + 297.5f));
  38. GUIUtility.ScaleAroundPivot(new Vector2(TD.scale * 2.25f, TD.scale * 2.25f), new Vector2(sliderPos.x, sliderPos.y));
  39. if (selectItem.outputId != TC.objectOutput)
  40. {
  41. if (selectItem.outputId == TC.colorOutput)
  42. {
  43. Color colOld = selectItem.color;
  44. if (Event.current.button != 2) selectItem.color = EditorGUI.ColorField(new Rect(sliderPos.x, sliderPos.y + 4, 93, 10), selectItem.color);
  45. else EditorGUI.ColorField(new Rect(sliderPos.x, sliderPos.y + 4, 93, 10), selectItem.color);
  46. selectItem.color.a = 1;
  47. if (selectItem.color != colOld) selectItem.Refresh();
  48. }
  49. else
  50. {
  51. int selectIndexOld = selectItem.selectIndex;
  52. int total = selectItem.GetItemTotalFromTerrain();
  53. if (total > 1)
  54. {
  55. if (selectItem.outputId == TC.treeOutput) sliderPos.y -= 17;
  56. if (Event.current.button != 2) selectItem.selectIndex = (int)GUI.HorizontalSlider(new Rect(sliderPos.x, sliderPos.y, 110, 16), selectItem.selectIndex, 0, total - 1);
  57. else GUI.HorizontalSlider(new Rect(sliderPos.x, sliderPos.y, 110, 16), selectItem.selectIndex, 0, total - 1);
  58. }
  59. if (selectItem.selectIndex != selectIndexOld) selectItem.Refresh();
  60. }
  61. }
  62. if (selectItem.outputId == TC.splatOutput)
  63. {
  64. // if (selectItem.splatCustom) DrawSplatCustomPreview(selectItem, rectPreview);
  65. }
  66. GUI.matrix = Matrix4x4.Scale(new Vector3(1, 1, 1));
  67. TC_NodeGUI.DrawAddItem(rectPreview, pos, selectItem);
  68. TC_NodeGUI.LeftClickMenu(rectPreview, selectItem);
  69. }
  70. if (selectItem.outputId != TC.colorOutput)
  71. {
  72. Rect colorRect = new Rect(rectPreview.x + 0 * TD.scale, rectPreview.y + 0 * TD.scale, 60 * TD.scale, 16f * TD.scale);
  73. GUI.color = new Color(selectItem.color.r, selectItem.color.g, selectItem.color.b, 0.75f);
  74. GUI.DrawTexture(colorRect, Texture2D.whiteTexture);
  75. GUI.color = Color.white;
  76. }
  77. }
  78. }
  79. }