Exemplo n.º 1
0
    void Update()
    {
        if (Game.getInspectMode() && Time.time - Game.getObjClickClose().getTimeBuildClick() < 0.1f)
        {
            Vector3     localCoords = Game.getObjClickClose().getBuildingClicked().transform.localPosition;
            Transform[] children    = Game.getObjClickClose().getPlanetOfBuilding().GetComponentsInChildren <Transform>();
            List <Ship> objToMove   = Game.getObjClick().getObjHighlighted();

            foreach (Transform child in children)
            {
                if (child.localPosition == localCoords)
                {
                    foreach (Ship ship in objToMove)
                    {
                        ship.startAttack();
                        if (ship.gameObject.TryGetComponent(out FollowingMovingObject foll))
                        {
                            foll.setNewObject(child.gameObject);
                        }
                        else
                        {
                            ship.gameObject.AddComponent <FollowingMovingObject>().setNewObject(child.gameObject);
                        }
                    }
                }
            }
        }

        if (!Game.getInspectMode() && (Input.GetMouseButtonDown(1) || (Input.GetMouseButton(1) && Time.time - lastTime > 0.2f)))
        {
            lastTime = Time.time;

            Vector3     gamePos   = ClickCoords.getCords();
            List <Ship> objToMove = Game.getObjClick().getObjHighlighted();

            if (objToMove != null && objToMove.Count != 0)
            {
                foreach (Ship obj in objToMove)
                {
                    Vector3 position = obj.getObj().transform.position;

                    if (Mathf.Abs(position.x - ClickCoords.getX(position, gamePos)) <= 5 && Mathf.Abs(position.y - Game.getMesh().getHeight()) <= 5 &&
                        Mathf.Abs(ClickCoords.getZ(position, gamePos) - position.z) <= 5)
                    {
                        continue;
                    }

                    Vector3 end = new Vector3(ClickCoords.getX(position, gamePos), Game.getMesh().getHeight(), ClickCoords.getZ(position, gamePos));

                    if (obj.gameObject.TryGetComponent(out FollowingMovingObject foll))
                    {
                        foll.setNewObject(null);
                    }
                    obj.changeDest(end);
                    calcRoute(obj, end, 100);
                }
            }
        }
    }
Exemplo n.º 2
0
 public ColumnsView()
 {
     LastClick = new ClickCoords()
     {
         level = -1, column = -1
     };
     InitializeComponent();
     this.MinimumSize = new Size(minimumColumnWidth + infoColumnWidth, 500);
 }
Exemplo n.º 3
0
    private void HighlightMulti(Vector3 start, Vector3 end)
    {
        float xSmall, xBig, ySmall, yBig;

        xSmall = Mathf.Min(start.x, end.x);
        xBig   = Mathf.Max(start.x, end.x);
        ySmall = Mathf.Min(start.z, end.z);
        yBig   = Mathf.Max(start.z, end.z);

        foreach (Ship ship in Game.getShips())
        {
            Vector3 pos = ship.getObj().transform.position;
            float   xs, xb, ys, yb;
            xs = ClickCoords.getXSpec(pos, new Vector3(xSmall, 0f, yBig));
            xb = ClickCoords.getXSpec(pos, new Vector3(xBig, 0f, ySmall));
            ys = ClickCoords.getZSpec(pos, new Vector3(xBig, 0f, ySmall));
            yb = ClickCoords.getZSpec(pos, new Vector3(xSmall, 0f, yBig));
            if (pos.x <= xb && pos.x >= xs && pos.z <= yb && pos.z >= ys && ship.isFriendly())
            {
                highlight(ship.getObj(), true);
            }
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        float timeBetween = Time.time - timer;

        if (Input.GetMouseButtonDown(1) && Game.getInspectMode())
        {
            GameObject clicked = ShootLaser(Game.getCameraNow().ScreenPointToRay(Input.mousePosition), false);
            if (clicked != null && clicked.GetComponent <Clickable>().isBuilding())
            {
                highlight(clicked, false);
                timeBuildClicked = Time.time;
                buildingClicked  = clicked;
            }
        }
        if (Input.GetMouseButtonDown(1) && !Game.getInspectMode())
        {
            GameObject clicked = ShootLaser(Game.getCameraNow().ScreenPointToRay(Input.mousePosition), true);
            if (clicked != null && clicked.GetComponent <Clickable>().isPlanet() && isEmpty())
            {
                Planet planet = clicked.GetComponent <Planet>();
                Game.getSwitchCamera().makeMiniCamera(planet);
            }
            else if (clicked != null && clicked.GetComponent <Clickable>().isShip() && !clicked.GetComponent <Ship>().isFriendly())
            {
                //Ship clickedShip = clicked.GetComponent<Ship>();
                foreach (Ship ship in objHighlighted)
                {
                    if (ship.TryGetComponent(out FollowingMovingObject follow))
                    {
                        follow.setNewObject(clicked);
                    }
                    else
                    {
                        ship.gameObject.AddComponent <FollowingMovingObject>().setNewObject(clicked);
                    }
                }
            }
        }

        if (Game.getInspectMode())
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            onWatch      = ShootLaser(Game.getCameraNow().ScreenPointToRay(Input.mousePosition), true);
            startCoursor = ClickCoords.getCords();
            // double click on a planet moves game to designated scene
            if (timeBetween <= 0.2f)
            {
                if (onWatch != null && onWatch.GetComponent <Clickable>().isPlanet())
                {
                    Planet planet = onWatch.GetComponent <Planet>();
                    Game.getSwitchCamera().SwitchCamera(planet);
                }
            }
            timer    = Time.time;
            pixStart = Input.mousePosition;
        }
        else if (Input.GetMouseButton(0) && timeBetween >= 0.2f)
        {
            drawBox    = true;
            endCoursor = ClickCoords.getCords();
            pixEnd     = Input.mousePosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (timeBetween < 0.2f)
            {
                if (onWatch != null && onWatch.GetComponent <Clickable>().isShip() && onWatch.GetComponent <Ship>().isFriendly())
                {
                    highlight(onWatch, true);
                }
            }
            else
            {
                drawBox = false;
                HighlightMulti(startCoursor, endCoursor);
            }
        }
    }