public override void AssignValues(List<ActionParameter> parameters) { charToMove = AssignFile <Char> (parameters, charToMoveParameterID, charToMoveID, charToMove); movePath = AssignFile <Paths> (parameters, movePathParameterID, movePathID, movePath); if (isPlayer) { charToMove = KickStarter.player; } }
public void SetPath(Paths pathOb, PathSpeed _speed) { SetPath (pathOb, _speed, 0, 0); }
public void SetPath(Paths pathOb, int _targetNode, int _prevNode, bool affectY) { if (pathOb) { SetPath (pathOb, pathOb.pathSpeed, _targetNode, _prevNode); activePath.affectY = affectY; } }
public void SetLastPath(Paths _lastPathActivePath, int _lastPathTargetNode, int _lastPathPrevNode) { lastPathActivePath = _lastPathActivePath; lastPathTargetNode = _lastPathTargetNode; lastPathPrevNode = _lastPathPrevNode; }
public void Halt() { if (GetComponent <Paths>() && activePath == GetComponent <Paths>()) {} else { lastPathPrevNode = prevNode; lastPathTargetNode = targetNode; lastPathActivePath = activePath; } activePath = null; targetNode = 0; moveSpeed = 0f; if (charState == CharState.Move || charState == CharState.Decelerate) { charState = CharState.Idle; } }
public void EndPath() { if (GetComponent <Paths>() && activePath == GetComponent <Paths>()) { activePath.nodes.Clear (); } else { lastPathPrevNode = prevNode; lastPathTargetNode = targetNode; lastPathActivePath = activePath; } activePath = null; targetNode = 0; if (charState == CharState.Move) { charState = CharState.Decelerate; if (AccurateDestination ()) { moveSpeed = 0f; doExactLerp = true; } } }
override public float Run() { if (!isRunning) { isRunning = true; if (charToMove && marker) { Paths path = charToMove.GetComponent <Paths>(); if (path == null) { ACDebug.LogWarning("Cannot move a character with no Paths component"); } else { if (charToMove is NPC) { NPC npcToMove = (NPC)charToMove; npcToMove.StopFollowing(); } path.pathType = AC_PathType.ForwardOnly; path.pathSpeed = speed; path.affectY = true; Vector3[] pointArray; Vector3 targetPosition = marker.transform.position; if (KickStarter.settingsManager.ActInScreenSpace()) { targetPosition = AdvGame.GetScreenNavMesh(targetPosition); } if (pathFind && KickStarter.navigationManager) { pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(charToMove.transform.position, targetPosition, charToMove); } else { List <Vector3> pointList = new List <Vector3>(); pointList.Add(targetPosition); pointArray = pointList.ToArray(); } if (speed == PathSpeed.Walk) { charToMove.MoveAlongPoints(pointArray, false, pathFind); } else { charToMove.MoveAlongPoints(pointArray, true, pathFind); } if (charToMove.GetPath()) { if (!pathFind && doFloat) { charToMove.GetPath().affectY = true; } else { charToMove.GetPath().affectY = false; } } if (willWait) { return(defaultPauseTime); } } } return(0f); } else { if (charToMove.GetPath() == null) { isRunning = false; return(0f); } else { return(defaultPauseTime); } } }
/** * <summary>Locks the Player to a Paths object during gameplay, if using Direct movement. * This allows the designer to constrain the Player's movement to a Path, even though they can move freely along it.</summary> * <param name = "pathOb">The Paths to lock the Player to</param> */ public void SetLockedPath(Paths pathOb) { // Ignore if using "point and click" or first person methods if (KickStarter.settingsManager) { if (KickStarter.settingsManager.movementMethod == MovementMethod.Direct) { lockedPath = true; if (pathOb.pathSpeed == PathSpeed.Run) { isRunning = true; } else { isRunning = false; } if (pathOb.affectY) { transform.position = pathOb.transform.position; } else { transform.position = new Vector3 (pathOb.transform.position.x, transform.position.y, pathOb.transform.position.z); } activePath = pathOb; targetNode = 1; charState = CharState.Idle; } else { ACDebug.LogWarning ("Path-constrained player movement is only available with Direct control."); } } }
/** * <summary>Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined.</summary> * <param name = "pathOb">The Paths object to move along</param> */ public void SetPath(Paths pathOb) { if (pathOb != null && pathOb.nodes.Count > 0) { SetPath (pathOb, pathOb.pathSpeed, 1, 0); } else { SetPath (pathOb, pathOb.pathSpeed, 0, 0); } }
/** * <summary>Assigns the character to a Paths object to move along. This is not the same as pathfinding - this assumes a path has already been defined.</summary> * <param name = "pathOb">The Paths object to move along</param> * <param name = "_speed">The speed to move along the path (Walk, Run)</param> */ public void SetPath(Paths pathOb, PathSpeed _speed) { if (pathOb != null && pathOb.nodes.Count > 0) { if (pathOb.nodes.Count == 1 && pathOb.nodes[0] == transform.position) { return; } SetPath (pathOb, _speed, 1, 0); } else { SetPath (pathOb, _speed, 0, 0); } }
public override void ShowGUI(List<ActionParameter> parameters) { UpgradeSelf (); isPlayer = EditorGUILayout.Toggle ("Is Player?", isPlayer); if (!isPlayer) { charToMoveParameterID = Action.ChooseParameterGUI ("Character to move:", parameters, charToMoveParameterID, ParameterType.GameObject); if (charToMoveParameterID >= 0) { charToMoveID = 0; charToMove = null; } else { charToMove = (Char) EditorGUILayout.ObjectField ("Character to move:", charToMove, typeof (Char), true); charToMoveID = FieldToID <Char> (charToMove, charToMoveID); charToMove = IDToField <Char> (charToMove, charToMoveID, false); } } movePathMethod = (MovePathMethod) EditorGUILayout.EnumPopup ("Method:", movePathMethod); if (movePathMethod == MovePathMethod.MoveOnNewPath) { movePathParameterID = Action.ChooseParameterGUI ("Path to follow:", parameters, movePathParameterID, ParameterType.GameObject); if (movePathParameterID >= 0) { movePathID = 0; movePath = null; } else { movePath = (Paths) EditorGUILayout.ObjectField ("Path to follow:", movePath, typeof(Paths), true); movePathID = FieldToID <Paths> (movePath, movePathID); movePath = IDToField <Paths> (movePath, movePathID, false); } doTeleport = EditorGUILayout.Toggle ("Teleport to start?", doTeleport); if (movePath != null && movePath.pathType != AC_PathType.ForwardOnly) { willWait = false; } else { willWait = EditorGUILayout.Toggle ("Wait until finish?", willWait); } if (movePath != null && movePath.GetComponent <Char>()) { EditorGUILayout.HelpBox ("Can't follow a Path attached to a Character!", MessageType.Warning); } } else if (movePathMethod == MovePathMethod.ResumeLastSetPath) { // } AfterRunningOption (); }
private void ResetCommandList(Paths _target) { int numNodes = _target.nodes.Count; int numCommands = _target.nodeCommands.Count; if (numNodes < numCommands) { _target.nodeCommands.RemoveRange (numNodes, numCommands - numNodes); } else if (numNodes > numCommands) { if (numNodes > _target.nodeCommands.Capacity) { _target.nodeCommands.Capacity = numNodes; } for (int i=numCommands; i<numNodes; i++) { _target.nodeCommands.Add (new NodeCommand ()); } } }
private void SetPath (Paths pathOb, PathSpeed _speed, int _targetNode, int _prevNode) { activePath = pathOb; targetNode = _targetNode; prevNode = _prevNode; if (CanTurnBeforeMoving ()) { TurnBeforeWalking (); } if (pathOb) { if (_speed == PathSpeed.Run) { isRunning = true; } else { isRunning = false; } } charState = CharState.Idle; }
public void SetPath(Paths pathOb) { SetPath (pathOb, pathOb.pathSpeed, 0, 0); }
/** * <summary>Stops the character from moving along the current Paths object.</summary> */ public void EndPath() { if (GetComponent <Paths>() && activePath == GetComponent <Paths>()) { activePath.nodes.Clear (); } else { lastPathPrevNode = prevNode; lastPathTargetNode = targetNode; lastPathActivePath = activePath; } activePath = null; targetNode = 0; pathfindUpdateTime = 0f; StopTurning (); if (charState == CharState.Move) { charState = CharState.Decelerate; } }
public void SetPath(Paths pathOb, int _targetNode, int _prevNode) { SetPath (pathOb, pathOb.pathSpeed, _targetNode, _prevNode); }
private void SetPath(Paths pathOb, PathSpeed _speed, int _targetNode, int _prevNode) { activePath = pathOb; targetNode = _targetNode; prevNode = _prevNode; doExactLerp = false; exactDestination = pathOb.nodes [pathOb.nodes.Count-1]; if (CanTurnBeforeMoving ()) { TurnBeforeWalking (); } if (pathOb) { if (_speed == PathSpeed.Run) { isRunning = true; } else { isRunning = false; } } if (charState == CharState.Custom) { charState = CharState.Idle; } }
public override void ShowGUI() { if (IsSingleLockMovement ()) { doUpLock = (LockType) EditorGUILayout.EnumPopup ("Movement:", doUpLock); } else { doUpLock = (LockType) EditorGUILayout.EnumPopup ("Up movement:", doUpLock); doDownLock = (LockType) EditorGUILayout.EnumPopup ("Down movement:", doDownLock); doLeftLock = (LockType) EditorGUILayout.EnumPopup ("Left movement:", doLeftLock); doRightLock = (LockType) EditorGUILayout.EnumPopup ("Right movement:", doRightLock); } if (IsInFirstPerson ()) { freeAimLock = (LockType) EditorGUILayout.EnumPopup ("Free-aiming:", freeAimLock); } if (!IsUltimateFPS ()) { doRunLock = (PlayerMoveLock) EditorGUILayout.EnumPopup ("Walk / run:", doRunLock); doGravityLock = (LockType) EditorGUILayout.EnumPopup ("Affected by gravity?", doGravityLock); movePath = (Paths) EditorGUILayout.ObjectField ("Move path:", movePath, typeof (Paths), true); } if (AllowHeadTurning ()) { doHotspotHeadTurnLock = (LockType) EditorGUILayout.EnumPopup ("Hotspot head-turning?", doHotspotHeadTurnLock); } AfterRunningOption (); }
/** * <summary>Updates its own variables from a NPCData class.</summary> * <param name = "data">The NPCData class to load from</param> */ public void LoadData(NPCData data) { charState = (data.inCustomCharState) ? CharState.Custom : CharState.Idle; EndPath(); GetAnimEngine().LoadNPCData(data, this); walkSound = AssetLoader.RetrieveAsset(walkSound, data.walkSound); runSound = AssetLoader.RetrieveAsset(runSound, data.runSound); if (!string.IsNullOrEmpty(data.speechLabel)) { SetName(data.speechLabel, data.displayLineID); } portraitIcon.ReplaceTexture(AssetLoader.RetrieveAsset(portraitIcon.texture, data.portraitGraphic)); walkSpeedScale = data.walkSpeed; runSpeedScale = data.runSpeed; // Rendering lockDirection = data.lockDirection; lockScale = data.lockScale; if (spriteChild && spriteChild.GetComponent <FollowSortingMap>()) { spriteChild.GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else if (GetComponent <FollowSortingMap>()) { GetComponent <FollowSortingMap>().lockSorting = data.lockSorting; } else { ReleaseSorting(); } if (data.lockDirection) { spriteDirection = data.spriteDirection; UpdateFrameFlipping(true); } if (data.lockScale) { spriteScale = data.spriteScale; } if (data.lockSorting) { if (spriteChild && spriteChild.GetComponent <Renderer>()) { spriteChild.GetComponent <Renderer>().sortingOrder = data.sortingOrder; spriteChild.GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } else if (GetComponent <Renderer>()) { GetComponent <Renderer>().sortingOrder = data.sortingOrder; GetComponent <Renderer>().sortingLayerName = data.sortingLayer; } } AC.Char charToFollow = null; if (data.followTargetID != 0) { RememberNPC followNPC = ConstantID.GetComponent <RememberNPC> (data.followTargetID); if (followNPC.GetComponent <AC.Char>()) { charToFollow = followNPC.GetComponent <AC.Char>(); } } if (charToFollow != null || (data.followTargetIsPlayer && KickStarter.player != null)) { FollowAssign(charToFollow, data.followTargetIsPlayer, data.followFrequency, data.followDistance, data.followDistanceMax, data.followFaceWhenIdle, data.followRandomDirection); } else { StopFollowing(); } Halt(); if (!string.IsNullOrEmpty(data.pathData) && GetComponent <Paths>()) { Paths savedPath = GetComponent <Paths>(); savedPath = Serializer.RestorePathData(savedPath, data.pathData); SetPath(savedPath, data.targetNode, data.prevNode, data.pathAffectY); isRunning = data.isRunning; } else if (data.pathID != 0) { Paths pathObject = ConstantID.GetComponent <Paths> (data.pathID); if (pathObject != null) { SetPath(pathObject, data.targetNode, data.prevNode); } else { ACDebug.LogWarning("Trying to assign a path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } if (data.lastPathID != 0) { Paths pathObject = ConstantID.GetComponent <Paths> (data.lastPathID); if (pathObject != null) { SetLastPath(pathObject, data.lastTargetNode, data.lastPrevNode); } else { ACDebug.LogWarning("Trying to assign the previous path for NPC " + this.name + ", but the path was not found - was it deleted?", gameObject); } } // Head target if (data.isHeadTurning) { ConstantID _headTargetID = ConstantID.GetComponent <ConstantID> (data.headTargetID); if (_headTargetID != null) { SetHeadTurnTarget(_headTargetID.transform, new Vector3(data.headTargetX, data.headTargetY, data.headTargetZ), true); } else { ClearHeadTurnTarget(true); } } else { ClearHeadTurnTarget(true); } if (GetComponentsInChildren <FollowSortingMap>() != null) { FollowSortingMap[] followSortingMaps = GetComponentsInChildren <FollowSortingMap>(); SortingMap customSortingMap = ConstantID.GetComponent <SortingMap> (data.customSortingMapID); foreach (FollowSortingMap followSortingMap in followSortingMaps) { followSortingMap.followSortingMap = data.followSortingMap; if (!data.followSortingMap && customSortingMap != null) { followSortingMap.SetSortingMap(customSortingMap); } else { followSortingMap.SetSortingMap(KickStarter.sceneSettings.sortingMap); } } } if (GetAnimEngine() != null && GetAnimEngine().IKEnabled) { LeftHandIKController.LoadData(data.leftHandIKState); RightHandIKController.LoadData(data.rightHandIKState); } _spriteDirectionData.LoadData(data.spriteDirectionData); }