Пример #1
0
        /// <summary>
        /// Gets the visual sensor position.
        /// </summary>
        /// <returns>The visual sensor position.</returns>
        public Vector3 GetVisualSensorPosition()
        {
            if (Owner == null)
            {
                return(Vector3.zero);
            }

            Vector3 _position = Vector3.zero;

            if (UseDynamicVisualSensorPosition)
            {
                if (m_VisualSensorTransform == null)
                {
                    m_VisualSensorTransform = SystemTools.FindChildByName(VisualSensorName, Owner.transform);
                }
            }
            else
            {
                m_VisualSensorTransform = null;
            }

            if (m_VisualSensorTransform != null)
            {
                _position = m_VisualSensorTransform.position;
            }
            else
            {
                _position = PositionTools.FixTransformPoint(Owner.transform, VisualSensorOffset);
            }

            return(_position);
        }
Пример #2
0
        public Vector3 GetStartPosition(GameObject _object, Vector3 _offset)
        {
            if (_object == null)
            {
                return(Vector3.zero);
            }

            if (AttachedCollider == null)
            {
                AttachedCollider = GetComponent <BoxCollider>();
            }

            Vector3 _point = AttachedCollider.bounds.ClosestPoint(_object.transform.position);

            Vector3 _point_offset = PositionTools.FixInverseTransformPoint(AttachedCollider.transform, _point);

            Vector3 _size = AttachedCollider.size * 0.5f;

            _point_offset.z = (_point_offset.z < 0 ? _point_offset.z + _size.z: _point_offset.z - _size.z);
            _point_offset.x = (_point_offset.x < 0 ? _point_offset.x + _size.x : _point_offset.x - _size.x);

            _point_offset += ClimbingOffset + _offset;

            _point = PositionTools.FixTransformPoint(AttachedCollider.transform, _point_offset);

            _start_point = _point;

            return(_point);
        }
        public void Display()
        {
            if (Camera.main != null && Owner != null)
            {
                if (string.IsNullOrEmpty(Name))
                {
                    Name = Owner.name;
                }

                Vector3 _pos = Camera.main.WorldToScreenPoint(PositionTools.FixTransformPoint(Owner.transform, Offset));
                GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                GUI.Label(new Rect(_pos.x, Screen.height - _pos.y, 200, 60), (ShowCommand ? Command : "") + (ShowName ? Name : ""));
            }
        }
Пример #4
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--;
            }
        }
Пример #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();

                        //
                    }
                }
            }
        }
Пример #6
0
        private GameObject InstantiateNewEffect()
        {
            if (Owner == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(MountPointName.Trim()) && (m_MountPointTransform == null || m_MountPointTransform.name != MountPointName.Trim()))
            {
                m_MountPointTransform = SystemTools.FindChildByName(MountPointName, Owner.transform);
            }

            if (m_MountPointTransform == null)
            {
                m_MountPointTransform = Owner.transform;
            }

            Vector3 _position = m_MountPointTransform.position;
            Vector3 _offset   = Vector3.zero;

            if (OffsetType == RandomOffsetType.EXACT)
            {
                _offset = Offset;
            }
            else if (OffsetRadius > 0)
            {
                Vector2 _pos = Random.insideUnitCircle * OffsetRadius;

                _offset.x = _pos.x;
                _offset.z = _pos.y;

                if (OffsetType == RandomOffsetType.HEMISPHERE)
                {
                    _offset.y = Random.Range(0, OffsetRadius);
                }
                else if (OffsetType == RandomOffsetType.SPHERE)
                {
                    _offset.y = Random.Range(-OffsetRadius, OffsetRadius);
                }
            }

            _position = PositionTools.FixTransformPoint(m_MountPointTransform, _offset);

            GameObject _effect = (GameObject)Object.Instantiate(ReferenceObject, _position, Quaternion.identity);

            if (_effect != null)
            {
                _effect.name = ReferenceObject.name;

                if (m_MountPointTransform != null)
                {
                    _effect.transform.rotation = m_MountPointTransform.rotation * Rotation;
                }
                else
                {
                    _effect.transform.rotation = Rotation;
                }

                if (Detach == false)
                {
                    _effect.transform.SetParent(m_MountPointTransform, true);
                }

                _effect.SetActive(true);
            }

            return(_effect);
        }
Пример #7
0
        private GameObject InstantiateEffect()
        {
            if (Owner == null || !Enabled || ReferenceObject == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(MountPointName.Trim()) && (m_MountPointTransform == null || m_MountPointTransform.name != MountPointName.Trim()))
            {
                m_MountPointTransform = SystemTools.FindChildByName(MountPointName, Owner.transform);
            }

            if (m_MountPointTransform == null)
            {
                m_MountPointTransform = Owner.transform;
            }

            Vector3 _position = m_MountPointTransform.position;
            Vector3 _offset   = Vector3.zero;

            if (OffsetType == RandomOffsetType.EXACT)
            {
                _offset = Offset;
            }
            else if (OffsetRadius > 0)
            {
                Vector2 _pos = Random.insideUnitCircle * OffsetRadius;

                _offset.x = _pos.x;
                _offset.z = _pos.y;

                if (OffsetType == RandomOffsetType.HEMISPHERE)
                {
                    _offset.y = Random.Range(0, OffsetRadius);
                }
                else if (OffsetType == RandomOffsetType.SPHERE)
                {
                    _offset.y = Random.Range(-OffsetRadius, OffsetRadius);
                }
            }

            _position = PositionTools.FixTransformPoint(m_MountPointTransform, _offset);

            GameObject _effect = WorldManager.Instantiate(ReferenceObject, _position, Rotation);

            if (_effect != null)
            {
                _effect.name = ReferenceObject.name;

                if (m_MountPointTransform != null)
                {
                    _effect.transform.rotation = m_MountPointTransform.rotation * Rotation;
                }
                else
                {
                    _effect.transform.rotation = Rotation;
                }

                _effect.SetActive(true);

                if (Attached == true && m_MountPointTransform != null && Owner.activeInHierarchy)
                {
                    _effect.transform.SetParent(m_MountPointTransform, true);
                }
                else if (Attached == false && Lifetime > 0)
                {
                    WorldManager.Destroy(_effect, Lifetime);
                    _effect = null;
                }
            }

            return(_effect);
        }