public bool SetProps(PathMarkerInstanceTemplate newProps) { if (newProps != null && (newProps == mProps)) { return(true); } if (HasPathMarkerProps) { //tell the props we have now that it no longer has an instance mProps.HasInstance = false; } mProps = newProps; if (mProps == null) { //Debug.Log ("props were null in set props"); name = "(Empty)"; } else { mProps.Owner = this; name = mProps.PathName + "-" + mProps.IndexInParentPath.ToString(); } RefreshPathMarkerProps(true); return(true); }
public void CreatePathMarkerProps() { if (HasPathMarkerProps) { return; } mProps = new PathMarkerInstanceTemplate(); switch (worlditem.State) { case "PathMarker": default: mProps.Type = PathMarkerType.PathMarker; break; case "CrossMarker": mProps.Type = PathMarkerType.CrossMarker; break; } mProps.Position = worlditem.tr.position; mProps.Rotation = worlditem.tr.rotation.eulerAngles; mProps.Owner = this; Visitable visitable = worlditem.Get <Visitable>(); mProps.Visitable = visitable.State; Revealable revealable = worlditem.Get <Revealable>(); mProps.Revealable = revealable.State; }
protected void FollowPath() { if (LastMarker == null) { //if we don't have a 'last marker' //get one by finding the closest marker LastMarker = Paths.GetMarkerClosestTo(mActivePath, worlditem.Position); } if (NextMarker == null) { //if we don't find a marker in this direction if (!Paths.GetNextMarkerInDirection(mActivePath, State.Direction, LastMarker, out NextMarker)) { //try another direction State.Direction = Paths.ReverseDirection(State.Direction); if (!Paths.GetNextMarkerInDirection(mActivePath, State.Direction, LastMarker, out NextMarker)) { Debug.Log("Still failed to get next marker, how is that possible?"); //kill the script Finish(); return; } } } if (!mFollowingPathOverTime) { mFollowingPathOverTime = true; StartCoroutine(FollowPathOverTime()); } //TODO use an animation override in the motile action //this is strictly temporary character.Body.Animator.animator.SetBool("Walking", true); }
protected IEnumerator UpdateFollowPath() { //check if we're still supposed to be doing this if (!HasActivePath) //whoops stuff is gone { State.PathMode = FollowPathMode.None; yield break; } else { switch (State.PathMode) { case FollowPathMode.ReachedEndOfPath: //TODO instead of ping-ponging, make it possible for pilgrims //to choose another path to use //Paths.ReverseDirection(State.Direction); //Paths.GetNextMarkerInDirection(ActivePath, State.Direction, LastMarker, out NextMarker); State.PathMode = FollowPathMode.FollowingPath; break; case FollowPathMode.ReachedPilgrimStop: // PilgrimStop pilgrimStop = null; // if (LastLocationReached.worlditem.Is <PilgrimStop>(out pilgrimStop) // && LastLocationReached != StartLocationTarget // && State.TookDirection) { //if we've hit a pilgrim stop AND we're not at the start location AND we took direction // //move to the pilgrim stop after which we'll wait for directions // State.PathMode = FollowPathMode.MovingToPilgrimStop; // PathFollower.transform.position = LastLocationReached.RandomPilgrimPosition + Vector3.up; // } else if (CurrentPath.GetNeighbor(LastLocationReached, State.Direction, new List <string>(), out NextLocationTarget)) { //if we've reached the pilgrim stop and we can still get a neighbor // //set the follower to the next node // ////Debug.Log ("Reached location " + LastLocationReached.name + ", got next in line, going to " + NextLocationTarget.name); // State.PathMode = FollowPathMode.FollowingPath; // PathFollower.transform.position = NextLocationTarget.transform.position + Vector3.up; // } else { //otherwise we've reached the end of the path // ////Debug.Log ("Reached end of path after hitting pilgrim stop"); // State.PathMode = FollowPathMode.ReachedEndOfPath; // } break; case FollowPathMode.MovingToPilgrimStop: //move next to the pilgrim stop // if (Vector3Extensions.Distance2D(transform.position, PathFollower.transform.position) < 1.0f) { //if we're really close then we've reached end of path // State.PathMode = FollowPathMode.ReachedEndOfPath; // } break; case FollowPathMode.WaitingForObstruction: //if the obstruction is null or no longer obstructs the path // if (CurrentObstruction == null || !CurrentObstruction.ObstructedPaths.Contains(State.LastPathUsed)) { //continue walking along the path // State.PathMode = FollowPathMode.FollowingPath; // } break; case FollowPathMode.FollowingPath: default: // State.CurrentMeters = CurrentPath.MetersFromPosition(transform.position); // see if we're ready to move to next point along meters // Vector3 pathPoint = PathFollower.position; // Vector3 normal = Vector3.zero; // bool hitWater = false; // bool hitTerrainMesh = false; // // if (WorldItems.IsInActiveRange (NextLocationTarget.worlditem, transform.position, gMaxPilgrimStopRange)) { //if we've gotten to the location // ////Debug.Log ("Reached location target " + NextLocationTarget.name); // State.PathMode = FollowPathMode.ReachedPilgrimStop; // LastLocationReached = NextLocationTarget; // //wait a tad // yield return new WaitForSeconds (0.5f); // } // if (Vector3.Distance (pathPoint, transform.position) < gPathFollowGoalRange) // { ////Debug.Log ("Moved goal object"); // //we're ready to move the goal farther along the path // else if (Vector3.Distance (transform.position, EndLocationTarget.transform.position) < gPathFollowGoalRange) // { //if this returns false, that means we've reached the goal meters // //Debug.Log ("Reached end of path at " + State.CurrentMeters + " due to proximity"); // State.PathMode = FollowPathMode.ReachedEndOfPath; // } // pathPoint = CurrentPath.PositionFromMeters (State.CurrentMeters); // pathPoint.y = GameWorld.Get.TerrainHeightAtInGamePosition (pathPoint, true, ref hitWater, ref hitTerrainMesh, ref normal) + 0.5f; // } if (mFollowPathAction.IsInRange) { //get the next marker after the current marker PathMarkerInstanceTemplate newGoal = null; if (Paths.GetNextMarkerInDirection(mActivePath, State.Direction, NextMarker, out newGoal)) { LastMarker = NextMarker; NextMarker = newGoal; } else { //reverse direction! State.Direction = Paths.ReverseDirection(State.Direction); //go to the last marker instead newGoal = LastMarker; LastMarker = NextMarker; } } break; } //wait for a tick yield return(null); } yield break; }