본문 바로가기
NOTE/SaveSource

[SaveSource] ViveTouchPad

by DevAthena 2017. 1. 4.
이제 사용하지 않는 소스

using UnityEngine;
using UnityEngine.UI;
 
// TODO : 각 버튼 클릭시 맞는 특수무기 장착&활성화
 
public enum SPweapon
{
    Grenade,
    Recover,
    Mine,
    Drone,
    None
}
 
class ViveTouchPad : MonoBehaviour
{
    SteamVR_TrackedController trackedController;
    SteamVR_Controller.Device device;
    SteamVR_TrackedObject trackedObj;
    Perform m_eqip;
 
    // in Hierarchy
    public GameObject m_touchpadUI;
    public GameObject m_weaponEqip;
    public GameObject m_controllerModel;
    public string grenadePrefab;
    public string recoverPrefab;
 
    private void Start()
    {
        trackedController = GetComponent<SteamVR_TrackedController>();
        trackedObj = GetComponent<SteamVR_TrackedObject>();
    }
 
    private void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
 
        if (trackedController.padTouched && transform.GetComponentInChildren<SpecialWeapon>() == null)
        {
            m_touchpadUI.SetActive(true);
            m_weaponEqip.SetActive(false);
            m_controllerModel.SetActive(true);
 
            Vector2 touchpad = (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
 
            if (device.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad) && transform.GetComponentInChildren<SpecialWeapon>() == null)
            {                
                if (touchpad.y > 0.7f)  // Up
                {
                    
                }
                else if (touchpad.y < -0.7f)    // Down
                {
                    
                }
 
                if (touchpad.x > 0.7f)  // Right
                {
                    EqipSpecialWeapon(SPweapon.Recover);
                }
                else if (touchpad.x < -0.7f)    // Left
                {
                    EqipSpecialWeapon(SPweapon.Grenade);
                }
            }
        }
        else
        {
            m_touchpadUI.SetActive(false);
 
            if (transform.GetComponentInChildren<SpecialWeapon>() == null)
            {
                m_weaponEqip.SetActive(true);
            }
 
            if(m_weaponEqip.GetComponentInChildren<GrableTarget>() != null || transform.GetComponentInChildren<SpecialWeapon>() != null)
            {
                m_controllerModel.SetActive(false);
            }
        }
    }
 
    public void ClearSpecialWeapon()
    {
        if (m_weaponEqip.GetComponentInChildren<GrableTarget>() != null)
        {
            m_weaponEqip.SetActive(true);
        }
        else
        {
            m_controllerModel.SetActive(true);
        }
    }
 
    private void EqipSpecialWeapon(SPweapon spweapon)
    {
        m_controllerModel.SetActive(false);
 
        switch(spweapon)
        {
            case SPweapon.Recover:
                m_eqip = AssetManager.Perform.Retrieve("HandRecovery"as Perform;
                m_eqip.transform.parent = transform.FindChild("SpecialEqip");
                m_eqip.transform.localPosition = new Vector3(000);
                break;
            case SPweapon.Grenade:
                m_eqip = AssetManager.Perform.Retrieve("HandGrenade"as Perform;
                m_eqip.transform.parent = transform.FindChild("SpecialEqip");
                m_eqip.transform.localPosition = new Vector3(000);
                m_eqip.transform.localEulerAngles = new Vector3(25f, 80f, 80f);
                break;
            default:
                break;
        }
    }
}
cs


'NOTE > SaveSource' 카테고리의 다른 글

[SaveSource] SpeicalWeapon  (0) 2017.01.12
[SaveSource] WeaponDrob  (0) 2017.01.04
[SaveSource] Unity Editor Study  (0) 2016.11.17
[SaveSource] 만보기소스(펌)  (0) 2016.11.09
[Source Save] GyhroCameraMove.cs  (0) 2016.11.09