//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 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); }