主頁 >  其他 > unity開發 相機旋轉、縮放、拖動、抖動等控制

unity開發 相機旋轉、縮放、拖動、抖動等控制

2020-12-14 12:10:17 其他

下面展示一些 相機旋轉、縮放、拖動、抖動等控制

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HedgehogTeam.EasyTouch;
using MR_LBS.Client.Unity3D;
using UnityEngine.EventSystems;

/***
 * 相機移動旋轉
 * **/
public class CameraController : MonoBehaviour
{
    [HideInInspector]
    public static CameraController instance;
    [HideInInspector]
    public bool dragSign;
    //拖動
    public float size = 45;
    public float maxSize = 55;
    public float minSize = 25;
    private float desiredDistance;
    private Vector3 desiredPosition;//單指拖動后,相機的未來坐標

    public float xSpeed = 20.0f;
    public float ySpeed = 20.0f;
    public float pinchSpeed = 10f;

    private float xDeg = 0.0f;
    private float yDeg = 0.0f;

    //抖屏
    public float shakeLevel = 4f;// 震動幅度
    public float setShakeTime = 0.7f;   // 震動時間
    public float shakeFps = 45f;    // 震動的FPS

    /// <summary>
    /// 震動標志
    /// </summary>
    private bool isshakeCamera = true;
    /// <summary>
    /// 是否允許抖屏(防止投兵出問題)
    /// </summary>
    private bool enableIsshake = true;
    private float fps;
    private float shakeTime = 0.0f;
    private float frameTime = 0.0f;
    private float shakeDelta = 0.005f;
    private Camera selfCamera;
    MainView mainView;
   
    private void Awake()
    {
        instance = this;
        EasyTouch.AddCamera(Camera.main);//給easytouch的相機賦值
    }
    void Start()
    {
        dragSign = true;
        Init();
        mainView = MainView.instance;
    }
    private void Update()
    {
        // Debug.Log(Vector3.Magnitude(transform.position - target.position));
    }
    /// <summary>
    /// 在OnEnable中注冊EasyTouch事件
    /// </summary>
    void OnEnable()
    {
        Init();
        //添加委托
        EasyTouch.On_Drag += On_Drag;
        //EasyTouch.On_DragStart += On_DragStart;
        //EasyTouch.On_DragEnd += On_DragEnd;

        //EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;
        EasyTouch.On_PinchIn += On_PinchIn;
        EasyTouch.On_PinchOut += On_PinchOut;
        EasyTouch.On_OverUIElement += On_OverUIElement;
        EasyTouch.On_UIElementTouchUp += On_UIElementTouchUp;
        //EasyTouch.On_PinchEnd += On_PinchEnd;
        //螢屏抖動
        selfCamera = gameObject.GetComponent<Camera>();
        shakeTime = setShakeTime;
        fps = shakeFps;
        frameTime = 0.03f;
        shakeDelta = 0.005f;
    }
    /// <summary>
    /// 在OnDisable中取消注冊事件
    /// </summary>
    void OnDisable()
    {
        UnsubscribeEvent_Drag();
        UnsubscribeEvent_Pinch();
    }
    /// <summary>
    /// 在OnDestroy中洗掉注冊事件
    /// </summary>
    void OnDestroy()
    {
        UnsubscribeEvent_Drag();
        UnsubscribeEvent_Pinch();
    }

    void UnsubscribeEvent_Pinch()
    {
        //洗掉委托
        //EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;
        EasyTouch.On_PinchIn -= On_PinchIn;
        EasyTouch.On_PinchOut -= On_PinchOut;
        EasyTouch.On_Drag -= On_Drag;

        EasyTouch.On_OverUIElement -= On_OverUIElement;
        EasyTouch.On_UIElementTouchUp -= On_UIElementTouchUp;
        //EasyTouch.On_PinchEnd -= On_PinchEnd;
    }
    void UnsubscribeEvent_Drag()
    {
        EasyTouch.On_Drag -= On_Drag;
        //EasyTouch.On_DragStart -= On_DragStart;
        //EasyTouch.On_DragEnd -= On_DragEnd;
    }
    public void Init()
    {
        transform.position = new Vector3(-36, 70, 0);
        this.GetComponent<Camera>().orthographicSize = size;
    }
    /// <summary>
    /// 相機歸位
    /// </summary>
    public void CameraHoming()
    {
        Init();
    }
    /// <summary>
    /// 開啟螢屏抖動
    /// </summary>
    public void OpenShakeCamera()
    {
#if Cheng
        if (isshakeCamera && enableIsshake)
            StartCoroutine(ShakeCamera());
#endif
    }

    IEnumerator ShakeCamera()
    {
        isshakeCamera = false;
        shakeTime = setShakeTime;
        while (shakeTime > 0)
        {
            yield return new WaitForSecondsRealtime(Time.deltaTime);
            shakeTime -= Time.deltaTime;
            frameTime += Time.deltaTime;
            if (frameTime > 1.0 / fps)
            {
                frameTime = 0;
                selfCamera.rect = new Rect(shakeDelta * (-1.0f + shakeLevel * Random.value), shakeDelta * (-1.0f + shakeLevel * Random.value), 1.0f, 1.0f);
            }
        }
        selfCamera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        isshakeCamera = true;
    }
    void On_DragStart(Gesture gesture)
    {
    }
    void On_Drag(Gesture gesture)
    {
        //Debug.Log("2222");
        //單指拖動移動
        if (gesture.touchCount > 1 || !dragSign)
        {
            //Debug.Log("禁止多指拖動");
            return;
        }
        xDeg = gesture.deltaPosition.x * xSpeed * 0.001f;
        yDeg = gesture.deltaPosition.y * ySpeed * 0.001f;
        desiredPosition = new Vector3(transform.position.x - yDeg, 70, transform.position.z + xDeg * 0.6f);
        desiredPosition.z = Mathf.Clamp(desiredPosition.z, -6, 6);
        desiredPosition.x = Mathf.Clamp(desiredPosition.x, -45, -32);

        transform.position = desiredPosition;
    }
    void On_DragEnd(Gesture gesture)
    {
    }

    private void On_TouchStart2Fingers(Gesture gesture)
    {

        //Debug.Log("pinch111");
        //Verification that the action on the object
        //if (gesture.pickedObject == gameObject)
        //{
        //    // disable twist gesture recognize for a real pinch end
        //    EasyTouch.SetEnableTwist(false);
        //    EasyTouch.SetEnablePinch(true);
        //}
    }
    // At the pinch in
    private void On_PinchIn(Gesture gesture)
    {
        desiredDistance = this.GetComponent<Camera>().orthographicSize;

        desiredDistance += gesture.deltaPinch * Time.deltaTime * pinchSpeed * 0.1f;//Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//
        //Debug.Log(desiredDistance);
        desiredDistance = Mathf.Clamp(desiredDistance, minSize, maxSize);
        this.GetComponent<Camera>().orthographicSize = desiredDistance;
    }
    // At the pinch out
    private void On_PinchOut(Gesture gesture)
    {
        desiredDistance = this.GetComponent<Camera>().orthographicSize;

        desiredDistance -= gesture.deltaPinch * Time.deltaTime * pinchSpeed * 0.1f;//Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//
        //Debug.Log(desiredDistance);
        desiredDistance = Mathf.Clamp(desiredDistance, minSize, maxSize);
        this.GetComponent<Camera>().orthographicSize = desiredDistance;
    }
    // At the pinch end
    private void On_PinchEnd(Gesture gesture)
    {

    }

    [HideInInspector]
    public PetButton petButtonTemp;
    [HideInInspector]
    public BigSkillButton skillButtonTemp;
    public Transform wormholePet;
    Vector3 parentMove;
    Color green  = new Color(145/225f, 1f, 220/225f, 230 / 255f);
    Color red  = new Color(255 / 255f, 83 / 255f, 0f, 230 / 255f);
    SpriteRenderer effectScopeTemp;
    SpriteRenderer shotRangeTemp;
    int changeMesh = 0;

    private Vector3 changePos = new Vector3(30,0,0);
    private Vector3 targetPos = new Vector3(0, 0, 0);
    private Vector3 tempPos = new Vector3(0, 0, 0);
    /// <summary>
    /// 是否允許卡牌解鎖(拖動大招時禁止解鎖)
    /// </summary>
    [HideInInspector]
    public bool openLockSign = true;
    /// <summary>
    /// 獲取點擊的UI(持續每幀獲取)
    /// </summary>
    /// <param name="gesture"></param>
    void On_OverUIElement(Gesture gesture)
    {
        //Debug.Log(gesture.position.y);
        //GuideController.instance.CloseGuide();
        if (gesture.touchCount > 1)
        {
            //Debug.Log("存在多指點擊");
            mainView.closeSkillS.SetActive(false);
            return;
        }
        if (gesture.pickedUIElement != null )
        {
            enableIsshake = false;
            if (gesture.pickedUIElement.name == "PetButton")
            {
                petButtonTemp = gesture.pickedUIElement.GetComponent<PetButton>();
                if (petButtonTemp.petPrefab != null)
                {
                    //投兵拖動ing
                    if (!petButtonTemp.canPickUp)
                    {
                        //Debug.Log(111);
                        //跟隨手指移動
                        tempPos = Camera.main.ScreenToWorldPoint(gesture.position) + changePos;
                        if (tempPos.x > -1)
                            targetPos.x = -1;
                        else if (tempPos.x < -31)
                            targetPos.x = -31;
                        else
                            targetPos.x = tempPos.x;
                        if (tempPos.z > 19)
                            targetPos.z = 19;
                        else if (tempPos.z < -19)
                            targetPos.z = -19;
                        else
                            targetPos.z = tempPos.z;
                        targetPos.y = 0;//petButtonTemp.petPrefab.transform.position.y;
                        petButtonTemp.petPrefab.transform.position = targetPos;

                        if (gesture.position.y > Camera.main.WorldToScreenPoint(wormholePet.position).y)
                        {
                            petButtonTemp.dragClose.SetActive(true);//打開拖動取消圖示
                            petButtonTemp.petPrefab.SetActive(true);
                            if (GuideController.instance.StepSign < 5)
                            {
                                GuideController.instance.StepControl(5, 0);//投兵區域引導
                            }
                        }
                    }
                    //投兵開始拖動
                    else if (petButtonTemp.canPickUp)
                    {
                        foreach (PetButton tempButton in mainView.buttonToggle)
                        {
                            if (tempButton.gameObject != gesture.pickedUIElement)
                            {
                                tempButton.canPickUp = true;
                                tempButton.transform.localScale = tempButton.minScale;
                            }
                            else
                            {
                                petButtonTemp.canPickUp = false;
                                //dragSign = false;//禁止拖動場景
                                petButtonTemp.transform.localScale = petButtonTemp.maxScale;
                            }
                            petButtonTemp.TapSign = false;
                        }

                        if (petButtonTemp.Prefab.tag == "AirForce")
                        {
                            petButtonTemp.areaTip_All.SetActive(true);//打開投放區域提示
                            petButtonTemp.areaTip_4.SetActive(false);
                        }
                        else
                        {
                            petButtonTemp.areaTip_All.SetActive(true);//打開投放區域提示
                            petButtonTemp.areaTip_4.SetActive(true);
                        }
                        petButtonTemp.getGeneratePos = false;
                    }
                }
                else
                {

                    petButtonTemp = null;
                }
                skillButtonTemp = null;
            }
            else if (gesture.pickedUIElement.name == "SkillButton")
            {
                skillButtonTemp = gesture.pickedUIElement.GetComponent<BigSkillButton>();

                //大招拖動
                if (skillButtonTemp.petSubControl != null)
                {
                    GuideController.instance.CloseGuide();
                    gesture.pickedUIElement.transform.localScale = skillButtonTemp.maxScale;

                    //控制大招區域跟隨寵物一起動,同時高度不變
                    parentMove = skillButtonTemp.petSubControl.gameObject.transform.position;
                    parentMove.y = skillButtonTemp.petSubControl.bigSkillArea.transform.position.y;

                    if (IsPointerOverUIObject("CloseSkillS"))
                    {
                        //變成紅色
                        skillButtonTemp.petSubControl.shotRange.GetComponent<SpriteRenderer>().color = red;
                        if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
                        {
                            skillButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
                            skillButtonTemp.petSubControl.effectScope.GetComponent<SpriteRenderer>().color = red;
                        }
                        else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
                        {
                            //petButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
                            skillButtonTemp.petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<SpriteRenderer>().color = red;
                        }
                        //Debug.Log("變紅");
                    }
                    else
                    {
                        //變成綠色
                        skillButtonTemp.petSubControl.shotRange.GetComponent<SpriteRenderer>().color = green;
                        mainView.closeSkillS.SetActive(true);
                        if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
                        {
                            skillButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = true;
                            skillButtonTemp.petSubControl.effectScope.GetComponent<SpriteRenderer>().color = green;
                        }
                        else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
                        {
                            //petButtonTemp.petSubControl.effectScope.GetComponent<CapsuleCollider>().enabled = false;
                            skillButtonTemp.petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<SpriteRenderer>().color = green;
                        }
                    }

                    skillButtonTemp.petSubControl.bigSkillArea.SetActive(true);
                    skillButtonTemp.petSubControl.bigSkillArea.transform.position = parentMove;
                    if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
                    {
                        skillButtonTemp.petSubControl.rotateDirection.SetActive(true);
                        skillButtonTemp.petSubControl.rotateDirection.transform.position = parentMove;
                    }
                }
                else
                {

                    skillButtonTemp = null;
                    mainView.closeSkillS.SetActive(false);
                }
                petButtonTemp = null;
            }
            //Debug.Log(gesture.pickedUIElement.name);
          
        }
        //label.text = "You touch UI Element : " + gesture.pickedUIElement.name + " (from On_OverUIElement event)";
    }

    void On_UIElementTouchUp(Gesture gesture)
    {
        if (!BattleController.instance.startBattleSign)
            return;

        //投兵區域判定
        if (petButtonTemp != null && petButtonTemp.petPrefab != null && !petButtonTemp.canPickUp)
        {
            //Debug.Log(222);

            //已被打開,說明觸發了拖動
            if (petButtonTemp.petPrefab.activeInHierarchy)
            {
                petButtonTemp.petPrefab.SetActive(false);
                //如果放在按鈕上,取消投放
                if (!IsPointerOverUIObject("PetButton"))
                {
                    petButtonTemp.DragGeneratePos(petButtonTemp.petPrefab.transform.position);
                    //投放后按鈕設為空
                    //petButtonTemp = null;
                }
                else
                {
                    SoundManager.Instance.PlaySound(SoundSkill.errorTips);
                }
                foreach (PetButton tempButton in mainView.buttonToggle)
                {
                    tempButton.canPickUp = true;
                    tempButton.dragClose.SetActive(false);
                    tempButton.transform.localScale = tempButton.minScale;
                    tempButton.areaTip_All.SetActive(false);//關閉投放區域提示
                    tempButton.areaTip_4.SetActive(false);

                }
            }
            //沒打開,說明未出發拖動,是點擊事件
            else
            {
                //Debug.Log("等待點擊投兵");
                foreach (PetButton tempButton in mainView.buttonToggle)
                {
                    if (tempButton.gameObject != gesture.pickedUIElement)
                    {
                        tempButton.canPickUp = true;
                        tempButton.transform.localScale = petButtonTemp.minScale;
                    }
                    tempButton.dragClose.SetActive(false);
                }
                petButtonTemp.StartGeneratePos();
            }
        }
        else if (skillButtonTemp != null && skillButtonTemp.petPrefab != null)
        {
            if (!IsPointerOverUIObject("CloseSkillS"))
            {
                if (GuideController.instance.StepSign == 5)
                    GuideController.instance.StepControl(6, 10f);
                switch (skillButtonTemp.petSubControl.bigSkillType)
                {
                    case BigSkillType.click:
                        skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
                        break;
                    case BigSkillType.dragPosition:
                        DragPositionCon(skillButtonTemp.petSubControl);
                        skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
                        break;
                    case BigSkillType.dragRotation:
                        DragRotateCon(skillButtonTemp.petSubControl);
                        skillButtonTemp.petSubControl.bigSkillPostion = skillButtonTemp.petSubControl.effectScope.transform.position;
                        //碰撞檢測
                        skillButtonTemp.petSubControl.bTree.SetVariableValue("OnBigSkill", true);
                        break;
                }
            }
            else
                Debug.LogError("取消釋放");
            skillButtonTemp.petSubControl.bigSkillArea.SetActive(false);
            if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragPosition)
            {
                skillButtonTemp.petSubControl.effectScope.transform.localPosition = new Vector3(0, 0, 0);
                //恢復變白的寵物
                skillButtonTemp.petSubControl.effectScope.GetComponent<DragSkillController>().CloseFX();
            }
            else if (skillButtonTemp.petSubControl.bigSkillType == BigSkillType.dragRotation)
            {
                skillButtonTemp.petSubControl.effectScope.transform.localPosition = new Vector3(1, 0, 0);
                skillButtonTemp.petSubControl.rotateDirection.SetActive(false);
            }

        }
        //抬起后按鈕設為空
        skillButtonTemp = null;
        petButtonTemp = null;
        mainView.closeSkillS.SetActive(false);
        enableIsshake = true;
       
    }
    private Vector3 startPoint = new Vector3(0, 15, 0);//圓柱形觸發器上部位置
    private Vector3 endPoint = new Vector3(0, -5, 0);//圓柱形觸發器下部位置
    private Collider[] hitColliders;

    /// <summary>
    ///  范圍性技能,目標獲取方法
    /// </summary>
    /// <param name="petSubControl"></param>
    public void DragPositionCon(PetSubControl petSubControl) {
        startPoint.x = petSubControl.effectScope.transform.position.x;
        startPoint.z = petSubControl.effectScope.transform.position.z;
        endPoint.x = startPoint.x;
        endPoint.z = startPoint.z;
        hitColliders = Physics.OverlapCapsule(startPoint, endPoint, 0.1f, 1<<12, QueryTriggerInteraction.Collide);
        if (hitColliders.Length > 0)
        {
            petSubControl.bigSkillTarget = hitColliders[0].gameObject;
            //Debug.LogError(petSubControl.bigSkillTarget.name);
        }
        else {
            petSubControl.bigSkillPostion = petSubControl.effectScope.transform.position;
            petSubControl.bigSkillPostion.y = 2;
            //Debug.LogError(petSubControl.bigSkillPostion);
        }
    }

    /// <summary>
    /// 指向性技能,目標獲取方法
    /// </summary>
    /// <param name="petSubControl"></param>
    public void DragRotateCon(PetSubControl petSubControl) {
        if(petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<RotateSkillController>().target != null)
            petSubControl.bigSkillTarget =  petSubControl.rotateDirection.transform.Find("GameObject/Direction").GetComponent<RotateSkillController>().target;
        //Debug.Log(petSubControl.bigSkillTarget.name);
    }
    MonsterControlBase enemyControlBase;
   
    /// <summary>
    /// 判斷拖動大招后,抬起的位置是否在取消大招的按鈕位置
    /// </summary>
    /// <param name="targetName"></param>
    /// <returns></returns>
    public bool IsPointerOverUIObject(string targetName)
    {
        PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE)
        eventDataCurrentPosition.position = Input.GetTouch(0).position;
#else
        eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
#endif

        List<RaycastResult> results = new List<RaycastResult>();
        if (EventSystem.current)
        {
            EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
        }

        foreach(var temps in results)
        {
            if (temps.gameObject.name == targetName)//LayerMask.NameToLayer("UI"))
            {
                //Debug.LogError(temps.gameObject.name);
                return true;
            }
        }
        return false;
    }
}

#region   相機旋轉方法
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using HedgehogTeam.EasyTouch;

//public class CameraCon : MonoBehaviour
//{
//    public Transform target;
//    public Vector3 targetOffset;
//    public float distance = 32;//5.0f;
//    public float maxDistance = 33;//20;
//    public float minDistance = 5;//.6f;
//    public float xSpeed = 20.0f;
//    public float ySpeed = 20.0f;
//    public int yMinLimit = 30;//-80;
//    public int yMaxLimit = 90;
//    public int zoomRate = 40;
//    //public float panSpeed = 0.3f;
//    public float zoomDampening = 5.0f;
//    //public float autoRotate = 1;
//    private float xDeg = 0.0f;
//    private float yDeg = 0.0f;
//    private float currentDistance;
//    private float desiredDistance;
//    private Quaternion currentRotation;
//    private Quaternion desiredRotation;
//    private Quaternion rotation;
//    private Vector3 position;
//    private float idleTimer = 0.0f;
//    private float idleSmooth = 0.0f;
//    void Start() { Init(); }
//    /// <summary>
//    /// 在OnEnable中注冊EasyTouch事件
//    /// </summary>
//    void OnEnable()
//    {
//        Init();
//        //添加委托
//        EasyTouch.On_Drag += On_Drag;
//        EasyTouch.On_DragStart += On_DragStart;
//        EasyTouch.On_DragEnd += On_DragEnd;

//        EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;
//        EasyTouch.On_PinchIn += On_PinchIn;
//        EasyTouch.On_PinchOut += On_PinchOut;
//        EasyTouch.On_PinchEnd += On_PinchEnd;
//    }
//    /// <summary>
//    /// 在OnDisable中取消注冊事件
//    /// </summary>
//    void OnDisable()
//    {
//        UnsubscribeEvent_Drag();
//        UnsubscribeEvent_Pinch();
//    }
//    /// <summary>
//    /// 在OnDestroy中洗掉注冊事件
//    /// </summary>
//    void OnDestroy()
//    {
//        UnsubscribeEvent_Drag();
//        UnsubscribeEvent_Pinch();
//    }

//    void UnsubscribeEvent_Pinch()
//    {
//        //洗掉委托
//        EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;
//        EasyTouch.On_PinchIn -= On_PinchIn;
//        EasyTouch.On_PinchOut -= On_PinchOut;
//        EasyTouch.On_PinchEnd -= On_PinchEnd;
//    }
//    void UnsubscribeEvent_Drag()
//    {
//        EasyTouch.On_Drag -= On_Drag;
//        EasyTouch.On_DragStart -= On_DragStart;
//        EasyTouch.On_DragEnd -= On_DragEnd;
//    }
//    public void Init()
//    {
//        //If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
//        if (!target)
//        {
//            GameObject go = new GameObject("Cam Target");
//            go.transform.position = transform.position + (transform.forward * distance);
//            target = go.transform;
//        }

//        //distance = Vector3.Distance(transform.position, target.position);
//        currentDistance = distance;
//        desiredDistance = distance;

//        //be sure to grab the current rotations as starting points.
//        position = transform.position;
//        rotation = transform.rotation;
//        currentRotation = transform.rotation;
//        desiredRotation = transform.rotation;

//        xDeg = Vector3.Angle(Vector3.right, transform.right);
//        yDeg = Vector3.Angle(Vector3.up, transform.up);
//        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
//    }


//    void On_DragStart(Gesture gesture)
//    {
//    }
//    void On_Drag(Gesture gesture)
//    {
//        if (gesture.touchCount > 1)
//        {
//            Debug.Log("禁止單指拖動");
//            return;
//        }

//        xDeg += gesture.deltaPosition.x * xSpeed * 0.02f;//Input.GetAxis("Mouse X") * xSpeed * 0.02f;
//        yDeg -= gesture.deltaPosition.y * xSpeed * 0.02f;//Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
//        //Clamp the vertical axis for the orbit
//        yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
//        // set camera rotation
//        desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
//        currentRotation = transform.rotation;
//        rotation = Quaternion.Lerp(currentRotation, desiredRotation, 0.02f * zoomDampening);
//        transform.rotation = rotation;
//        / Reset idle timers
//        idleTimer = 0;
//        idleSmooth = 0;


//        //Orbit Position
//        // affect the desired Zoom distance if we roll the scrollwheel
//        desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
//        //clamp the zoom min/max
//        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
//        // For smoothing of the zoom, lerp distance
//        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
//        //calculate position based on the new currentDistance
//        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
//        transform.position = position;
//    }
//    void On_DragEnd(Gesture gesture)
//    {
//    }

//    private void On_TouchStart2Fingers(Gesture gesture)
//    {

//        //Debug.Log("pinch111");
//        //Verification that the action on the object
//        //if (gesture.pickedObject == gameObject)
//        //{
//        //    // disable twist gesture recognize for a real pinch end
//        //    EasyTouch.SetEnableTwist(false);
//        //    EasyTouch.SetEnablePinch(true);
//        //}
//    }
//    // At the pinch in
//    private void On_PinchIn(Gesture gesture)
//    {
//        // Debug.Log("pinch222");
//        desiredDistance -= Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//gesture.deltaPosition.y * 0.002f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);

//        // affect the desired Zoom distance if we roll the scrollwheel
//        desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
//        //clamp the zoom min/max
//        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
//        // For smoothing of the zoom, lerp distance
//        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
//        // calculate position based on the new currentDistance
//        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
//        transform.position = position;

//    }

//    // At the pinch out
//    private void On_PinchOut(Gesture gesture)
//    {
//        desiredDistance -= Input.GetAxis("Mouse Y") * 0.02f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//gesture.deltaPosition.y * 0.002f * zoomRate * 0.125f * Mathf.Abs(desiredDistance);//

//        // affect the desired Zoom distance if we roll the scrollwheel
//        desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * 0.02f * zoomRate * Mathf.Abs(desiredDistance);
//        //clamp the zoom min/max
//        desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
//        // For smoothing of the zoom, lerp distance
//        currentDistance = Mathf.Lerp(currentDistance, desiredDistance, 0.02f * zoomDampening);
//        // calculate position based on the new currentDistance
//        position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
//        transform.position = position;
//        //Debug.Log("pinch333");
//    }
//    // At the pinch end
//    private void On_PinchEnd(Gesture gesture)
//    {
//        //ragCon.GetComponent<DragCon>().enabled = true;
//        Debug.Log("pinch444");
//    }
//    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);
//    }
//}
#endregion

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/234331.html

標籤:其他

上一篇:Codeforces 成長之路 #689 div2 題解

下一篇:HarmonyOS(鴻蒙)運動手表—從零實作投骰子小游戲

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more