| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using UnityStandardAssets.Characters.FirstPerson;
- [RequireComponent(typeof(UnityEngine.AudioSource))]
- public abstract class WeaponsBaseLegacy : MonoBehaviour
- {
- #region Fields
- public WeaponAnimations weaponAnimations;
- protected Animation[] myAnims;
- protected bool canFire = true;
- public AudioClip TakeSound;
- public AudioClip FireSound;
- [HideInInspector] public bool isAimed;
- protected bool canAim;
- private Quaternion defaultCamRot;
- protected bool isReloading = false;
- protected bool disableWeapon = false;
- protected AudioSource Source;
- [HideInInspector]
- public bool blockHit = false;
- #endregion
- protected virtual void Awake()
- {
- Source = GetComponent<AudioSource>();
- myAnims = GetComponentsInChildren <Animation> ();
- disableWeapon = false;
- }
- protected virtual void Start()
- {
- defaultCamRot = Camera.main.transform.localRotation;
- }
- protected virtual void OnEnable()
- {
- Source.clip = TakeSound;
- Source.Play();
- canFire = true;
- canAim = true;
- disableWeapon = false;
- playerSync.UpdateCurrentWeapon (GetComponent <WeaponsBaseLegacy> ());
- playerSync.WpState = WeaponState.Raising;
- }
- protected virtual void OnDisable ()
- {
- disableWeapon = false;
- }
- void Update()
- {
- InputUpdate();
- Aim();
- SyncState();
- }
- protected abstract void InputUpdate ();
- protected abstract void SyncState ();
- protected virtual void Aim () {}
- protected void PlayWeaponAnimation (string name, WrapMode wp = WrapMode.Default)
- {
- // myAnims.wrapMode = wp;
- //
- // if (wp == WrapMode.Loop)
- // myAnims.CrossFade (name);
- // else
- // myAnims.Play (name);
- foreach (Animation a in myAnims)
- {
- a.wrapMode = wp;
- if (a.wrapMode == WrapMode.Loop)
- a.CrossFade (name);
- else
- a.Play (name);
- }
- }
- protected IEnumerator WaitAnimationFinish (AnimationClip clip)
- {
- float reloadTime = clip.length;
- yield return new WaitForSeconds (reloadTime);
- }
-
- public virtual void DisableWeapon ()
- {
- canFire = false;
- disableWeapon = true;
- StopAllCoroutines();
- }
- public virtual IEnumerator ReloadNormal ()
- {
- yield return null;
- }
- protected FirstPersonController controller
- {
- get
- {
- return transform.root.GetComponent<FirstPersonController>();
- }
- }
- protected PlayerSyncLegacy playerSync
- {
- get
- {
- return PlayerSyncLegacy.Instance;
- }
- }
- protected PlayerManager playerManager
- {
- get
- {
- return PlayerManager.Instance;
- }
- }
- public bool CanFire
- {
- get
- {
- if (canFire && !isReloading && !controller.IsRunning)
- // if (canFire && !isReloading && !controller.IsRunning && isLoaded)
- return true;
- else
- return false;
- }
- }
- public bool CanAim
- {
- get
- {
- if (canAim && !controller.IsRunning )
- return true;
- else
- return false;
- }
- }
- public bool IsReloading
- {
- get
- {
- return isReloading;
- }
- }
- } // class
|