Ejemplo n.º 1
0
 public bool contains(fRectangle other)
 {
     return(m_left <= other.m_right &&
            m_right >= other.m_left &&
            m_top >= other.m_bottom &&
            m_bottom <= other.m_top);
 }
Ejemplo n.º 2
0
    private void Start()
    {
        Assert.IsNotNull(m_selectionBox);
        m_selectionBox.SetActive(false);

        m_AABB = new fRectangle(transform.position, transform.localScale);
    }
Ejemplo n.º 3
0
    public void selectUnits(fRectangle selectionBox)
    {
        foreach (Unit unit in m_units)
        {
            Selection unitSelection = unit.gameObject.GetComponent <Selection>();
            Assert.IsNotNull(unitSelection);

            unitSelection.Select(selectionBox);
        }
    }
Ejemplo n.º 4
0
 public void Select(fRectangle selectionBox)
 {
     if (selectionBox.contains(m_AABB))
     {
         m_selectionBox.SetActive(true);
     }
     else
     {
         m_selectionBox.SetActive(false);
     }
 }
Ejemplo n.º 5
0
    public void switchToState(eHarvesterState newState, BoidSpawner boidSpawner = null)
    {
        m_harvesterState = newState;
        m_currentState   = eUnitState.InUseBySecondaryState;
        m_targetID       = Utilities.INVALID_ID;

        switch (newState)
        {
        case eHarvesterState.SetBoidSpawner:
        {
            Assert.IsNotNull(boidSpawner);

            m_harvester.m_boidSpawner = boidSpawner;
        }
        break;

        case eHarvesterState.TargetAvailableBoid:
        {
            Assert.IsNotNull(m_harvester.m_boidSpawner);

            m_harvester.m_targetBoid = m_harvester.m_boidSpawner.getAvailableBoid(m_unit.getID());
            if (m_harvester.m_targetBoid)
            {
                m_tankMovement.moveTo(m_harvester.m_targetBoid.transform.position);
                m_harvesterState    = eHarvesterState.MovingToTargetedBoid;
                m_findAvailableBoid = false;
            }
            else
            {
                m_findAvailableBoid = true;
            }
        }
        break;

        case eHarvesterState.SetDestinationResourceBuilding:
        {
            Assert.IsNotNull(m_harvester.m_buildingToReturnResource);

            fRectangle AABB = m_harvester.m_buildingToReturnResource.GetComponent <Selection>().getAABB();
            m_tankMovement.moveTo(
                Utilities.getClosestPositionOutsideAABB(AABB, transform.position,
                                                        m_harvester.m_buildingToReturnResource.transform.position, m_harvester.m_destinationOffSetHQ));

            m_harvesterState = eHarvesterState.MovingToResourceBuilding;
        }
        break;
        }
    }
Ejemplo n.º 6
0
    static public Vector3 getClosestPositionOutsideAABB(fRectangle AABB, Vector3 unitPosition, Vector3 centrePosition, float offSet)
    {
        Assert.IsNotNull(AABB);

        Vector3 direction = (unitPosition - centrePosition).normalized;
        Vector3 position  = centrePosition;
        int     distance  = 1;

        while (AABB.contains(position))
        {
            position += direction * distance;
        }
        position += direction * offSet;

        return(new Vector3(position.x, 1, position.z));
    }
Ejemplo n.º 7
0
    static public Vector3 getRandomPositionOutsideAABB(fRectangle AABB, Vector3 centrePosition, float offSet)
    {
        Assert.IsNotNull(AABB);

        Vector3 direction = new Vector3(Random.Range(-1.0f, 1.0f), 1, Random.Range(-1.0f, 1.0f)).normalized;
        Vector3 position  = centrePosition;
        int     distance  = 1;

        while (AABB.contains(position))
        {
            position += direction * distance;
        }
        position += direction * offSet;

        return(new Vector3(position.x, 1, position.z));
    }
Ejemplo n.º 8
0
    private void onLeftClick()
    {
        if (Input.GetMouseButtonDown(0) && !m_leftButtonHeld)
        {
            m_player.deselectAllUnits();

            Ray        ray = m_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << 10)) && hit.collider.tag == "Ground")
            {
                m_mousePressedPosition = hit.point;
            }
            else if (Physics.Raycast(ray, out hit) && hit.collider.tag == "PlayerBuilding")
            {
                m_player.selectBuilding(hit.point);
                return;
            }

            m_leftButtonHeld    = true;
            m_selectionBoxClone = Instantiate(m_selectionBoxPrefab, hit.point, Quaternion.identity);
            m_selectionBoxClone.transform.position = m_mousePressedPosition;
        }

        else if (m_leftButtonHeld)
        {
            Ray        ray = m_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << 10)) && hit.collider.tag == "Ground")
            {
                Assert.IsNotNull(m_selectionBoxClone);
                m_selectionBoxClone.transform.localScale = hit.point - m_mousePressedPosition;
                m_selectionBoxClone.transform.localScale =
                    new Vector3(m_selectionBoxClone.transform.localScale.x, m_selectionBoxHeight, m_selectionBoxClone.transform.localScale.z);
                m_selectionBoxClone.transform.position = m_mousePressedPosition + (hit.point - m_mousePressedPosition) / 2.0f;

                fRectangle selectionBoxAABB = new fRectangle(m_selectionBoxClone.transform.position, m_selectionBoxClone.transform.localScale);
                m_player.selectUnits(selectionBoxAABB);
            }

            if (Input.GetMouseButtonUp(0))
            {
                clearSelectionBox();
            }
        }
    }
Ejemplo n.º 9
0
 private void setRectangle(Rectangle levelBounds)
 {
     backgroundRect = new fRectangle(new Vector2(levelBounds.X - Offset, levelBounds.Y - Offset), levelBounds.Width + (Offset * 2), levelBounds.Height + (Offset* 2));
 }