Beispiel #1
0
        /// <summary>
        /// Attachs to transform.
        /// </summary>
        /// <returns><c>true</c>, if to transform was attached, <c>false</c> otherwise.</returns>
        /// <param name="_object">Object.</param>
        /// <param name="_transform">Transform.</param>
        public bool AttachToTransform(GameObject _object, Transform _transform, bool _use_transform_position)
        {
            if (_object == null)
            {
                return(false);
            }

            if (_use_transform_position)
            {
                _object.transform.position = _transform.position;
                _object.transform.rotation = _transform.rotation;
            }

            _object.transform.SetParent(_transform, true);

            Rigidbody _rigidbody = _object.GetComponent <Rigidbody>();

            if (_rigidbody != null)
            {
                _rigidbody.useGravity  = false;
                _rigidbody.isKinematic = true;
                _rigidbody.constraints = RigidbodyConstraints.FreezeAll;
            }

            SystemTools.EnableColliders(_object.transform, false);

            _object.SetActive(true);

            return(true);
        }
        public override void Update()
        {
            if (AnimatorComponent != null && AnimatorComponent.isInitialized)
            {
                if (Input.GetAxis(AxisInput.Name) > 0)
                {
                    if (HandleColliders)
                    {
                        SystemTools.EnableColliders(transform, true);
                    }

                    AnimatorComponent.SetBool(Parameter, true);
                }
                else
                {
                    if (HandleColliders)
                    {
                        SystemTools.EnableColliders(transform, false);
                    }

                    AnimatorComponent.SetBool(Parameter, false);
                }
            }

            base.Update();
        }
Beispiel #3
0
        /// <summary>
        /// Sets the ground level.
        /// </summary>
        /// <param name="_transform">Transform.</param>
        /// <param name="_offset">Offset.</param>
        public static void SetGroundLevel(Transform _transform, float _offset)
        {
            SystemTools.EnableColliders(_transform, false);
            float _ground_level = GetGroundLevel(_transform.position, _offset);

            _transform.position = new Vector3(
                _transform.position.x,
                _ground_level + _offset,
                _transform.position.z);
            SystemTools.EnableColliders(_transform, true);
        }
        /// <summary>
        /// Scan for targets within the scanning range
        /// </summary>
        public void Scan()
        {
            if (m_IsForced && m_ActiveTarget != null)
            {
                return;
            }

            m_ScanIntervalTimer += Time.deltaTime;
            if (Owner == null && m_ScanIntervalTimer > ScanInterval)
            {
                return;
            }

            m_ScanIntervalTimer = 0;
            m_ActiveTarget      = null;

            Collider[] _colliders = Physics.OverlapSphere(Owner.transform.position, ScanRange, Layers.Mask);
            foreach (Collider _collider in _colliders)
            {
                if (_collider.transform.IsChildOf(Owner.transform) || Owner.transform.IsChildOf(_collider.transform))
                {
                    continue;
                }

                DebugLine(Owner.transform.position, _collider.transform.position + Vector3.up, Color.yellow);

                RaycastHit _obstacle;
                SystemTools.EnableColliders(Owner.transform, false);
                Physics.Linecast(Owner.transform.position + Vector3.up, _collider.transform.position + Vector3.up, out _obstacle);
                SystemTools.EnableColliders(Owner.transform, true);
                if (_obstacle.collider != null && _obstacle.collider != _collider && !_obstacle.transform.IsChildOf(_collider.transform.root))
                {
                    continue;
                }

                //TODO : improve the selection
                m_ActiveTarget = _collider.transform;
                return;
            }

            return;
        }
Beispiel #5
0
        /// <summary>
        /// Detachs from transform.
        /// </summary>
        /// <returns><c>true</c>, if from transform was detached, <c>false</c> otherwise.</returns>
        /// <param name="_object">Object.</param>
        public bool DetachFromTransform(GameObject _object)
        {
            if (_object == null)
            {
                return(false);
            }

            if (!Register(_object))
            {
                ICECreatureEntity _entity = _object.GetComponent <ICECreatureEntity>();

                // if the object is an ICE entity we have to adapt the parent according to it's hierarchy settings
                if (_entity != null && _entity.UseHierarchyManagement)
                {
                    _object.transform.SetParent(UpdateGroupParent(), true);
                }
                else
                {
                    _object.transform.SetParent(null, true);
                }
            }

            Rigidbody _rigidbody = _object.GetComponent <Rigidbody>();

            if (_rigidbody != null)
            {
                _rigidbody.useGravity  = true;
                _rigidbody.isKinematic = false;
                _rigidbody.constraints = RigidbodyConstraints.None;
            }

            SystemTools.EnableColliders(_object.transform, true);

            _object.SetActive(true);

            return(true);
        }
Beispiel #6
0
        public virtual bool DetachFromTransform(GameObject _object)
        {
            if (_object == null)
            {
                return(false);
            }

            _object.transform.SetParent(null, true);

            Rigidbody _rigidbody = _object.GetComponent <Rigidbody>();

            if (_rigidbody != null)
            {
                _rigidbody.useGravity  = true;
                _rigidbody.isKinematic = false;
                _rigidbody.constraints = RigidbodyConstraints.None;
            }

            SystemTools.EnableColliders(_object.transform, true);

            _object.SetActive(true);

            return(true);
        }
Beispiel #7
0
        public void Fire(Transform _target)
        {
            if (_target != null && DebugLogIsEnabled)
            {
                PrintDebugLog(this, "Fire - " + _target.name + " (" + _target.position + ")");
            }

            if (Type == RangedWeaponAmmunitionType.Simulated && _target != null)
            {
                ICEWorldEntity.SendDamage(Owner, _target.gameObject, ImpactType, MethodDamage, MethodName, ForceType, UnityEngine.Random.Range(ForceMin, ForceMax), ExplosionRadius);
            }
            else if (Type == RangedWeaponAmmunitionType.Projectile || Type == RangedWeaponAmmunitionType.BallisticProjectile)
            {
                Vector3    _position = Vector3.zero;
                Quaternion _rotation = Quaternion.identity;


                if (Type == RangedWeaponAmmunitionType.Projectile)
                {
                    if (_target != null)
                    {
                        _position = _target.position;
                    }

                    if (ProjectileSpawnPoint != null)
                    {
                        Debug.DrawRay(ProjectileSpawnPoint.transform.position, ProjectileSpawnPoint.transform.forward * 100);
                        RaycastHit _hit;
                        if (Physics.Raycast(ProjectileSpawnPoint.transform.position, ProjectileSpawnPoint.transform.forward, out _hit, Mathf.Infinity, -1, WorldManager.TriggerInteraction))
                        {
                            _position = _hit.point;
                        }
                    }

                    GameObject _projectile = WorldManager.Instantiate(Projectile, _position, _rotation);
                    if (_projectile != null)
                    {
                        _projectile.name = Projectile.name;
                        _projectile.transform.localScale = new Vector3(ProjectileScale, ProjectileScale, ProjectileScale);

                        SystemTools.EnableColliders(_projectile.transform, false);

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

                        _projectile.transform.SetParent(_target, true);

                        ICECreatureProjectile _p = _projectile.GetComponent <ICECreatureProjectile>();
                        if (_p != null)
                        {
                            _p.Hit(_target.gameObject, _position);
                        }
                    }
                }
                else if (Type == RangedWeaponAmmunitionType.BallisticProjectile)
                {
                    if (ProjectileSpawnPoint != null)
                    {
                        _position = ProjectileSpawnPoint.transform.position;
                        _rotation = ProjectileSpawnPoint.transform.rotation;
                    }
                    else
                    {
                        _position = Owner.transform.position;
                        _rotation = Owner.transform.rotation;
                    }

                    GameObject _projectile = WorldManager.Instantiate(Projectile, _position, _rotation);
                    if (_projectile != null)
                    {
                        _projectile.name = Projectile.name;
                        _projectile.transform.localScale = new Vector3(ProjectileScale, ProjectileScale, ProjectileScale);

                        Rigidbody _rb = _projectile.GetComponent <Rigidbody>();
                        if (_rb != null)
                        {
                            _rb.AddForce(ProjectileSpawnPoint.transform.TransformDirection(new Vector3(0, 0, ProjectileMuzzleVelocity)));
                        }
                    }
                }
            }
        }