internal void Initialize(UTerrainData data, bool newObj) { if (m_Terrain == null || newObj) { m_Terrain = data.terrain; } if (m_GameObject == null || newObj) { m_GameObject = new GameObject("Tree"); m_GameObject.transform.parent = data.gameObject.transform; m_GameObject.transform.localEulerAngles = Vector3.zero; m_GameObject.transform.localPosition = Vector3.zero; m_GameObject.transform.localScale = Vector3.one; m_GameObject.hideFlags = HideFlags.DontSave; } active = m_Active; m_Trees.ForEach(g => g.Initialize(this, newObj)); }
void CreateData() { int i, max; UTools.CheckAndCreateFolder(dataPath); string path = AssetDatabase.GUIDToAssetPath(AssetDatabase.CreateFolder(dataPath, name)); m_NewMesh = new Mesh(); m_NewMesh.name = "Mesh"; m_NewMesh.subMeshCount = m_OldMesh.subMeshCount; m_NewMesh.vertices = m_OldMesh.vertices; m_NewMesh.normals = m_OldMesh.normals; m_NewMesh.tangents = m_OldMesh.tangents; for (i = 0, max = m_OldMesh.subMeshCount; i < max; i++) { m_NewMesh.SetTriangles(m_OldMesh.GetTriangles(i), i); } m_NewMesh.bounds = m_OldMesh.bounds; m_NewMesh.colors = m_OldMesh.colors; m_NewMesh.uv = m_OldMesh.uv; m_NewMesh.uv2 = m_OldMesh.uv2; AssetDatabase.CreateAsset(m_NewMesh, path + "/" + m_NewMesh.name + ".asset"); UpdateSubMesh(); for (i = 0, max = m_SubMesh.Length; i < max; i++) { Mesh sm = m_SubMesh[i]; AssetDatabase.CreateAsset(sm, path + "/" + sm.name + ".asset"); } m_MC.sharedMesh = m_NewMesh; m_Data = ScriptableObject.CreateInstance <UTerrainData>(); m_Data.name = "Data"; AssetDatabase.CreateAsset(m_Data, path + "/" + m_Data.name + ".asset"); AssetDatabase.ImportAsset(path); }
internal void Initialize(UTerrainData data, bool newObj) { if (m_Terrain == null || newObj) { m_Terrain = data.terrain; } Transform trans = terrain.transform.Find("SubMesh"); if (trans != null) { m_GameObject = trans.gameObject; } if (m_GameObject == null || newObj) { m_GameObject = new GameObject("SubMesh"); m_GameObject.transform.parent = terrain.transform; m_GameObject.transform.localPosition = Vector3.zero; m_GameObject.transform.localEulerAngles = Vector3.zero; m_GameObject.transform.localScale = Vector3.one; m_GameObject.hideFlags = HideFlags.HideInHierarchy; } int i, max; if (m_SubMeshes.Count == 0) { for (i = 0, max = m_Terrain.GetAllSubMesh().Length; i < max; i++) { m_SubMeshes.Add(new USubMesh(this, i)); } } for (i = 0, max = m_SubMeshes.Count; i < max; i++) { m_SubMeshes[i].Initialize(this, i, newObj); } active = m_Active; }
public void Initialize(UTerrainData data) { Initialize(data, false); }