Example #1
0
        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;

                if (runtimeChar && marker)
                {
                    Paths path = runtimeChar.GetComponent <Paths>();
                    if (path == null)
                    {
                        ACDebug.LogWarning("Cannot move a character with no Paths component");
                    }
                    else
                    {
                        if (runtimeChar is NPC)
                        {
                            NPC npcToMove = (NPC)runtimeChar;
                            npcToMove.StopFollowing();
                        }

                        path.pathType  = AC_PathType.ForwardOnly;
                        path.pathSpeed = speed;
                        path.affectY   = true;

                        Vector3[] pointArray;
                        Vector3   targetPosition = marker.transform.position;

                        if (SceneSettings.ActInScreenSpace())
                        {
                            targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                        }

                        float distance = Vector3.Distance(targetPosition, runtimeChar.transform.position);
                        if (distance <= KickStarter.settingsManager.GetDestinationThreshold())
                        {
                            isRunning = false;
                            return(0f);
                        }

                        if (pathFind && KickStarter.navigationManager)
                        {
                            pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(runtimeChar.transform.position, targetPosition, runtimeChar);
                        }
                        else
                        {
                            List <Vector3> pointList = new List <Vector3>();
                            pointList.Add(targetPosition);
                            pointArray = pointList.ToArray();
                        }

                        if (speed == PathSpeed.Walk)
                        {
                            runtimeChar.MoveAlongPoints(pointArray, false, pathFind);
                        }
                        else
                        {
                            runtimeChar.MoveAlongPoints(pointArray, true, pathFind);
                        }

                        if (runtimeChar.GetPath())
                        {
                            if (!pathFind && doFloat)
                            {
                                runtimeChar.GetPath().affectY = true;
                            }
                            else
                            {
                                runtimeChar.GetPath().affectY = false;
                            }
                        }

                        if (willWait)
                        {
                            currentTimer = maxTime;
                            return(defaultPauseTime);
                        }
                    }
                }

                return(0f);
            }
            else
            {
                if (runtimeChar.GetPath() == null)
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    if (doTimeLimit)
                    {
                        currentTimer -= Time.deltaTime;
                        if (currentTimer <= 0)
                        {
                            switch (onReachTimeLimit)
                            {
                            case OnReachTimeLimit.StopMoving:
                                runtimeChar.EndPath();
                                break;

                            case OnReachTimeLimit.TeleportToDestination:
                                Skip();
                                break;
                            }

                            isRunning = false;
                            return(0f);
                        }
                    }

                    return(defaultPauseTime);
                }
            }
        }
        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;

                if (faceObject == null && (faceType == CharFaceType.Body || (faceType == CharFaceType.Head && !stopLooking)))
                {
                    return(0f);
                }

                if (charToMove)
                {
                    if (faceType == CharFaceType.Body)
                    {
                        if (!isInstant && charToMove.IsMovingAlongPath())
                        {
                            charToMove.EndPath();
                        }

                        if (lookUpDown && isPlayer && KickStarter.settingsManager.IsInFirstPerson())
                        {
                            Player player = (Player)charToMove;
                            player.SetTilt(faceObject.transform.position, isInstant);
                        }

                        charToMove.SetLookDirection(GetLookVector(KickStarter.settingsManager), isInstant);
                    }
                    else if (faceType == CharFaceType.Head)
                    {
                        if (stopLooking)
                        {
                            charToMove.ClearHeadTurnTarget(isInstant, HeadFacing.Manual);
                        }
                        else
                        {
                            Vector3 offset = Vector3.zero;

                            Hotspot faceObjectHotspot = faceObject.GetComponent <Hotspot>();
                            Char    faceObjectChar    = faceObject.GetComponent <Char>();

                            if (lookAtHead && faceObjectChar != null)
                            {
                                Transform neckBone = faceObjectChar.neckBone;
                                if (neckBone != null)
                                {
                                    faceObject = neckBone.gameObject;
                                }
                                else
                                {
                                    ACDebug.Log("Cannot look at " + faceObjectChar.name + "'s head as their 'Neck bone' has not been defined.", faceObjectChar);
                                }
                            }
                            else if (faceObjectHotspot != null)
                            {
                                if (faceObjectHotspot.centrePoint != null)
                                {
                                    faceObject = faceObjectHotspot.centrePoint.gameObject;
                                }
                                else
                                {
                                    offset = faceObjectHotspot.GetIconPosition(true);
                                }
                            }

                            charToMove.SetHeadTurnTarget(faceObject.transform, offset, isInstant);
                        }
                    }

                    if (isInstant)
                    {
                        return(0f);
                    }
                    else
                    {
                        if (willWait)
                        {
                            return(defaultPauseTime);
                        }
                        else
                        {
                            return(0f);
                        }
                    }
                }

                return(0f);
            }
            else
            {
                if (faceType == CharFaceType.Head && charToMove.IsMovingHead())
                {
                    return(defaultPauseTime);
                }
                else if (faceType == CharFaceType.Body && charToMove.IsTurning())
                {
                    return(defaultPauseTime);
                }
                else
                {
                    isRunning = false;
                    return(0f);
                }
            }
        }
Example #3
0
        override public float Run()
        {
            UpgradeSelf();

            if (movePath && movePath.GetComponent <Char>())
            {
                ACDebug.LogWarning("Can't follow a Path attached to a Character!");
                return(0f);
            }

            if (!isRunning)
            {
                isRunning = true;

                if (runtimeChar)
                {
                    if (runtimeChar is NPC)
                    {
                        NPC npcToMove = (NPC)runtimeChar;
                        npcToMove.StopFollowing();
                    }

                    if (movePathMethod == MovePathMethod.StopMoving)
                    {
                        runtimeChar.EndPath();
                        if (runtimeChar.IsPlayer && KickStarter.playerInteraction.GetHotspotMovingTo() != null)
                        {
                            KickStarter.playerInteraction.StopMovingToHotspot();
                        }

                        if (stopInstantly)
                        {
                            runtimeChar.Halt();
                        }
                    }
                    else if (movePathMethod == MovePathMethod.MoveOnNewPath)
                    {
                        if (movePath)
                        {
                            int randomIndex = -1;
                            if (movePath.pathType == AC_PathType.IsRandom && startRandom)
                            {
                                if (movePath.nodes.Count > 1)
                                {
                                    randomIndex = Random.Range(0, movePath.nodes.Count);
                                }
                            }

                            PrepareCharacter(randomIndex);

                            if (willWait && movePath.pathType != AC_PathType.ForwardOnly && movePath.pathType != AC_PathType.ReverseOnly)
                            {
                                willWait = false;
                                ACDebug.LogWarning("Cannot pause while character moves along a linear path, as this will create an indefinite cutscene.");
                            }

                            if (randomIndex >= 0)
                            {
                                runtimeChar.SetPath(movePath, randomIndex, 0);
                            }
                            else
                            {
                                runtimeChar.SetPath(movePath);
                            }

                            if (willWait)
                            {
                                return(defaultPauseTime);
                            }
                        }
                    }
                    else if (movePathMethod == MovePathMethod.ResumeLastSetPath)
                    {
                        runtimeChar.ResumeLastPath();
                    }
                }

                return(0f);
            }
            else
            {
                if (runtimeChar.GetPath() != movePath)
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    return(defaultPauseTime);
                }
            }
        }
Example #4
0
        override public float Run()
        {
            UpgradeSelf();

            if (movePath && movePath.GetComponent <Char>())
            {
                ACDebug.LogWarning("Can't follow a Path attached to a Character!");
                return(0f);
            }

            if (!isRunning)
            {
                isRunning = true;

                if (charToMove)
                {
                    if (charToMove is NPC)
                    {
                        NPC npcToMove = (NPC)charToMove;
                        npcToMove.StopFollowing();
                    }

                    if (movePathMethod == MovePathMethod.StopMoving)
                    {
                        charToMove.EndPath();
                    }
                    else if (movePathMethod == MovePathMethod.MoveOnNewPath)
                    {
                        if (movePath)
                        {
                            if (doTeleport)
                            {
                                charToMove.Teleport(movePath.transform.position);

                                // Set rotation if there is more than one node
                                if (movePath.nodes.Count > 1)
                                {
                                    charToMove.SetLookDirection(movePath.nodes[1] - movePath.nodes[0], true);
                                }
                            }

                            if (willWait && movePath.pathType != AC_PathType.ForwardOnly)
                            {
                                willWait = false;
                                ACDebug.LogWarning("Cannot pause while character moves along a non-forward only path, as this will create an indefinite cutscene.");
                            }

                            charToMove.SetPath(movePath);

                            if (willWait)
                            {
                                return(defaultPauseTime);
                            }
                        }
                    }
                    else if (movePathMethod == MovePathMethod.ResumeLastSetPath)
                    {
                        charToMove.ResumeLastPath();
                    }
                }

                return(0f);
            }
            else
            {
                if (charToMove.GetPath() != movePath)
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    return(defaultPauseTime);
                }
            }
        }
Example #5
0
    override public float Run()
    {
        if (!isRunning)
        {
            isRunning = true;

            if (isPlayer)
            {
                charToMove = GameObject.FindWithTag(Tags.player).GetComponent <Player>();
            }

            if (charToMove)
            {
                if (doStop)
                {
                    charToMove.EndPath();
                }
                else
                {
                    if (doTeleport)
                    {
                        charToMove.transform.position = movePath.transform.position;

                        // Set rotation if there is more than one node
                        if (movePath.nodes.Count > 1)
                        {
                            charToMove.SetLookDirection(movePath.nodes[1] - movePath.nodes[0], true);
                        }
                    }

                    if (movePath)
                    {
                        if (isPlayer && movePath.pathType != PathType.ForwardOnly)
                        {
                            Debug.LogWarning("Cannot move player along a non-forward only path, as this will create an indefinite cutscene.");
                        }
                        else
                        {
                            if (willWait && movePath.pathType != PathType.ForwardOnly)
                            {
                                willWait = false;
                                Debug.LogWarning("Cannot pause while character moves along a non-forward only path, as this will create an indefinite cutscene.");
                            }

                            charToMove.SetPath(movePath);

                            if (willWait || isPlayer)
                            {
                                return(defaultPauseTime);
                            }
                        }
                    }
                }
            }

            return(0f);
        }
        else
        {
            if (charToMove.GetPath() != movePath)
            {
                isRunning = false;
                return(0f);
            }
            else
            {
                return(defaultPauseTime);
            }
        }
    }