fix:1
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 945409011363ca84bb9e2ae17a1aa5f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,287 @@
|
||||
|
||||
/************************************************************
|
||||
Copyright (C), 2007-2017,BJ Rainier Tech. Co., Ltd.
|
||||
FileName: FirstViewControl.cs
|
||||
Author:汪海波 Version :1.0 Date:
|
||||
Description:
|
||||
************************************************************/
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
|
||||
public class FirstViewControl : MonoBehaviour
|
||||
{
|
||||
public enum FirstViewControlState
|
||||
{
|
||||
noUse,//不使用
|
||||
playerControl,//第一人称控制
|
||||
playerAnim,//第一人动画
|
||||
}
|
||||
|
||||
public Transform characterTrans, camTrans;
|
||||
|
||||
|
||||
/// <summary> /// 单例公开属性 /// </summary>
|
||||
public static FirstViewControl instance { set { } get { return _instance; } }
|
||||
private static FirstViewControl _instance;
|
||||
void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (characterTrans == null)
|
||||
characterTrans = this.gameObject.transform;
|
||||
if (camTrans == null)
|
||||
camTrans = this.gameObject.transform.Find("Main Camera").transform;
|
||||
|
||||
IniQuaternion();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
JueSeKongZhi();
|
||||
}
|
||||
public FirstViewControlState playerState = FirstViewControlState.playerControl;
|
||||
[HideInInspector]
|
||||
public bool isCanSimpleMove = true, isCanRotate = true, isCanUpDown = true, isCanScrollView = true;
|
||||
[HideInInspector]
|
||||
public bool isTextInput;
|
||||
|
||||
void JueSeKongZhi()
|
||||
{
|
||||
if (playerState == FirstViewControlState.playerControl)
|
||||
{
|
||||
if (isCanSimpleMove && !isTextInput)
|
||||
SimpleMove();
|
||||
if (isCanRotate)
|
||||
RotateCamera();
|
||||
if (isCanUpDown)
|
||||
CamUpDown();
|
||||
if (isCanScrollView)
|
||||
CamViewScale();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#region 人物移动
|
||||
[Header("人物移动")]
|
||||
Vector3 movedir;
|
||||
public float moveSpeed = 0.1f;
|
||||
[Header("是否添加重力效果")]
|
||||
public bool Isvelocity = false;
|
||||
|
||||
/// <summary>
|
||||
/// 人物移动
|
||||
/// </summary>
|
||||
public void SimpleMove()
|
||||
{
|
||||
float h = Input.GetAxis("Horizontal");
|
||||
float v = Input.GetAxis("Vertical");
|
||||
if (h != 0 || v != 0)
|
||||
{
|
||||
|
||||
float va = camTrans.gameObject.GetComponent<Camera>().fieldOfView;
|
||||
movedir = transform.TransformDirection(new Vector3(h, 0, v).normalized * moveSpeed * va * Time.deltaTime);
|
||||
characterTrans.GetComponent<CharacterController>().Move(movedir);
|
||||
if (Isvelocity)
|
||||
{
|
||||
//有重力的效果
|
||||
var velocity = GetComponent<CharacterController>().velocity;
|
||||
var currentMovementOffset = velocity * Time.deltaTime;
|
||||
var pushDownOffset = Mathf.Max(GetComponent<CharacterController>().stepOffset, new Vector3(currentMovementOffset.x, 0, currentMovementOffset.z).magnitude);
|
||||
currentMovementOffset = (-1) * pushDownOffset * Vector3.up;
|
||||
|
||||
characterTrans.GetComponent<CharacterController>().Move(currentMovementOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 相机旋转
|
||||
[Header("相机旋转")]
|
||||
private float XSensitivity = 3f;
|
||||
private float YSensitivity = 3f;
|
||||
private Quaternion m_CharacterTargetRot;
|
||||
private Quaternion m_CameraTargetRot;
|
||||
private bool clampVerticalRotation = true;
|
||||
private bool smooth = true;
|
||||
private float smoothTime = 5f;
|
||||
|
||||
public void IniQuaternion()
|
||||
{
|
||||
m_CharacterTargetRot = characterTrans.localRotation;
|
||||
m_CameraTargetRot = camTrans.localRotation;
|
||||
}
|
||||
/// <summary>
|
||||
/// 相机旋转
|
||||
/// </summary>
|
||||
public void RotateCamera()
|
||||
{
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
float yRot = Input.GetAxis("Mouse X") * XSensitivity;
|
||||
float xRot = Input.GetAxis("Mouse Y") * YSensitivity;
|
||||
|
||||
m_CharacterTargetRot *= Quaternion.Euler(0f, yRot, 0f);
|
||||
m_CameraTargetRot *= Quaternion.Euler(-xRot, 0f, 0f);
|
||||
|
||||
if (clampVerticalRotation)
|
||||
m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
|
||||
if (smooth)
|
||||
{
|
||||
characterTrans.localRotation = Quaternion.Slerp(characterTrans.localRotation, m_CharacterTargetRot,
|
||||
smoothTime * Time.deltaTime);
|
||||
camTrans.localRotation = Quaternion.Slerp(camTrans.localRotation, m_CameraTargetRot,
|
||||
smoothTime * Time.deltaTime);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
characterTrans.localRotation = m_CharacterTargetRot;
|
||||
camTrans.localRotation = m_CameraTargetRot;
|
||||
}
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
if (smooth)
|
||||
{
|
||||
m_CharacterTargetRot = characterTrans.localRotation;
|
||||
m_CameraTargetRot = camTrans.localRotation;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private float MinimumX = -60F;
|
||||
private float MaximumX = 60F;
|
||||
Quaternion ClampRotationAroundXAxis(Quaternion q)
|
||||
{
|
||||
q.x /= q.w;
|
||||
q.y /= q.w;
|
||||
q.z /= q.w;
|
||||
q.w = 1.0f;
|
||||
|
||||
float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
|
||||
|
||||
angleX = Mathf.Clamp(angleX, MinimumX, MaximumX);
|
||||
|
||||
q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
|
||||
|
||||
return q;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 相机上下移动
|
||||
[Header("相机上下移动")]
|
||||
private int dirNum = 0;//判断中建按下停止不动时 是向下还是向上移动
|
||||
private float camUpDownSpeed = 0.8f;//相机上下速度
|
||||
|
||||
private float shangXia;
|
||||
|
||||
public float camHeightMax = 0.5f;//相机最高高度
|
||||
public float camHeightMin = -0.5f;//相机最低高度
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 相机上下移动
|
||||
/// </summary>
|
||||
public void CamUpDown()
|
||||
{
|
||||
if (Input.GetMouseButton(2))//?м?????
|
||||
{
|
||||
shangXia = shangXia + 0.5f * Input.GetAxis("Mouse Y");
|
||||
shangXia = Mathf.Clamp(shangXia, -5.3f, 5.3f);
|
||||
|
||||
camTrans.localPosition = new Vector3(camTrans.localPosition.x, Mathf.Clamp(camTrans.localPosition.y, camHeightMin, camHeightMax), camTrans.localPosition.z);
|
||||
|
||||
camTrans.Translate(0, shangXia * 0.01f, 0,Space.World);
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(2))
|
||||
{
|
||||
shangXia = 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 相机view值变化
|
||||
//[Header("相机视角值变化")]
|
||||
private float camViewSpeed = -50;//相机view变化速度
|
||||
public void CamViewScale()
|
||||
{
|
||||
|
||||
float h = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (h != 0)
|
||||
{
|
||||
float value = Mathf.Clamp(camTrans.GetComponent<Camera>().fieldOfView + camViewSpeed * h, 20, 60);
|
||||
DOTween.To(() => camTrans.GetComponent<Camera>().fieldOfView, x => camTrans.GetComponent<Camera>().fieldOfView = x, value, 0.2f).SetEase(Ease.Linear);
|
||||
camUpDownSpeed = (camTrans.GetComponent<Camera>().fieldOfView - 20) * 0.7f / 40 + 0.05f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//摄像机动画
|
||||
public void MoveToDestination(Vector3 pos, Vector3 ros, Vector3 cameraRos, float hight, float delay, float time, float View = 60)
|
||||
{
|
||||
playerState = FirstViewControlState.playerAnim;
|
||||
if (camTrans.GetComponent<Camera>().fieldOfView < 59 && Mathf.Abs(camTrans.GetComponent<Camera>().fieldOfView - View) > 5)
|
||||
{
|
||||
DOTween.To(() => camTrans.GetComponent<Camera>().fieldOfView, x => camTrans.GetComponent<Camera>().fieldOfView = x, 60, 1f).SetDelay(delay).SetEase(Ease.InOutQuad);
|
||||
delay += 1;
|
||||
}
|
||||
|
||||
characterTrans.DOLocalMove(pos, time).SetRelative(false).SetDelay(delay).SetEase(Ease.InOutQuad);
|
||||
characterTrans.DOLocalRotate(ros, time).SetRelative(false).SetDelay(delay).SetEase(Ease.InOutQuad);
|
||||
|
||||
camTrans.GetComponent<Camera>().transform.DOLocalRotate(cameraRos, time).SetRelative(false).SetDelay(delay).SetEase(Ease.InOutQuad);
|
||||
camTrans.transform.DOLocalMoveY(hight, time).SetDelay(delay).SetEase(Ease.InOutQuad);
|
||||
DOTween.To(() => camTrans.GetComponent<Camera>().fieldOfView, x => camTrans.GetComponent<Camera>().fieldOfView = x, View, time).SetRelative(false).SetDelay(delay).SetEase(Ease.Linear).OnComplete(() =>
|
||||
{
|
||||
if (smooth)
|
||||
IniQuaternion();
|
||||
playerState = FirstViewControlState.playerControl;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Tweener MoveToDestination(Vector3 playerPos, Vector3 playerRot, Vector3 camPos, Vector3 _camRot, float time, float detime, float fieldvalue)
|
||||
{
|
||||
playerState = FirstViewControlState.playerAnim;
|
||||
//CommandManager.instance.ExecuteCommand(this, false, "playermove", playerPos, playerRot, camPos, _camRot, time, detime, fieldvalue);
|
||||
if (camTrans.GetComponent<Camera>().fieldOfView < 59 && Mathf.Abs(camTrans.GetComponent<Camera>().fieldOfView - fieldvalue) > 5)
|
||||
{
|
||||
DOTween.To(() => camTrans.GetComponent<Camera>().fieldOfView, x => camTrans.GetComponent<Camera>().fieldOfView = x, 60, 1f).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
detime += 1;
|
||||
}
|
||||
Tweener t = default(Tweener);
|
||||
this.transform.DOLocalMove(playerPos, time).SetRelative(false).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
this.transform.DOLocalRotate(playerRot, time).SetRelative(false).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
Camera.main.transform.DOLocalMove(camPos, time).SetRelative(false).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
t = Camera.main.transform.DOLocalRotate(_camRot, time).SetRelative(false).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
|
||||
Tweener tt = DOTween.To(() => Camera.main.fieldOfView, x => Camera.main.fieldOfView = x, fieldvalue, time).SetRelative(false).SetDelay(detime).SetEase(Ease.InOutQuad);
|
||||
if (smooth)
|
||||
{
|
||||
t.OnComplete(() =>
|
||||
IniQuaternion());
|
||||
playerState = FirstViewControlState.playerControl;
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void StopMoveToDestination()
|
||||
{
|
||||
//停止摄像机动画,重置参数
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ea8ab2f94469924ab7d765184972bdb
|
||||
timeCreated: 1514444584
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &5533819937247208742
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5533819937247496256}
|
||||
- component: {fileID: 5533819937245942196}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5533819937247496256
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5533819937247208742}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.76, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 5533819937247542244}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!20 &5533819937245942196
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5533819937247208742}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.01
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!1 &5533819937247440894
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5533819937247542244}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5533819937247542244
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5533819937247440894}
|
||||
m_LocalRotation: {x: 0, y: 0.9994945, z: 0, w: -0.031792928}
|
||||
m_LocalPosition: {x: 34.78, y: 4, z: 21.78}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 5533819937247496256}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 183.6438, z: 0}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20a53dff31d74754d8843d781cfdb7f0
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user