// Use this for initialization
 void Start()
 {
     recordCollection = new BlockRecordCollection();
     //DaggerfallUnity.Instance = DaggerfallUnity.Instance;
     //if (runTest)
     //StartCoroutine(Test());
 }
        /// <summary>
        /// Test function.  Builds list of block records, writes to XML & reads it back in.
        /// </summary>
        /// <returns></returns>
        IEnumerator Test()
        {
            Debug.Log("Waiting on dfUnity...");
            while (!dfUnity.IsReady)
            {
                yield return(new WaitForEndOfFrame());
            }

            Debug.Log("Finished waiting");
            bool check = false;

            recordCollection = new BlockRecordCollection();
            check            = BuildRecordList(out recordCollection.blockRecords);
            Debug.Log("BuildRecordList returned: " + check);
            if (check)
            {
                check = WriteBlockData(
                    recordCollection.FilterBlocks(DFBlock.BlockTypes.Rdb),
                    defaultFileName, FileMode.Create);

                Debug.Log("WriteBlockData returned: " + check);
            }
            if (check)
            {
                check = ReadBlockData(out recordCollection.blockRecords, defaultFileName);
                Debug.Log("ReadBlockData returned: " + check);
            }

            Debug.Log("Finished Test");
            yield break;
        }
 public bool WriteBlockData(BlockRecordCollection collection, string fileName = "BlockRecordExport.xml", FileMode writeMode = FileMode.CreateNew)
 {
     try
     {
         return(WriteBlockData(collection.blockRecords, fileName, writeMode));
     }
     catch (Exception ex)
     {
         Debug.LogError(ex.Message);
         return(false);
     }
 }
        public bool ReadBlockData(out BlockRecordCollection collection, string fileName, FileMode readMode = FileMode.Open)
        {
            collection = new BlockRecordCollection();

            try
            {
                ReadBlockData(out collection.blockRecords, fileName, readMode);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
                return(false);
            }

            return(true);
        }
        public bool StartUp()
        {
            if (!DaggerfallUnity.Instance.IsReady)
            {
                StartCoroutine(ReadyCheck());
            }

            if (seed != 0)
            {
                UnityEngine.Random.seed = seed;
            }

            dimension       = DaggerfallWorkshop.Utility.RDBLayout.RDBSide;
            blocks          = new List <BlockRecord>();
            blockCollection = new BlockRecordCollection();

            shifts = new Vector2[]
            {
                new Vector2(dimension, 0),
                new Vector2(-dimension, 0),
                new Vector2(0, dimension),
                new Vector2(0, -dimension)
            };


            numOfExits     = Mathf.Min(numOfInternalBlocks, numOfExits);
            distanceLookup = new Dictionary <Vector2, float>();

            if (!GetBlockList())                //failed to get list of RDB blocks
            {
                Debug.LogError("Failed to get block list, stopping");
                this.enabled = false;
                isReady      = false;
            }
            isReady = true;
            return(isReady);
        }
 void OnDestroy()
 {
     recordCollection = null;
     serializer       = null;
     stream           = null;
 }
 public bool BuildRecordList(out BlockRecordCollection collection)
 {
     collection = new BlockRecordCollection();
     return(BuildRecordList(out collection.blockRecords));
 }