由于在项目制作中经常要对相机进行移动 所以采用了公司的工具类
CameraOrbit 和 CameraControl
在项目中需要添加 FingerGestures 插件 相机脚本是基于FingerGestures 上改写 并搭配
在相机物体中添加
Root 和Orgin 是和相机相同位置的 相机的移动也是基于 root 和origin的
以下是CameraOrbit代码
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Adaptation of the standard MouseOrbit script to use the finger drag gesture to rotate the current object using
/// the fingers/mouse around a target object
/// </summary>
public class XgCameraOrbit : MonoBehaviour
{
public enum PanMode
{
Disabled,
OneFinger,
TwoFingers
}
/// <summary>
/// The object to orbit around
/// </summary>
public Transform target;
public Transform camRoot;
public Transform camOrigin;
private XgCameraManager xg_Cm;
//private XgIntellControl xg_IC;
//private XgPictrueControl xg_Pc;
/// <summary>
/// Initial camera distance to target
/// </summary>
public float initialDistance = 10.0f;
/// <summary>
/// Minimum distance between camera and target
/// </summary>
public float minDistance = 1.0f;
/// <summary>
/// Maximum distance between camera and target
/// </summary>
public float maxDistance = 30.0f;
/// <summary>
/// Affects horizontal rotation speed (in degrees per cm)
/// </summary>
public float yawSensitivity = 45.0f;
/// <summary>
/// Affects vertical rotation speed (in degrees per cm)
/// </summary>
public float pitchSensitivity = 45.0f;
/// <summary>
/// Keep yaw angle value between minYaw and maxYaw?
/// </summary>
public bool clampYawAngle = false;
public float minYaw = -75;
public float maxYaw = 75;
/// <summary>
/// Keep pitch angle value between minPitch and maxPitch?
/// </summary>
public bool clampPitchAngle = true;
public float minPitch = -20;
public float maxPitch = 80;
/// <summary>
/// Allow the user to affect the orbit distance using the pinch zoom gesture
/// </summary>
public bool allowPinchZoom = true;
/// <summary>
/// Affects pinch zoom speed
/// </summary>
public float pinchZoomSensitivity = 5.0f;
private float pinchZoomSensMax;
private float pinchZoomSens;
/// <summary>
/// Use smooth camera motions?
/// </summary>
public bool smoothMotion = true;
public float smoothZoomSpeed = 5.0f;
public float smoothOrbitSpeed = 10.0f;
/// <summary>
/// Two-Finger camera panning.
/// Panning will apply an offset to the pivot/camera target point
/// </summary>
public bool allowPanning = false;
public bool invertPanningDirections = false;
public float panningSensitivity = 1.0f;
private float panningSensMax;
private float panningSens;
public Transform panningPlane;
// reference transform used to apply the panning translation (using panningPlane.right and panningPlane.up vectors)
public bool smoothPanning = true;
public float smoothPanningSpeed = 12.0f;
// collision test
public LayerMask collisionLayerMask;
private Transform myTrans;
private float distance = 10.0f;
private float yaw = 0;
private float pitch = 0;
private float idealDistance = 0;
private float idealYaw = 0;
private float idealPitch = 0;
private Vector3 idealPanOffset = Vector3.zero;
private Vector3 panOffset = Vector3.zero;
private Vector3 rPanOffset;
private bool slideCentered = false;
private Vector3 slideOffset;
private PinchRecognizer pinchRecognizer;
private bool UIdrag = false;
private bool canControl = true;
private bool canInput = true;
private float fl_MovePos = 0f;
private float fl_IdeaMovePos;
//messager
//SLCameraMessager sCm;
//调用
//Main_Control main_control;
public bool UIDrag
{
get { return UIdrag; }
set { UIdrag = value; }
}
public float Distance
{
get { return distance; }
}
public float IdealDistance
{
get { return idealDistance; }
set { idealDistance = Mathf.Clamp(value, minDistance, maxDistance); }
}
public float Yaw
{
get { return yaw; }
}
public float IdealYaw
{
get { return idealYaw; }
set { idealYaw = clampYawAngle ? ClampAngle(value, minYaw, maxYaw) : value; }
}
public float Pitch
{
get { return pitch; }
}
public float IdealPitch
{
get { return idealPitch; }
set { idealPitch = clampPitchAngle ? ClampAngle(value, minPitch, maxPitch) : value; }
}
public Vector3 IdealPanOffset
{
get { return idealPanOffset; }
set { idealPanOffset = value; }
}
public Vector3 PanOffset
{
get { return panOffset; }
}
public Vector3 ROffset
{
get { return rPanOffset; }
}
private void InstallGestureRecognizers()
{
//xg_IC = GameObject.Find(str_Intell_Control).GetComponent<XgIntellControl>();
//xg_Pc = GameObject.Find(str_Pic_Control).GetComponent<XgPictrueControl>();
List<GestureRecognizer> recogniers = new List<GestureRecognizer>(GetComponents<GestureRecognizer>());
DragRecognizer drag = recogniers.Find(r => r.EventMessageName == "OnDrag") as DragRecognizer;
DragRecognizer twoFingerDrag =
recogniers.Find(r => r.EventMessageName == "OnTwoFingerDrag") as DragRecognizer;
PinchRecognizer pinch = recogniers.Find(r => r.EventMessageName == "OnPinch") as PinchRecognizer;
// check if we need to automatically add a screenraycaster
if (OnlyRotateWhenDragStartsOnObject)
{
ScreenRaycaster raycaster = gameObject.GetComponent<ScreenRaycaster>();
if (!raycaster)
raycaster = gameObject.AddComponent<ScreenRaycaster>();
}
if (!drag)
{
drag = gameObject.AddComponent<DragRecognizer>();
drag.RequiredFingerCount = 1;
drag.IsExclusive = true;
drag.MaxSimultaneousGestures = 1;
drag.SendMessageToSelection = GestureRecognizer.SelectionType.None;
}
if (!pinch)
pinch = gameObject.AddComponent<PinchRecognizer>();
if (!twoFingerDrag)
{
twoFingerDrag = gameObject.AddComponent<DragRecognizer>();
twoFingerDrag.RequiredFingerCount = 2;
twoFingerDrag.IsExclusive = true;
twoFingerDrag.MaxSimultaneousGestures = 1;
twoFingerDrag.ApplySameDirectionConstraint = true;
twoFingerDrag.EventMessageName = "OnTwoFingerDrag";
}
}
public void Init_Camera()
{
xg_Cm = gameObject.GetComponent<XgCameraManager>();
if (xg_Cm != null)
xg_Cm.Init_CameraManager();
InstallGestureRecognizers();
myTrans = transform;
if (!panningPlane)
panningPlane = myTrans;
Vector3 angles = myTrans.eulerAngles;
distance = IdealDistance = initialDistance;
yaw = IdealYaw = angles.y;
pitch = IdealPitch = angles.x;
pinchZoomSensMax = pinchZoomSensitivity;
panningSensMax = panningSensitivity;
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().freezeRotation = true;
Apply();
}
#region Gesture Event Messages
private float nextDragTime = 0;
public bool OnlyRotateWhenDragStartsOnObject = false;
private void OnDrag(DragGesture gesture)
{
if (canControl)
{
if (!canInput) return;
if (!UIdrag)
{
// don't rotate unless the drag started on our target object
if (OnlyRotateWhenDragStartsOnObject)
{
if (gesture.Phase == ContinuousGesturePhase.Started)
{
if (!gesture.Recognizer.Raycaster)
{
Debug.LogWarning("The drag recognizer on " + gesture.Recognizer.name +
" has no ScreenRaycaster component set. This will prevent OnlyRotateWhenDragStartsOnObject flag from working.");
OnlyRotateWhenDragStartsOnObject = false;
return;
}
if (target && !target.GetComponent<Collider>())
{
Debug.LogWarning(
"The target object has no collider set. OnlyRotateWhenDragStartsOnObject won't work.");
OnlyRotateWhenDragStartsOnObject = false;
return;
}
}
if (!target || gesture.StartSelection != target.gameObject)
return;
}
// wait for drag cooldown timer to wear off
// used to avoid dragging right after a pinch or pan, when lifting off one finger but the other one is still on screen
if (Time.time < nextDragTime)
return;
if (target)
{
IdealYaw += gesture.DeltaMove.x.Centimeters() * yawSensitivity;
IdealPitch -= gesture.DeltaMove.y.Centimeters() * pitchSensitivity;
}
}
}
}
private void OnPinch(PinchGesture gesture)
{
if (canControl)
{
if (!canInput) return;
if (allowPinchZoom)
{
pinchZoomSens = Distance / 5.0f * pinchZoomSensMax;
IdealDistance -= gesture.Delta.Centimeters() * pinchZoomSens;
nextDragTime = Time.time + 0.25f;
}
}
}
private void OnTwoFingerDrag(DragGesture gesture)
{
if (canControl)
{
if (!canInput) return;
if (allowPanning)
{
panningSens = Distance / 5.0f * panningSensMax;
Vector3 move = -panningSens *
(panningPlane.right * gesture.DeltaMove.x.Centimeters() +
panningPlane.up * gesture.DeltaMove.y.Centimeters());
if (invertPanningDirections)
IdealPanOffset = -move;
else
IdealPanOffset = move;
//reset idealPanPositon
if (gesture.Phase == ContinuousGesturePhase.Ended)
IdealPanOffset = Vector3.zero;
nextDragTime = Time.time + 0.25f;
}
}
}
private void OnTap(TapGesture gesture)
{
if (canControl && gesture.Selection)
{
xg_Cm.OnManagerTap(gesture);
}
//if (canControl && gesture.Selection)
//{
// if (gesture.Selection.CompareTag("MD_Main"))
// {
// main_control.
// }
//}
}
//IN assemble mode, double tap to auto disassemble
private void OnDoubleTap(TapGesture gesture)
{
if (canControl)
if (gesture.Selection)
xg_Cm.OnManagerTap(gesture);
}
#endregion
private void Apply()
{
if (smoothMotion)
{
distance = Mathf.Lerp(distance, IdealDistance, Time.deltaTime * smoothZoomSpeed);
yaw = Mathf.LerpAngle(yaw, IdealYaw, Time.deltaTime * smoothOrbitSpeed);
pitch = Mathf.LerpAngle(pitch, IdealPitch, Time.deltaTime * smoothOrbitSpeed);
}
else
{
distance = IdealDistance;
yaw = IdealYaw;
pitch = IdealPitch;
}
//print(IdealYaw);
if (smoothPanning)
panOffset = Vector3.Lerp(panOffset, idealPanOffset, Time.deltaTime * smoothPanningSpeed);
else
panOffset = idealPanOffset;
if (canInput)
rPanOffset = camOrigin.InverseTransformPoint(panOffset + myTrans.position);
//rotate the orignal camera
camOrigin.rotation = Quaternion.Euler(pitch, yaw, 0);
//change rotation to the orginal camera
myTrans.rotation = camOrigin.rotation;
camOrigin.position = target.position - camOrigin.forward * distance;
//set position for camera
myTrans.position = camOrigin.TransformPoint(rPanOffset);
//Debug.Log(rPanOffset);
}
private void LateUpdate()
{
if (canControl)
Apply();
}
public void CameraProperty(bool pan, bool zoom)
{
allowPanning = pan;
allowPinchZoom = zoom;
}
private static float ClampAngle(float angle, float min, float max)
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp(angle, min, max);
}
public void SlideCenter(bool enable, Vector3 offset)
{
slideCentered = enable;
if (enable)
{
slideOffset = offset;
}
else
{
slideOffset = Vector3.zero;
}
}
public void CanControl(bool enable)
{
canControl = enable;
}
// recenter the camera
public void ResetPanning()
{
IdealPanOffset = Vector3.zero;
}
//获取角度
public float GetCamYawAngle()
{
return yaw % 360 < 0 ? 360 + yaw % 360 : Yaw % 360;
}
public float GetCamPitchAngle()
{
return pitch;
}
public IEnumerator PauseControl(float time)
{
canControl = false;
yield return new WaitForSeconds(time + 0.1f);
canControl = true;
}
public void PauseInput(float time)
{
StopCoroutine("PauseCamInput");
StartCoroutine("PauseCamInput", time);
}
private IEnumerator PauseCamInput(float time)
{
canInput = false;
yield return new WaitForSeconds(time);
canInput = true;
}
public void TeleportCam(Transform pivot, Vector3 originPos, Vector3 rot, float dis, Vector3 pan)
{
target = pivot;
distance = idealDistance = dis;
yaw = idealYaw = rot.y >= 180 ? rot.y - 360 : rot.y;
pitch = idealPitch = rot.x >= 180 ? rot.x - 360 : rot.x;
panOffset = idealPanOffset = Vector3.zero;
rPanOffset = pan;
camOrigin.position = originPos;
camOrigin.eulerAngles = rot;
}
public void Cam_CoreComValue()
{
maxDistance = 20f;
minDistance = 15f;
maxPitch = 40;
allowPanning = false;
}
public void Cam_DefaultValue()
{
maxDistance = 20f;
minDistance = 12f;
maxPitch = 40;
minPitch = 0;
clampYawAngle = false;
allowPanning = false;
}
public void Cam_SellingPoint_BaoXianDeng()
{
minYaw = 10;
maxYaw = 170;
maxPitch = 60;
minPitch = 1;
minDistance = 1f;
maxDistance = 10f;
clampYawAngle = true;
allowPanning = false;
}
public void Cam_SellingPoint_TiaoShiMoKuai()
{
maxDistance = 5f;
minDistance = 1f;
maxPitch = 80;
minPitch = 0;
clampYawAngle = false;
allowPanning = false;
}
public void OnDistance(float dis)
{
//Debug.Log("distance: " + dis);
distance = dis;
idealDistance = dis;
}
public void OnViewAngle(Vector3 angle)
{
//Debug.Log("angle: " + angle);
camOrigin.eulerAngles = angle;
yaw = idealYaw = angle.y;
pitch = idealPitch = angle.x;
}
public void OnComplete()
{
print("sdf");
}
public void OnPanOffset(Vector3 offset)
{
panOffset = idealPanOffset = Vector3.zero;
rPanOffset = offset;
}
}
以下是CameraControl代码
using UnityEngine;
using System.Collections;
public class XgCameraControl : MonoBehaviour
{
public delegate void TravelCallback();
public delegate void CACProcess();
public float fl_Time;
private float time_Shift = 0.8f;
private float spd_Shift = 0.5f;
private static iTween.EaseType posEaseType = iTween.EaseType.easeOutQuad;
private static iTween.EaseType rotEaseType = iTween.EaseType.easeOutQuad;
private XgCameraOrbit xGo;
private void Awake()
{
xGo = GameObject.Find("Main Camera").GetComponent<XgCameraOrbit>();
}
/// <summary>
/// 设置相机的Yaw
/// </summary>
/// <param name="yaw"></param>
public void CamAutoCorrection(float yaw)
{
xGo.IdealYaw = yaw;
}
/// <summary>
/// 获取相机角度
/// </summary>
/// <returns></returns>
public float GetCamYawAngle()
{
return xGo.GetCamYawAngle();
}
public float GetCamPitchAngle()
{
return xGo.GetCamPitchAngle();
}
public void TravelToMenu(Transform cam, Transform center, TravelCallback callback = null, float time = -1f)
{
float hybirdPitch = 2f;
float distance = 9;
Vector3 rot = new Vector3(hybirdPitch, cam.eulerAngles.y, cam.eulerAngles.z);
Transform temp = GameObject.FindGameObjectWithTag("camRoot").transform;
Vector3 offset = Vector3.zero;
temp.eulerAngles = rot;
Vector3 pos = center.position - temp.forward * distance + offset;
StopAllCoroutines();
time = time == -1f ? fl_Time : time;
StartCoroutine(xGo.PauseControl(fl_Time));
xGo.TeleportCam(center, pos, rot, distance, offset);
Travel(cam, pos, rot, time);
if (callback != null)
StartCoroutine(Callback(time, callback));
}
private IEnumerator Callback(float time, TravelCallback callback)
{
yield return new WaitForSeconds(time);
callback();
}
//public void TravelToPoint(Transform cam, Transform viewPoint, Transform center = null)
//{
// if (!center)
// center = xGo.target.transform;
// Vector3 pos = viewPoint.position;
// viewPoint.LookAt(center);
// Vector3 rot = viewPoint.eulerAngles;
// Vector3 desiredPos = center.position - Vector3.Project(center.position - pos, viewPoint.forward);
// float distance = Vector3.Distance(desiredPos, center.position);
// //offset between new pos and the current position
// Vector3 offset = pos - desiredPos;
// StopAllCoroutines();
// StartCoroutine(xGo.PauseControl(fl_Time));
// xGo.TeleportCam(center, desiredPos, rot, distance, offset);
// Travel(cam, pos, rot, fl_Time);
//}
public void TravelToPointNotDistance(Transform cam, Transform viewPoint, Transform tran_lookPos, Transform center = null, float time = -1f)
{
if (!center)
center = xGo.target.transform;
if (time == -1f)
time = fl_Time;
Vector3 pos = viewPoint.position;
viewPoint.LookAt(tran_lookPos);
Vector3 rot = viewPoint.eulerAngles;
Vector3 desiredPos = center.position - Vector3.Project(center.position - pos, viewPoint.forward);
float distance = Vector3.Distance(desiredPos, center.position);
//offset between new pos and the current position
Vector3 offset = pos - desiredPos;
StopAllCoroutines();
StartCoroutine(xGo.PauseControl(time));
xGo.TeleportCam(center, desiredPos, rot, distance, offset);
Travel(cam, pos, rot, time);
}
public void TravelToDistance(Transform cam, float distance, Transform center = null)
{
if (!center)
center = xGo.target.transform;
Vector3 pos = center.position - (center.position - cam.position).normalized * distance;
Vector3 rot = CamEulerAngles(center.position - cam.position);
StopAllCoroutines();
StartCoroutine(xGo.PauseControl(fl_Time));
//Transform.ReferenceEquals
xGo.TeleportCam(center, pos, rot, distance, Vector3.zero);
Travel(cam, pos, rot, fl_Time);
}
public void TravelWithDistanceOffset(Transform cam, float distance, Vector3 offset, Transform center = null)
{
if (!center)
center = xGo.target.transform;
Vector3 pos = center.position - (center.position - cam.position).normalized * distance;
Vector3 rot = CamEulerAngles(center.position - cam.position);
StopAllCoroutines();
StartCoroutine(xGo.PauseControl(fl_Time));
Transform temp = GameObject.FindGameObjectWithTag("camRoot").transform;
temp.position = pos;
temp.eulerAngles = rot;
Vector3 v = temp.TransformPoint(offset);
xGo.TeleportCam(center, pos, rot, distance, offset);
Travel(cam, v, rot, fl_Time);
}
public void TravelWithPointOffset(Transform cam, Transform viewPoint, Vector3 offset, Transform center = null)
{
if (!center)
center = xGo.target.transform;
Vector3 pos = viewPoint.position;
viewPoint.LookAt(center.position + offset);
Vector3 rot = viewPoint.eulerAngles;
Vector3 desiredPos = center.position - Vector3.Project(center.position - pos, viewPoint.forward);
float distance = Vector3.Distance(desiredPos, center.position);
StopAllCoroutines();
StartCoroutine(xGo.PauseControl(fl_Time));
xGo.TeleportCam(center, desiredPos, rot, distance, offset);
Travel(cam, pos, rot, fl_Time);
}
//public void TravelToPoint(Transform cam, Transform pos,Transform center,Vector3 v3_Offset=default(Vector3))
//{
// Transform camTrans = cam.transform;
// Vector3 desiredPos = position - Vector3.Project(center.position - position, forward);
// float newDistance = Vector3.Distance(desiredPos, center.position);
// Vector3 newOffset = v3_Offset == Vector3.zero ? position - desiredPos : v3_Offset;
// Vector3 newViewAngle = eulerAngles;
// Transform oldPivot = xGo.target;
// Vector3 oldViewAngle = camTrans.eulerAngles;
// //print(newViewAngle - oldViewAngle);
// float oldDistance = xGo.Distance;
// Vector3 oldOffset = xGo.ROffset;
// float time = time_Shift;
// StopAllCoroutines();
// xGo.PauseInput(time + 0.1f);
// //shifting
// iTween.MoveTo(xGo.target.gameObject, iTween.Hash("position", center.position, "time", time, "easeType", posEaseType));
// //shift view angles
// float anplyYDiff = oldViewAngle.y - newViewAngle.y;
// float anglyXDiff = oldViewAngle.x - newViewAngle.x;
// if (Mathf.Abs(anplyYDiff) > 180)
// newViewAngle = new Vector3(newViewAngle.x, oldViewAngle.y + (anplyYDiff > 0 ? 360 - anplyYDiff : -(360 + anplyYDiff)), newViewAngle.z);
// if (Mathf.Abs(anglyXDiff) > 180)
// newViewAngle = new Vector3(oldViewAngle.x + (anglyXDiff > 0 ? 360 - anglyXDiff : -(360 + anglyXDiff)), newViewAngle.y, newViewAngle.z);
// iTween.ValueTo(cam.gameObject, iTween.Hash(
// "from", oldViewAngle,
// "to", newViewAngle,
// "time", time,
// "onupdatetarget", cam.gameObject,
// "onupdate", "OnViewAngle",
// "easetype", rotEaseType));
// //shift view distance
// iTween.ValueTo(cam.gameObject, iTween.Hash(
// "from", oldDistance,
// "to", newDistance,
// "time", time,
// "onupdatetarget", cam.gameObject,
// "onupdate", "OnDistance",
// "easetype", rotEaseType));
// //shift view offset
// iTween.ValueTo(cam.gameObject, iTween.Hash(
// "from", oldOffset,
// "to", newOffset,
// "time", time,
// "onupdatetarget", cam.gameObject,
// "onupdate", "OnPanOffset",
// "easetype", rotEaseType));
//}
public void TravelToPoint(Transform cam, Transform tran_Pos, Transform tran_Center, Vector3 v3_Offset = default(Vector3))
{
Transform camTrans = cam.transform;
Vector3 desiredPos = tran_Center.position - Vector3.Project(tran_Center.position - tran_Pos.position, tran_Pos.forward);
float newDistance = Vector3.Distance(desiredPos, tran_Center.position);
Vector3 newOffset = v3_Offset == Vector3.zero ? tran_Pos.position - desiredPos : v3_Offset;
Vector3 newViewAngle = tran_Pos.eulerAngles;
Transform oldPivot = xGo.target;
Vector3 oldViewAngle = camTrans.eulerAngles;
//print(newViewAngle - oldViewAngle);
float oldDistance = xGo.Distance;
Vector3 oldOffset = xGo.ROffset;
float time = fl_Time;
StopAllCoroutines();
xGo.PauseInput(time + 0.1f);
//shifting
iTween.MoveTo(xGo.target.gameObject, iTween.Hash("position", tran_Center.position, "time", time, "easeType", posEaseType));
//shift view angles
float anplyYDiff = oldViewAngle.y - newViewAngle.y;
float anglyXDiff = oldViewAngle.x - newViewAngle.x;
if (Mathf.Abs(anplyYDiff) > 180)
newViewAngle = new Vector3(newViewAngle.x, oldViewAngle.y + (anplyYDiff > 0 ? 360 - anplyYDiff : -(360 + anplyYDiff)), newViewAngle.z);
if (Mathf.Abs(anglyXDiff) > 180)
newViewAngle = new Vector3(oldViewAngle.x + (anglyXDiff > 0 ? 360 - anglyXDiff : -(360 + anglyXDiff)), newViewAngle.y, newViewAngle.z);
iTween.ValueTo(cam.gameObject, iTween.Hash(
"from", oldViewAngle,
"to", newViewAngle,
"time", time,
"onupdatetarget", cam.gameObject,
"onupdate", "OnViewAngle",
"easetype", rotEaseType));
//shift view distance
iTween.ValueTo(cam.gameObject, iTween.Hash(
"from", oldDistance,
"to", newDistance,
"time", time,
"onupdatetarget", cam.gameObject,
"onupdate", "OnDistance",
"easetype", rotEaseType));
//shift view offset
iTween.ValueTo(cam.gameObject, iTween.Hash(
"from", oldOffset,
"to", newOffset,
"time", time,
"onupdatetarget", cam.gameObject,
"onupdate", "OnPanOffset",
"easetype", rotEaseType));
}
private Vector3 CamEulerAngles(Vector3 forward)
{
Quaternion q = Quaternion.LookRotation(forward);
//Vector3 v = (fromPos - toPos).normalized;
//Quaternion q = camTrams.rotation;
//q.SetLookRotation(camTrams.forward, toPos);
//Quaternion.FromToRotation(Vector3.up, transform.forward);
return q.eulerAngles;
}
//public void TravelToPoint(Transform tran_Point, Transform center = null, Transform tran_Cam = null)
//{
// if (!center)
// center = xGo.target.transform;
// if (!tran_Cam)
// tran_Cam = transform;
// Vector3 v3_Pos = tran_Point.position;
// Vector3 v3_Rot = tran_Point.eulerAngles;
// Vector3 v3_DesiredPos = center.position -
// Vector3.Project(center.position - v3_Pos, tran_Point.forward);
// float fl_Distance = Vector3.Distance(v3_Pos, center.position);
// Vector3 v3_Offset = v3_Pos - v3_DesiredPos;
// StopAllCoroutines();
// StartCoroutine(PauseMove(fl_Time));
// xGo.TeleportCam(center, v3_DesiredPos, v3_Rot, fl_Distance, v3_Offset);
// Travel(tran_Cam, v3_Pos, v3_Rot);
//}
private void Travel(Transform tran_Cam, Vector3 v3_Pos, Vector3 v3_Rot, float time)
{
XgControlTools.Move(tran_Cam, v3_Pos, time);
XgControlTools.Rotate(tran_Cam, v3_Rot, time);
}
}
[System.Serializable]
public class TravelPosition
{
public Transform tran_Center;
public Transform tran_Pos;
public Vector3 v3_Offset;
}
</pre>如果有需要点击的 在CameraManager中写入</div><div><pre code_snippet_id="1567432" snippet_file_name="blog_20160127_3_7931527" name="code" class="csharp">using UnityEngine;
using System.Collections;
public class XgCameraManager : MonoBehaviour
{
public string str_Control = "Control";
public string str_OverAllControlName = "S1";
public string str_OptionalControlName = "S2";
public string str_CoreComControlName = "S3";
public string str_SellingPointControlName = "S4";
private MainControl main_Control;
private S1_Control s1_Control;
private S2_Control s2_Control;
private S4_Control s4_Control;
public void Init_CameraManager()
{
main_Control = GameObject.Find(str_Control).GetComponent<MainControl>();
s1_Control = GameObject.Find(str_OverAllControlName).GetComponent<S1_Control>();
s2_Control = GameObject.Find(str_OptionalControlName).GetComponent<S2_Control>();
s4_Control = GameObject.Find(str_SellingPointControlName).GetComponent<S4_Control>();
}
public void OnManagerTap(TapGesture gesture)
{
if (gesture.Selection.layer == 10 && UICamera.isOverUI == false)
{
s1_Control.Btn_DoorClick();
}
if (gesture.Selection.layer == 11 && UICamera.isOverUI == false)
{
s2_Control.Sliver_Active(gesture.Selection.gameObject);
}
if (gesture.Selection.layer == 12 && UICamera.isOverUI == false)
{
s4_Control.Chiller_State();
}
}
}