public bool resetGlobal_NavigationCells(CTriCollector triCollector, ref CNaviMesh navigationMesh) { List <CTRI> listTris; triCollector.getTris(out listTris); // TriCollector에서 데이터 리스트를 얻어옴 navigationMesh.navigation.ConstructNavi(listTris); bool bResultMapping = navigationMesh.navigation.mappingNavigation(triCollector.m_listTris_naviGoal, triCollector.m_listTris_naviBlock, triCollector.m_listTris_naviBlockRoad, triCollector.m_listTris_naviStart, true); if (true == bResultMapping) { m_toolmoduleNavimesh.drawStartCellToGoal(m_meshNavigation_global.navigation, m_triCollector); } triCollector._bReadyToExecuteBuildup_NAVI = false; if (triCollector.getCount_NaviFunction_Tris() > 0) { m_toolmoduleNavimesh.drawAllTri_eachFunctional(m_meshNavigation_global.triCollector, false); } triCollector.setExtractAdjCells(navigationMesh.navigation); return(true); } // protected bool resetGlobal_NavigationCells()
protected bool resetGlobal_TrianglesAll(CNaviMesh naviMesh_active) { //@ Construct All Triangle naviMesh_active.ConstructAllTriangles(RecomputeAllIV); return(true); }
void setNew_NaviMesh(string strKey, CNaviMesh navimeshValue) { navimesh_name navimeshName = new navimesh_name(); navimeshName._naviMesh = navimeshValue; navimeshName._strNameNaviMesh = strKey; m_listNameNavimesh.Add(navimeshName); }
void Awake() { for (int iSeqNavimesh = 0; iSeqNavimesh < arrayStageMesh.Length; ++iSeqNavimesh) { CNaviMesh naviMesh = arrayStageMesh[iSeqNavimesh]; string strNavimesh = arrayStageName[iSeqNavimesh]; setNew_NaviMesh(strNavimesh, naviMesh); } }
//@Process private void Destroy_activeNaviMesh() { if (null != m_naviMesh_Instance && null != m_naviMesh_Instance.gameObject) { Destroy(m_naviMesh_Instance.gameObject); } m_naviMesh_Instance = null; m_iIdxNaviMesh_Instance = navimeshResource.null_navimesh_instance; }
public CNaviMesh getNavigationMesh(int iSeqKey) { if (true == outOfRangeNAVIMESH(iSeqKey)) { return(null); } Destroy_activeNaviMesh(); m_iIdxNaviMesh_Instance = iSeqKey; m_naviMesh_Instance = (CNaviMesh)Instantiate(m_listNameNavimesh[iSeqKey]._naviMesh); return(m_naviMesh_Instance); }
bool intersectNavimesh(CNaviMesh navimesh, Vector3 v3PosUnit, ref Vector3 v3PosIntersected) { Vector3 v3PosSimulate = v3PosUnit; v3PosSimulate.y = v3PosSimulate.y + dist_adjustpos_up; Ray rayTestsimulate = new Ray(v3PosSimulate, Vector3.down); RaycastHit casthitted = new RaycastHit(); bool bIntersected = navimesh.GetComponent<Collider>().Raycast(rayTestsimulate, out casthitted, dist_raycast_adjust); if (true == bIntersected) { v3PosIntersected = casthitted.point; } return bIntersected; }
protected bool resetGlobal_TrianglesAll_LoadBinaryFile(CNaviMesh naviMesh_active) { // Load triangle and naviinfo if (0 < m_stageMap.MapTriangle.Count) { naviMesh_active.setAllFunctionalTris(m_stageMap.MapTriangle, m_stageMap.GroundBlockPoint_List, m_stageMap.GroundBlockRoadPoint_List, m_stageMap.GroundStartPoint_List, m_stageMap.GoalPoint_List); } // if (0 < m_stageMap.MapTriangle.Count) if (0 == m_stageMap.MapTriangle.Count) { return(resetGlobal_TrianglesAll(naviMesh_active)); } return(true); }
} // void Initialize protected bool clearGLOBAL(bool isSkipLoadedData = false) { try { //@ Release & Clear Triangle, DrawMesh, Object Dyn UnitPool unitpool_ = UnitPool.GetInstance; unitpool_.TruncateAll(); m_intervalUnitWalking.DestructIntervalsAll(); m_processInput.DestructInput(); if (false == isSkipLoadedData) { m_stageMap.Release(); } m_baseTowerCollector.DestructBaseAll(); m_baseCoreCollector.DestructBaseAll(); m_baseCoresubCollector.DestructBaseAll(); m_baseStartCollector.DestructBaseAll(); m_baseBlockCollector.DestructBaseAll(); m_toolmoduleNavimesh.ReleaseNaviMeshTool(); if (null != m_meshNavigation_global) { m_meshNavigation_global.DestructNaviMesh(); m_meshNavigation_global = null; } GC.Collect(); return(true); } catch (Exception e) { Debug.Log(e); return(false); } } // protected void clearGLOBAL()
} // public bool SetPositionLandDirectly() #endregion // #region movement_unitwalking #region animationstatus protected override void DoAction(float deltaTime) { if (e_navistate.navistate_stop == _eStateNaviUnitWalking) { return; } CNaviMesh meshNavi = getNavimeshcurr(); if (null == meshNavi) { //Debug.Log("ERROR! null == meshNavi //" + UnityEngine.Random.Range(0.0f, 1000.0f)); return; } switch (m_UnitState) { case UNIT_STATE.SPAWN: break; case UNIT_STATE.MOVE: { if (true == Update_unitWalking_Movement(deltaTime, meshNavi)) { Update_Collision_sameforce(deltaTime, meshNavi, ref m_listCollides); } } break; case UNIT_STATE.ATTACK: { //Update_Collision_sameforce(fTimeDeltaProcess, ref m_listCollides); m_AttackTime += deltaTime; //Debug.DrawLine(transform.position, field.FindCoreMocel(m_TargetCoreID).transform.position, new Color(255, 0, 0)); } break; case UNIT_STATE.DIE: break; default: break; } } // protected override void DoAction(float deltaTime)
public bool resetGlobal(int iIdxKeyNavi, bool bInitFromGeometry) { if (iIdxKeyNavi < 0) { return(false); } _IdxKeyNavi = iIdxKeyNavi; bool bResultProcess = false; //@ Clear all managers bResultProcess = clearGLOBAL(true); if (false == bResultProcess) { Debug.Log("Error. clearGLOBAL()!/////"); } //@ Instantiate NaviMesh m_meshNavigation_global = m_datanavimeshs.getNavigationMesh(iIdxKeyNavi); m_meshNavigation_global.InitializeNaviMesh(); m_triCollector = m_meshNavigation_global.triCollector; m_SplineCurve = m_meshNavigation_global.splinecurve; if (true == bInitFromGeometry) { //@ Construct All Triangle bResultProcess = resetGlobal_TrianglesAll(m_meshNavigation_global); if (false == bResultProcess) { Debug.Log("Error!.//"); } //@ Set constant objects to start position bResultProcess = resetGlobal_constantObjects(m_triCollector, false); if (false == bResultProcess) { Debug.Log("Error!.//"); } //@ Intiailzie basemanets LinkTriCollectorToAllBase(ref m_baseTowerCollector, ref m_baseCoreCollector, ref m_baseCoresubCollector, ref m_baseStartCollector, ref m_baseBlockCollector, m_triCollector); //@ Re-load navi cells from template pre-loads. LoadNaviFromTemplate(); //@ Load bases. Load_BaseTower_Binary(ref m_baseTowerCollector); Load_BaseCore_Binary(ref m_baseCoreCollector); Load_BaseCoreSub_Binary(ref m_baseCoresubCollector); Load_BaseStart_Binary(ref m_baseStartCollector); Load_BaseBlock_Binary(ref m_baseBlockCollector); //@ Load Curve Path through script bResultProcess = Load_CurvePath_Binary(ref m_SplineCurve); if (false == bResultProcess) { Debug.Log("loadingProcess_Binary Load_CurvePath_Binary_error. //"); } //@ Construct Navigation bResultProcess = resetGlobal_NavigationCells(m_triCollector, ref m_meshNavigation_global); if (false == bResultProcess) { Debug.Log("Error!.//"); } //@Initialze UnitWalking UnitWalking.SetStatusCellToCell(); } // if (true == bInitFromGeometry) else { //@ Load using script. loadingProcess_Binary(iIdxKeyNavi); } // if (false == bInitFromGeometry) //@ Input Process Initialize m_processInput.resetInput(this); m_intervalUnitWalking.InitIntervalUnitWalking(m_triCollector); return(true); } // public void resetGlobal
//@ Process //@ 1.landing position 2.set target dir to object public bool SetPositionLandDirectly(CNaviMesh meshNavi) { Vector3 v3DirDown = Vector3.down; Vector3 v3PosCurrent; Vector3 v3PosVertical; bool bIntersectedWithLanding = false; float fAdjust = dist_adjustpos_up; v3PosCurrent = positionUnit; v3PosVertical = v3PosCurrent + (Vector3.up * fAdjust); Ray rayObj = new Ray(v3PosVertical, v3DirDown); int iTriLandingCurr = -1; RaycastHit raycastHit_info = new RaycastHit(); bool bCrossoverAdjustedWayto = false; bIntersectedWithLanding = meshNavi.GetComponent<Collider>().Raycast(rayObj, out raycastHit_info, dist_raycast_adjust); if (false == bIntersectedWithLanding) { //Debug.Log("ERROR. SetPositionLandDirectly()//not Landing."); return false; } iTriLandingCurr = raycastHit_info.triangleIndex; setLandingTri(iTriLandingCurr); positionUnit = raycastHit_info.point; { Vector3 v3PosIntersected = raycastHit_info.point; Vector2[] arrv2PntOBJBoundary = boundaryUnit2D(); if (true == _bMoveShortestSight) { bCrossoverAdjustedWayto = meshNavi.navigation.getPosWayTo_Portal(iTriLandingCurr, arrv2PntOBJBoundary, ref m_pntWayTo); } else { CNAVICELL.E_CELL_STATUS ecellStatus = meshNavi.navigation.getPosCurrentWayToGoal(iTriLandingCurr, ref m_pntWayTo); switch (ecellStatus) { case CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL: { bCrossoverAdjustedWayto = true; reachtheGoal = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_BLOCK: case CNAVICELL.E_CELL_STATUS.CELL_STATUS_ROAD: { bCrossoverAdjustedWayto = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL: default: { bCrossoverAdjustedWayto = false; } break; } // switch (ecellStatus) } // if (true == _bMoveShortestSight) if (false == bCrossoverAdjustedWayto || (int)CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL == m_pntWayTo._idxnavicell) { Debug.Log("Error(critical) set Unit landing.=" + (CNAVICELL.E_CELL_STATUS)m_pntWayTo._idxnavicell + "//" + UnityEngine.Random.Range(0.0f, 1000.0f)); return false; } //@ Set dir standard forwardforMovement = m_pntWayTo._dirEntrytoNext; forwardforAngle = m_pntWayTo._dirEntrytoNext; positionUnit = v3PosIntersected; } // if (false == meshNavi.getCell(iTriLandingCurr).IsBlockCell()) //@ To slicely adjustment position for rigidbody height. //if (rigidbody) //{ // Vector3 v3PositionAdjust = new Vector3(); // v3PositionAdjust = positionUnit; // v3PositionAdjust.y = v3PositionAdjust.y + CMATH.FEPSILON_F3; // positionUnit = v3PositionAdjust; // setPosHeadObj(v3PositionAdjust, Vector3.zero); //} return bCrossoverAdjustedWayto; } // public bool SetPositionLandDirectly()
} // void Update_Collision_sameforce() #endregion // collisionupdateprocess //@ Update movement process bool Update_unitWalking_Movement(float fTimeDelta, CNaviMesh meshNavi) { if (true == _bRequestLandDirectly) { SetPositionLandDirectly(meshNavi); _bRequestLandDirectly = false; } //@1.Forced setting, Cell wasn't prepared go to way to goal. if (false == _bProcessWalking_Static) { return true; } //@2.No landing mesh. if (null == meshNavi) { Debug.Log("(ERROR. null == meshNavi//Update_objDyn//"); return false; } //@3.Current landing triangle is NULL. (== No landing mesh) if (CTRI.NULL_TRI == getLandingTri()) { //Vector3 v3PosObj = positionUnit; //Debug.Log("(ERROR. NULL_TRI == getLandingTri()//Position(x=" // + v3PosObj.x + ")(y=" // + v3PosObj.y + ")(z=" // + v3PosObj.z + ")//Update_objDyn//"); return false; } //@4.Reach GOAL if (true == reachtheGoal) { return true; } Vector3 v3PosCurrent = positionUnit; Vector3 v3PosCurrAdjusted = v3PosCurrent; Vector3 v3PosNextAdjusted = v3PosCurrent + (m_pntWayTo._dirEntrytoNext * fTimeDelta * speedmove); bool bCrossoverAdjustedWayto = false; //@ crossover == true than adjustment positioning. { int iCountofLevel = m_pntWayTo._ileveltoGoal; Vector3 v3PosIntersected = new Vector3(); CNavigation.CCellWayto pntWayTo_ = new CNavigation.CCellWayto(m_pntWayTo); CNAVICELL.E_CELL_STATUS ecellStatus = CNAVICELL.E_CELL_STATUS.CELL_STATUS_NULL; //@ penetrate n-cell. for (int iterlevel = 0; iterlevel <= iCountofLevel; ++iterlevel) { if (true == pntWayTo_.crossoverTest(v3PosCurrAdjusted, v3PosNextAdjusted)) { setLandingTri(pntWayTo_._idxnavicell); if (true == pntWayTo_.IntersectedPosToEdge(v3PosCurrAdjusted, v3PosNextAdjusted, ref v3PosIntersected)) { ecellStatus = meshNavi.navigation.getPosNextWayTo(pntWayTo_._idxnavicell, ref pntWayTo_); if (CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL == ecellStatus) { v3PosNextAdjusted = v3PosIntersected; } float fRemainder = (v3PosNextAdjusted - v3PosIntersected).magnitude; v3PosNextAdjusted = v3PosIntersected + (pntWayTo_._dirEntrytoNext * fRemainder); v3PosCurrAdjusted = v3PosIntersected; bCrossoverAdjustedWayto = true; } else { ecellStatus = meshNavi.navigation.getPosNextWayTo(pntWayTo_._idxnavicell, ref pntWayTo_); } } else { break; } } // for (int iterlevel = 0; iterlevel <= iCountofLevel; ++iterlevel) if (true == bCrossoverAdjustedWayto) { m_wayHorizon.renewRatioPerpend(pntWayTo_._dirEntrytoNext, pntWayTo_._posEdgeFrom0, pntWayTo_._posEdgeFrom1, pntWayTo_._ratioPerpen); m_pntWayTo = pntWayTo_; } switch (ecellStatus) { case CNAVICELL.E_CELL_STATUS.CELL_STATUS_GOAL: { reachtheGoal = true; bCrossoverAdjustedWayto = true; } break; case CNAVICELL.E_CELL_STATUS.CELL_STATUS_BLOCK: case CNAVICELL.E_CELL_STATUS.CELL_STATUS_ROAD: { bCrossoverAdjustedWayto = true; } break; } } //@ 목표각도 설정. if (true == bCrossoverAdjustedWayto) { Vector3 v3DirAngleTarget = m_pntWayTo._dirEntrytoNext; if (true == m_bVerticalInclination) { forwardforAngleTarget = new Vector3(v3DirAngleTarget.x, 0.0f, v3DirAngleTarget.z); } else { forwardforAngleTarget = v3DirAngleTarget; } forwardforMovement = m_pntWayTo._dirEntrytoNext; Vector3 v3PosRatioAdjusted = new Vector3(); m_wayHorizon.processPosPerpend(fTimeDelta, m_fratiohorizonRoad, v3PosNextAdjusted, ref v3PosRatioAdjusted); positionUnit = v3PosRatioAdjusted; } else { //@ position adjusted position, calculaed ratio on way perpendicular Vector3 v3PosRatioAdjusted = new Vector3(); m_wayHorizon.processPosPerpend(fTimeDelta, m_fratiohorizonRoad, v3PosCurrent, ref v3PosRatioAdjusted); positionUnit = v3PosRatioAdjusted; base.Update_unitDyn(fTimeDelta); } #region inclination_teritory //bool bWayInclination = false; //if(false == CMATH.similarEst_float(m_pntWayTo._dirEntrytoNext.y, 0.0f, CMATH.FEPSILON_F2)) //{ // bWayInclination = true; //} #endregion return true; } // public void Update_objWalk(float fTimeDelta)
} // void calculatePosCollision(Vector3 v3DirForceCollide, float fTimeDelta, Vector3 v3PosObject, CNaviMesh meshNavi) bool Update_Collision_sameforce(float fTimeDelta, CNaviMesh meshNavi, ref SortedDictionary<int, float> listCollider) { //@1.Forced setting, Cell wasn't prepared go to way to goal. if (false == _bProcessWalking_Static) { return false; } //@2.No landing mesh. if (null == meshNavi) { return false; } UnitPool unitpool = UnitPool.GetInstance; //@ 1 more colliders if (listCollider.Count > 0) { //@ If unit is null, Delete unit from collideList. List<UnitWalking> listCollideCollect = new List<UnitWalking>(); ICollection<int> collectionID = listCollider.Keys; List<int> listcollideremove = new List<int>(); foreach (int idunit in collectionID) { UnitWalking unitWalking = unitpool[idunit] as UnitWalking; if (null == unitWalking) { listcollideremove.Add(idunit); } else { if (true == unitWalking.IsUnitDie()) { listcollideremove.Add(idunit); } else { float fdistInterEstimate = (unitWalking.m_fRadius_aabb * unitWalking.m_fRadius_aabb + m_fRadius_aabb * m_fRadius_aabb); float fdistInterCurr = (positionUnit - unitWalking.positionUnit).sqrMagnitude; if (fdistInterEstimate > fdistInterCurr) { listCollideCollect.Add(unitWalking); } } } } // foreach (int idunit in collectionID) //@ for safety elimination foreach (int idunitremove in listcollideremove) { listCollider.Remove(idunitremove); } if (listCollideCollect.Count == 0) { return false; } Vector3 v3DirForceCollide = Vector3.zero; Vector3 v3PosCurrent = positionUnit, v3PosOther, v3DistanceOther; int iCntActualCollide = 0; foreach (UnitWalking colliderUnitWalking in listCollideCollect) { v3PosOther = colliderUnitWalking.positionUnit; v3DistanceOther = (positionUnit - v3PosOther).normalized; if (colliderUnitWalking.IsUnitAttack()) { v3DistanceOther = v3DistanceOther.normalized * spdcollision_unit; } v3DirForceCollide = v3DirForceCollide + v3DistanceOther; iCntActualCollide++; } v3DirForceCollide = v3DirForceCollide.normalized; if (Vector3.zero != v3DirForceCollide) { calculatePosCollision(v3DirForceCollide, fTimeDelta, v3PosCurrent, meshNavi); } } // if (listCollider.Count > 0) return true; } // void Update_Collision_sameforce()
void calculatePosCollision(Vector3 v3DirForceCollide, float fTimeDelta, Vector3 v3PosObject, CNaviMesh meshNavi) { float speedC_Curr = m_speedCollision * fTimeDelta; if (speedC_Curr > m_fRadius_aabb) { speedC_Curr = m_fRadius_aabb; } Vector3 dirForceCollide = v3DirForceCollide * (speedC_Curr); Vector3 v3PosSimulate = v3PosObject + dirForceCollide; Vector3 v3PosUnitIntersected = new Vector3(); bool naviintersected = intersectNavimesh(meshNavi, v3PosSimulate, ref v3PosUnitIntersected); if (true == naviintersected) { if (false == reachtheGoal) { positionUnit = m_wayHorizon.processPosPerpend_collision(v3PosObject, dirForceCollide); } else { //WORKING positionUnit = v3PosUnitIntersected; } } } // void calculatePosCollision(Vector3 v3DirForceCollide, float fTimeDelta, Vector3 v3PosObject, CNaviMesh meshNavi)
protected void setSplineGuide(int isplineguide, ref CSplineManufacturer.curvesection[] arrLineGuide) { CNaviMesh navimeshcurr = getNavimeshcurr(); CSplineManufacturer splinecurveManufacturer = navimeshcurr.splinecurve; arrLineGuide = splinecurveManufacturer.getLineGuide(isplineguide); }