Example #1
0
    private void Update()
    {
        _sceneManager = SceneManager.Instance;
        if (_sceneManager != null)
        {
            _dataReferences = _sceneManager.DataReferences;
        }

        StartCoroutine(SelectPlayer());

        if (_buildingUI.activeSelf == true)
        {
            ResourceManager t_resourceManager = ResourceManager.Instance;
            if (Input.GetKeyDown(KeyCode.B) && t_resourceManager.Wood >= 500 && t_resourceManager.Rock >= 500)
            {
                PlaceBuilding();
                t_resourceManager.Wood -= 500;
                t_resourceManager.Rock -= 500;

                var t_resourceInfo = _dataReferences.FindElement <ResourceInfo>("RESOURCE_DATA");
                t_resourceInfo.Wood = t_resourceManager.Wood;
                t_resourceInfo.Rock = t_resourceManager.Rock;
                t_resourceInfo.Save();
            }
        }
    }
    private IEnumerator MoveTowards(Ray p_ray)
    {
        RaycastHit t_hit;

        if (Physics.Raycast(p_ray, out t_hit, _layerMask))
        {
            Vector3 targetPostition = new Vector3(t_hit.point.x, t_hit.point.y, t_hit.point.z);
            transform.LookAt(targetPostition);

            yield return(new WaitForSeconds(.1f));

            while (true)
            {
                GetComponent <LineRenderer>().SetPosition(0, transform.position);
                GetComponent <LineRenderer>().SetPosition(1, t_hit.point);

                transform.Translate(transform.forward / .2f * Time.deltaTime, Space.World);

                Ray        t_ray = new Ray(transform.position, transform.forward);
                RaycastHit t_hitJump;
                if (Physics.Raycast(t_ray, out t_hitJump, 1.5f))
                {
                    GetComponent <Rigidbody>().AddForce(transform.up * 2000);
                }

                _canMove = false;

                if (Vector3.Distance(transform.position, t_hit.point) <= 10)
                {
                    transform.position = Vector3.MoveTowards(transform.position, t_hit.point, 5f * Time.deltaTime);
                }

                yield return(new WaitForSeconds(.01f));

                if ((int)transform.position.x == (int)t_hit.point.x && (int)transform.position.z == (int)t_hit.point.z)
                {
                    GetComponent <LineRenderer>().enabled = false;
                    SceneManager   t_sceneManager   = SceneManager.Instance;
                    DataReferences t_dataReferences = t_sceneManager.DataReferences;

                    for (int i = 0; i < t_dataReferences.FindElement <CollonistInfo>("COLLONIST_DATA").Collonists.Count; i++)
                    {
                        if (t_dataReferences.FindElement <CollonistInfo>("COLLONIST_DATA") != null && t_dataReferences.FindElement <CollonistInfo>("COLLONIST_DATA").Collonists[i].Position == _currentPosition)
                        {
                            _currentPosition = transform.position;
                            t_dataReferences.FindElement <CollonistInfo>("COLLONIST_DATA").Collonists[i].Position = transform.position;
                            t_dataReferences.FindElement <CollonistInfo>("COLLONIST_DATA").Save();
                        }
                    }

                    break;
                }
            }
        }
    }
    private void Start()
    {
        _sceneManager   = SceneManager.Instance;
        _dataReferences = _sceneManager.DataReferences;

        CollonistInfo t_collonistInfoArray = null;

        if (_dataReferences != null)
        {
            t_collonistInfoArray = _dataReferences.FindElement <CollonistInfo>(_collonistDataArrayID);
        }
        if (t_collonistInfoArray != null && _dataReferences != null)
        {
            for (int i = 0; i < _collonists.Length; i++)
            {
                _collonists[i].transform.position = t_collonistInfoArray.Collonists[i].Position;
                _collonists[i].SetActive(true);
                _collonists[i].transform.parent = _collonists[i].transform.parent.parent;

                _collonists[i].GetComponent <CollonistController>().enabled = true;
                _collonists[i].GetComponent <GravityHandler>().enabled      = true;

                Destroy(gameObject);
            }
            _text.enabled = false;
        }
    }
Example #4
0
    private void Start()
    {
        _sceneManager   = SceneManager.Instance;
        _dataReferences = _sceneManager.DataReferences;

        if (_dataReferences != null)
        {
            _resourceInfo = _dataReferences.FindElement <ResourceInfo>(_resourceInfoID);
        }
        if (_resourceInfo == null && _dataReferences != null)
        {
            _dataReferences.AddElement <ResourceInfo>(_resourceInfoID);
            _resourceInfo = _dataReferences.FindElement <ResourceInfo>(_resourceInfoID);
        }
        else
        {
            _wood = _resourceInfo.Wood;
            _rock = _resourceInfo.Rock;
        }
    }
    private void Update()
    {
        Ray        t_ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit t_hit;

        if (Physics.Raycast(t_ray, out t_hit))
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                for (uint i = 0; i < _collonists.Length; i++)
                {
                    transform.position = t_hit.point;
                    _collonists[i].SetActive(true);
                    _collonists[i].transform.parent = _collonists[i].transform.parent.parent;
                    Destroy(gameObject);

                    _collonists[i].GetComponent <CollonistController>().enabled = true;
                    _collonists[i].GetComponent <GravityHandler>().enabled      = true;

                    _text.enabled = false;

                    CollonistInfo t_collonistInfoArray = null;
                    if (_dataReferences != null)
                    {
                        t_collonistInfoArray = _dataReferences.FindElement <CollonistInfo>(_collonistDataArrayID);
                    }
                    if (t_collonistInfoArray == null && _dataReferences != null)
                    {
                        _dataReferences.AddElement <CollonistInfo>(_collonistDataArrayID);
                        t_collonistInfoArray = _dataReferences.FindElement <CollonistInfo>(_collonistDataArrayID);
                    }
                    if (_dataReferences.FindElement <CollonistInfo>(_collonistDataArrayID) != null)
                    {
                        _dataReferences.FindElement <CollonistInfo>(_collonistDataArrayID).Collonists.Add(new Collonist(_collonists[i].transform.position, Quaternion.identity, _prefab));
                    }

                    t_collonistInfoArray.Save();
                }
            }
        }
    }
    private void Setup()
    {
        _dataReferences = SceneManager.Instance.DataReferences;

        _data = _dataReferences.FindElement <DropManagerData>(_id);
        if (_data == null)
        {
            _data = _dataReferences.AddElement <DropManagerData>(_id);
            return;
        }

        LoadDrops();
    }
Example #7
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();
        }
    }
Example #8
0
    public void Setup(string p_id)
    {
        if (p_id == "none")
        {
            return;
        }

        _id = p_id;

        _dataReferences = SceneManager.Instance.DataReferences;

        _data = _dataReferences.FindElement <ItemData>(p_id);
        if (_data == null)
        {
            _data = _dataReferences.AddElement <ItemData>(p_id);
            return;
        }

        LoadAlife();
    }
Example #9
0
    public bool Setup(string p_id)
    {
        if (_id == "none")
        {
            return(false);
        }

        _id = p_id;

        StartCoroutine(ContinuousSave());

        _dataReferences = SceneManager.Instance.DataReferences;

        _data = _dataReferences.FindElement <ExampleData>(_id);
        if (_data == null)
        {
            _data = _dataReferences.AddElement <ExampleData>(_id);
            return(false);
        }

        LoadText();

        return(true);
    }
Example #10
0
    private void Setup()
    {
        _dataReferences = SceneManager.Instance.DataReferences;

        _data = _dataReferences.FindElement <PlayerData>(_id);
        if (_data == null)
        {
            _data = _dataReferences.AddElement <PlayerData>(_id);
            StartCoroutine(SavePlayer());
            return;
        }

        if (_data.Inventory.Count != 0)
        {
            LoadInventory();
        }

        if (_data.Position != null && _data.Rotation != null)
        {
            LoadPlayer();
        }

        StartCoroutine(SavePlayer());
    }
Example #11
0
    private void Command()
    {
        _field.text += _input.text + "\n";

        if (_input.text.Contains(_save))
        {
            string t_saveInput = _input.text.Replace(_save, "");
            t_saveInput = t_saveInput.TrimEnd();
            if (t_saveInput == "")
            {
                _field.text += new NullReferenceException() + "\n";
                return;
            }

            _dataManager.GenerateSave(t_saveInput.ToUpper());
            _input.text  = "";
            _field.text += "Succesfull. \n";
        }
        else if (_input.text == _godmode)
        {
            ResourceManager t_resourceManager = ResourceManager.Instance;
            _field.text           += "Succesfully initiated godmode. \n";
            t_resourceManager.Wood = 100000;
            t_resourceManager.Rock = 100000;

            SceneManager   t_sceneManager   = SceneManager.Instance;
            DataReferences t_dataReferences = t_sceneManager.DataReferences;

            ResourceInfo t_resourceInfo = t_dataReferences.FindElement <ResourceInfo>("RESOURCE_DATA");
            t_resourceInfo.Wood = 100000;
            t_resourceInfo.Rock = 100000;

            t_resourceInfo.Save();
        }
        else if (_input.text == _exit)
        {
            Application.Quit();
        }
        else if (_input.text == _pause)
        {
            UIManager t_uiManager = UIManager.Instance;

            t_uiManager.SetTimeScale(0);
            t_uiManager.ClosePrompt();
            t_uiManager.LockCursor(true);
            t_uiManager.CommandsOpened = !t_uiManager.CommandsOpened;
        }
        else if (_input.text == _unpause)
        {
            UIManager t_uiManager = UIManager.Instance;

            t_uiManager.SetTimeScale(1);
            t_uiManager.ClosePrompt();
            t_uiManager.LockCursor(true);
            t_uiManager.CommandsOpened = !t_uiManager.CommandsOpened;
        }
        else
        {
            _field.text += new InvalidOperationException() + "\n";
        };
    }
    private IEnumerator PlaceRocks(Orientation p_orientation, Transform p_position)
    {
        LoadingscreenManager t_loadingscreenManager = LoadingscreenManager.Instance;
        UIManager            t_uiManager            = UIManager.Instance;
        RockInfo             t_rockInfoArray        = null;

        if (_dataReferences != null)
        {
            t_rockInfoArray = _dataReferences.FindElement <RockInfo>(_rockDataArrayID);
        }
        if (t_rockInfoArray == null && _dataReferences != null)
        {
            _dataReferences.AddElement <RockInfo>(_rockDataArrayID);
            t_rockInfoArray = _dataReferences.FindElement <RockInfo>(_rockDataArrayID);
        }

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

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

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

            GameObject t_tree       = _rockGen.obj[UnityEngine.Random.Range(0, _rockGen.obj.Length)];
            Vector2    t_spawnPosV2 = UnityEngine.Random.insideUnitCircle * _rockGen.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"))
                {
                    _rocks.Add(Instantiate(t_tree, t_finalSpawnPos, Quaternion.identity));
                    if (t_rockInfoArray != null)
                    {
                        t_rockInfoArray.Rocks.Add(new Rock(t_finalSpawnPos, Quaternion.identity, t_tree));
                    }
                }
            }
        }

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