public void Update() { if (_vertexes == null && _building != null && !UMath.nearEqualByDistance(_building.transform.position, new Vector3(), 1f)) { _vertexes = _building.Geometry.GetComponent <MeshFilter>().mesh.vertices; _diff = _building.transform.position - new Vector3(); } if (_count < _vertexes.Length) { var cube = UVisHelp.CreateHelpers(_vertexes[_count] + _diff, Root.cube); GameObject go = new GameObject(); go.transform.SetParent(_container.transform); go.transform.localPosition = new Vector3(); cube.transform.SetParent(go.transform); go.transform.localScale = _building.Geometry.transform.localScale; go.transform.localRotation = _building.Geometry.transform.localRotation; go.transform.localPosition = _building.Geometry.transform.localPosition; _show.Add(cube); _empties.Add(go); _count++; } }
// Update is called once per frame public void Update() { //correcting bug where kids stay in front of storage with path completed if ((_destWasSet && _agent.isOnNavMesh && _agent.enabled && !_person.IsMajor && !UMath.nearEqualByDistance(_agent.destination, Destiny, 0.1f) && _agent.pathStatus == NavMeshPathStatus.PathComplete) || (_agent.pathStatus == NavMeshPathStatus.PathInvalid && _agent.enabled && _agent.isOnNavMesh) ) { //so i set the destination again to the real one so they move towards it _agent.SetDestination(Destiny); } if (_nextDest != new Vector3() && !_destWasSet && _agent.isOnNavMesh && _agent.enabled) { _destWasSet = true; _agent.SetDestination(Destiny); _startDate = Program.gameScene.GameTime1.CurrentDate(); } CheckIfGoingIntoBuild(); RadiusForHeavyLoaders(); CheckVelocity(); CheckIfTempSpeed(); CheckIfPathPending(); CheckIfStuck(); }
List <CheckPoint> validCheckPoints = new List <CheckPoint>(); //checkpoint validated they will be used for last result private void DeltaQualityCheck() { for (int i = 0; i < bucketCheckPoints.Count - 1; i++) { //if is not the same if (!UMath.nearEqualByDistance(bucketCheckPoints[i].Point, bucketCheckPoints[i + 1].Point, 0.1f)) { if (!RouterManager.IsWaterOrMountainBtw(bucketCheckPoints[i].Point, bucketCheckPoints[i + 1].Point)) { validCheckPoints.Add(bucketCheckPoints[i]); } //if is in water wont add the current one else { RestartDeltaRouter(bucketCheckPoints[i].Point); Init(); deltaRouted = false; return; } } } //add the last one validCheckPoints.Add(bucketCheckPoints[bucketCheckPoints.Count - 1]); DoneDelta(); }
private bool ReturnBridgeRoadEquality() { if (UMath.nearEqualByDistance(_curr.Position, U2D.FromV3ToV2(_two.Position), .1f)) { return(true); } return(false); }
private bool CheckOnShortDest() { if (UMath.nearEqualByDistance(transform.position, _agentDest, _distToDisable)) { MilitarBody.DisableAgent(); return(true); } return(false); }
/// <summary> /// Will tell u if is just crossing a brdige this time /// </summary> /// <param name="_curr"></param> /// <param name="crystal"></param> /// <returns></returns> private bool IsGettingIntoBridge(Crystal currP, Crystal eval) { var samePos = UMath.nearEqualByDistance(U2D.FromV2ToV3(eval.Position), _two.Position, 0.1f); if (samePos) { return(true); } return(false); }
/// <summary> /// Need to elimianted duplicated in rare ocasions will show duplicates /// </summary> void EliminateDupConsecutive() { for (int i = 0; i < _checkPoints.Count - 1; i++) { if (UMath.nearEqualByDistance(_checkPoints[i].Point, _checkPoints[i + 1].Point, 0.001f)) { _checkPoints.RemoveAt(i); i--; } } }
private bool IsOnEaten(Vector3 a) { for (int i = 0; i < _eaten.Count; i++) { if (UMath.nearEqualByDistance(a, _eaten[i], 0.3f)) { return(true); } } return(false); }
/// <summary> /// Wil return current exact pos of light, if found in one stage, otherwisw /// ret -1 /// </summary> /// <returns></returns> private int FindStateOfLight() { for (int i = 0; i < _stages.Count; i++) { if (UMath.nearEqualByDistance(_main.transform.position, _stages[i].transform.position, 0.02f)) { return(i); } } return(-1); }
private void CheckIfGoingIntoBuild() { if (_person == null) { return; } if (UMath.nearEqualByDistance(Destiny, _person.transform.position, ReachRadius)) { if (_nextDest != new Vector3()) { //Debug.Log("Point reached:" + _person.Name); _nextDest = new Vector3(); _agent.enabled = false; } } }
private void ValidateRoute() { validCheckPoints.Clear(); for (int i = 0; i < bucket.Count - 1; i++) { //if is not the same if (!UMath.nearEqualByDistance(bucket[i].Point, bucket[i + 1].Point, 0.1f)) { validCheckPoints.Add(bucket[i]); } } //add the last one validCheckPoints.Add(bucket[bucket.Count - 1]); }
/// <summary> /// Will return true if _curr and _two are really close /// </summary> /// <returns></returns> private bool CheckIfDone() { //bz Bridge road on Y is really far apart if (_two != null && _two.MyBuildKey != null && _two.MyBuildKey.Contains("BridgeRoad")) { return(ReturnBridgeRoadEquality()); } //2d only bz then it wont care about Y difference so Docks cant get built var currPos = new Vector3(_curr.Position.x, _two.Position.y, _curr.Position.y); if (UMath.nearEqualByDistance(currPos, _two.Position, .1f)) //if (UMath.nearEqualByDistance(U2D.FromV2ToV3(_curr.Position), _two.Position, .1f)) { return(true); } return(false); }
/// <summary> /// The Drag action of the way /// </summary> public void Drag() { if (UMath.nearEqualByDistance(ClosestVertOld, ClosestSubMeshVert, 0.01f)) { return; } CreateWay(); ClearPrevWay(); if (onScreenPoly.Count == 0) { return; } //this is what creaetes both ways RetListOfWay(onScreenPoly, _dir); //this will remove duplicates and will in a road if the tile is overlapping other //will push it a bit down so in it renders fine //if is a bridge is not needed since we do exaclty this on Bridge.cs and brige needs //all tiles in the same height if (HType != H.BridgeRoad && HType != H.BridgeTrail) { RemoveDupRectifyPath(); } //if paths are less than the max amt allowed we will check coll and will update preview pos if (_verticPath.Count + _horPath.Count < MaxStepsWay) { CollideCheckRoutineUpdatePrev(_verticPath, _horPath); _verticPathNew = _verticPath; _horPathNew = _horPath; } else if (_verticPath.Count + _horPath.Count >= MaxStepsWay) { CollideCheckRoutineUpdatePrev(_verticPathNew, _horPathNew); } base.UpdateClosestVertexAndOld();//so ClosestSubMeshVert and ClosestVertOld are taken care of _isWayOK = CheckEvenTerraCollWater(); UpdateBigBoxesPrev(); }
/// <summary> /// Will return position if 'oringin' was not contained in a building ... /// other wise will recurse keep moving towards target... until a spot is find it that /// is not contained in a building or 'origin' is equals 'target' /// </summary> public Vector3 AssignIniPositionIfNotInBuild(Vector3 origin, Vector3 target) { var personBounds = UPoly.CreatePolyFromVector3(origin, _person.PersonDim, _person.PersonDim); //if bound collide will recurse if (BuildingPot.Control.Registro.IsCollidingWithExisting(personBounds)) { //if both are the same they the origin was moved all the way untli the target //so no more recursion is needed... i couldnt find a point where was not building //this is covering a infinite loop, should nt happen ever if (UMath.nearEqualByDistance(origin, target, 0.1f)) { throw new Exception("origin reach target on AssignIniPositionIfNotInBuild() DeltaRouter"); } origin = Vector3.MoveTowards(origin, target, 0.04f); origin = AssignIniPositionIfNotInBuild(origin, target); } return(origin); }
private IEnumerator ThreeSecUpdate() { while (true) { yield return(new WaitForSeconds(0.1f)); // wait var samePos = UMath.nearEqualByDistance(transform.position, iniPos, 1); var buildNull = Building == null; //means is showing if (samePos && !buildNull && BuildingPot.Control.Registro.SelectBuilding != null) { LoadMenu(); //then orders need to be reloaded from dispatch and shown on Tab if (_orders.gameObject.activeSelf == _orders) { ShowOrders(); } } } }
public static Dir TellMeWhichCornerIsThis(List <Vector3> poly, Vector3 commonCorner) { Dir res = Dir.None; if (UMath.nearEqualByDistance(commonCorner, poly[0], 0.01f)) { res = Dir.NW; } if (UMath.nearEqualByDistance(commonCorner, poly[1], 0.01f)) { res = Dir.NE; } if (UMath.nearEqualByDistance(commonCorner, poly[2], 0.01f)) { res = Dir.SE; } if (UMath.nearEqualByDistance(commonCorner, poly[3], 0.01f)) { res = Dir.SW; } return(res); }
/// <summary> /// Will rtell u if current Vectors 3 List can be feed. Need to know if the are a perfect Rectangle /// /// Will try to find all the Current Vector3 asked for on the first 1000 on the grid /// </summary> /// <returns></returns> private bool FeedIsOk() { int local = 0; var top = DefineTop(); for (int i = 0; i < _currVector3s.Count; i++) { if (IsOnEaten(_currVector3s[i])) { local++; continue; } for (int j = 0; j < top; j++) { if (UMath.nearEqualByDistance(_currVector3s[i], _grid[j], 0.3f)) { //so it can be removed _currVector3s[i] = _grid[j]; local++; break; } } //means tht one went trheu and didnt find a mathc if (i > local) { return(false); } } if (local == _currVector3s.Count) { return(true); } return(false); }
///// <summary> ///// Will push the 'val' away from the center of the '_currRect.TheRect.center' ///// Use to grow the rectagle . Is needed when addressing delta routing ///// </summary> ///// <param name="val"></param> ///// <returns></returns> //Vector3 PushAwayFromCurrRectCenter(Vector3 val) //{ // var center = U2D.FromV2ToV3(_currRect.TheRect.center); // var dist = Vector3.Distance(center, val);//distnace to center of the rect // //so its moves away from center // Vector3 res = Vector3.MoveTowards(val, center, -grow * dist); // return res; //} /// <summary> /// Will check if _currRect needs to grow bz _curr didnt change . /// /// Created to avoid bugg where Rect was gettting created again and again bz could not find any crystalls /// </summary> private bool CheckIfNeedGrow() { if (_oldCurr == null) { return(false); } var closeEnogh = UMath.nearEqualByDistance(_oldCurr.Position, _curr.Position, 0.3f); var closeAndTerraObs = UMath.nearEqualByDistance(_oldCurr.Position, _curr.Position, 1.5f) && (_oldCurr.IsTerrainObstacle() || _curr.IsTerrainObstacle()); if (closeEnogh || closeAndTerraObs) { //Debug.Log("closeEnogh:" + closeEnogh + " closeAndTerraObs:" + closeAndTerraObs); ////Debug.Log("Rect grow"); grow *= 2; //_currRect.Grow(); return(true); } grow = GROWC; return(false); }
private int oldCurrent;//the previus route point /// <summary> /// The walk handler is being called on Update() if MovingNow = true /// </summary> void WalkHandler() { if (oldCurrent != _currentRoutePoint) { InitRotaVars(); oldCurrent = _currentRoutePoint; InitRotaVarsOnSpeed(); } CheckRotation(); MoveAction(); Vector3 curr = _gameObject.transform.position; Vector3 next = _routePoins[_currentRoutePoint].Point; if (UMath.nearEqualByDistance(curr, next, 0.01f))// 0.001f { if (next == _routePoins[lastRoutePoint].Point) { WalkDone(); } SetNextPoint(); } }
/// <summary> /// Updates the Big Box when is behaving as a Cursor /// </summary> public void UpdateCursor() { //update submesh vert UpdateClosestSubMeshVert(); if (UMath.nearEqualByDistance(ClosestVertOld, ClosestSubMeshVert, 0.01f)) { return; } UpdateClosestVertexAndOld(); //creates poly var locPoly = UPoly.CreateSubMeshPoly(ClosestSubMeshVert, prevWideSquares); locPoly = UPoly.ScalePoly(locPoly, -0.04f);//a bit smaller is not colliding with every edge UpdatePos(locPoly, 0.75f); bool isEven = AreAllPointsEven(locPoly, 0.01f); bool isCollide = CheckIfColliding(locPoly); bool isOnFloor = IsOnTheFloor(locPoly); //if is even not coll and is on floor CheckAndSwitchColor(isEven && !isCollide && isOnFloor); }
/// <summary> /// Move an vertex of a poly aways from the Poly dependeing on which one is . /// /// Needs to be called bz we need to push person away from building other wise /// when checking for collisions is always in bz algorith will do it on the edge /// So wehen i call this i push the edge away from Building /// </summary> Vector3 MoveAnchorAwayFromBuild(Vector3 anchorToMoveAndRet, List <Vector3> anchors, float inX, float inZ) { int anchorIndex = -1; for (int i = 0; i < anchors.Count; i++) { if (UMath.nearEqualByDistance(anchors[i], anchorToMoveAndRet, 0.01f)) { anchorIndex = i; } } //this is to addres when the Anchor was sanitize... will nt be tht close to an anchor anymore //and wont find which one is closer ... therefore will return the save value pased if (anchorIndex == -1) { return(anchorToMoveAndRet); } float newX = anchorToMoveAndRet.x + inX * polyMapXSing[anchorIndex]; float newZ = anchorToMoveAndRet.z + inZ * polyMapZSing[anchorIndex]; return(new Vector3(newX, anchorToMoveAndRet.y, newZ)); }