예제 #1
0
    /// <summary>
    /// Calculates the camera top parameter position.
    /// If the topdown mode = Default | ParameterControl , the position is runtime calculated.
    /// If the topdown mode = PositionAtPivot, the position is directly set to the pivot transform's position.
    /// </summary>
    void AlignCameraPosition(bool smoothDamp, TopDownCameraControlParameter topdownCameraControlParameter)
    {
        Vector3 CameraPivotPosition        = Vector3.zero;
        Vector3?ParameterCalculatePosition = null;
        Vector3 CameraLookAtPosition       = Vector3.zero;

        switch (topdownCameraControlParameter.mode)
        {
        //note: for Default mode, CameraLookAtPosition IS NOT ASSIGNED ! Because in runtime, we can't focus camera on player, that will shake the camera too much!
        case TopDownCameraControlMode.Default:
            ParameterCalculatePosition = CalculateParameterControlPosition(smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           GetCharacterCenter());
            CameraPivotPosition  = ParameterCalculatePosition.Value;
            CameraLookAtPosition = GetCharacterCenter();
            break;

        case TopDownCameraControlMode.ParameterControlPositionAndLookAtPosition:
            ParameterCalculatePosition = CalculateParameterControlPosition(smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           topdownCameraControlParameter.cameraFocusOnPosition);
            CameraPivotPosition  = ParameterCalculatePosition.Value;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;

        case TopDownCameraControlMode.ParameterControlPositionAndLookAtTransform:
            ParameterCalculatePosition = CalculateParameterControlPosition(smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           topdownCameraControlParameter.cameraFocusOnTransform.position);
            CameraPivotPosition  = ParameterCalculatePosition.Value;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;

        case TopDownCameraControlMode.PoisitonAtPivotAndLookAtPlayer:
            CameraPivotPosition  = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = GetCharacterCenter();
            break;

        case TopDownCameraControlMode.PositionAtPivotAndLookAtPosition:
            CameraPivotPosition  = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;

        case TopDownCameraControlMode.PositionAtPivotAndLookAtTransform:
            CameraPivotPosition  = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        }

        //finally, asign the position and rotation of the camera.
        //handle position:
        CameraPivotPosition = AdjustLineOfSight(CameraPivotPosition, CameraLookAtPosition);
        transform.position  = CameraPivotPosition;
    }
    public void OnGameEvent(GameEvent _event)
    {
        switch (_event.type)
        {
        case GameEventType.ApplyTopdownCameraParameter:
            TopDownCameraControlParameter controlParameter = GetTopDownCameraControlParameter(_event.StringParameter);
            PlayerTopdownCamera.SetCurrentTopdownCameraParameter(controlParameter);
            break;

        case GameEventType.ResetTopdownCameraParameter:
            PlayerTopdownCamera.ResetCurrentTopdownCameraParameter();
            break;
        }
    }
예제 #3
0
    void AlignCameraRotation(bool smoothDamp, TopDownCameraControlParameter topdownCameraControlParameter)
    {
        Vector3?CameraLookAtPosition = null;

        switch (topdownCameraControlParameter.mode)
        {
        //note: for Default mode, CameraLookAtPosition IS NOT ASSIGNED ! Because in runtime, we can't focus camera on player, that will shake the camera too much!
        case TopDownCameraControlMode.Default:
            CameraLookAtPosition = GetCharacterCenter();
            break;

        case TopDownCameraControlMode.ParameterControlPositionAndLookAtPosition:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;

        case TopDownCameraControlMode.ParameterControlPositionAndLookAtTransform:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;

        case TopDownCameraControlMode.PoisitonAtPivotAndLookAtPlayer:
            CameraLookAtPosition = GetCharacterCenter();
            break;

        case TopDownCameraControlMode.PositionAtPivotAndLookAtPosition:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;

        case TopDownCameraControlMode.PositionAtPivotAndLookAtTransform:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        }
        //handle rotation:
        if (CameraLookAtPosition.HasValue)
        {
            if (smoothDamp)
            {
                Quaternion ToRotation = transform.rotation;
                ToRotation.SetLookRotation(CameraLookAtPosition.Value - transform.position, Vector3.up);
                transform.rotation = Quaternion.Lerp(transform.rotation, ToRotation, topdownCameraControlParameter.smoothLag_Rotation * Time.deltaTime);
                transform.rotation = ToRotation;
            }
            else
            {
                transform.LookAt(CameraLookAtPosition.Value);
            }
        }
    }
예제 #4
0
 /// <summary>
 /// Applies the camera control parameter to the current camera.
 /// smoothDamp - if smoothly damp from current camera position ? if false, the camera control parameter takes effect immediately.
 /// CharacterCenter - the camera center.
 /// topdownCameraControlParameter - the topDownCameraControlParameter.
 /// </summary>
 public virtual void ApplyCameraControlParameter(bool SmoothDamp,
                                                 TopDownCameraControlParameter topdownCameraControlParameter)
 {
     AlignCameraPosition(SmoothDamp, topdownCameraControlParameter);
     AlignCameraRotation(SmoothDamp, topdownCameraControlParameter);
 }
예제 #5
0
 public void ResetCurrentTopdownCameraParameter()
 {
     this.CurrentTopDownCameraParameter = this.topDownCameraParameter;
 }
예제 #6
0
 public void SetCurrentTopdownCameraParameter(TopDownCameraControlParameter topdownCameraControlParameter)
 {
     this.CurrentTopDownCameraParameter = topdownCameraControlParameter;
 }
예제 #7
0
 void Awake()
 {
     PlayerCharacter = transform.root.GetComponentInChildren <CharacterController> ();
     CurrentTopDownCameraParameter = topDownCameraParameter;
 }
예제 #8
0
 public void SetCurrentTopdownCameraParameter(TopDownCameraControlParameter topdownCameraControlParameter)
 {
     this.CurrentTopDownCameraParameter = topdownCameraControlParameter;
 }
예제 #9
0
 public void ResetCurrentTopdownCameraParameter()
 {
     this.CurrentTopDownCameraParameter = this.topDownCameraParameter;
 }
예제 #10
0
    /// <summary>
    /// Applies the camera control parameter to the current camera.
    /// smoothDamp - if smoothly damp from current camera position ? if false, the camera control parameter takes effect immediately.
    /// CharacterCenter - the camera center.
    /// topdownCameraControlParameter - the topDownCameraControlParameter.
    /// </summary>
    public virtual void ApplyCameraControlParameter(bool SmoothDamp,
		                                             TopDownCameraControlParameter topdownCameraControlParameter)
    {
        AlignCameraPosition (SmoothDamp, topdownCameraControlParameter);
        AlignCameraRotation (SmoothDamp, topdownCameraControlParameter);
    }
예제 #11
0
 void Awake()
 {
     PlayerCharacter = transform.root.GetComponentInChildren<CharacterController> ();
     CurrentTopDownCameraParameter = topDownCameraParameter;
 }
예제 #12
0
    void AlignCameraRotation(bool smoothDamp, TopDownCameraControlParameter topdownCameraControlParameter)
    {
        Vector3? CameraLookAtPosition = null;
        switch (topdownCameraControlParameter.mode) {

            //note: for Default mode, CameraLookAtPosition IS NOT ASSIGNED ! Because in runtime, we can't focus camera on player, that will shake the camera too much!
        case TopDownCameraControlMode.Default:
            CameraLookAtPosition = GetCharacterCenter();
            break;
        case TopDownCameraControlMode.ParameterControlPositionAndLookAtPosition:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;
        case TopDownCameraControlMode.ParameterControlPositionAndLookAtTransform:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        case TopDownCameraControlMode.PoisitonAtPivotAndLookAtPlayer:
            CameraLookAtPosition = GetCharacterCenter ();
            break;
        case TopDownCameraControlMode.PositionAtPivotAndLookAtPosition:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;
        case TopDownCameraControlMode.PositionAtPivotAndLookAtTransform:
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        }
        //handle rotation:
        if(CameraLookAtPosition.HasValue)
        {
           if(smoothDamp)
           {
              Quaternion ToRotation = transform.rotation;
              ToRotation.SetLookRotation(CameraLookAtPosition.Value - transform.position, Vector3.up);
              transform.rotation = Quaternion.Lerp(transform.rotation, ToRotation, topdownCameraControlParameter.smoothLag_Rotation * Time.deltaTime);
              transform.rotation = ToRotation;
           }
           else
           {
              transform.LookAt (CameraLookAtPosition.Value);
           }
        }
    }
예제 #13
0
    /// <summary>
    /// Calculates the camera top parameter position.
    /// If the topdown mode = Default | ParameterControl , the position is runtime calculated.
    /// If the topdown mode = PositionAtPivot, the position is directly set to the pivot transform's position.
    /// </summary>	
    void AlignCameraPosition(bool smoothDamp, TopDownCameraControlParameter topdownCameraControlParameter)
    {
        Vector3 CameraPivotPosition = Vector3.zero;
        Vector3? ParameterCalculatePosition = null;
        Vector3 CameraLookAtPosition = Vector3.zero;
        switch (topdownCameraControlParameter.mode) {

            //note: for Default mode, CameraLookAtPosition IS NOT ASSIGNED ! Because in runtime, we can't focus camera on player, that will shake the camera too much!
        case TopDownCameraControlMode.Default:
            ParameterCalculatePosition = CalculateParameterControlPosition (smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           GetCharacterCenter ());
            CameraPivotPosition = ParameterCalculatePosition.Value;
            CameraLookAtPosition = GetCharacterCenter();
            break;
        case TopDownCameraControlMode.ParameterControlPositionAndLookAtPosition:
            ParameterCalculatePosition = CalculateParameterControlPosition (smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           topdownCameraControlParameter.cameraFocusOnPosition);
            CameraPivotPosition = ParameterCalculatePosition.Value;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;
        case TopDownCameraControlMode.ParameterControlPositionAndLookAtTransform:
            ParameterCalculatePosition = CalculateParameterControlPosition (smoothDamp, topdownCameraControlParameter.DynamicHeight,
                                                                           topdownCameraControlParameter.DynamicDistance,
                                                                           topdownCameraControlParameter.smoothLag_Position,
                                                                           topdownCameraControlParameter.cameraFocusOnTransform.position);
            CameraPivotPosition = ParameterCalculatePosition.Value;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        case TopDownCameraControlMode.PoisitonAtPivotAndLookAtPlayer:
            CameraPivotPosition = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = GetCharacterCenter();
            break;
        case TopDownCameraControlMode.PositionAtPivotAndLookAtPosition:
            CameraPivotPosition = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnPosition;
            break;
        case TopDownCameraControlMode.PositionAtPivotAndLookAtTransform:
            CameraPivotPosition = topdownCameraControlParameter.CameraPositionPivot.position;
            CameraLookAtPosition = topdownCameraControlParameter.cameraFocusOnTransform.position;
            break;
        }

        //finally, asign the position and rotation of the camera.
        //handle position:
        CameraPivotPosition = AdjustLineOfSight (CameraPivotPosition, CameraLookAtPosition);
        transform.position = CameraPivotPosition;
    }