TC_TerrainLayer.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace TerrainComposer2
  6. {
  7. public class TC_TerrainLayer : TC_ItemBehaviour
  8. {
  9. // [NonSerialized] static public TC_TerrainLayer current;
  10. [NonSerialized] public TC_LayerGroup[] layerGroups = new TC_LayerGroup[6];
  11. // [NonSerialized]
  12. public List<TC_SelectItem> objectSelectItems;
  13. // [NonSerialized]
  14. public List<TC_SelectItem> treeSelectItems;
  15. public float treeResolutionPM = 128;
  16. public float objectResolutionPM = 128;
  17. public Vector2 objectAreaSize;
  18. public Transform objectTransform; // stream around camera
  19. public int colormapResolution = 128;
  20. public int meshResolution = 2048;
  21. public float seedChild;
  22. public TC_LayerGroup Clone()
  23. {
  24. GameObject obj = (GameObject)Instantiate(gameObject, t.position, t.rotation);
  25. obj.transform.parent = TC_Area2D.current.transform;
  26. return obj.GetComponent<TC_LayerGroup>();
  27. }
  28. public void LinkClone(TC_TerrainLayer terrainLayerS)
  29. {
  30. TC_LayerGroup layerGroup;
  31. for (int i = 0; i < layerGroups.Length; i++)
  32. {
  33. layerGroup = layerGroups[i];
  34. if (layerGroup != null)
  35. {
  36. layerGroup.LinkClone(terrainLayerS.layerGroups[i]);
  37. }
  38. }
  39. }
  40. public void New(bool undo)
  41. {
  42. //#if UNITY_EDITOR
  43. //if (undo) UnityEditor.Undo.RecordObject(gameObject, "Undo New TerrainComposer Project");
  44. //#endif
  45. bool autoGenerateOld = TC_Generate.instance.autoGenerate;
  46. TC_Generate.instance.autoGenerate = false;
  47. Reset();
  48. CreateLayerGroups();
  49. TC_Generate.instance.autoGenerate = autoGenerateOld;
  50. }
  51. public void CreateLayerGroups()
  52. {
  53. TC_ItemBehaviour item;
  54. for (int i = 0; i < 6; i++)
  55. {
  56. item = (TC_ItemBehaviour)Add<TC_LayerGroup>(TC.outputNames[i] + " Output", false, false, false, i);
  57. item.visible = false;
  58. }
  59. }
  60. // (arg0 : NodeTYpe) (arg1 : OutputId) (arg2 : Command)
  61. public int ExecuteCommand(string[] arg)
  62. {
  63. if (arg == null) return -1;
  64. if (arg.Length == 0) return -1;
  65. int returnValue = -1;
  66. if (arg[0] == "TerrainLayer" || arg[0] == "All")
  67. {
  68. }
  69. else
  70. {
  71. if (arg.Length <= 1) return -1;
  72. int outputId = TC.OutputNameToOutputID(arg[1]);
  73. if (outputId == -1)
  74. {
  75. for (int i = 0; i < 6; i++) returnValue = layerGroups[i].ExecuteCommand(arg);
  76. }
  77. else returnValue = layerGroups[outputId].ExecuteCommand(arg);
  78. }
  79. return returnValue;
  80. }
  81. public void ResetPlaced()
  82. {
  83. layerGroups[TC.treeOutput].ResetPlaced();
  84. layerGroups[TC.objectOutput].ResetPlaced();
  85. }
  86. public void CalcTreePlaced()
  87. {
  88. layerGroups[TC.treeOutput].CalcPlaced();
  89. }
  90. public void CalcObjectPlaced()
  91. {
  92. layerGroups[TC.objectOutput].CalcPlaced();
  93. }
  94. public void ResetObjects()
  95. {
  96. layerGroups[TC.objectOutput].ResetObjects();
  97. }
  98. public void Reset()
  99. {
  100. TC.DestroyChildrenTransform(t);
  101. }
  102. public void GetItems(bool refresh)
  103. {
  104. GetItems(refresh, true, false);
  105. }
  106. public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
  107. {
  108. // current = this;
  109. if (TC_Settings.instance == null) return;
  110. TC_Settings.instance.HasMasterTerrain();
  111. if (resetTextures)
  112. {
  113. TC_Compute.instance.DisposeTextures();
  114. TC_Area2D.current.DisposeTextures();
  115. TC_Settings.instance.DisposeTextures();
  116. }
  117. for (int i = 0; i < layerGroups.Length; i++) GetItem(i, rebuildGlobalLists, resetTextures);
  118. TC.MoveToDustbinChildren(t, 6);
  119. }
  120. public void GetItem(int outputId, bool rebuildGlobalLists, bool resetTextures)
  121. {
  122. // Debug.Log("Terrain Layer GetItem " + TC.outputNames[outputId]);
  123. active = visible;
  124. if (t.childCount < 6)
  125. {
  126. active = false;
  127. return;
  128. }
  129. if (outputId == TC.objectOutput)
  130. {
  131. if (objectSelectItems == null) objectSelectItems = new List<TC_SelectItem>();
  132. else objectSelectItems.Clear();
  133. }
  134. else if (outputId == TC.treeOutput)
  135. {
  136. if (treeSelectItems == null) treeSelectItems = new List<TC_SelectItem>();
  137. else treeSelectItems.Clear();
  138. }
  139. Transform child = t.GetChild(outputId);
  140. TC_LayerGroup layerGroup = child.GetComponent<TC_LayerGroup>();
  141. if (layerGroup != null)
  142. {
  143. layerGroup.level = 0;
  144. layerGroup.outputId = outputId;
  145. layerGroup.listIndex = outputId;
  146. layerGroup.parentItem = this;
  147. layerGroup.GetItems(true, rebuildGlobalLists, resetTextures);
  148. layerGroups[outputId] = layerGroup;
  149. }
  150. }
  151. }
  152. }