void OnDestroy() { if (m_Chunks != null) { m_Chunks.Clear(); m_Chunks = null; } s_Instance = null; }
void Awake() { Debug.Log("Creating RSubTerrainMgr!"); // Assign instance if (s_Instance != null) { Debug.LogError("Can not have a second instance of RSubTerrainMgr !"); } 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); }
//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); } }
private IEnumerator RefreshRegion() { bProcessing = true; #region PREPARE_DATA yield return(0); m_allTreesInLayer.Clear(); m_mapPrototype.Clear(); m_listPrototype.Clear(); List <int> cnk_list_to_render = RSubTerrainMgr.Instance.ChunkListToRender(); int cnk_count = cnk_list_to_render.Count; for (int i = 0; i < cnk_count; ++i) { int idx = cnk_list_to_render[i]; List <TreeInfo> trees_in_zone = RSubTerrainMgr.ReadChunk(idx).TreeList; foreach (TreeInfo ti in trees_in_zone) { // Add tree float height = RSubTerrainMgr.Instance.GlobalPrototypeBounds[ti.m_protoTypeIdx].extents.y * 2F; // Trees in this layer if (RSubTerrainMgr.Instance.Layers[LayerIndex].MinTreeHeight <= height && height < RSubTerrainMgr.Instance.Layers[LayerIndex].MaxTreeHeight) { m_allTreesInLayer.Add(ti); // 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); } } } } TreePrototype [] FinalPrototypeArray = new TreePrototype [m_listPrototype.Count]; for (int i = 0; i < m_listPrototype.Count; ++i) { FinalPrototypeArray[i] = new TreePrototype(); FinalPrototypeArray[i].bendFactor = RSubTerrainMgr.Instance.GlobalPrototypeBendFactorList[m_listPrototype[i]]; FinalPrototypeArray[i].prefab = RSubTerrainMgr.Instance.GlobalPrototypePrefabList[m_listPrototype[i]]; } yield return(0); int tree_cnt = m_allTreesInLayer.Count; TreeInstance [] FinalTreeInstanceArray = new TreeInstance [tree_cnt]; for (int t = 0; t < tree_cnt; ++t) { TreeInfo ti = m_allTreesInLayer[t]; Vector3 new_pos = ti.m_pos - _TargetPos; new_pos.x /= RSubTerrConstant.TerrainSize.x; new_pos.y /= RSubTerrConstant.TerrainSize.y; new_pos.z /= RSubTerrConstant.TerrainSize.z; #if false if (new_pos.x < 0 || new_pos.y < 0 || new_pos.z < 0 || new_pos.x > 1 || new_pos.y > 1 || new_pos.z > 1) { Debug.LogError("a tree was out of terrain bound, error!"); continue; } #endif if (m_mapPrototype.ContainsKey(ti.m_protoTypeIdx)) // Add key present check { 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; FinalTreeInstanceArray[t].prototypeIndex = m_mapPrototype[ti.m_protoTypeIdx]; } } 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 = _TargetPos; gameObject.SetActive(true); #endregion bProcessing = false; }
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); } } } } }
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); }