Esempio n. 1
0
			void LoadGenerator (Vector2 pos)
			{
				string path= UnityEditor.EditorUtility.OpenFilePanel(
						"Load Node",
						"Assets",
						"asset");
				if (path==null || path.Length==0) return;
				path = path.Replace(Application.dataPath, "Assets");

				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 IOutput && MapMagic.instance.gens.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.gens.list, loadedGens.list);
				MapMagic.instance.gens.ChangeGenerator(null);
				repaint=true; Repaint();
			}
Esempio n. 2
0
			private GeneratorsAsset SmartCopyGenerator (Generator gen)
			{
				GeneratorsAsset copyGens = ScriptableObject.CreateInstance<GeneratorsAsset>();

				//saving all gens if clicked to background
				if (gen == null) 
				{
					copyGens.list = (Generator[])Serializer.DeepCopy(MapMagic.instance.gens.list);
				}

				//saving group
				else if (gen is Group)
				{
					Group copyGroup = (Group)Serializer.DeepCopy(gen);
					copyGens.UnlinkGenerator(copyGroup, unlinkGroup: true);
					Generator[] copyAllGens= (Generator[])Serializer.DeepCopy(MapMagic.instance.gens.list);
					copyGens.list = new Generator[] { copyGroup };

					for (int i=0; i<copyAllGens.Length; i++)
					{
						if (!copyGroup.guiRect.Contains(copyAllGens[i].guiRect)) continue;
						
						//un-linking copy gens
						foreach (Generator.Input input in copyAllGens[i].Inputs())
						{
							if (input.link == null) continue;
							if (!copyGroup.guiRect.Contains(input.linkGen.guiRect)) input.Unlink();
						}
						
						ArrayUtility.Add(ref copyGens.list, copyAllGens[i]);
					}
				}

				//saving single generator
				else
				{
					Generator copyGen = (Generator)Serializer.DeepCopy(gen);
					copyGens.UnlinkGenerator(copyGen);
					copyGens.list = new Generator[] { copyGen };
				}

				return copyGens;
			}
Esempio n. 3
0
			void DuplicateGenerator (Generator gen)
			{
				GeneratorsAsset copyGens = SmartCopyGenerator(gen);
				
				//ignoring already existing outputs
				for (int i=copyGens.list.Length-1; i>=0; i--)
				{
					Generator copyGen = copyGens.list[i];

					if (copyGen is IOutput && MapMagic.instance.gens.GetGenerator(gen.GetType())!=null)
					{
						Debug.Log ("MapMagic: tried to copy Output which already exists (" + copyGen + "). Skipping.");
						copyGens.UnlinkGenerator(copyGen);
						ArrayUtility.RemoveAt(ref copyGens.list, i);
					}

					copyGen.guiRect.position += new Vector2(0, gen.guiRect.height + 10);
				}

				ArrayUtility.AddRange(ref MapMagic.instance.gens.list, copyGens.list);
				MapMagic.instance.gens.ChangeGenerator(null);
				repaint=true; Repaint();
			}