private void RunToTime(float _time, bool isSkipping)
        {
            if (transformType == TransformType.CopyMarker)
            {
                if (marker)
                {
                    linkedProp.Move(marker, moveMethod, inWorldSpace, _time, timeCurve);
                }
            }
            else
            {
                Vector3 targetVector = Vector3.zero;

                if (setVectorMethod == SetVectorMethod.FromVector3Variable)
                {
                    if (variableLocation == VariableLocation.Global)
                    {
                        targetVector = GlobalVariables.GetVector3Value(vectorVarID);
                    }
                    else if (variableLocation == VariableLocation.Local && !isAssetFile)
                    {
                        targetVector = LocalVariables.GetVector3Value(vectorVarID);
                    }
                }
                else if (setVectorMethod == SetVectorMethod.EnteredHere)
                {
                    targetVector = newVector;
                }

                if (transformType == TransformType.Translate)
                {
                    if (toBy == ToBy.By)
                    {
                        targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.localPosition);
                    }
                }
                else if (transformType == TransformType.Rotate)
                {
                    if (toBy == ToBy.By)
                    {
                        int numZeros = 0;
                        if (Mathf.Approximately(targetVector.x, 0f))
                        {
                            numZeros++;
                        }
                        if (Mathf.Approximately(targetVector.y, 0f))
                        {
                            numZeros++;
                        }
                        if (Mathf.Approximately(targetVector.z, 0f))
                        {
                            numZeros++;
                        }

                        if (numZeros == 2)
                        {
                            targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.eulerAngles);
                        }
                        else
                        {
                            Quaternion currentRotation = linkedProp.transform.localRotation;
                            linkedProp.transform.Rotate(targetVector, Space.World);
                            targetVector = linkedProp.transform.localEulerAngles;
                            linkedProp.transform.localRotation = currentRotation;
                        }
                    }
                }
                else if (transformType == TransformType.Scale)
                {
                    if (toBy == ToBy.By)
                    {
                        targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.localScale);
                    }
                }

                if (transformType == TransformType.Rotate)
                {
                    linkedProp.Move(targetVector, moveMethod, inWorldSpace, _time, transformType, doEulerRotation, timeCurve, clearExisting);
                }
                else
                {
                    linkedProp.Move(targetVector, moveMethod, inWorldSpace, _time, transformType, false, timeCurve, clearExisting);
                }
            }
        }
        override public float Run()
        {
            if (_gameObject == null)
            {
                return(0f);
            }

            if (invAction == InvAction.Add)
            {
                // Instantiate

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (_gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    RememberTransform rememberTransform = oldOb.GetComponent <RememberTransform>();

                    if (rememberTransform != null && rememberTransform.saveScenePresence && rememberTransform.linkedPrefabID != 0)
                    {
                        // Bypass this check
                    }
                    else
                    {
                        ACDebug.LogWarning(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                        return(0f);
                    }
                }

                Vector3    position = _gameObject.transform.position;
                Quaternion rotation = _gameObject.transform.rotation;

                if (positionRelativeTo != PositionRelativeTo.Nothing)
                {
                    float forward = _gameObject.transform.position.z;
                    float right   = _gameObject.transform.position.x;
                    float up      = _gameObject.transform.position.y;

                    if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera)
                    {
                        Transform mainCam = KickStarter.mainCamera.transform;
                        position              = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up);
                        rotation.eulerAngles += mainCam.transform.rotation.eulerAngles;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer)
                    {
                        if (KickStarter.player)
                        {
                            Transform playerTranform = KickStarter.player.transform;
                            position              = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up);
                            rotation.eulerAngles += playerTranform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                    {
                        if (relativeGameObject != null)
                        {
                            Transform relativeTransform = relativeGameObject.transform;
                            position              = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up);
                            rotation.eulerAngles += relativeTransform.rotation.eulerAngles;
                        }
                    }
                    else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                    {
                        position += relativeVector;
                    }
                    else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                    {
                        if (variableLocation == VariableLocation.Global)
                        {
                            position += GlobalVariables.GetVector3Value(vectorVarID);
                        }
                        else if (variableLocation == VariableLocation.Local && !isAssetFile)
                        {
                            position += LocalVariables.GetVector3Value(vectorVarID);
                        }
                    }
                }

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;

                if (newObject.GetComponent <RememberTransform>())
                {
                    newObject.GetComponent <RememberTransform>().OnSpawn();
                }

                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }
            else if (invAction == InvAction.Remove)
            {
                // Delete
                KickStarter.sceneChanger.ScheduleForDeletion(_gameObject);
            }
            else if (invAction == InvAction.Replace)
            {
                if (replaceGameObject == null)
                {
                    ACDebug.LogWarning("Cannot perform swap because the object to remove was not found in the scene.");
                    return(0f);
                }

                Vector3    position = replaceGameObject.transform.position;
                Quaternion rotation = replaceGameObject.transform.rotation;

                GameObject oldOb = AssignFile(constantID, _gameObject);
                if (gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy))
                {
                    ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.");
                    return(0f);
                }

                KickStarter.sceneChanger.ScheduleForDeletion(replaceGameObject);

                GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation);
                newObject.name = _gameObject.name;
                KickStarter.stateHandler.IgnoreNavMeshCollisions();
            }

            return(0f);
        }
Ejemplo n.º 3
0
        override public float Run()
        {
            if (teleporter && obToMove)
            {
                Vector3    position = teleporter.transform.position;
                Quaternion rotation = teleporter.transform.rotation;

                if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera)
                {
                    Transform mainCam = KickStarter.mainCamera.transform;

                    float right   = teleporter.transform.position.x;
                    float up      = teleporter.transform.position.y;
                    float forward = teleporter.transform.position.z;

                    position              = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up);
                    rotation.eulerAngles += mainCam.transform.rotation.eulerAngles;
                }
                else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer && !isPlayer)
                {
                    if (KickStarter.player)
                    {
                        Transform playerTranform = KickStarter.player.transform;

                        float right   = teleporter.transform.position.x;
                        float up      = teleporter.transform.position.y;
                        float forward = teleporter.transform.position.z;

                        position              = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up);
                        rotation.eulerAngles += playerTranform.rotation.eulerAngles;
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                {
                    if (relativeGameObject != null)
                    {
                        Transform relativeTransform = relativeGameObject.transform;

                        float right   = teleporter.transform.position.x;
                        float up      = teleporter.transform.position.y;
                        float forward = teleporter.transform.position.z;

                        position              = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up);
                        rotation.eulerAngles += relativeTransform.rotation.eulerAngles;
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                {
                    position += relativeVector;
                }
                else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                {
                    if (variableLocation == VariableLocation.Global)
                    {
                        position += GlobalVariables.GetVector3Value(vectorVarID);
                    }
                    else if (variableLocation == VariableLocation.Local && !isAssetFile)
                    {
                        position += LocalVariables.GetVector3Value(vectorVarID);
                    }
                }

                if (copyRotation)
                {
                    obToMove.transform.rotation = rotation;

                    if (obToMove.GetComponent <Char>())
                    {
                        // Is a character, so set the lookDirection, otherwise will revert back to old rotation
                        obToMove.GetComponent <Char>().SetLookDirection(teleporter.transform.forward, true);
                        obToMove.GetComponent <Char>().Halt();
                    }
                }

                if (obToMove.GetComponent <Char>())
                {
                    obToMove.GetComponent <Char>().Teleport(position, recalculateActivePathFind);
                }
                else
                {
                    obToMove.transform.position = position;
                }

                if (isPlayer && snapCamera)
                {
                    if (KickStarter.mainCamera != null && KickStarter.mainCamera.attachedCamera != null && KickStarter.mainCamera.attachedCamera.targetIsPlayer)
                    {
                        KickStarter.mainCamera.attachedCamera.MoveCameraInstant();
                    }
                }
            }

            return(0f);
        }