示例#1
0
 IEnumerator UnequipItemRoutine(EquipPoint equipPoint, Item item)
 {
     if (!inEquip)
     {
         inventory.canEquip = false;
         inEquip            = true;
         if (equipPoint != null && equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
         {
             var equipment = equipPoint.equipmentReference.equipedObject.GetComponent <IEquipment>();
             if (equipment != null)
             {
                 equipment.OnUnequip(item);
             }
             if (!inventory.isOpen)
             {
                 while (equipTimer > 0)
                 {
                     equipTimer -= Time.deltaTime;
                     yield return(new WaitForEndOfFrame());
                 }
             }
             Destroy(equipPoint.equipmentReference.equipedObject);
             equipPoint.equipmentReference.item = null;
         }
         inEquip            = false;
         inventory.canEquip = true;
     }
 }
示例#2
0
        void CheckTwoHandItem(EquipPoint equipPoint, Item item)
        {
            if (item == null)
            {
                return;
            }

            var opposite = equipPoints.Find(ePoint => ePoint.area != null && ePoint.equipPointName.Equals("LeftArm") && ePoint.area.currentEquipedItem != null);

            if (equipPoint.equipPointName.Equals("LeftArm"))
            {
                opposite = equipPoints.Find(ePoint => ePoint.area != null && ePoint.equipPointName.Equals("RightArm") && ePoint.area.currentEquipedItem != null);
            }
            else if (!equipPoint.equipPointName.Equals("RightArm"))
            {
                return;
            }
            if (opposite != null && (item.twoHandWeapon || opposite.area.currentEquipedItem.twoHandWeapon))
            {
                opposite.area.RemoveCurrentItem();
            }
        }
示例#3
0
        public void Test(ItemManager itemManager, MeleeManager meleeManager)
        {
            animator = itemManager.GetComponent <Animator>();
            if (itemManager.equipPoints == null)
            {
                itemManager.equipPoints = new List <EquipPoint>();
            }

            #region LeftEquipPoint
            var equipPointL = itemManager.equipPoints.Find(p => p.equipPointName == "LeftArm");
            if (equipPointL == null)
            {
                EquipPoint pointL = new EquipPoint();
                pointL.equipPointName = "LeftArm";
                if (meleeManager)
                {
                    pointL.onInstantiateEquiment.AddListener(meleeManager.SetLeftWeapon);

//#if UNITY_EDITOR
//                    UnityEventTools.AddPersistentListener<GameObject>(pointL.onInstantiateEquiment, meleeManager.SetLeftWeapon);
//#else
//                  pointL.onInstantiateEquiment.AddListener(manager.SetLeftWeapon);
//#endif
                }

                if (animator)
                {
                    var defaultEquipPointL = new GameObject("defaultEquipPoint");
                    var parent             = animator.GetBoneTransform(HumanBodyBones.LeftHand);
                    defaultEquipPointL.transform.SetParent(parent);
                    defaultEquipPointL.transform.localPosition = Vector3.zero;
                    defaultEquipPointL.transform.forward       = itemManager.transform.forward;
                    defaultEquipPointL.gameObject.tag          = "Ignore Ragdoll";
                    pointL.handler = new Handler();
                    pointL.handler.defaultHandler = defaultEquipPointL.transform;
                }
                itemManager.equipPoints.Add(pointL);
            }
            else
            {
                if (equipPointL.handler.defaultHandler == null)
                {
                    if (animator)
                    {
                        var parent       = animator.GetBoneTransform(HumanBodyBones.LeftHand);
                        var defaultPoint = parent.Find("defaultEquipPoint");

                        if (defaultPoint)
                        {
                            equipPointL.handler.defaultHandler = defaultPoint;
                        }
                        else
                        {
                            var _defaultPoint = new GameObject("defaultEquipPoint");
                            _defaultPoint.transform.SetParent(parent);
                            _defaultPoint.transform.localPosition = Vector3.zero;
                            _defaultPoint.transform.forward       = itemManager.transform.forward;
                            _defaultPoint.gameObject.tag          = "Ignore Ragdoll";
                            equipPointL.handler.defaultHandler    = _defaultPoint.transform;
                        }
                    }
                }

                bool containsListener = false;
                for (int i = 0; i < equipPointL.onInstantiateEquiment.GetPersistentEventCount(); i++)
                {
                    if (equipPointL.onInstantiateEquiment.GetPersistentTarget(i).GetType().Equals(typeof(MeleeManager)) && equipPointL.onInstantiateEquiment.GetPersistentMethodName(i).Equals("SetLeftWeapon"))
                    {
                        containsListener = true;
                        break;
                    }
                }

                if (!containsListener && meleeManager)
                {
                    equipPointL.onInstantiateEquiment.AddListener(meleeManager.SetLeftWeapon);
//#if UNITY_EDITOR
//                    UnityEventTools.AddPersistentListener<GameObject>(equipPointL.onInstantiateEquiment, meleeManager.SetLeftWeapon);
//#else
//                    equipPointL.onInstantiateEquiment.AddListener(manager.SetLeftWeapon);
//#endif
                }
            }
            #endregion

            #region RightEquipPoint
            var equipPointR = itemManager.equipPoints.Find(p => p.equipPointName == "RightArm");
            if (equipPointR == null)
            {
                EquipPoint pointR = new EquipPoint();
                pointR.equipPointName = "RightArm";
                if (meleeManager)
                {
                    pointR.onInstantiateEquiment.AddListener(meleeManager.SetRightWeapon);
                    //#if UNITY_EDITOR
                    //                    UnityEventTools.AddPersistentListener<GameObject>(pointR.onInstantiateEquiment, meleeManager.SetRightWeapon);
                    //#else
                    //                    pointR.onInstantiateEquiment.AddListener(manager.SetRightWeapon);
                    //#endif
                }

                if (animator)
                {
                    var defaultEquipPointR = new GameObject("defaultEquipPoint");
                    var parent             = animator.GetBoneTransform(HumanBodyBones.RightHand);
                    defaultEquipPointR.transform.SetParent(parent);
                    defaultEquipPointR.transform.localPosition = Vector3.zero;
                    defaultEquipPointR.transform.forward       = itemManager.transform.forward;
                    defaultEquipPointR.gameObject.tag          = "Ignore Ragdoll";
                    pointR.handler = new Handler();
                    pointR.handler.defaultHandler = defaultEquipPointR.transform;
                }
                itemManager.equipPoints.Add(pointR);
            }
            else
            {
                if (equipPointR.handler.defaultHandler == null)
                {
                    if (animator)
                    {
                        var parent       = animator.GetBoneTransform(HumanBodyBones.RightHand);
                        var defaultPoint = parent.Find("defaultEquipPoint");
                        if (defaultPoint)
                        {
                            equipPointR.handler.defaultHandler = defaultPoint;
                        }
                        else
                        {
                            var _defaultPoint = new GameObject("defaultEquipPoint");
                            _defaultPoint.transform.SetParent(parent);
                            _defaultPoint.transform.localPosition = Vector3.zero;
                            _defaultPoint.transform.forward       = itemManager.transform.forward;
                            _defaultPoint.gameObject.tag          = "Ignore Ragdoll";
                            equipPointR.handler.defaultHandler    = _defaultPoint.transform;
                        }
                    }
                }

                bool containsListener = false;
                for (int i = 0; i < equipPointR.onInstantiateEquiment.GetPersistentEventCount(); i++)
                {
                    if (equipPointR.onInstantiateEquiment.GetPersistentTarget(i).GetType().Equals(typeof(MeleeManager)) && equipPointR.onInstantiateEquiment.GetPersistentMethodName(i).Equals("SetRightWeapon"))
                    {
                        containsListener = true;
                        break;
                    }
                }

                if (!containsListener && meleeManager)
                {
                    equipPointR.onInstantiateEquiment.AddListener(meleeManager.SetRightWeapon);
//#if UNITY_EDITOR
//                    UnityEventTools.AddPersistentListener<GameObject>(equipPointR.onInstantiateEquiment, meleeManager.SetRightWeapon);
//#else
//                    equipPointR.onInstantiateEquiment.AddListener(manager.SetRightWeapon);
//#endif
                }
                #endregion
            }
        }
示例#4
0
        IEnumerator EquipItemRoutine(EquipPoint equipPoint, Item item)
        {
            if (!inEquip)
            {
                inventory.canEquip = false;
                inEquip            = true;
                if (!inventory.isOpen)
                {
                    while (equipTimer > 0)
                    {
                        equipTimer -= Time.deltaTime;
                        if (item == null)
                        {
                            break;
                        }
                        yield return(new WaitForEndOfFrame());
                    }
                }
                if (equipPoint != null)
                {
                    if (item.originalObject)
                    {
                        if (equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
                        {
                            var _equipment = equipPoint.equipmentReference.equipedObject.GetComponent <IEquipment>();
                            if (_equipment != null)
                            {
                                _equipment.OnUnequip(equipPoint.equipmentReference.item);
                            }
                            Destroy(equipPoint.equipmentReference.equipedObject);
                        }

                        var point          = equipPoint.handler.customHandlers.Find(p => p.name == item.customEquipPoint);
                        var equipTransform = point != null ? point : equipPoint.handler.defaultHandler;
                        var equipedObject  = Instantiate(item.originalObject, equipTransform.position, equipTransform.rotation) as GameObject;
                        equipedObject.transform.parent = equipTransform;

                        if (equipPoint.equipPointName.Contains("Left"))
                        {
                            var scale = equipedObject.transform.localScale;
                            scale.x *= -1;
                            equipedObject.transform.localScale = scale;
                        }

                        equipPoint.equipmentReference.item          = item;
                        equipPoint.equipmentReference.equipedObject = equipedObject;
                        var equipment = equipedObject.GetComponent <IEquipment>();
                        if (equipment != null)
                        {
                            equipment.OnEquip(item);
                        }
                        equipPoint.onInstantiateEquiment.Invoke(equipedObject);
                    }
                    else if (equipPoint.equipmentReference != null && equipPoint.equipmentReference.equipedObject != null)
                    {
                        var _equipment = equipPoint.equipmentReference.equipedObject.GetComponent <IEquipment>();

                        if (_equipment != null)
                        {
                            _equipment.OnUnequip(equipPoint.equipmentReference.item);
                        }
                        Destroy(equipPoint.equipmentReference.equipedObject);
                        equipPoint.equipmentReference.item = null;
                    }
                }
                inEquip            = false;
                inventory.canEquip = true;
                if (equipPoint != null)
                {
                    CheckTwoHandItem(equipPoint, item);
                }
            }
        }