ps4 move controller

能上代码不BB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PS4;
using UnityEngine.PS4.VR;
using UnityEngine.UI;
using UnityEngine.VR;

public class PSHand : MonoBehaviour
{
    public enum HandType
    {
        left,
        right
    }
    public HandType type;
    Vector3 point;
    Quaternion rotion;
    public PlayStationVRTrackingType trackingType = PlayStationVRTrackingType.Absolute;
    public PlayStationVRTrackerUsage trackerUsageType = PlayStationVRTrackerUsage.OptimizedForHmdUser;
    int devId = -1;
    void Start()
    {
        VRSettings.enabled = true;
        VRSettings.renderScale = 1.5f;
        VRSettings.showDeviceView = true;
        StartCoroutine(register());
    }

    public bool GetTouchDown()
    {
        return touchDown;
    }
    public bool GetTouch()
    {
        return pressing;
    }

    public bool GetTouchUp()
    {
        return touchUp;
    }

    bool pressing = false;

    bool touchDown = false;
    bool touchUp = false;
    IEnumerator register()
    {
        while (!PS4Input.MoveIsConnected(0, 0) || !PS4Input.MoveIsConnected(0, 1))
        {
            yield return 0;
        }
        int[] primaryHandles = new int[1];
        int[] secondaryHandles = new int[1];
        PS4Input.MoveGetUsersMoveHandles(1, primaryHandles, secondaryHandles);
        if (type == HandType.left)
        {
            devId = secondaryHandles[0];
        }
        else
        {
            devId = primaryHandles[0];

        }
        PlayStationVRResult result;
        PlayStationVRTrackingColor trackedColor;

        // Get the tracking for the primary Move device, and wait for it to start
        result = Tracker.RegisterTrackedDevice(PlayStationVRTrackedDevice.DeviceMove, devId, trackingType, trackerUsageType);

        if (result == PlayStationVRResult.Ok)
        {
            PlayStationVRTrackingStatus trackingStatusPrimary = new PlayStationVRTrackingStatus();

            while (trackingStatusPrimary == PlayStationVRTrackingStatus.NotStarted)
            {
                Tracker.GetTrackedDeviceStatus(devId, out trackingStatusPrimary);
                yield return null;
            }

            Tracker.GetTrackedDeviceLedColor(devId, out trackedColor);
        }

    }
    void Update()
    {
        PlayStationVRResult result = PlayStationVRResult.Error;
        result = Tracker.GetTrackedDevicePosition(devId, out point);
        Tracker.GetTrackedDeviceOrientation(devId, out rotion);
        if (result == PlayStationVRResult.Ok)
        {
            transform.localPosition = point;
            transform.localRotation = rotion;
        }
        switch (type)
        {
            case HandType.left:
                if (PS4Input.MoveGetAnalogButton(0, 1) > 0)
                {
                    PressProcess();
                }
                else
                {
                    NotPressProcess();
                }
                break;
            case HandType.right:
                if (PS4Input.MoveGetAnalogButton(0, 0) > 0)
                {
                    PressProcess();
                }
                else
                {
                    NotPressProcess();
                }
                break;
        }


    }

    void PressProcess()
    {
        if (!pressing)
        {
            touchDown = true;
            pressing = true;
        }
        else if (touchDown)
        {
            touchDown = false;
        }
    }
    void NotPressProcess()
    {
        if (pressing)
        {
            touchUp = true;
            pressing = false;
        }
        else if (touchUp)
        {
            touchUp = false;
        }
    }
}

最近的文章

ps4 pad controller

能上代码不BBusing UnityEngine;using UnityEngine.PS4;using System;using System.Collections;public class GamePad : MonoBehaviour{ // Custom class for holding all the gamepad sprites [System.Serializable] public class PS4GamePad { public SpriteRenderer t...…

阅读全文
更早的文章

unity dll加密

1.1 加密方案Unity 3D项目游戏逻辑采用C#脚本,我们知道C#编译生成的DLL或EXE是IL程序集。IL程序集中有一个MetaData,记录了程序集中的一切信息,所以容易被反编译。传统的防破解方式是是对IL程序集进行混淆或者加壳。但是这种混淆基本上只是做一些名称混淆或流程混淆或者加一些打花指令。这种混淆或加壳的结果基本上还是保留了IL程序集的原貌,还是很容易被破解的。因为有这些缺点,我们实现了一套自己的加密方案:直接对IL程序集进行加密。改变程序集形态,这样子,它就不再是IL程...…

阅读全文