Пример #1
0
    protected override void Fire()
    {
        Vector3 secondPoint;

        if (!bFiring)
        {
            lineRenderer.SetVertexCount(2);
        }

        RaycastHit hit;

        if (Physics.RaycastAll(transform.position, transform.forward, distance)
            .WithMin(h => h.distance, h => !ShipIdentification.IsThisShip(h.transform, driver.ship), out hit))
        {
            var ship = hit.transform.GetComponent <ShipController>();
            if (ship != null)
            {
                ship.AddEffect(new FreezeEffect());
            }
            secondPoint = hit.point;
        }
        else
        {
            secondPoint = firePoint.position + firePoint.forward * distance;
        }

        lineRenderer.SetPosition(0, firePoint.position);
        lineRenderer.SetPosition(1, secondPoint);
        bFiring = true;
    }
Пример #2
0
    bool SeeEnemy()
    {
        if (enemy == null)
        {
            return(false);
        }
        RaycastHit hit;

        //var seeHits = Physics.RaycastAll(ship.transform.position, enemy.transform.position - ship.transform.position);
        if (Physics.Raycast(ship.transform.position, enemy.transform.position - ship.transform.position, out hit))
        {
            //var hit = seeHits.WithMin(h => h.distance);
            return(ShipIdentification.IsThisShip(hit.transform.root, enemy));
        }
        else
        {
            return(false);
        }
    }
Пример #3
0
    bool CheckHits(int length, SShot shot, out RaycastHit hit)
    {
        RaycastHit nearesthit;
        float      distance;

        RaycastHit t_hit;
        int        i = 0;

        for (; i < length; i++)
        {
            t_hit = hits[i];
            if (!ShipIdentification.IsThisShip(t_hit.transform, shot.friend))
            {
                nearesthit = t_hit;
                distance   = t_hit.distance;
                i++;
                goto begin;
            }
        }
        hit = new RaycastHit();
        return(false);

begin:
        float t_distance;

        for (; i < length; i++)
        {
            t_hit = hits[i];
            if (!ShipIdentification.IsThisShip(t_hit.transform, shot.friend))
            {
                t_distance = t_hit.distance;
                if (t_distance < distance)
                {
                    nearesthit = t_hit;
                    distance   = t_distance;
                }
            }
        }
        hit = nearesthit;
        return(true);
    }
Пример #4
0
 public bool IsListener(Transform transform)
 {
     return(ShipIdentification.IsThisShip(transform, listener));
 }
Пример #5
0
    public override void SlowUpdate()
    {
        base.SlowUpdate();

        ski.Update();
        if (Input.GetKeyDown(KeyCode.F12))
        {
            ui.ShowHide();
        }
        if (Input.GetMouseButtonDown(3))
        {
            if (lockCamera)
            {
                watcher.sensetive = Vector2.one;
            }
            lockCamera = !lockCamera;
        }
        if (lockCamera)
        {
            SetAim(new Vector2(Mathf.Clamp(aimPoint.x + UInput.RotateX() * .02f / Screen.width * Screen.height, .1f, .9f), Mathf.Clamp(aimPoint.y + UInput.RotateY() * -.02f / Screen.height * Screen.width, .1f, .9f)));
            watcher.sensetive = new Vector2(Mathf.Abs(aimPoint.x - .5f) / .4f, Mathf.Abs(aimPoint.y - .5f) / .4f);
            watcher.sensetive = Vector2.Scale(watcher.sensetive, watcher.sensetive);
        }

        bFire   = UInput.Fire() != 0 || everyTimeFire;
        bRotate = UInput.Fire2() != 0 || everyTimeRotate;

        watcher.Update(); // rotate camera manually because else it does bad
        ui.Update();      // Same reason as ^
        moveDirection = camera.transform.rotation;

        firePoints.Clear();

        var point = new Vector3(Screen.width * aimPoint.x, Screen.height * aimPoint.y);

        var ray = camera.ScreenPointToRay(point);

        Debug.DrawRay(ship.tempTransform.position, BattleBehaviour.current.navigation.GetMovePoint(ship.tempTransform.position, ship.tempTransform.position + ray.direction * 10000) - ship.tempTransform.position, Color.blue);
        RaycastHit hit;

        if (Physics.SphereCastAll(ray, 10f, 100000).WithMin(h => (h.point - camera.transform.position).sqrMagnitude, h => !ShipIdentification.IsThisShip(h.transform, ship), out hit))
        {
            float distance = Vector3.Distance(hit.point, ship.transform.position);
            if (UInput.Fire() != 0)
            {
                firePoints.AddPoint(hit.point);
            }
            var si = hit.transform.GetComponentInParent <ShipIdentification>();
            if (si != null)
            {
                var s = si.ship;

                if (!s.alive)
                {
                    ui.GetAim().SetTarget(AimTarget.Neutral, distance);
                }
                else if (s.team != ship.team)
                {
                    ui.GetAim().SetTarget(AimTarget.Enemy, distance);
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        lockedEnemy = s;
                    }
                }
                else
                {
                    ui.GetAim().SetTarget(AimTarget.Friend, distance);
                }
            }
            else
            {
                ui.GetAim().SetTarget(AimTarget.Neutral, distance);
            }
        }
        else
        {
            ui.GetAim().SetTarget(AimTarget.None, 0);
        }

        if (lockedEnemy != null && lockedEnemy.alive)
        {
            firePoints.AddPoint(lockedEnemy.tempTransform.position);
        }
        uiBehaviour.targetView.SetTargets(firePoints.GetFirePoints().Select(p => p.point));

        SetAim();


        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            everyTimeFire = !everyTimeFire;
        }
        if (Input.GetKeyDown(KeyCode.LeftAlt))
        {
            everyTimeRotate = !everyTimeRotate;
        }
    }