예제 #1
0
    public void StopDragging(Vector2 dragAmount, Vector2 dragPos)
    {
        Vector3    pos       = new Vector3(dragPos.x, dragPos.y);
        Ray        cameraRay = Camera.main.ScreenPointToRay(pos);
        LayerMask  uiMask    = 1 << LayerMask.NameToLayer("UI");
        RaycastHit hit;

        if (Physics.Raycast(cameraRay, out hit, 1000, uiMask))
        {
            FormationSlot slot = hit.transform.GetComponent <FormationSlot>();
            if (dragging)
            {
                if (slot)
                {
                    slot.HandoffUnit(dragging.gameObject, dragTarget.GetFormation());
                }
                else
                {
                    Instantiate(cubeSparklePrefab, dragging.transform.position, Quaternion.identity);
                    Destroy(dragging.gameObject);
                }
            }
        }
        else
        {
            if (dragging)
            {
                Instantiate(cubeSparklePrefab, dragging.transform.position, Quaternion.identity);
                Destroy(dragging.gameObject);
            }
        }
        dragTarget     = null;
        dragging       = null;
        isDraggingList = false;
    }
예제 #2
0
    void Start()
    {
        homePos = transform.localPosition;

        cameraControl = Camera.main.transform.root.GetComponent <CameraControl>();
        cameraControl.SetCameraMode(CameraControl.Mode.EditRedTeam);

        eventSystem = EventSystem.current;
        screenSize  = new Vector2(Screen.width, Screen.height);
        spawner     = GameObject.Find("Spawner").GetComponent <FormationSpawner>();

        Formations.formation[] allFormations = Formations.allFormations;
        markers = new List <Transform>();
        slots   = new List <Transform>();
        for (int i = 0; i < 18; i++)
        {
            Transform marker = transform.Find(string.Format("Slot{0}", i.ToString("D2")));
            markers.Add(marker);
            marker.GetComponent <Renderer>().enabled = false;
        }

        for (int i = 0; i < allFormations.Length; i++)
        {
            Transform  marker      = markers[Mathf.Clamp(i, 0, markers.Count - 1)];
            GameObject newUnitSlot = Instantiate(unitSlotPrefab, marker.position, marker.rotation) as GameObject;
            newUnitSlot.transform.SetParent(transform);
            newUnitSlot.transform.localScale = Vector3.one;
            slots.Add(newUnitSlot.transform);
            newUnitSlot.GetComponent <UnitSelectorSlot>().Init(allFormations[i], spawner);
        }

        int gridSize      = 4;
        int formationSize = 8;

        for (int x = 0; x < gridSize; x++)
        {
            for (int y = 0; y < 4; y++)
            {
                float      xPos   = (x * formationSize) - (formationSize * (gridSize - 1) / 2);
                float      yPos   = (y * formationSize) - (formationSize * (gridSize - 1) / 2);
                Vector3    newPos = spawnGridOrigin.position + new Vector3(xPos, 0.25f, yPos);
                Quaternion newRot = Quaternion.identity;
                if (team == Team.Blue)
                {
                    newRot = Quaternion.AngleAxis(180, Vector3.up);
                }

                GameObject    newFormationSlot = Instantiate(formationSlotPrefab, newPos, newRot) as GameObject;
                FormationSlot slotControl      = newFormationSlot.GetComponent <FormationSlot>();
                slotControl.SetUnitSelector(this);
            }
        }
        listScrollGoal = markers.Count / 4;

        SetScreenWidth();
    }