public void OnAfterDeserialize()
        {
            //System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start();

            if (serializedVersion < 10)
            {
                Debug.LogError("MapMagic: trying to load unknow version scene (v." + serializedVersion / 10f + "). " +
                               "This may cause errors or drastic drop in performance. " +
                               "Delete this MapMagic object and create the new one from scratch when possible.");
            }

            //loading old serializer
            if (classes.Length == 0 && serializer.entities.Count != 0)
            {
                serializer.ClearLinks();
                list = (Generator[])serializer.Retrieve(listNum);
                serializer.ClearLinks();

                OnBeforeSerialize();
                serializer = null;                         //will not make it null, just 0-length
            }

            List <string>             classesList = new List <string>();  classesList.AddRange(classes);
            List <UnityEngine.Object> objectsList = new List <UnityEngine.Object>();  objectsList.AddRange(objects);
            List <float> floatsList = new List <float>();  floatsList.AddRange(floats);

            references.Clear();
            list = (Generator[])CustomSerialization.ReadClass(0, classesList, objectsList, floatsList, references);
            references.Clear();

            //timer.Stop(); Debug.Log("Deserialize Time: " + timer.ElapsedMilliseconds + "ms");
        }
Beispiel #2
0
        public static object DeepCopy(object src)
        {
            List <string>             classes = new List <string>();
            List <UnityEngine.Object> objects = new List <UnityEngine.Object>();
            List <float>  floats         = new List <float>();
            List <object> saveReferences = new List <object>();
            List <object> loadReferences = new List <object>();

            int num = CustomSerialization.WriteClass(src, classes, objects, floats, saveReferences);

            return(CustomSerialization.ReadClass(num, classes, objects, floats, loadReferences));
        }
Beispiel #3
0
			void LoadGenerator (Vector2 pos)
			{
				if (MapMagic.instance.guiGens == null) MapMagic.instance.guiGens = MapMagic.instance.gens;	

				string path= UnityEditor.EditorUtility.OpenFilePanel(
						"Import Nodes",
						"", 
						"nodes");
				if (path==null || path.Length==0) return;

				//preparing serialization arrays
				List<string> classes = new List<string>();
				List<UnityEngine.Object> objects = new List<UnityEngine.Object>();
				List<object> references = new List<object>();
				List<float> floats = new List<float>();

				//loading
				System.IO.StreamReader reader = new System.IO.StreamReader(path);
				CustomSerialization.ImportXML(reader.ReadToEnd(), out classes, out objects, out floats);
				Generator[] loadedGens = (Generator[])CustomSerialization.ReadClass(0, classes, objects, floats, references);

				//offset 
				for (int i=loadedGens.Length-1; i>=0; i--) loadedGens[i].guiRect.position += pos;
				

				//GeneratorsAsset loadedGens = (GeneratorsAsset)AssetDatabase.LoadAssetAtPath(path, typeof(GeneratorsAsset));

				/*for (int i=loadedGens.list.Length-1; i>=0; i--)
				{
					//cloning
					//loadedGens.list[i] = loadedGens.list[i].ReflectionCopy();
					Generator gen = loadedGens.list[i];

					//offset
					gen.guiRect.position += pos;
					
					//ignoring already existing outputs
					if (gen is Generator.IOutput && MapMagic.instance.guiGens.GetGenerator(gen.GetType())!=null)
					{
						Debug.Log ("MapMagic: tried to load Output which already exists (" + gen + "). Skipping.");
						loadedGens.UnlinkGenerator(gen);
						ArrayUtility.RemoveAt(ref loadedGens.list, i);
					}

				}*/

				ArrayUtility.AddRange(ref MapMagic.instance.guiGens.list, loadedGens);
				MapMagic.instance.guiGens.ChangeGenerator(null);
				repaint=true; forceAll=true; Repaint();
			}