Пример #1
0
        /// <summary>
        /// Spawns a new item object, changes its name and sets it active.
        /// </summary>
        /// <returns>The item object.</returns>
        /// <param name="_position">Position.</param>
        /// <param name="_rotation">Rotation.</param>
        public GameObject SpawnItemObject(Vector3 _position, Quaternion _rotation)
        {
            GameObject _item = CreatureRegister.Spawn(ItemReferenceObject, _position, _rotation);

            if (_item != null)
            {
                _item.name = ItemReferenceObject.name;
                _item.SetActive(true);
            }

            return(_item);
        }
Пример #2
0
        public void Start()
        {
            if (ReferenceShell == null || SpawnPoint == null)
            {
                return;
            }

            GameObject _shell = CreatureRegister.Spawn(ReferenceShell, SpawnPoint.transform.position, SpawnPoint.transform.rotation);

            Rigidbody _shell_rigidbody = _shell.GetComponent <Rigidbody>();

            if (_shell_rigidbody != null)
            {
                _shell_rigidbody.AddForce(SpawnPoint.transform.forward * EjectionSpeed);
            }
        }
Пример #3
0
        /// <summary>
        /// Drops an detached item.
        /// </summary>
        public void DropItem()
        {
            GameObject _item = GiveItem();

            if (_item == null)
            {
                Quaternion _rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
                Vector3    _position = PositionTools.FixTransformPoint(Owner.transform, new Vector3(0, 5, 3));
                if (DropRange > 0)
                {
                    _position = ICE.World.Utilities.PositionTools.GetRandomPosition(_position, DropRange);
                }

                _item = CreatureRegister.Spawn(ItemReferenceObject, _position, _rotation);

                Amount--;
            }
        }
Пример #4
0
        public void DetachOnDie()
        {
            foreach (InventorySlotObject _slot in Slots)
            {
                if (_slot != null && (_slot.UseDetachOnDie == true || UseDetachOnDie == true) && _slot.Amount > 0)
                {
                    GameObject _reference = _slot.ItemReferenceObject;
                    if (_reference != null)
                    {
                        Vector3    _position = Owner.transform.TransformPoint(Vector3.zero);
                        Quaternion _rotation = Owner.transform.rotation;

                        while (_slot.Amount > 0)
                        {
                            if (_slot.DropRange > 0)
                            {
                                _position = ICE.World.Utilities.PositionTools.GetRandomPosition(_position, _slot.DropRange);
                            }

                            GameObject _item = CreatureRegister.Spawn(_reference, _position, _rotation);
                            //GameObject _item = (GameObject)GameObject.Instantiate( _reference, _position, _rotation );
                            if (_item != null)
                            {
                                _item.name = _reference.name;

                                if (_item.GetComponent <Rigidbody>() != null)
                                {
                                    _item.GetComponent <Rigidbody>().useGravity  = true;
                                    _item.GetComponent <Rigidbody>().isKinematic = false;
                                    _item.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                                }
                            }

                            _slot.Amount--;
                        }

                        if (_slot.ItemObject)
                        {
                            WorldManager.Remove(_slot.ItemObject);
                        }
                    }
                }
            }
        }
Пример #5
0
        public void Action(InventoryActionDataObject _action)
        {
            if (_action == null || !_action.Enabled)
            {
                return;
            }

            if (_action.DropItemRequired())
            {
                InventorySlotObject _slot = GetSlotByItemName(_action.ItemName);
                if (_slot != null && _slot.Amount > 0)
                {
                    Transform _transform = ICE.World.Utilities.SystemTools.FindChildByName(_action.ParentName, Owner.transform);
                    _transform = (_transform != null ? _transform : Owner.transform);

                    Quaternion _rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
                    Vector3    _position = PositionTools.FixTransformPoint(_transform, _action.Offset);

                    GameObject _item = _slot.GiveItem(_position, _rotation);
                    if (_item == null)
                    {
                        _item = CreatureRegister.Spawn(_slot.ItemReferenceObject, _position, _rotation);
                        _slot.Amount--;
                    }
                }
            }
            else if (_action.ParentUpdateRequired())
            {
                InventorySlotObject _slot = GetSlotByItemName(_action.ItemName);
                if (_slot != null && _slot.Amount > 0)
                {
                    if (_slot.ItemObject != null)
                    {
                        _slot.MountPointName = _action.ParentName;
                    }
                }
            }
            else if (_action.CollectActiveItemRequired())
            {
                ICECreatureControl _control = OwnerComponent as ICECreatureControl;
                TargetObject       _target  = _control.Creature.ActiveTarget;

                if (_control != null && _target != null && _target.Selectors.TotalCheckIsValid)                  //&& LastCollectedObjectID != _target.TargetID  )
                {
                    GameObject _item = _target.TargetGameObject;

                    //LastCollectedObjectID = _target.TargetID;

                    if (_target.EntityComponent != null && _target.EntityComponent.IsChildEntity)
                    {
                        ICEWorldEntity _parent = _target.EntityComponent.RootEntity;
                        if (_parent != null)
                        {
                            if (DebugLogIsEnabled)
                            {
                                PrintDebugLog(this, "CollectActiveItem : take '" + _target.Name + "' from " + _parent.name + " (" + _parent.ObjectInstanceID + ")");
                            }

                            InventorySlotObject _slot = GetInventorySlot(_parent.gameObject, _target.TargetName);
                            if (_slot != null)
                            {
                                _item = _slot.GiveItem();
                            }
                        }
                    }

                    if (Insert(_item))
                    {
                        //Debug.Log( _control.Creature.ActiveTarget.TargetGameObject.name + " - " +  _control.Creature.ActiveTarget.TargetGameObject.GetInstanceID() );
                        //_target.ResetTargetGameObject();
                        _control.Creature.ResetActiveTarget();

                        //
                    }
                }
            }
        }