TC_TerrainLayerGroup.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. namespace TerrainComposer2
  6. {
  7. public class TC_TerrainLayerGroup : TC_GroupBehaviour
  8. {
  9. List<TerrainLayerGroupItem> itemList = new List<TerrainLayerGroupItem>();
  10. //public void ComputeValue(ref ComputeBuffer totalBuffer)
  11. //{
  12. // TCCompute compute = TCCompute.singleton;
  13. // LayerGroupItem item;
  14. // ComputeBuffer layerBuffer = null;
  15. // ComputeBuffer layerMaskBuffer = null;
  16. // // ComputeBuffer layerGroupBuffer = null;
  17. // TCLayerGroup layerLevel;
  18. // for (int i = 0; i < itemList.Count; i++)
  19. // {
  20. // item = itemList[i];
  21. // layerLevel = item.layerGroup;
  22. // if (i == 0)
  23. // {
  24. // layerMaskBuffer = layerLevel.ComputeValue(ref totalBuffer, TC.heightOutput);
  25. // }
  26. // else
  27. // {
  28. // layerMaskBuffer = layerLevel.ComputeValue(ref layerBuffer, TC.heightOutput);
  29. // if (layerBuffer != null) compute.RunComputeMethod(this, layerLevel, totalBuffer, ref layerBuffer, itemList.Count, i < itemList.Count - 1 ? null : m_previewRenderTex, true, layerMaskBuffer);
  30. // }
  31. // }
  32. // if (layerMaskBuffer != null) { compute.DisposeBuffer(ref layerMaskBuffer); }
  33. // if (totalBuffer == null) Debug.Log("Layer buffer null");
  34. //}
  35. //public override void GetItems()
  36. //{
  37. // Transform child;
  38. // TCLayerGroup layerLevel;
  39. // int childCount = t.childCount;
  40. // Init();
  41. // itemList.Clear();
  42. // // if (preview.tex == null || preview.bytes == null) preview.Create();
  43. // for (int i = 0; i < childCount; i++)
  44. // {
  45. // child = t.GetChild(i);
  46. // layerLevel = child.GetComponent<TCLayerLevel>();
  47. // if (layerLevel != null)
  48. // {
  49. // layerLevel.outputId = i;
  50. // layerLevel.active = layerLevel.go.activeSelf;
  51. // itemList.Add(new LayerGroupMultiItem(layerLevel));
  52. // layerLevel.GetItems();
  53. // }
  54. // }
  55. //}
  56. public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
  57. {
  58. Transform child;
  59. TC_TerrainLayerGroup terrainLayerGroup;
  60. TC_TerrainLayer terrainLayer;
  61. int childCount = transform.childCount;
  62. // Init();
  63. itemList.Clear();
  64. lastActive = -1;
  65. totalActive = 0;
  66. // if (preview.tex == null || preview.bytes == null) preview.Create();
  67. bool newBounds = true;
  68. active = visible;
  69. int listIndex = 0;
  70. for (int i = childCount - 1; i >= 0; i--)
  71. {
  72. child = transform.GetChild(i);
  73. terrainLayer = child.GetComponent<TC_TerrainLayer>();
  74. if (terrainLayer != null)
  75. {
  76. terrainLayer.SetParameters(this, listIndex++);
  77. terrainLayer.terrainLevel = terrainLevel + 1;
  78. terrainLayer.GetItems(refresh, rebuildGlobalLists, resetTextures);
  79. terrainLayer.GetItem(outputId, rebuildGlobalLists, resetTextures);
  80. //{
  81. ++totalActive;
  82. itemList.Add(new TerrainLayerGroupItem(null, terrainLayer));
  83. lastActive = itemList.Count - 1;
  84. if (newBounds) { bounds = terrainLayer.bounds; newBounds = false; }
  85. else bounds.Encapsulate(terrainLayer.bounds);
  86. //}
  87. // else layer.displayRenderTex = null;
  88. }
  89. else
  90. {
  91. terrainLayerGroup = child.GetComponent<TC_TerrainLayerGroup>();
  92. if (terrainLayerGroup != null)
  93. {
  94. terrainLayerGroup.SetParameters(this, listIndex++);
  95. terrainLayerGroup.terrainLevel = terrainLevel + 1;
  96. terrainLayerGroup.GetItems(refresh, rebuildGlobalLists, resetTextures);
  97. ++totalActive;
  98. itemList.Add(new TerrainLayerGroupItem(terrainLayerGroup, null));
  99. lastActive = itemList.Count - 1;
  100. if (newBounds) { bounds = terrainLayerGroup.bounds; newBounds = false; }
  101. else bounds.Encapsulate(terrainLayerGroup.bounds);
  102. }
  103. }
  104. }
  105. TC_Reporter.Log(TC.outputNames[outputId] + " Level " + level + " activeTotal " + totalActive);
  106. if (!active) totalActive = 0;
  107. else if (totalActive == 0) active = false; else active = visible;
  108. }
  109. }
  110. [Serializable]
  111. public class TerrainLayerGroupItem
  112. {
  113. public TC_TerrainLayerGroup terrainLayerGroup;
  114. public TC_TerrainLayer terrainLayer;
  115. public TerrainLayerGroupItem(TC_TerrainLayerGroup terrainLayerGroup, TC_TerrainLayer terrainLayer)
  116. {
  117. this.terrainLayer = terrainLayer;
  118. this.terrainLayerGroup = terrainLayerGroup;
  119. }
  120. }
  121. }