Exemple #1
0
        protected virtual IEnumerator HideWeaponAnimation()
        {
            WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
            Transform       curTransform     = cacheIDToTransform[currentID];
            IWeaponAnimator currrentAnimator = null;

            if (curTransform != null)
            {
                currrentAnimator = curTransform.GetComponent <IWeaponAnimator>();
            }
            else
            {
                hideWeaponAnimation = null;
                yield break;
            }

            if (currrentAnimator != null)
            {
                currrentAnimator.PutAway();
                yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
            }

            curTransform.gameObject.SetActive(false);
            hideWeaponAnimation = null;
            yield break;
        }
Exemple #2
0
        public virtual IEnumerator Dynamic()
        {
            yield return(new WaitForEndOfFrame());

            IWeaponAnimator   weaponAnimator       = GetComponent <IWeaponAnimator>();
            IEnumerator       setSpreadIEnumerator = null;
            WeaponActionState lastState            = WeaponActionState.Idle;

            while (true)
            {
                if (lastState != weaponAnimator.GetActiveState())
                {
                    for (int i = 0; i < animationStates.Length; i++)
                    {
                        AnimationState animationState = animationStates[i];
                        if (animationState.state == weaponAnimator.GetActiveState())
                        {
                            if (setSpreadIEnumerator != null)
                            {
                                StopCoroutine(setSpreadIEnumerator);
                            }
                            setSpreadIEnumerator = SetSpread(animationState.spread, animationState.smooth);
                            StartCoroutine(setSpreadIEnumerator);
                            lastState = weaponAnimator.GetActiveState();
                            break;
                        }
                    }
                }
                yield return(null);
            }
        }
Exemple #3
0
        protected virtual IEnumerator SwitchWeaponAnimation(KeyCode targetWeaponKey)
        {
            if (currentWeaponKey != KeyCode.None)
            {
                WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
                Transform       currentTransform = cacheIDToTransform[currentID];
                IWeaponAnimator currrentAnimator = null;
                if (currentTransform != null)
                {
                    currrentAnimator = currentTransform.GetComponent <IWeaponAnimator>();
                }
                else
                {
                    switchWeaponAnimation = null;
                    yield break;
                }

                if (currrentAnimator != null)
                {
                    currrentAnimator.PutAway();
                    yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
                }

                currentTransform.gameObject.SetActive(false);
                currentWeaponKey = KeyCode.None;
            }

            WeaponID targetID = cacheKeyToID[targetWeaponKey];

            if (targetID == null)
            {
                switchWeaponAnimation = null;
                yield break;
            }
            Transform       targetTransform = cacheIDToTransform[targetID];
            IWeaponAnimator targetAnimator  = null;

            if (targetTransform != null)
            {
                targetAnimator = targetTransform.GetComponent <IWeaponAnimator>();
            }
            else
            {
                switchWeaponAnimation = null;
                yield break;
            }

            targetTransform.gameObject.SetActive(true);

            if (targetAnimator != null)
            {
                yield return(new WaitForSeconds(targetAnimator.GetTakeTime()));
            }

            currentWeaponKey      = targetWeaponKey;
            switchWeaponAnimation = null;
            yield break;
        }
Exemple #4
0
        /// <summary>
        /// Awake is called when the script instance is being loaded.
        /// </summary>
        protected virtual void Awake()
        {
            audioSource     = GetComponent <AudioSource>();
            weaponReloading = GetComponent <IWeaponReloading>();
            weaponAnimator  = GetComponent <IWeaponAnimator>();

            if (spreadProperties != null)
            {
                spreadProperties.Initialize(firePoint);
            }
        }
Exemple #5
0
        protected virtual IEnumerator DropWeaponAnimation()
        {
            WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
            Transform       curTransform     = cacheIDToTransform[currentID];
            DropProperties  dropProperties   = currentID.GetDropProperties();
            IWeaponAnimator currrentAnimator = null;

            if (curTransform != null)
            {
                currrentAnimator = curTransform.GetComponent <IWeaponAnimator>();
            }

            if (currrentAnimator != null)
            {
                currrentAnimator.PutAway();
                yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
            }

            curTransform.gameObject.SetActive(false);
            Remove(currentID);

            if (dropProperties != DropProperties.Empty)
            {
                Vector3    pos        = _FPCamera.position + (_FPCamera.forward * dropProperties.GetDistance());
                GameObject dropObject = Instantiate(dropProperties.GetDropObject(), pos, Quaternion.Euler(dropProperties.GetRotation()));
                if (dropObject != null)
                {
                    Rigidbody rigidbody = dropObject.GetComponent <Rigidbody>();
                    if (rigidbody != null)
                    {
                        rigidbody.AddForce(_FPCamera.forward * dropProperties.GetForce(), ForceMode.Impulse);
                    }
                }
            }

            currentWeaponKey    = KeyCode.None;
            dropWeaponAnimation = null;
            yield break;
        }
Exemple #6
0
        protected virtual IEnumerator ReplaceWeaponAnimation(WeaponID targetWeaponID)
        {
            if (currentWeaponKey != KeyCode.None)
            {
                WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
                Transform       currentTransform = cacheIDToTransform[currentID];
                DropProperties  dropProperties   = currentID.GetDropProperties();
                IWeaponAnimator currrentAnimator = null;
                if (currentTransform != null)
                {
                    currrentAnimator = currentTransform.GetComponent <IWeaponAnimator>();
                }
                else
                {
                    switchWeaponAnimation = null;
                    yield break;
                }

                if (currrentAnimator != null)
                {
                    currrentAnimator.PutAway();
                    yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
                }

                if (dropProperties != DropProperties.Empty)
                {
                    Vector3    pos        = _FPCamera.position + (_FPCamera.forward * dropProperties.GetDistance());
                    GameObject dropObject = Instantiate(dropProperties.GetDropObject(), pos, Quaternion.Euler(dropProperties.GetRotation()));
                    if (dropObject != null)
                    {
                        Rigidbody rigidbody = dropObject.GetComponent <Rigidbody>();
                        if (rigidbody != null)
                        {
                            rigidbody.AddForce(_FPCamera.forward * dropProperties.GetForce(), ForceMode.Impulse);
                        }
                    }
                }

                currentTransform.gameObject.SetActive(false);
                currentWeaponKey = KeyCode.None;
            }

            Transform       targetTransform = cacheIDToTransform[targetWeaponID];
            IWeaponAnimator targetAnimator  = null;

            if (targetTransform != null)
            {
                targetAnimator = targetTransform.GetComponent <IWeaponAnimator>();
            }
            else
            {
                switchWeaponAnimation = null;
                yield break;
            }

            targetTransform.gameObject.SetActive(true);

            if (targetAnimator != null)
            {
                yield return(new WaitForSeconds(targetAnimator.GetTakeTime()));
            }

            List <InventorySlot> slots = cacheGroupToSlots[targetWeaponID.GetGroup()];

            for (int i = 0, length = slots.Count; i < length; i++)
            {
                InventorySlot slot = slots[i];
                if (slot.GetWeapon() == targetWeaponID)
                {
                    currentWeaponKey = slot.GetKey();
                    break;
                }
            }
            switchWeaponAnimation = null;
            yield break;
        }
Exemple #7
0
        protected virtual IEnumerator SwitchWeaponAnimation(WeaponID targetWeaponID)
        {
            if (currentWeaponKey != KeyCode.None)
            {
                WeaponID        currentID        = cacheKeyToID[currentWeaponKey];
                Transform       currentTransform = cacheIDToTransform[currentID];
                IWeaponAnimator currrentAnimator = null;
                if (currentTransform != null)
                {
                    currrentAnimator = currentTransform.GetComponent <IWeaponAnimator>();
                }
                else
                {
                    switchWeaponAnimation = null;
                    yield break;
                }

                if (currrentAnimator != null)
                {
                    currrentAnimator.PutAway();
                    yield return(new WaitForSeconds(currrentAnimator.GetPutAwayTime()));
                }

                currentTransform.gameObject.SetActive(false);
                currentWeaponKey = KeyCode.None;
            }

            Transform       targetTransform = cacheIDToTransform[targetWeaponID];
            IWeaponAnimator targetAnimator  = null;

            if (targetTransform != null)
            {
                targetAnimator = targetTransform.GetComponent <IWeaponAnimator>();
            }
            else
            {
                switchWeaponAnimation = null;
                yield break;
            }

            targetTransform.gameObject.SetActive(true);

            if (targetAnimator != null)
            {
                yield return(new WaitForSeconds(targetAnimator.GetTakeTime()));
            }

            List <InventorySlot> slots = cacheGroupToSlots[targetWeaponID.GetGroup()];

            for (int i = 0, length = slots.Count; i < length; i++)
            {
                InventorySlot slot = slots[i];
                if (slot.GetWeapon() == targetWeaponID)
                {
                    currentWeaponKey = slot.GetKey();
                    break;
                }
            }
            switchWeaponAnimation = null;
            yield break;
        }
 /// <summary>
 /// Awake is called when the script instance is being loaded.
 /// </summary>
 protected virtual void Awake()
 {
     audioSource    = GetComponent <AudioSource>();
     weaponAnimator = GetComponent <IWeaponAnimator>();
 }
 public void SetweaponAnimator(IWeaponAnimator value)
 {
     weaponAnimator = value;
 }