void OnDestroy() { if (m_Nodes != null) { foreach (KeyValuePair <int, LSubTerrain> kvp in m_Nodes) { kvp.Value.Release(); } m_Nodes.Clear(); } if (m_map32Trees != null) { m_map32Trees.Clear(); } if (m_mapExistTempTrees != null) { m_mapExistTempTrees.Clear(); } if (m_mapTempTreeInfos != null) { m_mapTempTreeInfos.Clear(); } LSubTerrIO.DestroyInst(m_IO); s_Instance = null; }
void Awake() { Debug.Log("Creating LSubTerrainMgr!"); // Assign instance if (s_Instance != null) { Debug.LogError("Can not have a second instance of LSubTerrainMgr !"); } s_Instance = this; }
void GetGlobalTreeInfoForGather() { if (null != LSubTerrainMgr.Instance) { mGlobalTreeInfos = LSubTerrainMgr.Picking(position, transform.forward, false, m_Data.GatherRadius, 360f); } else if (null != RSubTerrainMgr.Instance) { mGlobalTreeInfos = RSubTerrainMgr.Picking(position, transform.forward, false, m_Data.GatherRadius, 360f); } }
bool CanCather(float radius = 2.0f, float angle = 360.0f) { List <GlobalTreeInfo> grassInfoList = new List <GlobalTreeInfo>(); if (null != LSubTerrainMgr.Instance) { grassInfoList = LSubTerrainMgr.Picking(position, transform.forward, false, radius, angle); } else if (null != RSubTerrainMgr.Instance) { grassInfoList = RSubTerrainMgr.Picking(position, transform.forward, false, radius, angle); } return(grassInfoList.Count > 0); }
void Update() { // Determine node area LSubTerrUtils.WorldPosToPos(s_Instance.CameraTransform.position, _iTmpCamPos); if (!m_IO.TryFill_T(_iTmpCamPos, m_Nodes)) { return; } // Apply CamPos _iCurCamPos.x = _iTmpCamPos.x; _iCurCamPos.y = _iTmpCamPos.y; _iCurCamPos.z = _iTmpCamPos.z; // Determine near tree area if (PlayerTransform == null) { PlayerTransform = CameraTransform; } else if (IsAllNodeFinishedProcess()) { RefreshTreeGos(); } #if false if (Application.isEditor) { DrawOutline(); } #endif // Delete the LSubTerrains out of cache DeleteNodesOutfield(_iCurCamPos); if (_bDataDirty) { _bDataDirty = false; LSubTerrainMgr.RefreshAllLayerTerrains(); } }
private IEnumerator RefreshRegion() { bProcessing = true; #region PREPARE_DATA yield return(0); m_mapPrototype.Clear(); m_listPrototype.Clear(); for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData) { yield return(0); } if (m_allTreesInLayer.ContainsKey(idx)) { List <TreeInfo> trees_in_zone = m_allTreesInLayer[idx]; foreach (TreeInfo ti in trees_in_zone) { // New prototype ? if (!m_mapPrototype.ContainsKey(ti.m_protoTypeIdx)) { int next_index = m_listPrototype.Count; m_mapPrototype.Add(ti.m_protoTypeIdx, next_index); m_listPrototype.Add(ti.m_protoTypeIdx); } } } } yield return(0); } TreePrototype [] FinalPrototypeArray = new TreePrototype [m_listPrototype.Count]; for (int i = 0; i < m_listPrototype.Count; ++i) { FinalPrototypeArray[i] = new TreePrototype(); FinalPrototypeArray[i].bendFactor = LSubTerrainMgr.Instance.GlobalPrototypeBendFactorList[m_listPrototype[i]]; FinalPrototypeArray[i].prefab = LSubTerrainMgr.Instance.GlobalPrototypePrefabList[m_listPrototype[i]]; } // Calc Count int tree_count = 0; for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); if (m_allTreesInLayer.ContainsKey(idx)) { tree_count += m_allTreesInLayer[idx].Count; } } } TreeInstance [] FinalTreeInstanceArray = new TreeInstance [tree_count]; int t = 0; for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); if (m_allTreesInLayer.ContainsKey(idx)) { List <TreeInfo> trees_in_zone = m_allTreesInLayer[idx]; foreach (TreeInfo ti in trees_in_zone) { if (t < FinalTreeInstanceArray.Length) { Vector3 new_pos = ti.m_pos; new_pos += new Vector3(x - xIndex + 1, 0, z - zIndex + 1); new_pos.x /= 3; new_pos.z /= 3; FinalTreeInstanceArray[t].color = ti.m_clr; FinalTreeInstanceArray[t].heightScale = ti.m_heightScale; FinalTreeInstanceArray[t].widthScale = ti.m_widthScale; FinalTreeInstanceArray[t].lightmapColor = ti.m_lightMapClr; FinalTreeInstanceArray[t].position = new_pos; if (!m_mapPrototype.ContainsKey(ti.m_protoTypeIdx)) { FinalTreeInstanceArray[t].heightScale = 0; FinalTreeInstanceArray[t].widthScale = 0; FinalTreeInstanceArray[t].position = Vector3.zero; FinalTreeInstanceArray[t].prototypeIndex = 0; continue; } FinalTreeInstanceArray[t].prototypeIndex = m_mapPrototype[ti.m_protoTypeIdx]; } t++; } } } } yield return(0); #endregion #region ASSIGN_DATA gameObject.SetActive(false); m_TerrData.treeInstances = new TreeInstance[0]; m_TerrData.treePrototypes = FinalPrototypeArray; m_TerrData.treeInstances = FinalTreeInstanceArray; if (Application.isEditor) { _TreePrototypeCount = m_TerrData.treePrototypes.Length; _TreeInstanceCount = m_TerrData.treeInstances.Length; } transform.position = LSubTerrUtils.PosToWorldPos(new IntVector3(xIndex - 1, 0, zIndex - 1)); gameObject.SetActive(true); #endregion bProcessing = false; if (OnRefreshRegion != null) { OnRefreshRegion(); } StartCoroutine("RefreshBillboards"); }
private IEnumerator RefreshBillboards() { // Check if the highest layer if (LSubTerrainMgr.Instance.Layers[LayerIndex].MaxTreeHeight < 50) { bBillboardProcessing = false; yield break; } bBillboardProcessing = true; // Delete Far BTerrains List <int> del_list = new List <int> (); long tempIndexX, tempIndexZ; foreach (KeyValuePair <int, BillboardTerrain> kvp in m_BillboardTerrains) { IntVector3 pos = LSubTerrUtils.IndexToPos(kvp.Key); tempIndexX = pos.x - xIndex; tempIndexZ = pos.z - zIndex; //lz-2017.07.27 差值如果是Int.MinValue用Mathf.Abs会报错: OverflowException: Value is too small if (System.Math.Abs(tempIndexX) > 3 || System.Math.Abs(tempIndexZ) > 3 || System.Math.Abs(tempIndexX) <= 1 && System.Math.Abs(tempIndexZ) <= 1) { kvp.Value.Reset(); GameObject.Destroy(kvp.Value.gameObject); del_list.Add(kvp.Key); } } foreach (int del in del_list) { m_BillboardTerrains.Remove(del); } // Add new BTerrains for (int x = Last_x - 1; x <= Last_x + 1; ++x) { for (int z = Last_z - 1; z <= Last_z + 1; ++z) { if (x >= xIndex - 1 && x <= xIndex + 1 && z >= zIndex - 1 && z <= zIndex + 1) { continue; } if (x > xIndex + 3 || x < xIndex - 3 || z > zIndex + 3 || z < zIndex - 3) { continue; } int idx = LSubTerrUtils.PosToIndex(x, z); while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData) { yield return(0); } if (m_allTreesInLayer.ContainsKey(idx)) { CreateOneBTerrain(x, z); } } } yield return(0); // Add new BTerrains for (int x = xIndex - 3; x <= xIndex + 3; ++x) { for (int z = zIndex - 3; z <= zIndex + 3; ++z) { if (x >= xIndex - 1 && x <= xIndex + 1 && z >= zIndex - 1 && z <= zIndex + 1) { continue; } if (x >= Last_x - 1 && x <= Last_x + 1 && z >= Last_z - 1 && z <= Last_z + 1) { continue; } int idx = LSubTerrUtils.PosToIndex(x, z); while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData) { yield return(0); } if (m_allTreesInLayer.ContainsKey(idx)) { CreateOneBTerrain(x, z); } } yield return(0); } Last_x = xIndex; Last_z = zIndex; bBillboardProcessing = false; }
//Vector3 mayCenter; Vector3 GetStandPos(GlobalTreeInfo _GlobaltreeInfo, PeEntity player, PeEntity Npc) { if (_GlobaltreeInfo._treeInfo == null) { return(Vector3.zero); } if (_GlobaltreeInfo.HasCreatPickPos) { Vector3 cutPos; if (_GlobaltreeInfo.AddCutter(Npc.Id, out cutPos)) { return(cutPos); } return(Vector3.zero); } else { GameObject obj = null; if (null != RSubTerrainMgr.Instance) { if (RSubTerrainMgr.HasCollider(_GlobaltreeInfo._treeInfo.m_protoTypeIdx)) { obj = RSubTerrainMgr.Instance.GlobalPrototypeColliders[_GlobaltreeInfo._treeInfo.m_protoTypeIdx]; } } else if (null != LSubTerrainMgr.Instance) { if (LSubTerrainMgr.HasCollider(_GlobaltreeInfo._treeInfo.m_protoTypeIdx)) { obj = LSubTerrainMgr.Instance.GlobalPrototypeColliders[_GlobaltreeInfo._treeInfo.m_protoTypeIdx]; } } if (obj == null) { return(Vector3.zero); } CapsuleCollider collider = obj.GetComponent <CapsuleCollider>(); if (collider == null) { return(Vector3.zero); } Vector3 loacl = new Vector3(_GlobaltreeInfo._treeInfo.m_widthScale, _GlobaltreeInfo._treeInfo.m_heightScale, _GlobaltreeInfo._treeInfo.m_widthScale); Vector3 c = new Vector3(collider.center.x * loacl.x, collider.center.y * loacl.y, collider.center.z * loacl.z); _GlobaltreeInfo.TreeCapCenterPos = new Vector3(_GlobaltreeInfo.WorldPos.x + c.x, _GlobaltreeInfo.WorldPos.y, _GlobaltreeInfo.WorldPos.z + c.z); Vector3 direction = (player.peTrans.position - _GlobaltreeInfo.TreeCapCenterPos).normalized; if (_GlobaltreeInfo.CreatCutPos(_GlobaltreeInfo.TreeCapCenterPos, direction, collider.radius)) { Vector3 cutPos; if (_GlobaltreeInfo.AddCutter(Npc.Id, out cutPos)) { return(cutPos); } return(Vector3.zero); } return(Vector3.zero); } }
protected void RPC_SKFellTree(uLink.BitStream stream, uLink.NetworkMessageInfo info) { /*int typeIndex = */ stream.Read <int> (); Vector3 pos = stream.Read <Vector3> (); /*float maxHP = */ stream.Read <float> (); float hp = stream.Read <float> (); TreeInfo tree = null; // = RSubTerrainMgr.TreesAtPosF(pos); if (null != LSubTerrainMgr.Instance) { int x = Mathf.FloorToInt(pos.x); int y = Mathf.FloorToInt(pos.y); int z = Mathf.FloorToInt(pos.z); List <GlobalTreeInfo> tree_list = LSubTerrainMgr.Picking(new IntVector3(x, y, z), true); if (tree_list.Count > 0) { foreach (var iter in tree_list) { if (hp <= 0) { PeEntity entity = EntityMgr.Instance.Get(Id); SkEntity skEntity = null == entity ? null : entity.skEntity; SkEntitySubTerrain.Instance.OnTreeCutDown(skEntity, iter); DigTerrainManager.RemoveTree(iter); if (IsOwner) { SkEntitySubTerrain.Instance.SetTreeHp(iter.WorldPos, hp); } } else { if (IsOwner) { SkEntitySubTerrain.Instance.SetTreeHp(iter.WorldPos, hp); } } } } } else if (null != RSubTerrainMgr.Instance) { RSubTerrSL.AddDeletedTree(pos); tree = RSubTerrainMgr.TreesAtPosF(pos); if (null != tree) { GlobalTreeInfo gTree = new GlobalTreeInfo(-1, tree); if (hp <= 0) { PeEntity entity = EntityMgr.Instance.Get(Id); SkEntity skEntity = null == entity ? null : entity.skEntity; SkEntitySubTerrain.Instance.OnTreeCutDown(skEntity, gTree); DigTerrainManager.RemoveTree(gTree); if (IsOwner) { SkEntitySubTerrain.Instance.SetTreeHp(gTree.WorldPos, hp); } } else { if (IsOwner) { SkEntitySubTerrain.Instance.SetTreeHp(gTree.WorldPos, hp); } } } } }
void OnCollisionEnter(Collision colInfo) { GameObject go = colInfo.collider.gameObject; if (go.layer == Layer.TreeStatic) { // Proceed one each time /* * ContactPoint point = colInfo.contacts[0]; * Vector3 vPt = point.point; * int x = Mathf.CeilToInt(vPt.x); * int y = Mathf.CeilToInt(vPt.y); * int z = Mathf.CeilToInt(vPt.z); * for(int dx = 0; dx < 2; dx++) { * for(int dy = 0; dx < 2; dx++) { * for(int dx = 0; dx < 2; dx++) { * } * } * } */ } else if (go.layer == Layer.NearTreePhysics) { if (Pathea.PeGameMgr.IsStory || Pathea.PeGameMgr.IsAdventure) { PeEntity entity = GetComponentInParent <PeEntity>(); if (Pathea.PeGameMgr.IsStory) { if (entity != null) { if (entity.Field == MovementField.Sky && entity.commonCmpt.entityProto.proto == EEntityProto.Monster) { if (entity.maxRadius < MinCmpt(colInfo.collider.bounds.extents) * 2f) { return; } } else if (entity.carrier) { if (colInfo.relativeVelocity.magnitude * entity.carrier.rigidbody.mass < MinCmpt(colInfo.collider.bounds.extents) * PEVCConfig.instance.treeHardness) { return; } } GlobalTreeInfo tree = LSubTerrainMgr.TryGetTreeInfo(go); if (tree != null) { LSubTerrainMgr.DeleteTree(go); LSubTerrainMgr.RefreshAllLayerTerrains(); SkEntitySubTerrain.Instance.SetTreeHp(tree.WorldPos, 0); StroyManager.Instance.TreeCutDown(entity.position, tree._treeInfo, tree.WorldPos); } } } else // Pathea.PeGameMgr.IsAdventure { if (entity != null) { if (entity.Field == MovementField.Sky && entity.commonCmpt.entityProto.proto == EEntityProto.Monster) { if (entity.maxRadius < MinCmpt(colInfo.collider.bounds.extents) * 2f) { return; } } else if (entity.carrier) { if (colInfo.relativeVelocity.magnitude * entity.carrier.rigidbody.mass < MinCmpt(colInfo.collider.bounds.extents) * PEVCConfig.instance.treeHardness) { return; } } TreeInfo tree = RSubTerrainMgr.TryGetTreeInfo(go); if (tree != null) { RSubTerrainMgr.DeleteTree(go); RSubTerrainMgr.RefreshAllLayerTerrains(); SkEntitySubTerrain.Instance.SetTreeHp(tree.m_pos, 0); StroyManager.Instance.TreeCutDown(entity.position, tree, tree.m_pos); } } } } } //50吨以15米/秒速度撞击的伤害缩放为1 50 * 15 * 15 = 11250 else if (go.layer == Layer.AIPlayer || go.layer == Layer.Player) { PeEntity target = go.GetComponentInParent <PeEntity>(); if (target != null && m_Entity != null && m_Entity.carrier != null && colInfo.relativeVelocity.sqrMagnitude > 2.0f * 2.0f) { NetCmpt net = m_Entity.GetComponent <NetCmpt>(); if (net == null || net.IsController) { float scale = 1.0f / 11250.0f; float mass = m_Entity.carrier.creationController.creationData.m_Attribute.m_Weight * 0.001f; float speed = colInfo.relativeVelocity.sqrMagnitude; float damageScale = Mathf.Clamp(mass * speed * scale, 0.0f, 2.0f); //Debug.LogError("Mass:" + mass + " Speed:" + speed + " Scale:" + damageScale); if (m_RigidBody == null || m_RigidBody.velocity.sqrMagnitude < 5.0f * 5.0f || damageScale < 0.01) { damageScale = 0.0f; } else { PECapsuleHitResult hitResult = new PECapsuleHitResult(); hitResult.selfTrans = transform; hitResult.hitTrans = go.transform; hitResult.hitPos = colInfo.contacts[0].point; hitResult.hitDir = -colInfo.contacts[0].normal; hitResult.damageScale = damageScale; m_Entity.skEntity.CollisionCheck(hitResult); //if(go.layer == Layer.Player && target.NpcCmpt != null && speed > 10.0f*10.0f) //{ // if(target.biologyViewCmpt != null) // { // RagdollHitInfo hitInfo = new RagdollHitInfo(); // hitInfo.hitTransform = target.biologyViewCmpt.monoRagdollCtrlr.ragdollRootBone; // hitInfo.hitPoint = colInfo.contacts[0].point; // hitInfo.hitNormal = colInfo.contacts[0].normal; // hitInfo.hitForce = colInfo.impulse; // target.biologyViewCmpt.ActivateRagdoll(hitInfo); // } //} } } } } //50吨以15米/秒速度撞击的伤害缩放为1 50 * 15 * 15 = 11250 if (go.layer == Layer.VFVoxelTerrain || go.layer == Layer.TreeStatic //|| go.layer == Layer.NearTreePhysics || go.layer == Layer.Building || go.layer == Layer.SceneStatic || go.layer == Layer.Unwalkable || go.layer == Layer.GIEProductLayer) { bool isWheel = false; if (go.layer == Layer.VFVoxelTerrain) { for (int i = 0; i < colInfo.contacts.Length; i++) { if (colInfo.contacts[i].thisCollider.gameObject.GetComponentInParent <VCPVehicleWheel>() != null) { isWheel = true; } } } if (!isWheel && m_Entity != null && m_Entity.carrier != null && colInfo.relativeVelocity.sqrMagnitude > 2.0f * 2.0f) { NetCmpt net = m_Entity.GetComponent <NetCmpt>(); if (net == null || net.IsController) { float scale = 1.0f / 11250.0f; float mass = m_Entity.carrier.creationController.creationData.m_Attribute.m_Weight * 0.001f; float speed = colInfo.relativeVelocity.sqrMagnitude; float damageScale = Mathf.Clamp(mass * speed * scale, 0.0f, 2.0f); Vector3 v = m_RigidBody.velocity; float curSpeed = Mathf.Sqrt(v.x * v.x + v.z * v.z) * 3.6f; //Debug.LogError("Mass:" + mass + " Speed:" + speed + " Scale:" + damageScale); if (curSpeed < 45f || damageScale < 0.01) { damageScale = 0.0f; } else { SkillSystem.SkEntity.MountBuff(m_Entity.skEntity, 30200174, new List <int> { 0 }, new List <float>() { damageScale }); //PECapsuleHitResult hitResult = new PECapsuleHitResult(); //hitResult.selfTrans = transform; //hitResult.hitTrans = go.transform; //hitResult.hitPos = colInfo.contacts[0].point; //hitResult.hitDir = -colInfo.contacts[0].normal; //hitResult.damageScale = damageScale; //m_Entity.skEntity.CollisionCheck(hitResult); //Debug.LogError(go.name + " --> " + colInfo.relativeVelocity.magnitude); } } } } }
// Update is called once per frame void Update() { if (BeginIndex != lastBeginIndex && Mathf.Abs(BeginIndex - EndIndex) > 3) { EndIndex = BeginIndex; } lastBeginIndex = BeginIndex; if (Input.GetAxis("Mouse ScrollWheel") > 0) { Radius *= 1.15f; if (Radius > 32F) { Radius = 32F; } RandOnce(); } else if (Input.GetAxis("Mouse ScrollWheel") < 0) { Radius *= 0.82f; if (Radius < 1F) { Radius = 1F; } RandOnce(); } if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals)) { Density *= 0.9f; RandOnce(); } if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)) { Density *= 1.18f; RandOnce(); } float MinDensity = 2.0f; if (Density > 36) { Density = 36; } if (Density < MinDensity) { Density = MinDensity; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rch; if (Physics.Raycast(ray, out rch, 500, 1 << Pathea.Layer.VFVoxelTerrain)) { Focus = rch.point; Normal = rch.normal; } else { Focus = Vector3.zero; Normal = Vector3.zero; } if (Input.GetKeyDown(KeyCode.X)) { RandOnce(); } if (Input.GetKeyDown(KeyCode.R)) { Eraser = !Eraser; } bool processing = false; for (int l = 0; l < LSubTerrainMgr.Instance.LayerCreators.Length; ++l) { if (LSubTerrainMgr.Instance.LayerCreators[l].bProcessing) { processing = true; break; } } if (Input.GetKeyDown(KeyCode.N) && !processing) { if (Eraser) { for (float x = Mathf.Floor(Focus.x - Radius); x <= Mathf.Ceil(Focus.x + Radius); x += 1.0f) { for (float z = Mathf.Floor(Focus.z - Radius); z <= Mathf.Ceil(Focus.z + Radius); z += 1.0f) { if (Normal.y > 0) { Vector3 pos = new Vector3(x, Focus.y + Radius, z); if (Physics.Raycast(pos, Vector3.down, out rch, 2 * Radius, 1 << Pathea.Layer.VFVoxelTerrain)) { if ((rch.point - Focus).magnitude <= Radius + 0.5f) { for (float h = rch.point.y + EraserHeightLBB; h <= rch.point.y + EraserHeightUBB; h += 1) { LSubTerrainMgr.DeleteTreesAtPos(new IntVector3(rch.point.x, h, rch.point.z), EraserFilterBegin, EraserFilterEnd); } } } } else { Vector3 pos = new Vector3(x, Focus.y - Radius, z); if (Physics.Raycast(pos, Vector3.up, out rch, 2 * Radius, 1 << Pathea.Layer.VFVoxelTerrain)) { if ((rch.point - Focus).magnitude <= Radius + 0.5f) { for (float h = rch.point.y + EraserHeightLBB; h <= rch.point.y + EraserHeightUBB; h += 1) { LSubTerrainMgr.DeleteTreesAtPos(new IntVector3(rch.point.x, h, rch.point.z), EraserFilterBegin, EraserFilterEnd); } } } } } } } else { for (int i = 0; i < TreeCount; ++i) { int prototype = (int)((Random.value) * (Mathf.Abs((float)EndIndex - (float)BeginIndex) + 0.99999F) + Mathf.Min(BeginIndex, EndIndex)); float widthscale = Random.value * (MaxWidthScale - MinWidthScale) + MinWidthScale; float heightscale = Random.value * (MaxHeightScale - MinHeightScale) + MinHeightScale; if (widthscale < 0.1f) { widthscale = 0.1f; } if (widthscale > 3.0f) { widthscale = 3.0f; } if (heightscale < 0.1f) { heightscale = 0.1f; } if (heightscale > 3.0f) { heightscale = 3.0f; } if (Normal.y > 0) { Vector3 pos = Focus + Vector3.up * Radius; pos.x += TreePositions[i].x; pos.z += TreePositions[i].y; if (Physics.Raycast(pos, Vector3.down, out rch, 2 * Radius, 1 << Pathea.Layer.VFVoxelTerrain)) { LSubTerrainMgr.AddTree(rch.point, prototype, widthscale, heightscale); } } else { Vector3 pos = Focus - Vector3.up * Radius; pos.x += TreePositions[i].x; pos.z += TreePositions[i].y; if (Physics.Raycast(pos, Vector3.up, out rch, 2 * Radius, 1 << Pathea.Layer.VFVoxelTerrain)) { LSubTerrainMgr.AddTree(rch.point, prototype, widthscale, heightscale); } } } } LSubTerrainMgr.RefreshAllLayerTerrains(); LSubTerrainMgr.CacheAllNodes(); } }
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); }
public bool UpdateOPTreeInfo() { mFindTreeInfo = null; if (null == trans) { return(false); } if (Vector3.Distance(trans.position, trans.position) > GatherMaxDis) { return(false); } List <GlobalTreeInfo> grassInfoList; if (null != LSubTerrainMgr.Instance) { grassInfoList = LSubTerrainMgr.Picking(trans.position, Vector3.forward, false, GatherMaxDis, 360f); } else if (null != RSubTerrainMgr.Instance) { grassInfoList = RSubTerrainMgr.Picking(trans.position, Vector3.forward, false, GatherMaxDis, 360f); } else { return(false); } for (int i = 0; i < grassInfoList.Count; i++) { NaturalRes resFind = NaturalResAsset.NaturalRes.GetTerrainResData(grassInfoList[i]._treeInfo.m_protoTypeIdx + 1000); if (null != resFind) { if (resFind.m_type == 10) { if (!PeCamera.cursorLocked) { if (null != LSubTerrainMgr.Instance) { Vector3 pos = grassInfoList[i].WorldPos; Bounds bound = new Bounds(); bound.SetMinMax(pos + grassInfoList[i]._treeInfo.m_heightScale * LSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].min, pos + grassInfoList[i]._treeInfo.m_heightScale * LSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].max); if (!bound.IntersectRay(PeCamera.mouseRay)) { continue; } } else if (null != RSubTerrainMgr.Instance) { Vector3 pos = grassInfoList[i]._treeInfo.m_pos; Bounds bound = new Bounds(); bound.SetMinMax(pos + grassInfoList[i]._treeInfo.m_heightScale * RSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].min, pos + grassInfoList[i]._treeInfo.m_heightScale * RSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].max); if (!bound.IntersectRay(PeCamera.mouseRay)) { continue; } } } mFindTreeInfo = grassInfoList[i]; break; } } } return(null != mFindTreeInfo); }