コード例 #1
0
    void UpdateAgents()
    {
        TroopBase[] troops = TroopManager.GetTroops(NetworkController.CurrentPlayerId);
        troopFogAgents = new FogAgent[troops.Length];

        for (int i = 0; i < troops.Length; i++)
        {
            TroopBase troop = troops[i];
            troopFogAgents[i] = new FogAgent(troop.transform, troop.sightRadius * 2);
        }

        foreach (FogAgent fogAgent in fogAgents)
        {
            fogAgent.Update();
        }
    }
コード例 #2
0
    void Select()
    {
        if (!Input.GetKey(Layer.addToSelectionKey1) && !Input.GetKey(Layer.addToSelectionKey2))
        {
            DeselectAll();
        }

        TroopBase[] troops = TroopManager.GetTroops(NetworkController.CurrentPlayerId);

        if (selectionRect.size.magnitude <= minBoxSize)
        {
            Ray        selectionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit selectionRayInfo;

            if (Physics.Raycast(selectionRay, out selectionRayInfo))
            {
                TroopBase troop = selectionRayInfo.collider.GetComponent <TroopBase>();

                if (troop != null && troop.playerId == NetworkController.CurrentPlayerId)
                {
                    troop.Selected = true;

                    if (!Layer.selectedTroops.Contains(troop))
                    {
                        Layer.selectedTroops.Add(troop);
                    }
                }
            }
        }
        else
        {
            foreach (TroopBase troop in troops)
            {
                Vector3 troopScreenPosition = Camera.main.WorldToScreenPoint(troop.transform.position);
                troopScreenPosition.y = Screen.height - troopScreenPosition.y;

                if (selectionRect.Contains(troopScreenPosition, true))
                {
                    troop.Selected = true;
                    Layer.selectedTroops.Add(troop);
                }
            }
        }
    }