Beispiel #1
0
        private void Clear()
        {
            if (ClipboardBoard == null)
            {
                return;
            }

            MegaBoardMeshManager.RemoveBoardsFrom(ClipboardBoard);
            MegaMesh.RemoveMeshesFrom(ClipboardBoard);
            Object.Destroy(ClipboardBoard);
            ClipboardBoard = null;
        }
Beispiel #2
0
        public GameObject Board(int width, int height,
                                Vector3 position, Quaternion rotation, Transform parent = null)
        {
            GameObject   board   = UnityEngine.Object.Instantiate(boardPlacer.BoardPrefab, position, rotation, parent);
            CircuitBoard circuit = board.GetComponent <CircuitBoard>();

            circuit.x = width;
            circuit.z = height;
            circuit.CreateCuboid();
            StuffPlacer.DestroyIntersectingConnections(board);
            DestroyInvalidWiresOnBoard(board);
            MegaMesh.AddMeshesFrom(board);
            MegaBoardMeshManager.AddBoardsFrom(board);
            SetChildCircuitsMegaMeshStatus(board, true);
            return(board);
        }
        /// <summary>
        /// Load coroutine, yields every now and then to delay
        /// loading
        /// </summary>
        private static IEnumerator LoadCoroutine()
        {
            loading = true;
            Stopwatch watch = new Stopwatch();

            watch.Start();
#if DEBUG
            IGConsole.Log($"Loading better save {GetSavePath()}");
#endif

            FileStream      fs        = new FileStream(GetSavePath(), FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();

            PlayerPosition player;
            Datum[]        data;
            try
            {
                player = formatter.Deserialize(fs) as PlayerPosition;
                data   = formatter.Deserialize(fs) as Datum[];
            }
            catch (Exception e)
            {
                IGConsole.Error($"Loading failed with {e.ToString()}");
                yield break;
            }
            finally
            {
                fs.Close();
            }
#if DEBUG
            IGConsole.Log($"Length of data {data.Length}");
#endif
            foreach (SaveThisObject obj in UnityEngine.Object.FindObjectsOfType <SaveThisObject>())
            {
                UnityEngine.Object.Destroy(obj.gameObject);
            }
            BehaviorManager.AllowedToUpdate = false;
            MegaBoardMeshManager.MegaBoardMeshesOfColor.Clear();
            SetPlayerPosition(player);
            int size = data.Length;
            maxProgress = size;
            for (int index = 0; index < size; index++)
            {
                Loader.Instantiate(data[index]);
                if ((index + 1) % instancesPerFrame == 0)
                {
                    progress = index;
                    yield return(new WaitForEndOfFrame());
                }
            }
            SaveManager.RecalculateAllClustersEverywhereWithDelay();
            MegaMesh.GenerateNewMegaMesh();
            MegaBoardMeshManager.GenerateAllMegaBoardMeshes();
            watch.Stop();
            loading = false;
            if (UIManager.SomeOtherMenuIsOpen)
            {
                SaveManager.SaveAll();
            }
            IGConsole.Log($"Loaded save in {watch.Elapsed.ToString()}");
        }