본문 바로가기
NOTE/SaveSource

[SaveSource] WeaponDrob

by DevAthena 2017. 1. 4.
using UnityEngine;
using System.Collections.Generic;
 
public enum EqipWeaponType
{
    General,
    Special,
    None
}
 
class WeaponDrob : MonoBehaviour
{
    SteamVR_TrackedController trackedController;
 
    public GameObject ControllerModel;
    public GrableTarget grabaleTarget;
    public SpecialWeapon specialWeapon;
 
    Transform m_trans;
    Rigidbody m_rigid;
    Vector3 m_curPos;
    Vector3 m_lasPos;
 
    EqipWeaponType m_thisWeapon;
 
    private void Start()
    {
        trackedController = GetComponent<SteamVR_TrackedController>();
    }
 
    private void Update()
    {
        #region Eqip Check
        grabaleTarget = GetComponentInChildren<GrableTarget>();
        specialWeapon = GetComponentInChildren<SpecialWeapon>();
 
        if (grabaleTarget != null)
        {
            m_trans = grabaleTarget.transform.parent;
            m_thisWeapon = EqipWeaponType.General;
            m_curPos = m_trans.position;
        }
        else if (specialWeapon != null)
        {
            m_trans = specialWeapon.transform;
            m_thisWeapon = EqipWeaponType.Special;
            m_curPos = m_trans.position;
        }
        else
        {
            m_thisWeapon = EqipWeaponType.None;
            return;
        }
        #endregion
 
        #region Lobby object drop for 혜린씨
        if (trackedController.gripped && grabaleTarget != null
            && grabaleTarget.GetComponent<UILobbyButton>() != null)
        {
            grabaleTarget.GetComponent<UILobbyButton>().Release_From_Controller();
            ControllerModel.SetActive(true);
            return;
        }
        #endregion
 
        #region Object Drop (버리는것:특수무기 작동x)
        if (trackedController.gripped)
        {
            switch (m_thisWeapon)
            {
                case EqipWeaponType.General:
                    if (grabaleTarget != null)
                    {
                        m_rigid = grabaleTarget.transform.parent.GetComponent<Rigidbody>();
                        m_rigid.useGravity = true;
                        m_rigid.isKinematic = false;
                        //m_rigid.AddForce((m_curPos - m_lasPos) / Time.fixedDeltaTime, ForceMode.Impulse);
 
                        #region Controller Right
                        if (this.name == "Controller (right)")
                        {                            
                            if (InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.lazer != null)
                            {
                                InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.lazer.GetComponent<LineRenderer>().enabled = false;
                            }
                            for (int i = 0; i < InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>().Length; i++)
                            {
                                /*
                                if (InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.WeaponKind.Equals(WeaponKinds.Rocket))
                                {
                                    Debug.LogError("로켓버림");
                                    InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>()[i].material = Resources.Load("/WeaponMaterial/RocketGun_rimlight", typeof(Material)) as Material;
                                }
                                else if (InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.WeaponKind.Equals(WeaponKinds.FireGun))
                                {
                                    Debug.LogError("화염버림");
                                    InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>()[i].material = Resources.Load("/WeaponMaterial/FireGun_rimlight", typeof(Material)) as Material;
                                }
                                */
                                if (InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.transform.parent.GetComponentsInChildren<MeshRenderer>()[i].name != "whole_model_group1")
                                {
                                    InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel.transform.parent.GetComponentsInChildren<MeshRenderer>()[i].material.shader = Shader.Find("Custom/rimlight");
                                }
                            }
 
                            InGameManager.Instance.Player.CurrentRightWeapon.m_fpWeaponModel = null;
                            ControllerManager.Instance.RightControllerModel.GetComponent<ControllerGrabable>().grabTime = 0.0f;
                        }
                        #endregion
 
                        #region Controller Left
                        else if (this.name == "Controller (left)")
                        {
                            if (InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.lazer != null)
                            {
                                InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.lazer.GetComponent<LineRenderer>().enabled = false;
                            }
                            for (int i = 0; i < InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>().Length; i++)
                            {
                                /*
                                if (InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.WeaponKind.Equals(WeaponKinds.Rocket))
                                {
                                    Debug.LogError("로켓버림");
                                    InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>()[i].material = Resources.Load("/WeaponMaterial/RocketGun_rimlight", typeof(Material)) as Material;
                                }
                                else if (InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.WeaponKind.Equals(WeaponKinds.FireGun))
                                {
                                    Debug.LogError("화염버림");
                                    InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.GetComponentsInChildren<MeshRenderer>()[i].material = Resources.Load("/WeaponMaterial/FireGun_rimlight", typeof(Material)) as Material;
                                }
                                */
                                if (InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.transform.parent.GetComponentsInChildren<MeshRenderer>()[i].name != "whole_model_group1")
                                {
                                    InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel.transform.parent.GetComponentsInChildren<MeshRenderer>()[i].material.shader = Shader.Find("Custom/rimlight");
                                }
                            }
 
                            InGameManager.Instance.Player.CurrentLeftWeapon.m_fpWeaponModel = null;
                            ControllerManager.Instance.LeftControllerModel.GetComponent<ControllerGrabable>().grabTime = 0.0f;
                        }
                        #endregion
 
                        grabaleTarget.gameObject.transform.parent.parent = null;
                        ControllerModel.SetActive(true);
 
                        #region 튜토리얼 지혜 02.07
                        if (GameManager.Instance.GetSceneType == SceneType.Tutorial)
                        {
                            TutorialManager.Instance.StepClear(TutorialState.GunDrop);
                            TutorialManager.Instance.StepClear(TutorialState.GatlingDrop);
                        }
                        #endregion
                    }
                    break;
 
                case EqipWeaponType.Special:
                    if (specialWeapon != null)
                    {
                        m_rigid = specialWeapon.GetComponent<Rigidbody>();
                        m_rigid.useGravity = true;
                        m_rigid.isKinematic = false;
                        //m_rigid.AddForce((m_curPos - m_lasPos) / Time.fixedDeltaTime, ForceMode.Impulse);
                        specialWeapon.gameObject.transform.parent = null;
                        ControllerModel.SetActive(true);
                        for (int i = 0; i < specialWeapon.GetComponentsInChildren<MeshRenderer>().Length; i++)
                        {
                            if (specialWeapon.GetComponentsInChildren<MeshRenderer>()[i].name != "whole_model_group1")
                            {
                                specialWeapon.GetComponentsInChildren<MeshRenderer>()[i].material.shader = Shader.Find("Custom/rimlight");
                            }
                        }
                    }
                    break;
 
                default:
                    break;
            }
 
        }
        #endregion
    }
 
    private void LateUpdate()
    {
        if (m_trans != null)
        {
            m_lasPos = m_trans.position;
        }
    }
 
}
 
 
 
cs


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

[SaveSource] WaveMoveTrigger  (0) 2017.01.12
[SaveSource] SpeicalWeapon  (0) 2017.01.12
[SaveSource] ViveTouchPad  (0) 2017.01.04
[SaveSource] Unity Editor Study  (0) 2016.11.17
[SaveSource] 만보기소스(펌)  (0) 2016.11.09