void Init() { // Assign global tree prototype lists GlobalPrototypePrefabList = VEditor.m_treePrototypeList; GlobalPrototypeBendFactorList = VEditor.m_treePrototypeBendfactor; GlobalPrototypeBounds = new Bounds [GlobalPrototypePrefabList.Length]; GlobalPrototypeCollidersType = new ColType[GlobalPrototypePrefabList.Length]; GlobalPrototypeColliders = new GameObject [GlobalPrototypePrefabList.Length]; GlobalPrototypeLights = new GameObject [GlobalPrototypePrefabList.Length]; GlobalPrototypeTPHInfo = new LTreePlaceHolderInfo [GlobalPrototypePrefabList.Length]; // Get bounds for (int i = 0; i < GlobalPrototypeBounds.Length; ++i) { { GameObject go = Instantiate(GlobalPrototypePrefabList[i]) as GameObject; go.transform.parent = PrototypeGroup.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; MeshRenderer mr = go.GetComponent <MeshRenderer>(); MeshFilter mf = go.GetComponent <MeshFilter>(); // Light[] ls = go.GetComponentsInChildren<Light>(); Animator ani = go.GetComponent <Animator>(); Animation anim = go.GetComponent <Animation>(); GlobalPrototypeBounds[i] = mf.mesh.bounds; if (i == TreePlaceHolderPrototypeIndex) { GlobalPrototypeBounds[i].extents = new Vector3(1, 2, 1); } Component.Destroy(mr); Component.Destroy(mf); // foreach (Light l in ls) // Light.Destroy(l); if (ani != null) { Component.Destroy(ani); } if (anim != null) { Component.Destroy(anim); } Collider col = go.GetComponent <Collider>(); if (col != null || go.GetComponentsInChildren <Light>(true).Length >= 1) { BoxCollider bc = go.GetComponent <BoxCollider>(); if (bc != null) { GlobalPrototypeTPHInfo[i] = new LTreePlaceHolderInfo(bc.center, bc.size.y * 0.5f, bc.size.x * 0.5f + bc.size.z * 0.5f); } else { GlobalPrototypeTPHInfo[i] = null; } #if !UNITY_5 Collider[] cs = go.GetComponents <Collider>(); foreach (Collider c in cs) { c.isTrigger = true; } #endif go.name = "Prototype [" + i.ToString() + "]'s Collider"; go.SetActive(false); GlobalPrototypeColliders[i] = go; GlobalPrototypeCollidersType[i] = bc != null ? ColType.BoxCollider : (col != null ? ColType.Collider : ColType.None); } else { Destroy(go); GlobalPrototypeColliders[i] = null; GlobalPrototypeCollidersType[i] = ColType.None; } } { GameObject go = Instantiate(GlobalPrototypePrefabList[i]) as GameObject; go.transform.parent = PrototypeGroup.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; MeshRenderer mr = go.GetComponent <MeshRenderer>(); MeshFilter mf = go.GetComponent <MeshFilter>(); Collider[] cs = go.GetComponentsInChildren <Collider>(); Animator ani = go.GetComponent <Animator>(); Animation anim = go.GetComponent <Animation>(); GlobalPrototypeBounds[i] = mf.mesh.bounds; if (i == TreePlaceHolderPrototypeIndex) { GlobalPrototypeBounds[i].extents = new Vector3(1, 2, 1); } Component.Destroy(mr); Component.Destroy(mf); foreach (Collider c in cs) { Collider.Destroy(c); } if (ani != null) { Component.Destroy(ani); } if (anim != null) { Component.Destroy(anim); } if (go.GetComponentsInChildren <Light>(true).Length >= 1) { go.name = "Prototype [" + i.ToString() + "]'s Light"; go.SetActive(false); GlobalPrototypeLights[i] = go; } else { Destroy(go); GlobalPrototypeLights[i] = null; } } } // Create i/o m_IO = LSubTerrIO.CreateInst(); }
private TreeInfo AddTreeInfo(TreeInfo ti) { // Tree place holder works if (ti.m_protoTypeIdx == LSubTerrainMgr.TreePlaceHolderPrototypeIndex || ti.m_pos.x < 0.00001 || ti.m_pos.z < 0.00001 || ti.m_pos.x > 0.99999 || ti.m_pos.z > 0.99999) // Avoid bugs { TreeInfo.FreeTI(ti); return(null); } // Add to tree map _tmpVec3.x = Mathf.FloorToInt(ti.m_pos.x * LSubTerrConstant.SizeF); _tmpVec3.y = Mathf.FloorToInt(ti.m_pos.y * LSubTerrConstant.HeightF); _tmpVec3.z = Mathf.FloorToInt(ti.m_pos.z * LSubTerrConstant.SizeF); int tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3); TreeInfo tmpTi; if (m_mapTrees.TryGetValue(tmpKey, out tmpTi)) { tmpTi.AttachTi(ti); } else { m_mapTrees.Add(tmpKey, ti); } // Add to tree list m_listTrees.Add(ti); // Add to 32 tree map if (LSubTerrainMgr.HasCollider(ti.m_protoTypeIdx) || LSubTerrainMgr.HasLight(ti.m_protoTypeIdx)) { tmpKey = LSubTerrUtils.TreeWorldPosTo32Key(LSubTerrUtils.TreeTerrainPosToWorldPos(X, Z, ti.m_pos)); List <TreeInfo> tmpTis; if (!LSubTerrainMgr.Instance.m_map32Trees.TryGetValue(tmpKey, out tmpTis)) { tmpTis = new List <TreeInfo>(); LSubTerrainMgr.Instance.m_map32Trees.Add(tmpKey, tmpTis); } tmpTis.Add(ti); } // Tree place holder works LTreePlaceHolderInfo tphinfo = LSubTerrainMgr.GetTreePlaceHolderInfo(ti.m_protoTypeIdx); if (tphinfo != null) { TreeInfo tph = TreeInfo.GetTI(); tph.m_clr = Color.white; tph.m_heightScale = tphinfo.m_HeightScale * ti.m_heightScale; tph.m_lightMapClr = Color.white; Vector3 tphoffset = tphinfo.TerrOffset; tphoffset.x *= ti.m_widthScale; tphoffset.y *= ti.m_heightScale; tphoffset.z *= ti.m_widthScale; tph.m_pos = ti.m_pos + tphoffset; tph.m_protoTypeIdx = LSubTerrainMgr.TreePlaceHolderPrototypeIndex; tph.m_widthScale = tphinfo.m_WidthScale * ti.m_widthScale; // Add to tree map _tmpVec3.x = Mathf.FloorToInt(tph.m_pos.x * LSubTerrConstant.SizeF); _tmpVec3.y = Mathf.FloorToInt(tph.m_pos.y * LSubTerrConstant.HeightF); _tmpVec3.z = Mathf.FloorToInt(tph.m_pos.z * LSubTerrConstant.SizeF); tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3); if (m_mapTrees.TryGetValue(tmpKey, out tmpTi)) { tmpTi.AttachTi(tph); } else { m_mapTrees.Add(tmpKey, tph); } // Add to tree list m_listTrees.Add(tph); m_mapTwoFeetTrees.Add(tph, ti); m_mapTwoFeetTrees.Add(ti, tph); } return(ti); }