- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
  
- 纳金币
- 20645
- 精华
- 62
|
屏幕滑动旋转代码- 用相机来做,using UnityEngine;
-
- using System.Collections;
-
- public class CRLuo_Camera_FingerTipRotation : MonoBehaviour
-
- {
-
- public string _ = “-=<CRLuo鼠标或触摸摄像机旋转控制程序>=-”;
-
- public string __ = “一级左右转对象”;
-
- public GameObject R_Y_Obj;
-
- public GameObject R_X_Obj;
-
- public string ____ = “三级摄像机对象”;
-
- //public Camera MainCamera;
-
- public GameObject Cube;
-
- public string _____ = “旋转鼠标速度”;
-
- public float MouseMoveSpeed = 10f;
-
- public string ______ = “推拉鼠标速度”;
-
- public float MouseScaleSpeed = 10f;
-
- public string _______ = “默认旋转角度(Z无效)”;
-
- public Vector3 Default_R;
-
- public string ________ = “默认摄像机距离”;
-
- public float Default_Distance = 5;
-
- //public string _______ = “默认焦距”;
-
- //public float Default_FOV = 60;
-
- Vector2 MousePotOld;
-
- float Distance_Old;
-
- float Distance_New;
-
- public string _________ = “界面说明显示开关”;
-
- public bool ShowRadme;
-
- void Start()
-
- {
-
- ResetPos();
-
- }
-
- void ResetPos()
-
- {
-
- R_Y_Obj.transform.localRotation = Quaternion.Euler(new Vector3(0, Default_R.y, 0));
-
- R_X_Obj.transform.localRotation = Quaternion.Euler(new Vector3(Default_R.x, 0, 0));
-
- // MainCamera.transform.localPosition = new Vector3(0, 0, -Default_Distance);
-
- Cube.transform.localPosition = new Vector3(0, 0, -Default_Distance+5);
-
- //MainCamera.fieldOfView = Default_FOV;
-
- }
-
- void Update()
-
- {
-
- if (Input.GetMouseButtonDown(0))
-
- {
-
- MousePotOld = Input.mousePosition;
-
- }
-
- else if (Input.GetMouseButton(0))
-
- {
-
- if (MousePotOld != null)
-
- {
-
- R_Y_Obj.transform.Rotate(new Vector3(0, (Input.mousePosition.x - MousePotOld.x) * Time.deltaTime * MouseMoveSpeed, 0));
-
- R_X_Obj.transform.Rotate(new Vector3(-(Input.mousePosition.y - MousePotOld.y) * Time.deltaTime * MouseMoveSpeed, 0, 0));
-
- MousePotOld = Input.mousePosition;
-
- }
-
- }
-
- if (Input.GetAxis(“Mouse ScrollWheel”) != 0)
-
- {
-
- Debug.Log(Input.GetAxis(“Mouse ScrollWheel”));
-
- //MainCamera.transform.localPosition = new Vector3(0, 0, MainCamera.transform.localPosition.z + Input.GetAxis(“Mouse ScrollWheel”)* MouseScaleSpeed);
-
- Cube.transform.localPosition = new Vector3(0, 0, Cube.transform.localPosition.z + Input.GetAxis(“Mouse ScrollWheel”)* MouseScaleSpeed);
-
- }
-
- if (Input.touchCount > 1)
-
- {
-
- Touch touch1 = Input.touches[0];
-
- Touch touch2 = Input.touches[1];
-
- if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
-
- {
-
- Distance_New = Vector2.Distance(touch1.position, touch2.position);
-
- if (Distance_Old != null)
-
- {
-
- //MainCamera.transform.localPosition = new Vector3(0, 0, MainCamera.transform.localPosition.z - (Distance_New - Distance_Old) * MouseScaleSpeed);
-
- Cube.transform.localPosition = new Vector3(0, 0, Cube.transform.localPosition.z + Input.GetAxis(“Mouse ScrollWheel”)* MouseScaleSpeed);
-
- }
-
- Distance_Old = Distance_New;
-
- }
-
- }
-
- }
-
- void OnGUI()
-
- {
-
- //界面按钮提示
-
- if (ShowRadme)
-
- {
-
- GUI.Label(new Rect(Screen.width * 0.5f - 100, Screen.height * 0.1f - 40f, 200, 100), “-=<<摄像机旋转程序>>=-”);
-
- GUI.Label(new Rect(Screen.width * 0.5f - 100, Screen.height * 0.1f - 20f, 200, 100), “点击/滑动旋转”);
-
- GUI.Label(new Rect(Screen.width * 0.5f - 100, Screen.height * 0.1f, 200, 100), “滚轮/双指缩放”);
-
- if (GUI.Button(new Rect(Screen.width * 0.5f - 100, Screen.height * 0.9f - 50, 200, 100), “Reset”))
-
- {
-
- ResetPos();
-
- }
-
- }
-
- }
-
- }
复制代码 |
|