|
|
@ -4,7 +4,8 @@ using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
|
|
|
|
public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
public class FourthGCamCtrl : MonoBehaviour |
|
|
|
|
|
|
|
{ |
|
|
|
public Vector3 QuaterView = Vector3.zero; |
|
|
|
public Vector3 QuaterView = Vector3.zero; |
|
|
|
public float InitY; |
|
|
|
public float InitY; |
|
|
|
private static FourthGCamCtrl instance; |
|
|
|
private static FourthGCamCtrl instance; |
|
|
@ -26,15 +27,16 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
private Transform target; |
|
|
|
private Transform target; |
|
|
|
private Vector3 preTargetPosition; |
|
|
|
private Vector3 preTargetPosition; |
|
|
|
private bool lookOver = false; |
|
|
|
private bool lookOver = false; |
|
|
|
private float height = 3; //查看人员模式下,摄像机高度 |
|
|
|
private float height = 1.5f; //查看人员模式下,摄像机高度 |
|
|
|
private float distance = 2; //查看人员模式下,人与摄像机之间的距离 |
|
|
|
private float distance = 2; //查看人员模式下,人与摄像机之间的距离 |
|
|
|
private float dampTrace = 20.0f; //查看人员模式下,摄像机平滑追踪的变量 |
|
|
|
private float dampTrace = 20.0f; //查看人员模式下,摄像机平滑追踪的变量 |
|
|
|
private float lookingAtHeight = 3.5f; |
|
|
|
private float lookingAtHeight = 2f; |
|
|
|
private float lookingAtDistance = 5; |
|
|
|
private float lookingAtDistance = 5; |
|
|
|
|
|
|
|
|
|
|
|
private bool isQuading = false; |
|
|
|
private bool isQuading = false; |
|
|
|
// Use this for initialization |
|
|
|
// Use this for initialization |
|
|
|
void Start () { |
|
|
|
void Start() |
|
|
|
|
|
|
|
{ |
|
|
|
MessageDispatcher.AddListener("OpenFourthG", EnableCamera); |
|
|
|
MessageDispatcher.AddListener("OpenFourthG", EnableCamera); |
|
|
|
MessageDispatcher.AddListener("QuadrupleMode", DisableCamera); |
|
|
|
MessageDispatcher.AddListener("QuadrupleMode", DisableCamera); |
|
|
|
MessageDispatcher.AddListener("4GNobodySelected", NobodySelected); |
|
|
|
MessageDispatcher.AddListener("4GNobodySelected", NobodySelected); |
|
|
@ -73,16 +75,16 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
{ |
|
|
|
{ |
|
|
|
var value = (bool)obj.Data; |
|
|
|
var value = (bool)obj.Data; |
|
|
|
//如果打开了4G图传,又处于四分屏模式,则此相机禁用 |
|
|
|
//如果打开了4G图传,又处于四分屏模式,则此相机禁用 |
|
|
|
if(value ==true && isQuading == true) |
|
|
|
if (value == true && isQuading == true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.enabled = false; |
|
|
|
this.enabled = false; |
|
|
|
cam.enabled = false; |
|
|
|
cam.enabled = false; |
|
|
|
} |
|
|
|
} |
|
|
|
//如果打开了4G图传,未处于四分屏模式,则此相机激活 |
|
|
|
//如果打开了4G图传,未处于四分屏模式,则此相机激活 |
|
|
|
else if(value==true && isQuading == false) |
|
|
|
else if (value == true && isQuading == false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.enabled = true; |
|
|
|
this.enabled = true; |
|
|
|
cam.enabled = true; |
|
|
|
cam.enabled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
//如果关闭了4G图传,则禁用此相机 |
|
|
|
//如果关闭了4G图传,则禁用此相机 |
|
|
|
else |
|
|
|
else |
|
|
@ -100,26 +102,27 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
var value = (bool)obj.Data; |
|
|
|
var value = (bool)obj.Data; |
|
|
|
isQuading = value; |
|
|
|
isQuading = value; |
|
|
|
this.enabled = !value; |
|
|
|
this.enabled = !value; |
|
|
|
cam.enabled = !value; |
|
|
|
cam.enabled = !value; |
|
|
|
} |
|
|
|
} |
|
|
|
// Update is called once per frame |
|
|
|
// Update is called once per frame |
|
|
|
void Update () { |
|
|
|
void Update() |
|
|
|
|
|
|
|
{ |
|
|
|
//有目标人员并且相机激活时才执行 |
|
|
|
//有目标人员并且相机激活时才执行 |
|
|
|
if (target != null && cam.enabled==true) |
|
|
|
if (target != null && cam.enabled == true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!lookOver) |
|
|
|
if (!lookOver) |
|
|
|
{ |
|
|
|
{ |
|
|
|
transform.position = new Vector3(target.position.x, transform.position.y, target.position.z); |
|
|
|
transform.position = new Vector3(target.position.x, transform.position.y, target.position.z); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
//相机的位置,在人员胸前 |
|
|
|
//相机的位置,在人员胸前 |
|
|
|
transform.position = Vector3.Lerp(transform.position, target.position + (target.forward * distance) + (Vector3.up * height), Time.deltaTime * dampTrace); |
|
|
|
transform.position = Vector3.Lerp(transform.position, target.position + (target.forward * distance) + (Vector3.up * height), Time.deltaTime * dampTrace); |
|
|
|
//transform.LookAt(target.position); |
|
|
|
//transform.LookAt(target.position); |
|
|
|
transform.LookAt(target.position + (target.forward * lookingAtDistance) + (Vector3.up * lookingAtHeight)); |
|
|
|
transform.LookAt(target.position + (target.forward * lookingAtDistance) + (Vector3.up * lookingAtHeight)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 查看人员视角 |
|
|
|
/// 查看人员视角 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -127,7 +130,7 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
private void LookOverTarget(IMessage obj) |
|
|
|
private void LookOverTarget(IMessage obj) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var targetInfo = (CloneGameObjInfo)obj.Data; |
|
|
|
var targetInfo = (CloneGameObjInfo)obj.Data; |
|
|
|
target = EntitiesManager.Instance.GetEntityByID(targetInfo.gameObjID).transform; |
|
|
|
target = EntitiesManager.Instance.GetEntityByID(targetInfo.gameObjID).transform; |
|
|
|
GetComponent<Camera>().orthographic = false; //改为透视视角 |
|
|
|
GetComponent<Camera>().orthographic = false; //改为透视视角 |
|
|
|
lookOver = true; |
|
|
|
lookOver = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -141,7 +144,7 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
transform.eulerAngles = QuaterView; |
|
|
|
transform.eulerAngles = QuaterView; |
|
|
|
transform.position = new Vector3(transform.position.x, InitY, transform.position.z); |
|
|
|
transform.position = new Vector3(transform.position.x, InitY, transform.position.z); |
|
|
|
GetComponent<Camera>().orthographic = true; //改回正交视角 |
|
|
|
GetComponent<Camera>().orthographic = true; //改回正交视角 |
|
|
|
lookOver = false; |
|
|
|
lookOver = false; |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 在4G图传中有人员被选中,相机跟随该人员 |
|
|
|
/// 在4G图传中有人员被选中,相机跟随该人员 |
|
|
@ -150,7 +153,7 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
public void SetTarget(Transform tar) |
|
|
|
public void SetTarget(Transform tar) |
|
|
|
{ |
|
|
|
{ |
|
|
|
target = tar; |
|
|
|
target = tar; |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 没有人员被选中,取消地图相机跟随 |
|
|
|
/// 没有人员被选中,取消地图相机跟随 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
@ -158,6 +161,6 @@ public class FourthGCamCtrl : MonoBehaviour { |
|
|
|
void NobodySelected(IMessage obj) |
|
|
|
void NobodySelected(IMessage obj) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//preTargetPosition = target.position; |
|
|
|
//preTargetPosition = target.position; |
|
|
|
target = null; |
|
|
|
target = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|