Exemplo n.º 1
0
        private void SpawnObject(Vector3 spawnPoint)
        {
            if (Spawning == null || ghostObject == null || ghostObject.ghostData.okayToPlace == false)
            {
                return;
            }

            Debug.Log($"Spawning {Spawning.name} at {spawnPoint}");

            if (GameHandler.instance.Money < Spawning.pVal)
            {
                NotificationManager.instance.ShowNotification($"You don't have enought money for that!\n${Spawning.pVal}");

                return;
            }

            if (worldObjectParent == null)
            {
                worldObjectParent = GameObject.Find("Building");

                if (worldObjectParent == null)
                {
                    worldObjectParent = new GameObject("Building");
                }
            }

            Color newColor = (Spawning.ChangableColor) ? PlacingColor : Spawning.color;

            GameObject spawnedObject = Constructor.GetObject(Constructor.CloneObjectData(Spawning, spawnPoint, ghostObject.transform.rotation, newColor), worldObjectParent.transform);

            if (ghostObject.ghostData.overlapping != null)
            {
                if (ghostObject.ghostData.overlapping[ghostObject.ghostData.overlapping.Length - 1].objectData.type == ObjectType.Abstract)
                {
                    MapLayoutManager.ReplaceTileInDictionary(spawnPoint, spawnedObject);
                }
            }

            GameHandler.instance.Money -= Spawning.pVal;

            Debug.Log($"Spawned {Spawning.name} at {spawnPoint}");
        }
Exemplo n.º 2
0
        public IEnumerator LoadGame(int index)
        {
            yield return(null);

            ActivePlayerData = savesData[index];

            Money    = ActivePlayerData.money;
            saveName = ActivePlayerData.userName;

            TimeScale.minutes = ActivePlayerData.minute;
            TimeScale.hours   = ActivePlayerData.hour;
            TimeScale.days    = ActivePlayerData.day;

            yield return(null);

            // Destroy existing workers
            var workersObjects = instance.workers.ToArray();

            for (int i = workersObjects.Length - 1; i >= 0; i--)
            {
                Destroy(workersObjects[i].gameObject);
            }

            yield return(null);

            // -----------------Load workers---------------

            SaveManager.SavableObject.Worker[] loadedWorkers;
            SaveManager.LoadWorkers(ActivePlayerData.userName, out loadedWorkers);

            if (loadedWorkers == null || loadedWorkers.Length == 0)
            {
                Debug.Log("No workers to load!");
            }
            else
            {
                foreach (var data in loadedWorkers)
                {
                    if (data == null)
                    {
                        continue;
                    }

                    Constructor.GetWorker(data);
                }
            }

            yield return(null);

            // -----------------Load objects---------------
            foreach (var item in FindObjectsOfType <PlacedObject>())
            {
                Destroy(item.gameObject);
            }

            SaveManager.SavableObject.WorldObject[] objects;

            SaveManager.LoadAllObjects(ActivePlayerData.userName, out objects);

            if (objects == null || objects.Length == 0)
            {
                Debug.Log("No objects to load!");
            }
            else
            {
                foreach (var data in objects)
                {
                    if (data == null)
                    {
                        continue;
                    }

                    MapLayoutManager.ReplaceTileInDictionary(data.position, Constructor.GetObject(data));
                }
            }

            yield return(null);

            NotificationManager.instance.ShowNotification("Game Loaded!");
        }