public void CopyBuiltFromSource(tk2dSpriteCollection source)
        {
            SpriteCollectionProxy target = this;

            target.spriteCollection = source.spriteCollection;
            CopyArray(ref target.altMaterials, source.altMaterials);
            CopyArray(ref target.atlasMaterials, source.atlasMaterials);
            CopyArray(ref target.atlasTextures, source.atlasTextures);
            CopyArray(ref target.atlasTextureFiles, source.atlasTextureFiles);
        }
	public void SetGenerator(tk2dSpriteCollection spriteCollection)
	{
		this._spriteCollection = spriteCollection;
		this.firstRun = true;
		spriteCollectionProxy = new SpriteCollectionProxy(spriteCollection);
		PopulateEntries();
	}
Ejemplo n.º 3
0
	public static void makeTK2DSpriteCollection(string prePath, string name, Texture2D[] textures)
	{
		tk2dSpriteCollectionIndex[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
		foreach (var v in spriteCollections)
		{
			if (v.name != name)
				continue;
				
			var prefabPath = getPrefabPath(name);
			var go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
			if (go == null)
				continue;
			
			tk2dSpriteCollection sc = go.GetComponent<tk2dSpriteCollection>();
			sc.defaults.anchor = tk2dSpriteCollectionDefinition.Anchor.UpperLeft;
			sc.textureParams = new tk2dSpriteCollectionDefinition[0]; //**??
#if TK2D_1_8
			var spriteCollectionProxy = 
				new tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy(sc);
			foreach (var tex in textures) {
				string tname = spriteCollectionProxy.FindUniqueTextureName(tex.name);
				int slot = spriteCollectionProxy.FindOrCreateEmptySpriteSlot();
				spriteCollectionProxy.textureParams[slot].name = tname;
				spriteCollectionProxy.textureParams[slot].colliderType = tk2dSpriteCollectionDefinition.ColliderType.ForceNone;
				spriteCollectionProxy.textureParams[slot].texture = (Texture2D)tex;
			}
			sc.maxTextureSize = maxTextureSize;
			
			saveCurrentScene();
			{
				spriteCollectionProxy.CopyToTarget();
				tk2dSpriteCollectionBuilder.ResetCurrentBuild();
				tk2dSpriteCollectionBuilder.Rebuild(sc);
				spriteCollectionProxy.CopyFromSource();
				tk2dEditorUtility.UnloadUnusedAssets();
			}
			saveCurrentScene();
#else
			sc.textureRefs = textures;
			sc.maxTextureSize = maxTextureSize;
			
			saveCurrentScene();
			{
				tk2dSpriteCollectionBuilder.ResetCurrentBuild();
				tk2dSpriteCollectionBuilder.Rebuild(sc);
				tk2dEditorUtility.UnloadUnusedAssets();
			}
			saveCurrentScene();
#endif
			return;
		}
		
		string path = prePath + "/" + name + ".prefab";
        if (!string.IsNullOrEmpty(name))
        {
            var go = new GameObject();
            go.AddComponent<tk2dSpriteCollection>();

#if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_4)
            go.active = false;
			
			var p = EditorUtility.CreateEmptyPrefab(path);
            var prefab = EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
#elif (UNITY_3_5)
            go.active = false;
			
			var p = PrefabUtility.CreateEmptyPrefab(path);
            var prefab = EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
#else
			go.SetActive(false);
			
			var p = PrefabUtility.CreateEmptyPrefab(path);
            var prefab = PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
#endif
			saveCurrentScene();
			var sc = prefab.GetComponent<tk2dSpriteCollection>();
			{
				sc.defaults.anchor = tk2dSpriteCollectionDefinition.Anchor.UpperLeft;
#if TK2D_1_8
				var spriteCollectionProxy = 
					new tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy(sc);
				foreach (var tex in textures) {
					string tname = spriteCollectionProxy.FindUniqueTextureName(tex.name);
					int slot = spriteCollectionProxy.FindOrCreateEmptySpriteSlot();
					spriteCollectionProxy.textureParams[slot].name = tname;
					spriteCollectionProxy.textureParams[slot].anchor = tk2dSpriteCollectionDefinition.Anchor.UpperLeft;
					spriteCollectionProxy.textureParams[slot].colliderType = tk2dSpriteCollectionDefinition.ColliderType.ForceNone;
					spriteCollectionProxy.textureParams[slot].texture = (Texture2D)tex;
				}
				sc.maxTextureSize = maxTextureSize;
				spriteCollectionProxy.CopyToTarget();
				tk2dSpriteCollectionBuilder.ResetCurrentBuild();
				tk2dSpriteCollectionBuilder.Rebuild(sc);
				spriteCollectionProxy.CopyFromSource();
#else
				sc.textureRefs = textures;
				sc.maxTextureSize = maxTextureSize;
				tk2dSpriteCollectionBuilder.Rebuild(sc);
#endif
			}
			
            GameObject.DestroyImmediate(go);
			tk2dEditorUtility.UnloadUnusedAssets();
			saveCurrentScene();
        }
	}