Exemplo n.º 1
0
    public void TakeDamage(int p_input)
    {
        _health -= p_input;
        if (_health <= 0)
        {
            SceneManager   t_sceneManager   = SceneManager.Instance;
            DataReferences t_dataReferences = t_sceneManager.DataReferences;

            Destroy(gameObject);
            TreeInfo t_treeInfoArray = t_dataReferences.FindElement <TreeInfo>("TREE_DATA");
            t_treeInfoArray.Save();
        }
    }
    IEnumerator PlaceTrees(Orientation p_orientation, Transform p_position)
    {
        LoadingscreenManager t_loadingscreenManager = LoadingscreenManager.Instance;
        UIManager            t_uiManager            = UIManager.Instance;
        TreeInfo             t_treeInfoArray        = null;

        if (_dataReferences != null)
        {
            t_treeInfoArray = _dataReferences.FindElement <TreeInfo>(_treeDataArrayID);
        }
        if (t_treeInfoArray == null && _dataReferences != null)
        {
            _dataReferences.AddElement <TreeInfo>(_treeDataArrayID);
            t_treeInfoArray = _dataReferences.FindElement <TreeInfo>(_treeDataArrayID);
        }

        if (t_loadingscreenManager != null)
        {
            t_loadingscreenManager.OpenLoadingscreen("Generating World.");
        }

        for (int i = 0; i < _treeGen.amount; i++)
        {
            if (i % (_treeGen.amount / 25) == 0 && i != 0)
            {
                yield return(new WaitForSecondsRealtime(0.01f));
            }

            if (t_loadingscreenManager != null)
            {
                t_uiManager.LoadingBar.value = t_uiManager.LoadingBar.maxValue * i / _treeGen.amount;
            }

            GameObject t_tree       = _treeGen.obj[UnityEngine.Random.Range(0, _treeGen.obj.Length)];
            Vector2    t_spawnPosV2 = UnityEngine.Random.insideUnitCircle * _treeGen.radius;
            Vector3    t_spawnPos   = new Vector3(t_spawnPosV2.x, 0, t_spawnPosV2.y);
            Vector3    t_offset     = p_position.position + t_spawnPos;

            Vector3 t_axis = new Vector3();
            if (p_orientation == Orientation.Up)
            {
                t_axis = Vector3.up;
            }
            if (p_orientation == Orientation.Down)
            {
                t_axis = Vector3.down;
            }

            RaycastHit t_hit;
            if (Physics.Raycast(t_offset, t_axis, out t_hit))
            {
                Vector3 t_finalSpawnPos = t_hit.point;
                if (!t_hit.collider.CompareTag("Tree") && !t_hit.collider.CompareTag("Rock"))
                {
                    _trees.Add(Instantiate(t_tree, t_finalSpawnPos, Quaternion.identity));
                    if (t_treeInfoArray != null)
                    {
                        t_treeInfoArray.Trees.Add(new Tree(t_finalSpawnPos, Quaternion.identity, t_tree));
                    }
                }
            }
        }

        if (t_treeInfoArray != null)
        {
            t_treeInfoArray.Save();
        }
        if (t_loadingscreenManager != null)
        {
            t_loadingscreenManager.CloseLoadingscreen();
        }
        yield return(null);
    }