public static Sprite CreateTeamSpritesheetAsset(int teamId, string rawSpriteAssetPath, Texture2D textureWithAlpha, Palette palette) { Texture2D tempTexture = new Texture2D(textureWithAlpha.width, textureWithAlpha.height, TextureFormat.ARGB32, false); // TODO // create subFolder "prepared" if not Exists, save teamSpritesheet there! // current workarrount: save in parent folder string workingFolder = Path.GetDirectoryName(rawSpriteAssetPath); string parentFolder = Path.GetDirectoryName(workingFolder); string assetFileName = Path.GetFileNameWithoutExtension(rawSpriteAssetPath) + "_" + (Teams)teamId + "_ARGB32" + ".png"; // !!!important!!! Order: originalName + _Team_ + "_ARGB32.png" // Generate Unique Asset Path for new Texture string teamAssetPath = parentFolder + "/" + assetFileName; string uniqueTeamAssetPath = AssetDatabase.GenerateUniqueAssetPath(teamAssetPath); //TeamColor.ChangeColors(TeamColor.referenceColors[i], textureWithAlpha); //TeamColor.ChangeColors(TeamColor.referenceColorsVerzweigt[i], textureWithAlpha); // Full Palette tempTexture.SetPixels(textureWithAlpha.GetPixels()); palette.ChangeColorsFast(teamId, tempTexture); // Save as PNG Sprite teamSpritesheet = SaveTextureAsSprite(tempTexture, uniqueTeamAssetPath); // Apply Import Settings, and Slice SetRawCharacterSpriteSheetTextureImporter(teamSpritesheet, false, true, true); // Clean Memory UnityEngine.Object.DestroyImmediate(tempTexture); return(teamSpritesheet); }
private void OnGUI_Test() { if (GUILayout.Button("load prepared Spritesheet")) { CopySprite(); } tempSpritesheet = EditorGUILayout.ObjectField("Temp Spritesheet", tempSpritesheet, typeof(Texture2D), false) as Texture2D; if (tempSpritesheet != null) { Rect controlRect = EditorGUILayout.GetControlRect(true, tempSpritesheet.height, GUILayout.ExpandWidth(false)); EditorGUI.DrawTextureTransparent(controlRect, tempSpritesheet); GUI.enabled = true; } else { GUI.enabled = false; } slectedTeam = (Teams)EditorGUILayout.EnumPopup("Team", slectedTeam); if (slectedTeam == Teams.count) { slectedTeam = Teams.yellow; } // Modify Texture //if (GUILayout.Button("ChangeColor old")) //{ // TeamColor.ChangeColors(TeamColor.referenceColorsVerzweigt[(int)slectedTeam], preparedSpritesheet.texture); //} // Modify Texture if (GUILayout.Button("ChangeColor full (edit)")) { palette.ChangeColorsFast((int)slectedTeam, tempSpritesheet); } if (GUILayout.Button("Save")) { preparedSpritesheet.texture.Apply(); EditorUtility.SetDirty(preparedSpritesheet); EditorUtility.SetDirty(preparedSpritesheet.texture); AssetDatabase.StartAssetEditing(); EditorUtility.SetDirty(preparedSpritesheet); EditorUtility.SetDirty(preparedSpritesheet.texture); AssetDatabase.StopAssetEditing(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } if (GUILayout.Button("ReImport")) { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(preparedSpritesheet)); } }