본문 바로가기
NOTE/SaveSource

[SaveSource] SpeicalWeapon

by DevAthena 2017. 1. 12.
using System;
using UnityEditor;
using UnityEngine;
 
public enum SPweapon
{
    Grenade,
    Mine
}
 
[RequireComponent(typeof(Rigidbody))]
public class SpecialWeapon : CachedAsset
{
    [Tooltip("특수무기 타입 설정")]
    public SPweapon m_Sweapon;
    [Tooltip("던져지려면 Check")]
    public bool m_isThrow;
    [Tooltip("던져질 힘(숫자가작을수록 세게 날라감)")]
    [Range(1f, 5f)]
    public float m_throwPower = 0.3f;
 
    SteamVR_TrackedController trackedController;
    SteamVR_TrackedObject trackedObject;
    SteamVR_Controller.Device device;
    Rigidbody m_rigid;
    Vector3 m_curPos;
    Vector3 m_lastPos;
    GameObject ControllerModel;
    bool m_throwDown;
 
    protected override void OnRestore() { }
    protected override void OnUse() { }
    internal override void OnInitialize(params object[] parameters) { }
 
    private void Awake()
    {
        for (int i = 0; i < this.gameObject.GetComponentsInChildren<MeshRenderer>().Length; i++)
        {
            this.gameObject.transform.parent.GetComponentsInChildren<MeshRenderer>()[i].material.shader = Shader.Find("Custom/rimlight");
        }
    }
    private void Update()
    {
        if (transform.parent != null && transform.parent.parent != null)
        {
            trackedController = transform.parent.parent.GetComponent<SteamVR_TrackedController>();
            trackedObject = transform.parent.parent.GetComponent<SteamVR_TrackedObject>();
 
            if (trackedObject != null)
            {
                device = SteamVR_Controller.Input((int)trackedObject.index);
 
                if (device.GetHairTriggerDown())
                {
                    m_throwDown = true;
                }
 
                if (m_throwDown && device.GetHairTriggerUp() && m_isThrow)
                {
                    // WeaponDrob != this->(던지는 것:특수무기 작동o)
                    m_curPos = gameObject.transform.position;
                    m_rigid = GetComponent<Rigidbody>();
                    m_rigid.useGravity = true;
                    m_rigid.isKinematic = false;
                    m_rigid.AddForce((m_curPos - m_lastPos) * m_throwPower / Time.fixedDeltaTime, ForceMode.Impulse);
 
                    if (m_Sweapon == SPweapon.Grenade)
                    {
                        EffectSoundPlayer.Instance.Play("Com_Grenade_Throw"false);
                        transform.GetComponent<HandGrenade>().m_isBomb = true;
                    }
                    else if(m_Sweapon == SPweapon.Mine)
                    {
                        EffectSoundPlayer.Instance.Play("Mine_Throw"false);
                        transform.GetComponent<HandMine>().m_isThrow = true;
                    }
 
                    ControllerModel = transform.parent.parent.FindChild("Model").gameObject;
                    transform.parent = null;
                    ControllerModel.SetActive(true);
 
                    #region 튜토리얼 지혜 02.07
                    if (GameManager.Instance.GetSceneType == SceneType.Tutorial)
                        TutorialManager.Instance.StepClear(TutorialState.SpecialThrow);
                    #endregion
                }
            }
        }
    }
 
    private void LateUpdate()
    {
        m_lastPos = transform.position;
    }
}
 
 
cs


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

[SaveSource] CameraOrbit  (0) 2017.01.12
[SaveSource] WaveMoveTrigger  (0) 2017.01.12
[SaveSource] WeaponDrob  (0) 2017.01.04
[SaveSource] ViveTouchPad  (0) 2017.01.04
[SaveSource] Unity Editor Study  (0) 2016.11.17