コード例 #1
0
    public IEnumerator ShowBuildingShade(EBuildingType eBuildingType)
    {
        m_bDraggingBuildingShade = true;

        for (int i = 0; i < m_pBuildingShadesPrefabs.Count; i++)
        {
            if (m_pBuildingShadesPrefabs[i].m_eType == eBuildingType)
            {
                m_pCurrentBuildingShade = Instantiate<BuildingShade>(m_pBuildingShadesPrefabs[i]);
                m_pCurrentBuildingShade.transform.SetParent(transform, false);
                break;
            }
        }

        if (m_pCurrentBuildingShade == null)
        {
            Debug.LogError("BuildingShade not found: " + eBuildingType);
            yield break;
        }

        RaycastHit tHit;

        do
        {
            if (m_pCurrentBuildingShade == null)
                yield break;

            Ray tRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(tRay, out tHit, 100.0f, LayersManager.Instance.GetLayer("Ground"), QueryTriggerInteraction.Ignore))
            {
                m_pCurrentBuildingShade.gameObject.SetActive(true);
                m_pCurrentBuildingShade.transform.position = tHit.point;
            }
            else
            {
                m_pCurrentBuildingShade.gameObject.SetActive(false);
            }

            yield return false;
        } while (!Input.GetButtonDown("Submit") || !m_pCurrentBuildingShade.CanBePlaced);

        DestroyCurrentShade();

        for (int i = 0; i < m_pBuildingsPrefabs.Count; i++)
        {
            if (m_pBuildingsPrefabs[i].m_eBuildingType == eBuildingType)
            {
                Building pNewBuilding = Instantiate<Building>(m_pBuildingsPrefabs[i]);
                pNewBuilding.transform.SetParent(transform, false);
                pNewBuilding.transform.position = tHit.point;
                break;
            }
        }

        m_bDraggingBuildingShade = false;
    }
コード例 #2
0
 void DestroyCurrentShade()
 {
     Destroy(m_pCurrentBuildingShade.gameObject);
     m_pCurrentBuildingShade = null;
 }