예제 #1
0
    void TryBuild()
    {
        if (buildQueue.Count == 0)
        {
            return;
        }
        if (building)
        {
            return;
        }
        ExoFabBuildInformation bi = buildQueue[0].BuildInformation;

        foreach (var cost in bi.costs)
        {
            if (resources[cost.resource] < cost.amount)
            {
                return;
            }
        }
        foreach (var cost in bi.costs)
        {
            resources[cost.resource] -= cost.amount;
        }
        UpdateResourceVisual();
        StartCoroutine(Build());
    }
예제 #2
0
    public void AddToQueue(ExoFabBuildInformation buildInformation)
    {
        GameObject buildGO = Instantiate(buildButtonPrefab, buildQueueContainer);;

        RectTransform buildRT = buildGO.GetComponent <RectTransform>();

        buildRT.localPosition = Vector3.zero;
        buildRT.localRotation = Quaternion.identity;

        ExoFabBuildButton build = buildGO.GetComponent <ExoFabBuildButton>();

        buildQueue.Add(build);
        build.BuildInformation = buildInformation;
        UpdateQueueIndexes();

        TryBuild();
    }
예제 #3
0
    IEnumerator Build()
    {
        building = true;
        noiseAudioSource.Play();
        ExoFabBuildInformation buildInformation = buildQueue[0].BuildInformation;

        SetupDisplayModel(buildInformation.displayModel);
        MeshRenderer displayRenderer = displayModel.GetComponent <MeshRenderer>();

        for (float t = 0; t < buildInformation.buildTime; t += Time.deltaTime)
        {
            float p = t / buildInformation.buildTime;
            buildQueue[0].Progress = p;
            displayRenderer.material.SetFloat("_ConstructY", p);
            yield return(null);
        }
        Instantiate(buildInformation.prefab, spawnPosition.transform.position, Quaternion.identity);
        Delete(0);
        noiseAudioSource.Stop();
        displayModel.mesh = null;
        building          = false;
        TryBuild();
    }