├── .gitignore ├── Assets ├── Editor.meta ├── Editor │ ├── PackageExporter.cs │ └── PackageExporter.cs.meta ├── RBPixelPalettemap.meta ├── RBPixelPalettemap │ ├── Editor.meta │ ├── Editor │ │ ├── AssetDatabaseUtility.cs │ │ ├── AssetDatabaseUtility.cs.meta │ │ ├── PaletteMapJob.cs │ │ ├── PaletteMapJob.cs.meta │ │ ├── RBPaletteCreator.cs │ │ ├── RBPaletteCreator.cs.meta │ │ ├── RBPaletteDrawer.cs │ │ ├── RBPaletteDrawer.cs.meta │ │ ├── RBPaletteGroup.cs │ │ ├── RBPaletteGroup.cs.meta │ │ ├── RBPaletteGroupEditor.cs │ │ ├── RBPaletteGroupEditor.cs.meta │ │ ├── RBPaletteMapper.cs │ │ ├── RBPaletteMapper.cs.meta │ │ ├── RBPaletteMapperWindow.cs │ │ └── RBPaletteMapperWindow.cs.meta │ ├── Examples.meta │ ├── Examples │ │ ├── Animations.meta │ │ ├── Animations │ │ │ ├── Knight.controller │ │ │ ├── Knight.controller.meta │ │ │ ├── Knight_Idle.anim │ │ │ └── Knight_Idle.anim.meta │ │ ├── Demo.unity │ │ ├── Demo.unity.meta │ │ ├── Materials.meta │ │ ├── Materials │ │ │ ├── Knight_Alt1.mat │ │ │ ├── Knight_Alt1.mat.meta │ │ │ ├── Knight_Alt2.mat │ │ │ ├── Knight_Alt2.mat.meta │ │ │ ├── Knight_MultiPalette.mat │ │ │ ├── Knight_MultiPalette.mat.meta │ │ │ ├── Knight_PaletteKey.mat │ │ │ ├── Knight_PaletteKey.mat.meta │ │ │ ├── Knight_Palette_Alt1.mat │ │ │ ├── Knight_Palette_Alt1.mat.meta │ │ │ ├── Knight_Palette_Alt2.mat │ │ │ ├── Knight_Palette_Alt2.mat.meta │ │ │ ├── Knight_Palette_Multi.mat │ │ │ ├── Knight_Palette_Multi.mat.meta │ │ │ ├── Knight_Palettized.mat │ │ │ ├── Knight_Palettized.mat.meta │ │ │ ├── Knight_Palettized_Transparent.mat │ │ │ ├── Knight_Palettized_Transparent.mat.meta │ │ │ ├── Waterfall.mat │ │ │ ├── Waterfall.mat.meta │ │ │ ├── World_Original.mat │ │ │ ├── World_Original.mat.meta │ │ │ ├── World_PaletteKey.mat │ │ │ ├── World_PaletteKey.mat.meta │ │ │ ├── World_PaletteMap.mat │ │ │ ├── World_PaletteMap.mat.meta │ │ │ ├── World_Palette_Blue.mat │ │ │ ├── World_Palette_Blue.mat.meta │ │ │ ├── World_Palettized.mat │ │ │ ├── World_Palettized.mat.meta │ │ │ ├── World_Palettized_Blue.mat │ │ │ └── World_Palettized_Blue.mat.meta │ │ ├── Textures.meta │ │ └── Textures │ │ │ ├── Knight.png │ │ │ ├── Knight.png.meta │ │ │ ├── Knight_PaletteKey.png │ │ │ ├── Knight_PaletteKey.png.meta │ │ │ ├── Knight_PaletteKey_CustomSort.png │ │ │ ├── Knight_PaletteKey_CustomSort.png.meta │ │ │ ├── Knight_PaletteMap.png │ │ │ ├── Knight_PaletteMap.png.meta │ │ │ ├── Knight_Palette_Alt1.png │ │ │ ├── Knight_Palette_Alt1.png.meta │ │ │ ├── Knight_Palette_Alt2.png │ │ │ ├── Knight_Palette_Alt2.png.meta │ │ │ ├── Knight_Palette_Multi.png │ │ │ ├── Knight_Palette_Multi.png.meta │ │ │ ├── Waterfall.png │ │ │ ├── Waterfall.png.meta │ │ │ ├── Waterfall_AnimatingKey.png │ │ │ ├── Waterfall_AnimatingKey.png.meta │ │ │ ├── Waterfall_PaletteKey.png │ │ │ ├── Waterfall_PaletteKey.png.meta │ │ │ ├── Waterfall_PaletteMap.png │ │ │ ├── Waterfall_PaletteMap.png.meta │ │ │ ├── Waterfall_SourceFile.png │ │ │ ├── Waterfall_SourceFile.png.meta │ │ │ ├── World.png │ │ │ ├── World.png.meta │ │ │ ├── World_PaletteKey.png │ │ │ ├── World_PaletteKey.png.meta │ │ │ ├── World_PaletteMap.png │ │ │ ├── World_PaletteMap.png.meta │ │ │ ├── World_Palette_blue.png │ │ │ └── World_Palette_blue.png.meta │ ├── Scripts.meta │ ├── Scripts │ │ ├── MaterialTween.cs │ │ ├── MaterialTween.cs.meta │ │ ├── PaletteScroll.cs │ │ ├── PaletteScroll.cs.meta │ │ ├── RBPalette.cs │ │ ├── RBPalette.cs.meta │ │ ├── RBPaletteDiff.cs │ │ ├── RBPaletteDiff.cs.meta │ │ ├── SetTextureVariableExample.cs │ │ └── SetTextureVariableExample.cs.meta │ ├── Shaders.meta │ └── Shaders │ │ ├── DefaultShaders.meta │ │ ├── DefaultShaders │ │ ├── Sprites-Default.shader │ │ ├── Sprites-Default.shader.meta │ │ ├── Unlit-Alpha.shader │ │ ├── Unlit-Alpha.shader.meta │ │ ├── Unlit-Normal.shader │ │ └── Unlit-Normal.shader.meta │ │ ├── PaletteSprite.shader │ │ ├── PaletteSprite.shader.meta │ │ ├── PaletteTexture-Normal.shader │ │ ├── PaletteTexture-Normal.shader.meta │ │ ├── PaletteTexture-Transparent.shader │ │ └── PaletteTexture-Transparent.shader.meta ├── Tests.meta └── Tests │ ├── FourColors.png │ ├── FourColors.png.meta │ ├── Rectangular.png │ ├── Rectangular.png.meta │ ├── ThreeColors.png │ ├── ThreeColors.png.meta │ ├── ThreeColorsAndAlpha.png │ ├── ThreeColorsAndAlpha.png.meta │ ├── ThreeColorsOrderSwap.png │ ├── ThreeColorsOrderSwap.png.meta │ ├── TwoColors.png │ └── TwoColors.png.meta ├── License.md ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ├── RBPixelPalettemap.unitypackage ├── RBPixelPalettemapDebug.unitypackage └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | /Assets/Textures/TestTextures/ 5 | 6 | # Windows ignore 7 | desktop.ini 8 | 9 | # Mac ignore 10 | .DS_Store 11 | *.swp 12 | *.Trashes 13 | 14 | # Autogenerated VS/MD solution and project files 15 | *.csproj 16 | *.unityproj 17 | *.sln 18 | *.pidb 19 | *.userprefs 20 | 21 | # Visual Studio Files 22 | *.suo 23 | 24 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a19384b532a346d782966ee6dd82ec3 3 | folderAsset: yes 4 | timeCreated: 1438710327 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/PackageExporter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class PackageExporter : UnityEditor.EditorWindow { 6 | 7 | static string assetPathName = "Assets/RBPixelPalettemap"; 8 | static string testsPathName = "Assets/Tests"; 9 | 10 | [MenuItem ("PackageExporter/Export Release")] 11 | public static void ExportPackage () 12 | { 13 | AssetDatabase.ExportPackage (assetPathName, "RBPixelPalettemap.unitypackage", ExportPackageOptions.Recurse | 14 | ExportPackageOptions.IncludeDependencies); 15 | Debug.Log ("Exported!"); 16 | } 17 | 18 | [MenuItem ("PackageExporter/Export with Tests")] 19 | public static void ExportPackageDebug () 20 | { 21 | AssetDatabase.ExportPackage (new string[] {assetPathName, testsPathName} , "RBPixelPalettemapDebug.unitypackage", ExportPackageOptions.Recurse | 22 | ExportPackageOptions.IncludeDependencies); 23 | Debug.Log ("Exported!"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/Editor/PackageExporter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e192185b24b58463a9629e0a74838523 3 | timeCreated: 1438710345 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f651f5fffa204b7f96777d6d1a3b58d 3 | folderAsset: yes 4 | timeCreated: 1438701871 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bffd9ec5039f4abeaca4ce15d4825ae 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/AssetDatabaseUtility.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.IO; 5 | 6 | public static class AssetDatabaseUtility { 7 | 8 | public static string GetDirectoryOfSelection () 9 | { 10 | // TODO THIS DOESN"T ALWAYS WORK. 11 | string path = "Assets"; 12 | foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets)) { 13 | path = AssetDatabase.GetAssetPath (obj); 14 | if (File.Exists (path)) { 15 | path = Path.GetDirectoryName (path); 16 | } 17 | break; 18 | } 19 | path += Path.DirectorySeparatorChar; 20 | return path; 21 | } 22 | 23 | public static string GetAssetDirectory (Object asset) 24 | { 25 | string path = AssetDatabase.GetAssetPath (asset); 26 | return Path.GetDirectoryName (path) + Path.DirectorySeparatorChar; 27 | } 28 | 29 | public static Object SaveObject (Object objectToSave, string path, string filename) 30 | { 31 | string fullpath = path + filename; 32 | 33 | AssetDatabase.CreateAsset (objectToSave, fullpath); 34 | AssetDatabase.SaveAssets (); 35 | 36 | return objectToSave; 37 | } 38 | 39 | public static Object SaveAndSelectObject (Object objectToSave, string path, string filename) 40 | { 41 | Object savedObject = SaveObject (objectToSave, path, filename); 42 | SelectObject (savedObject); 43 | 44 | return savedObject; 45 | } 46 | 47 | public static void SelectObject (Object objectToSelect) 48 | { 49 | EditorUtility.FocusProjectWindow (); 50 | Selection.activeObject = objectToSelect; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/AssetDatabaseUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 847e06a4453ab4f5785a513064da8241 3 | timeCreated: 1439301269 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/PaletteMapJob.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.IO; 5 | using RedBlueTools; 6 | 7 | public class PaletteMapJob : ScriptableObject 8 | { 9 | public string PaletteMapName; 10 | public Texture2D SourceTexture; 11 | public RBPaletteGroup PaletteGroup; 12 | public bool OverwriteExistingPaletteMap; 13 | public RBPaletteDiff CurrentDiff; 14 | 15 | [MenuItem ("Assets/Create/RBPaletteMap/PaletteMapJob")] 16 | public static PaletteMapJob CreatePaletteMapJob () 17 | { 18 | PaletteMapJob job = PaletteMapJob.CreateInstance (); 19 | string directory = AssetDatabaseUtility.GetDirectoryOfSelection (); 20 | string filename = "RBPaletteMapJob.asset"; 21 | string desiredPath = directory + filename; 22 | string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath (desiredPath); 23 | return (PaletteMapJob) AssetDatabaseUtility.SaveAndSelectObject (job, directory, Path.GetFileName(uniqueAssetPath)); 24 | } 25 | 26 | public static PaletteMapJob CreateInstance () 27 | { 28 | PaletteMapJob job = ScriptableObject.CreateInstance (); 29 | return job; 30 | } 31 | 32 | public void CreatePaletteGroupForTexture () 33 | { 34 | RBPaletteGroup paletteGroup = RBPaletteCreator.ExtractPaletteFromTexture (SourceTexture, AssetDatabaseUtility.GetAssetDirectory (this), 35 | name + "_PaletteGroup.asset"); 36 | if (paletteGroup != null) { 37 | paletteGroup.Locked = true; 38 | PaletteGroup = paletteGroup; 39 | } 40 | } 41 | 42 | public void DiffPaletteGroupWithTexture () 43 | { 44 | CurrentDiff = PaletteGroup.DiffWithTexture (SourceTexture); 45 | } 46 | } 47 | 48 | #if UNITY_EDITOR 49 | [CustomEditor(typeof(PaletteMapJob))] 50 | public class PaletteMapJobEditor : Editor { 51 | 52 | public override void OnInspectorGUI () 53 | { 54 | DrawDefaultInspector (); 55 | 56 | string path = AssetDatabaseUtility.GetAssetDirectory (target); 57 | PaletteMapJob targetJob = (PaletteMapJob) target; 58 | 59 | bool disableDiff = targetJob.SourceTexture == null || targetJob.PaletteGroup == null; 60 | EditorGUI.BeginDisabledGroup (disableDiff); 61 | if (GUILayout.Button ("Diff PaletteGroup")) { 62 | targetJob.DiffPaletteGroupWithTexture (); 63 | } 64 | EditorGUI.EndDisabledGroup (); 65 | 66 | bool generationDisabled = targetJob.PaletteGroup == null; 67 | // Palette Group Button 68 | EditorGUI.BeginDisabledGroup (!generationDisabled); 69 | if (GUILayout.Button ("Create New PaletteGroup from Texture")) { 70 | targetJob.CreatePaletteGroupForTexture (); 71 | } 72 | EditorGUI.EndDisabledGroup (); 73 | 74 | EditorGUILayout.Separator (); 75 | 76 | // Generate Palette Map Button 77 | EditorGUI.BeginDisabledGroup (generationDisabled); 78 | if (GUILayout.Button ("Generate PaletteMap")) { 79 | try { 80 | bool creationComplete = RBPaletteMapper.CreatePaletteMapAndKey ( 81 | path, targetJob.SourceTexture, targetJob.PaletteGroup, targetJob.OverwriteExistingPaletteMap, 82 | "Key", targetJob.PaletteMapName); 83 | if (creationComplete) { 84 | Debug.Log ("Palette Map created successfully for job: " + targetJob.name + 85 | "\nUpdated PaletteGroup: " + targetJob.PaletteGroup); 86 | } 87 | } catch (System.Exception e) { 88 | Debug.LogError (e, targetJob); 89 | } 90 | } 91 | EditorGUI.EndDisabledGroup (); 92 | } 93 | } 94 | #endif -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/PaletteMapJob.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a668d9e65305403d94869db3230dfcf 3 | timeCreated: 1439156816 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteCreator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.IO; 4 | 5 | public static class RBPaletteCreator { 6 | 7 | const string suffix = "_PaletteGroup"; 8 | 9 | [MenuItem ("Assets/Create/RBPaletteGroup/RBPalette")] 10 | static RBPaletteGroup CreatePaletteGroup () 11 | { 12 | string path = AssetDatabaseUtility.GetDirectoryOfSelection (); 13 | string filename = "RBPaletteGroup.asset"; 14 | string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath (path + filename); 15 | RBPaletteGroup createdGroup = null; 16 | try { 17 | createdGroup = CreatePaletteGroup (path, Path.GetFileName(uniqueAssetPath), false); 18 | } catch (IOException e){ 19 | throw new IOException ("Failed to create file. Encountered exception: " + e); 20 | } 21 | 22 | // Unlock standalone palette groups by default. 23 | createdGroup.Locked = false; 24 | 25 | AssetDatabaseUtility.SelectObject (createdGroup); 26 | 27 | return createdGroup; 28 | } 29 | 30 | public static RBPaletteGroup CreatePaletteGroup (string path, string filename, bool overwriteExisting) 31 | { 32 | ValidateSaveLocation (path + filename, overwriteExisting); 33 | RBPaletteGroup paletteAsset = RBPaletteGroup.CreateInstance (); 34 | return (RBPaletteGroup) AssetDatabaseUtility.SaveObject (paletteAsset, path, filename); 35 | } 36 | 37 | public static RBPaletteGroup CreatePaletteGroupFromTexture (string path, string filename, Texture2D sourceTexture, bool overwriteExisting) 38 | { 39 | ValidateSaveLocation (path + filename, overwriteExisting); 40 | RBPaletteGroup paletteGroup = RBPaletteGroup.CreateInstanceFromTexture (sourceTexture, sourceTexture.name + suffix); 41 | return (RBPaletteGroup) AssetDatabaseUtility.SaveObject (paletteGroup, path, filename); 42 | } 43 | 44 | public static RBPaletteGroup CreatePaletteGroupFromPaletteTexture (string path, string filename, Texture2D sourceTexture, bool overwriteExisting) 45 | { 46 | ValidateSaveLocation (path + filename, overwriteExisting); 47 | RBPaletteGroup paletteGroup = RBPaletteGroup.CreateInstanceFromPaletteTexture (sourceTexture, sourceTexture.name + suffix); 48 | return (RBPaletteGroup) AssetDatabaseUtility.SaveObject (paletteGroup, path, filename); 49 | } 50 | 51 | static void ValidateSaveLocation (string fullPathToFile, bool allowOverwrite) 52 | { 53 | if (!allowOverwrite && File.Exists (fullPathToFile)) { 54 | throw new IOException ("File exists at save location: " + fullPathToFile); 55 | } 56 | } 57 | 58 | [MenuItem ("Assets/RBPaletteGroup/Extract Palette from Texture")] 59 | public static RBPaletteGroup ExtractPaletteFromSelection () 60 | { 61 | Texture2D selectedTexture = (Texture2D) Selection.activeObject; 62 | string selectionPath = AssetDatabaseUtility.GetDirectoryOfSelection (); 63 | 64 | RBPaletteGroup extractedPaletteGroup = ExtractPaletteFromTexture (selectedTexture, selectionPath); 65 | AssetDatabaseUtility.SelectObject (extractedPaletteGroup); 66 | 67 | return extractedPaletteGroup; 68 | } 69 | 70 | public static RBPaletteGroup ExtractPaletteFromTexture (Texture2D extractTexture, string savePath, string filename = "") 71 | { 72 | if (string.IsNullOrEmpty (filename)) { 73 | filename = extractTexture.name + suffix + ".asset"; 74 | } 75 | 76 | RBPaletteGroup createdGroup = null; 77 | try { 78 | createdGroup = CreatePaletteGroupFromTexture (savePath, filename, extractTexture, false); 79 | } catch (IOException) { 80 | if (EditorUtility.DisplayDialog ("Warning!", 81 | "This will overwrite the existing file, " + filename + 82 | ". Are you sure you want to extract the palette?", "Yes", "No")) { 83 | createdGroup = CreatePaletteGroupFromTexture (savePath, filename, extractTexture, true); 84 | } 85 | } 86 | 87 | return createdGroup; 88 | } 89 | 90 | [MenuItem ("Assets/RBPaletteGroup/Extract Palette from Texture", true)] 91 | static bool ValidateExtractPalette () 92 | { 93 | if (!IsSelectionValidTexture ()) { 94 | return false; 95 | } 96 | 97 | // TODO: Could support multi-texture palette group extraction 98 | if (Selection.objects.Length > 1) { 99 | return false; 100 | } 101 | return true; 102 | } 103 | 104 | [MenuItem ("Assets/RBPaletteGroup/Create PaletteGroup from Palette")] 105 | public static RBPaletteGroup ExtractPaletteGroupFromPaletteTexture () 106 | { 107 | Texture2D selectedTexture = (Texture2D) Selection.activeObject; 108 | string selectionPath = AssetDatabaseUtility.GetDirectoryOfSelection (); 109 | 110 | RBPaletteGroup extractedPaletteGroup = ExtractPaletteGroupFromPaletteTexture (selectedTexture, selectionPath); 111 | AssetDatabaseUtility.SelectObject (extractedPaletteGroup); 112 | 113 | return extractedPaletteGroup; 114 | } 115 | 116 | static RBPaletteGroup ExtractPaletteGroupFromPaletteTexture (Texture2D extractTexture, string savePath, string filename = "") 117 | { 118 | if (string.IsNullOrEmpty (filename)) { 119 | filename = extractTexture.name + suffix + ".asset"; 120 | } 121 | 122 | RBPaletteGroup createdGroup = null; 123 | try { 124 | createdGroup = CreatePaletteGroupFromPaletteTexture (savePath, filename, extractTexture, false); 125 | } catch (IOException) { 126 | if (EditorUtility.DisplayDialog ("Warning!", 127 | "This will overwrite the existing file, " + filename + 128 | ". Are you sure you want to extract the palette group?", "Yes", "No")) { 129 | createdGroup = CreatePaletteGroupFromPaletteTexture (savePath, filename, extractTexture, true); 130 | } 131 | } 132 | 133 | return createdGroup; 134 | } 135 | 136 | [MenuItem ("Assets/RBPaletteGroup/Create PaletteGroup from Palette", true)] 137 | static bool ValidatePaletteToPaletteGroup () 138 | { 139 | if (!IsSelectionValidTexture ()) { 140 | return false; 141 | } 142 | 143 | if (Selection.objects.Length > 1) { 144 | return false; 145 | } 146 | return true; 147 | } 148 | 149 | static bool IsSelectionValidTexture () 150 | { 151 | if (Selection.activeObject == null) { 152 | return false; 153 | } 154 | 155 | return Selection.activeObject.GetType() == typeof(Texture2D); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a40d9aad1ce044a5ab2d5b27cef3b684 3 | timeCreated: 1435523902 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteDrawer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditorInternal; 3 | using UnityEditor; 4 | using System.Collections.Generic; 5 | using System.Collections; 6 | 7 | [CustomPropertyDrawer (typeof(RBPalette))] 8 | public class RBPaletteDrawer : PropertyDrawer 9 | { 10 | ReorderableList colorList; 11 | string listPropertyName = "ColorsInPalette"; 12 | #region Sizing 13 | float elementPadding = 5.0f; 14 | float elementSpacing = 5.0f; 15 | float minLabelWidth = 100.0f; 16 | float preferredLabelWeight = 0.4f; 17 | #endregion 18 | 19 | public override float GetPropertyHeight (SerializedProperty property, GUIContent label) 20 | { 21 | var listProperty = property.FindPropertyRelative (listPropertyName); 22 | // WORKAROUND: Get my own height instead of using ReorderableList.GetHeight () 23 | // because it doesn't calculate correctly on first frame 24 | float height = Mathf.Max (listProperty.arraySize, 1) * GetElementHeight (); 25 | float headerHeight = 20.0f; 26 | float addMinusHeight = 20.0f; 27 | return height + addMinusHeight + headerHeight; 28 | } 29 | 30 | float GetElementHeight () 31 | { 32 | return EditorGUIUtility.singleLineHeight + 2.0f * elementPadding; 33 | } 34 | 35 | void DrawListElement (Rect rect, int index, bool isActive, bool isFocused) 36 | { 37 | var element = colorList.serializedProperty.GetArrayElementAtIndex (index); 38 | rect.y += elementPadding; 39 | 40 | // Draw label 41 | SerializedProperty nameProperty = element.FindPropertyRelative ("Name"); 42 | float labelWidth = Mathf.Max (rect.width * preferredLabelWeight, minLabelWidth); 43 | Rect labelRect = new Rect (rect.x, rect.y, labelWidth, EditorGUIUtility.singleLineHeight); 44 | nameProperty.stringValue = EditorGUI.TextField (labelRect, nameProperty.stringValue); 45 | 46 | float remainingWidth = rect.width - (labelRect.width + elementSpacing); 47 | SerializedProperty colorProperty = element.FindPropertyRelative ("Color"); 48 | Rect colorRect = new Rect (rect.x + labelRect.width + elementSpacing, rect.y, 49 | remainingWidth, EditorGUIUtility.singleLineHeight); 50 | GUIContent colorGUIContent = new GUIContent (string.Empty, nameProperty.stringValue); 51 | colorProperty.colorValue = EditorGUI.ColorField (colorRect, colorGUIContent, colorProperty.colorValue); 52 | } 53 | 54 | public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 55 | { 56 | var listProperty = property.FindPropertyRelative (listPropertyName); 57 | var renderedList = BuildReorderableColorList (listProperty); 58 | renderedList.elementHeight = GetElementHeight (); 59 | 60 | renderedList.DoList (position); 61 | } 62 | 63 | ReorderableList BuildReorderableColorList (SerializedProperty property) 64 | { 65 | if (property == null) { 66 | Debug.LogError ("Trying to build list from null property. You may have searched" + 67 | " for an invalid RelativeProperty."); 68 | } 69 | if (colorList != null) { 70 | return colorList; 71 | } 72 | 73 | SerializedObject objectForProperty = property.serializedObject; 74 | colorList = new ReorderableList (objectForProperty, property, 75 | true, true, true, true); 76 | colorList.drawElementCallback = DrawListElement; 77 | colorList.drawHeaderCallback = (Rect rect) => { 78 | string parentPropertyName = property.propertyPath.Split ('.')[0]; 79 | EditorGUI.LabelField(rect, parentPropertyName); 80 | }; 81 | return colorList; 82 | } 83 | 84 | /// 85 | /// Gets the Serialized Property for a List member as a List of SerializedProperties. 86 | /// Suggested by StackOverflow: 87 | /// http://answers.unity3d.com/questions/682932/using-generic-list-with-serializedproperty-inspect.html 88 | /// 89 | /// The value of the serialized property as a List. 90 | /// The property that stores a list. 91 | List GetListFromSerializedProperty (SerializedProperty listAsProperty) 92 | { 93 | if (!listAsProperty.isArray) { 94 | return null; 95 | } 96 | 97 | // Apparently it's bad to iterate on the original... not sure why, but that's 98 | // what the StackOverflow said 99 | SerializedProperty listCopy = listAsProperty.Copy (); 100 | 101 | listCopy.Next (true); // Skip generic element 102 | listCopy.Next (true); // This is the array size 103 | 104 | int listSize = listCopy.intValue; 105 | int lastindex = listSize - 1; 106 | List listOfElements = new List (listSize); 107 | 108 | listCopy.Next (true); // Get first element in list 109 | for (int i = 0; i < listSize; i++) { 110 | // Copy elements or else we will just make a list of the enumerator 111 | SerializedProperty nextElement = listCopy.Copy (); 112 | listOfElements.Add (nextElement); 113 | if (i < lastindex) { 114 | listCopy.Next (false); 115 | } 116 | } 117 | 118 | return listOfElements; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab0adac460dbb4839b16109d693df045 3 | timeCreated: 1442275836 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteGroup.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using UnityEditor; 6 | 7 | public class RBPaletteGroup : ScriptableObject 8 | { 9 | public const string DefaultGroupName = "RBPaletteGroup"; 10 | public static Color DefaultNewColor = Color.magenta; 11 | public string GroupName; 12 | public bool Locked = true; 13 | [SerializeField] 14 | List 15 | palettes; 16 | [SerializeField] 17 | List 18 | colors; 19 | 20 | public RBPalette BasePalette { 21 | get { 22 | return palettes [0]; 23 | } 24 | private set { 25 | palettes [0] = value; 26 | } 27 | } 28 | 29 | public int NumColorsInPalette { 30 | get { 31 | if (palettes == null || palettes.Count == 0) { 32 | return 0; 33 | } else { 34 | return BasePalette.Count; 35 | } 36 | } 37 | } 38 | 39 | public int Count { 40 | get { 41 | if (palettes == null) { 42 | return 0; 43 | } else { 44 | return palettes.Count; 45 | } 46 | } 47 | } 48 | 49 | public static RBPaletteGroup CreateInstance (string groupPaletteName = DefaultGroupName, RBPalette basePalette = null) 50 | { 51 | RBPaletteGroup paletteGroup = ScriptableObject.CreateInstance (); 52 | paletteGroup.Initialize (groupPaletteName, basePalette); 53 | return paletteGroup; 54 | } 55 | 56 | public static RBPaletteGroup CreateInstanceFromTexture (Texture2D sourceTexture, string groupPaletteName = DefaultGroupName) 57 | { 58 | // Create a base palette from the Texture 59 | RBPalette paletteFromTexture = RBPalette.CreatePaletteFromTexture (sourceTexture); 60 | paletteFromTexture.PaletteName = "Base Palette"; 61 | // Create the paletteGroup with the base Palette 62 | RBPaletteGroup paletteGroup = RBPaletteGroup.CreateInstance (groupPaletteName, paletteFromTexture); 63 | return paletteGroup; 64 | } 65 | 66 | public static RBPaletteGroup CreateInstanceFromPaletteTexture (Texture2D paletteTexture, string groupPaletteName = DefaultGroupName) 67 | { 68 | RBPalette[] palettesInTexture = ExtractRBPalettesFromPaletteTexture (paletteTexture); 69 | // Create the paletteGroup with the base Palette 70 | RBPaletteGroup paletteGroup = CreateInstance (groupPaletteName, palettesInTexture [0]); 71 | for (int i = 1; i < palettesInTexture.Length; i++) { 72 | paletteGroup.AddPalette (palettesInTexture [i]); 73 | } 74 | return paletteGroup; 75 | } 76 | 77 | public void Initialize (string groupPaletteName = DefaultGroupName, RBPalette basePalette = null) 78 | { 79 | palettes = new List (); 80 | GroupName = groupPaletteName; 81 | if (basePalette == null) { 82 | basePalette = new RBPalette ("Base Palette"); 83 | } 84 | palettes.Add (basePalette); 85 | } 86 | 87 | public void SetBasePalette (RBPalette basePalette) 88 | { 89 | this.BasePalette = basePalette; 90 | this.BasePalette.PaletteName = "Base Palette"; 91 | // TODO: Extend or truncate existing palettes 92 | } 93 | 94 | public void AddPalette () 95 | { 96 | RBPalette newPalette = new RBPalette (BasePalette); 97 | newPalette.PaletteName = "Unnamed"; 98 | AddPalette (newPalette); 99 | } 100 | 101 | public void AddPalette (RBPalette paletteToAdd) 102 | { 103 | palettes.Add (paletteToAdd); 104 | } 105 | 106 | public void AddColor (Color colorToAdd) 107 | { 108 | if (Locked) { 109 | throw new System.AccessViolationException ("Can't Add Color to RBPaletteGroup. PaletteGroup is Locked."); 110 | } 111 | 112 | // Add magenta for all the palettes that are getting a new color 113 | foreach (RBPalette palette in palettes) { 114 | palette.AddColor (Color.magenta); 115 | } 116 | 117 | // Set base color to the desired color or default 118 | BasePalette [BasePalette.Count - 1] = colorToAdd; 119 | } 120 | 121 | public void RemoveColorAtIndex (int index) 122 | { 123 | if (Locked) { 124 | throw new System.AccessViolationException ("Can't Add Color to RBPaletteGroup. PaletteGroup is Locked."); 125 | } 126 | if (index < 0 || index >= NumColorsInPalette) { 127 | throw new System.IndexOutOfRangeException 128 | (string.Format ("Trying to remove color at invalid index, {0}", index)); 129 | } 130 | foreach (RBPalette palette in palettes) { 131 | palette.RemoveColorAtIndex (index); 132 | } 133 | } 134 | 135 | public void RemovePaletteAtIndex (int index) 136 | { 137 | if (Locked && index == 0) { 138 | throw new System.AccessViolationException ("Trying to remove base palette from Locked palette group. Locked palette groups " + 139 | "must have a Base Palette."); 140 | } 141 | 142 | if (index < 0 || index >= Count) { 143 | throw new System.IndexOutOfRangeException 144 | (string.Format ("Trying to remove palette at invalid index, {0}", index)); 145 | } 146 | palettes.RemoveAt (index); 147 | } 148 | 149 | public RBPaletteDiff DiffWithTexture (Texture2D textureToDiff) 150 | { 151 | RBPalette paletteFromTexture = RBPalette.CreatePaletteFromTexture (textureToDiff); 152 | RBPaletteDiff diff = RBPaletteDiff.Diff (BasePalette, paletteFromTexture); 153 | return diff; 154 | } 155 | 156 | public void ApplyDiff (RBPaletteDiff diff) 157 | { 158 | // Unlock the PaletteGroup so that we can edit it. 159 | bool wasLocked = Locked; 160 | Locked = false; 161 | 162 | // Add new colors to the palette 163 | for (int i = 0; i < diff.Insertions.Count; i++) { 164 | AddColor (diff.Insertions [i]); 165 | } 166 | 167 | // Remove unused colors 168 | for (int i = 0; i < diff.Deletions.Count; i++) { 169 | int unusedColorIndex = BasePalette.IndexOf (diff.Deletions [i]); 170 | RemoveColorAtIndex (unusedColorIndex); 171 | } 172 | 173 | // Relock the palette group 174 | Locked = wasLocked; 175 | } 176 | 177 | #region Output Functions 178 | public void WriteToFile (string fullPathToFile, bool allowOverwriting) 179 | { 180 | if (File.Exists (fullPathToFile) && !allowOverwriting) { 181 | throw new System.AccessViolationException ("Tried to write PaletteGroup but file already exists. " + 182 | "\nFile Path: " + fullPathToFile); 183 | } 184 | 185 | Texture2D paletteGroupAsTexture = CreateAsTexture (); 186 | try { 187 | byte[] outTextureData = paletteGroupAsTexture.EncodeToPNG (); 188 | File.WriteAllBytes (fullPathToFile, outTextureData); 189 | } catch (System.Exception e) { 190 | throw new System.IO.IOException ("Encountered IO exception during PaletteGroup write: " + e.Message); 191 | } 192 | 193 | // Force refresh so that we can set its Import settings immediately 194 | AssetDatabase.ImportAsset (fullPathToFile); 195 | 196 | // Assign correct settings to the file 197 | TextureImporter textureImporter = AssetImporter.GetAtPath (fullPathToFile) as TextureImporter; 198 | if (textureImporter == null) { 199 | throw new System.NullReferenceException ("Failed to import file at specified path: " + fullPathToFile); 200 | } 201 | textureImporter.textureType = TextureImporterType.Advanced; 202 | textureImporter.spriteImportMode = SpriteImportMode.None; 203 | textureImporter.filterMode = FilterMode.Point; 204 | textureImporter.textureFormat = TextureImporterFormat.RGBA32; 205 | textureImporter.alphaIsTransparency = false; 206 | textureImporter.mipmapEnabled = false; 207 | textureImporter.npotScale = TextureImporterNPOTScale.None; 208 | textureImporter.maxTextureSize = 256; 209 | 210 | // Force Unity to see the file and use the new import settings 211 | AssetDatabase.ImportAsset (fullPathToFile, ImportAssetOptions.ForceUpdate); 212 | } 213 | 214 | Texture2D CreateAsTexture () 215 | { 216 | // Write the colors into a texture 217 | Texture2D paletteGroupAsTexture = new Texture2D (NumColorsInPalette, Count, TextureFormat.RGBA32, false); 218 | paletteGroupAsTexture.hideFlags = HideFlags.HideAndDontSave; 219 | paletteGroupAsTexture.SetPixels (GetColorsAsArray ()); 220 | paletteGroupAsTexture.Apply (); 221 | 222 | return paletteGroupAsTexture; 223 | } 224 | 225 | Color[] GetColorsAsArray () 226 | { 227 | Color[] colorsAsArray = new Color [NumColorsInPalette * Count]; 228 | for (int paletteIndex = 0; paletteIndex < Count; paletteIndex++) { 229 | for (int colorIndex = 0; colorIndex < NumColorsInPalette; colorIndex++) { 230 | int i = paletteIndex * NumColorsInPalette + colorIndex; 231 | colorsAsArray [i] = palettes [paletteIndex] [colorIndex]; 232 | } 233 | } 234 | return colorsAsArray; 235 | } 236 | 237 | static RBPalette[] ExtractRBPalettesFromPaletteTexture (Texture2D paletteTexture) 238 | { 239 | Color[] sourcePixels = paletteTexture.GetPixels (); 240 | int numPalettes = paletteTexture.height; 241 | int numColors = paletteTexture.width; 242 | RBPalette[] palettes = new RBPalette[numPalettes]; 243 | for (int i = 0; i < palettes.Length; i++) { 244 | palettes [i] = new RBPalette ("Palette" + i); 245 | // Add all colors to the palette 246 | for (int color = 0; color < numColors; color++) { 247 | int colorIndex = i * paletteTexture.width + color; 248 | palettes [i].AddColor (sourcePixels [colorIndex]); 249 | } 250 | } 251 | 252 | return palettes; 253 | } 254 | #endregion 255 | } 256 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteGroup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78d671c22d3a94e4fbc6122749fd9f09 3 | timeCreated: 1437251908 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteGroupEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEditorInternal; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | [CustomEditor(typeof(RBPaletteGroup))] 8 | public class RBPaletteGroupEditor : Editor { 9 | 10 | int colorIndex = 0; 11 | 12 | bool isListLocked = false; 13 | #region Sizing 14 | float colorPaddingX = 10.0f; 15 | float colorSpacing = 5.0f; 16 | float palettePadding = 5.0f; 17 | float colorWidth = 50.0f; 18 | float labelWidth = 100.0f; 19 | #endregion 20 | 21 | private ReorderableList list; 22 | List lastValidPaletteList; 23 | 24 | private void OnEnable() { 25 | list = new ReorderableList(serializedObject, 26 | serializedObject.FindProperty("palettes"), 27 | true, true, true, true); 28 | list.onCanRemoveCallback = CanRemovePaletteFromList; 29 | list.drawHeaderCallback = (Rect rect) => { 30 | EditorGUI.LabelField(rect, ((RBPaletteGroup)target).GroupName + " - Palette Mode"); 31 | }; 32 | list.drawElementCallback = DrawListElement; 33 | list.drawElementBackgroundCallback = DrawListElementBackground; 34 | 35 | // TODO: Don't let them reorder Base Palette 36 | } 37 | 38 | #region Reorderable Callbacks 39 | 40 | bool CanRemovePaletteFromList (ReorderableList list) 41 | { 42 | // Don't let them remove the base palette 43 | if (list.index == 0) { 44 | return false; 45 | } 46 | 47 | return !isListLocked; 48 | } 49 | 50 | float GetElementHeight () 51 | { 52 | // Get number of lines we need to show all colors given the width 53 | RBPaletteGroup targetRBPaletteGroup = (RBPaletteGroup) target; 54 | int numColorsInPalette = targetRBPaletteGroup.NumColorsInPalette; 55 | int numColorLines = Mathf.CeilToInt (numColorsInPalette / (float) GetMaxNumColorsPerLine ()); 56 | 57 | // Get size we will need to show all lines 58 | float sizePerLine = EditorGUIUtility.singleLineHeight + palettePadding; 59 | float expectedSize = numColorLines * sizePerLine; 60 | // At minimum show a line per palette 61 | expectedSize = Mathf.Max (expectedSize, sizePerLine) + palettePadding; 62 | 63 | return expectedSize; 64 | } 65 | 66 | int GetMaxNumColorsPerLine () 67 | { 68 | // w = (n-1) * s + N * c + 2p [solve for n = (w - 2p + s) / (s + c)] 69 | // Where n = numColors, s = spacing, c = colorwidth, p = padding, w = availableWidth 70 | float windowWidth = Screen.width; 71 | float reorderableListDefaultPadding = ReorderableList.Defaults.padding; 72 | windowWidth -= (2 * reorderableListDefaultPadding); 73 | 74 | float handleWidth = list.draggable ? ReorderableList.Defaults.dragHandleWidth : 0.0f; 75 | float availableWidth = windowWidth - labelWidth - handleWidth; 76 | int numColors = Mathf.FloorToInt ((availableWidth - (2 * colorPaddingX) + colorSpacing) / 77 | (colorSpacing + colorWidth)); 78 | 79 | return numColors; 80 | } 81 | 82 | void DrawListElement (Rect rect, int index, bool isActive, bool isFocused) 83 | { 84 | var element = list.serializedProperty.GetArrayElementAtIndex(index); 85 | rect.y += palettePadding; 86 | 87 | // Draw label 88 | SerializedProperty paletteName = element.FindPropertyRelative ("PaletteName"); 89 | Rect labelRect = new Rect (rect.x, rect.y, labelWidth, EditorGUIUtility.singleLineHeight); 90 | bool isNameEditable = index > 0 && !isListLocked; 91 | if (isNameEditable) { 92 | paletteName.stringValue = EditorGUI.TextField (labelRect, paletteName.stringValue); 93 | } else { 94 | EditorGUI.LabelField (labelRect, paletteName.stringValue); 95 | } 96 | 97 | // Draw colors 98 | SerializedProperty colorsAsList = element.FindPropertyRelative ("ColorsInPalette"); 99 | int numColorsPerLine = GetMaxNumColorsPerLine (); 100 | List rbColorProperties = GetListFromSerializedProperty (colorsAsList); 101 | for (int i = 0; i < rbColorProperties.Count; i++) { 102 | int colorIndexOnLine = i % numColorsPerLine; 103 | float startX = labelRect.width + colorPaddingX + colorIndexOnLine * (colorWidth + colorSpacing); 104 | float startY = Mathf.FloorToInt (i / numColorsPerLine) * EditorGUIUtility.singleLineHeight; 105 | Rect colorRect = new Rect (rect.x + startX, rect.y + startY, 106 | colorWidth, EditorGUIUtility.singleLineHeight); 107 | SerializedProperty colorProperty = rbColorProperties[i].FindPropertyRelative ("Color"); 108 | colorProperty.colorValue = EditorGUI.ColorField (colorRect, colorProperty.colorValue); 109 | 110 | //EditorGUIUtility.DrawColorSwatch (colorRect, colorProperties[i].colorValue); 111 | } 112 | } 113 | 114 | void DrawListElementBackground (Rect rect, int index, bool isActive, bool isFocused) 115 | { 116 | // Draws a bar on top and bottom to give depth effect, 117 | // and box background to prevent element overlap while dragging. 118 | float barHeight = 1.0f; 119 | rect.width -= 3.0f; // Subtract and shift or it hangs over edges 120 | rect.x += 1.0f; 121 | 122 | Rect topRect = new Rect (rect.x, rect.y, rect.width, barHeight); 123 | EditorGUI.DrawRect (topRect, Color.gray); 124 | 125 | Rect bottomRect = new Rect (rect.x, rect.y + rect.height - barHeight, rect.width, barHeight); 126 | EditorGUI.DrawRect (bottomRect, new Color (0.2f, 0.2f, 0.2f)); 127 | 128 | // Draw default background to handle highlighting and selection. 129 | ReorderableList.defaultBehaviours.DrawElementBackground (rect, index, isActive, isFocused, true); 130 | } 131 | #endregion 132 | 133 | void SetGroupLocked (bool locked) 134 | { 135 | isListLocked = locked; 136 | list.displayAdd = !locked; 137 | list.displayRemove = !locked; 138 | list.draggable = !locked; 139 | } 140 | 141 | public override void OnInspectorGUI () 142 | { 143 | RBPaletteGroup targetRBPaletteGroup = (RBPaletteGroup) target; 144 | 145 | //DrawDefaultInspector (); 146 | serializedObject.Update(); 147 | 148 | list.elementHeight = GetElementHeight (); 149 | 150 | list.DoLayoutList(); 151 | 152 | SerializedProperty lockedProperty = serializedObject.FindProperty ("Locked"); 153 | lockedProperty.boolValue = EditorGUILayout.Toggle ("Locked", lockedProperty.boolValue); 154 | SetGroupLocked (lockedProperty.boolValue); 155 | 156 | EditorGUILayout.Space (); 157 | EditorGUILayout.LabelField ("Colors", EditorStyles.boldLabel); 158 | 159 | if( GUILayout.Button( "Add Color", GUILayout.ExpandWidth(false)) ) 160 | { 161 | targetRBPaletteGroup.AddColor (RBPaletteGroup.DefaultNewColor); 162 | } 163 | 164 | colorIndex = EditorGUILayout.IntSlider ("Color index: ", colorIndex, 0, targetRBPaletteGroup.NumColorsInPalette - 1); 165 | if( GUILayout.Button( "Remove Color At Index", GUILayout.ExpandWidth(false)) ) 166 | { 167 | targetRBPaletteGroup.RemoveColorAtIndex (colorIndex); 168 | } 169 | 170 | EditorGUILayout.Space (); 171 | EditorGUILayout.LabelField ("Utilities", EditorStyles.boldLabel); 172 | 173 | if( GUILayout.Button( "Export As Texture", GUILayout.ExpandWidth(false)) ) 174 | { 175 | string outputPath = AssetDatabaseUtility.GetAssetDirectory (targetRBPaletteGroup); 176 | string extension = ".png"; 177 | string filename = targetRBPaletteGroup.GroupName + extension; 178 | try { 179 | targetRBPaletteGroup.WriteToFile (outputPath + filename, false); 180 | } catch (System.AccessViolationException) { 181 | if (EditorUtility.DisplayDialog ("Warning!", 182 | "This will overwrite the existing file, " + filename + 183 | ". Are you sure you want to export the texture?", "Yes", "No")) { 184 | targetRBPaletteGroup.WriteToFile (outputPath + filename, true); 185 | } 186 | } 187 | } 188 | 189 | serializedObject.ApplyModifiedProperties(); 190 | } 191 | 192 | /// 193 | /// Gets the Serialized Property for a List member as a List of SerializedProperties 194 | /// 195 | /// The value of the serialized property as a List. 196 | /// The property that stores a list. 197 | List GetListFromSerializedProperty (SerializedProperty listAsProperty) 198 | { 199 | if (!listAsProperty.isArray) { 200 | return null; 201 | } 202 | 203 | // Apparently it's bad to iterate on the original... not sure why, but that's 204 | // what the StackOverflow said 205 | SerializedProperty listCopy = listAsProperty.Copy (); 206 | 207 | listCopy.Next (true); // Skip generic element 208 | listCopy.Next (true); // This is the array size 209 | 210 | int listSize = listCopy.intValue; 211 | int lastindex = listSize - 1; 212 | List listOfElements = new List (listSize); 213 | 214 | listCopy.Next (true); // Get first element in list 215 | for (int i = 0; i < listSize; i++) { 216 | // Copy elements or else we will just make a list of the enumerator 217 | SerializedProperty nextElement = listCopy.Copy (); 218 | listOfElements.Add (nextElement); 219 | if (i < lastindex) { 220 | listCopy.Next (false); 221 | } 222 | } 223 | 224 | return listOfElements; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteGroupEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9080838fa1c74251beea8eea433d5c3 3 | timeCreated: 1437334771 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteMapper.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Palette Mapper is a Red Blue Tool used to create indexed color images from 3 | * source images. 4 | * Copyright (C) 2014 Red Blue Games, LLC 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | ****************************************************************************/ 19 | using UnityEngine; 20 | using UnityEditor; 21 | using System.IO; 22 | using System.Collections; 23 | using System.Collections.Generic; 24 | 25 | namespace RedBlueTools 26 | { 27 | public static class RBPaletteMapper 28 | { 29 | public static void ValidateSourceTexture (Texture2D sourceTexture) 30 | { 31 | TextureImporter textureImporter = AssetImporter.GetAtPath (AssetDatabase.GetAssetPath (sourceTexture)) as TextureImporter; 32 | if (!textureImporter.isReadable) { 33 | throw new System.BadImageFormatException ("Source texture must be Read/Write enabled."); 34 | } 35 | 36 | if (sourceTexture.filterMode != FilterMode.Point) { 37 | throw new System.BadImageFormatException ("Source texture must have Point filter mode."); 38 | } 39 | 40 | if (sourceTexture.format != TextureFormat.RGBA32) { 41 | throw new System.BadImageFormatException ("Source texture must be uncompressed (RGBA32)"); 42 | } 43 | } 44 | 45 | public static void ValidatePaletteGroup (RBPaletteGroup paletteGroup) 46 | { 47 | // Nothing to validate as of right now. 48 | } 49 | 50 | public static bool CreatePaletteMapAndKey (string outputPath, Texture2D sourceTexture, RBPaletteGroup suppliedPaletteGroup, 51 | bool overwriteExistingFiles, string paletteKeyFileName, string paletteMapFilename) 52 | { 53 | // If no palette key texture is provided, create a new one from the source image 54 | RBPalette basePalette = null; 55 | if (suppliedPaletteGroup == null) { 56 | basePalette = RBPalette.CreatePaletteFromTexture (sourceTexture); 57 | } else { 58 | RBPaletteDiff diff = suppliedPaletteGroup.DiffWithTexture (sourceTexture); 59 | if (diff.NumChanges > 0) { 60 | if (!EditorUtility.DisplayDialog ("Palettes Differ", 61 | "Current BasePalette is different from the one that would generate from this texture. " + 62 | "Are you sure you want to sync this PaletteGroup to this texture?", "OK", "Cancel")) { 63 | return false; 64 | } 65 | } 66 | suppliedPaletteGroup.ApplyDiff (diff); 67 | basePalette = suppliedPaletteGroup.BasePalette; 68 | } 69 | 70 | // Create the palette map from the palette key 71 | PaletteMap palettemap; 72 | palettemap = new PaletteMap (sourceTexture, basePalette); 73 | 74 | if (suppliedPaletteGroup == null) { 75 | // Write PaletteGroup to disk 76 | try { 77 | string paletteGroupFilename = paletteKeyFileName + ".asset"; 78 | RBPaletteGroup createdGroup = RBPaletteCreator.CreatePaletteGroup (outputPath, paletteGroupFilename, overwriteExistingFiles); 79 | createdGroup.GroupName = paletteKeyFileName; 80 | createdGroup.SetBasePalette (basePalette); 81 | createdGroup.Locked = true; 82 | } catch (IOException) { 83 | throw new System.IO.IOException ("Failed to write PaletteMap. A PaletteGroup already exists by the name: " + paletteKeyFileName); 84 | } 85 | } 86 | 87 | // Write PaletteMap to disk 88 | string paletteMapFilenameWithExtension = paletteMapFilename + ".png"; 89 | string fullPathToPaletteMapFile = outputPath + paletteMapFilenameWithExtension; 90 | palettemap.WriteToFile (fullPathToPaletteMapFile, overwriteExistingFiles); 91 | 92 | return true; 93 | } 94 | 95 | class PaletteMap 96 | { 97 | Color[] pixels; 98 | int width; 99 | int height; 100 | 101 | public PaletteMap (Texture2D sourceTexture, RBPalette basePalette) 102 | { 103 | this.width = sourceTexture.width; 104 | this.height = sourceTexture.height; 105 | 106 | Color[] sourcePixels = sourceTexture.GetPixels (); 107 | pixels = new Color[sourcePixels.Length]; 108 | 109 | // Remap original colors to point to indeces in the palette 110 | for (int i = 0; i < sourcePixels.Length; i++) { 111 | // Get the alpha value by looking it up in the paletteKey 112 | int paletteIndex = basePalette.IndexOf (sourcePixels [i]); 113 | if (paletteIndex < 0) { 114 | Vector2 coordinateFromBottomLeft = new Vector2 (i % width, i / height); 115 | Vector2 coordinateFromTopLeft = new Vector2 (coordinateFromBottomLeft.x, height - coordinateFromBottomLeft.y); 116 | throw new System.ArgumentException ("Encountered color in source PaletteMap image that is not in the base palette." + 117 | " Color in PaletteMap: " + (Color32)sourcePixels [i] + 118 | " At coordinate: " + coordinateFromTopLeft); 119 | } 120 | float alpha; 121 | if (basePalette.Count == 1) { 122 | alpha = 0.0f; 123 | } else { 124 | alpha = paletteIndex / (float)(basePalette.Count - 1); 125 | // For some reason, 1.0f wraps around in the shader. Maybe it's epsilon issues. 126 | alpha = Mathf.Clamp (alpha, 0.0f, 0.99f); 127 | } 128 | pixels [i] = new Color (0.0f, 0.0f, 0.0f, alpha); 129 | } 130 | } 131 | 132 | Texture2D CreateAsTexture () 133 | { 134 | Texture2D paletteMapAsTexture = new Texture2D (width, height, TextureFormat.Alpha8, false); 135 | paletteMapAsTexture.hideFlags = HideFlags.HideAndDontSave; 136 | paletteMapAsTexture.SetPixels (pixels); 137 | paletteMapAsTexture.Apply (); 138 | 139 | return paletteMapAsTexture; 140 | } 141 | 142 | public void WriteToFile (string fullPath, bool allowOverwriting) 143 | { 144 | if (File.Exists (fullPath) && !allowOverwriting) { 145 | throw new System.AccessViolationException ("Tried to write PaletteMap but file already exists. " + 146 | "\nFile Path: " + fullPath); 147 | } 148 | 149 | Texture2D texture = CreateAsTexture (); 150 | try { 151 | byte[] outTextureData = texture.EncodeToPNG (); 152 | File.WriteAllBytes (fullPath, outTextureData); 153 | } catch (System.Exception e) { 154 | throw new System.IO.IOException ("Encountered IO exception during PaletteMap write: " + e.Message); 155 | } 156 | 157 | // Force refresh so that we can set its Import settings immediately 158 | AssetDatabase.ImportAsset (fullPath); 159 | 160 | // Assign correct settings to the file 161 | TextureImporter textureImporter = AssetImporter.GetAtPath (fullPath) as TextureImporter; 162 | if(textureImporter == null) { 163 | throw new System.NullReferenceException ("Failed to import file at specified path: " + fullPath); 164 | } 165 | textureImporter.textureType = TextureImporterType.Advanced; 166 | textureImporter.npotScale = TextureImporterNPOTScale.None; 167 | textureImporter.alphaIsTransparency = false; 168 | textureImporter.mipmapEnabled = false; 169 | textureImporter.filterMode = FilterMode.Point; 170 | textureImporter.textureFormat = TextureImporterFormat.Alpha8; 171 | 172 | // Force Unity to see the file and use the new import settings 173 | AssetDatabase.ImportAsset (fullPath); 174 | } 175 | } 176 | } 177 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteMapper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa6e290a689644887be022d69d5c1aeb 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteMapperWindow.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Palette Mapper is a Red Blue Tool used to create indexed color images from 3 | * source images. 4 | * Copyright (C) 2014 Red Blue Games, LLC 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | ****************************************************************************/ 19 | using UnityEngine; 20 | using UnityEditor; 21 | using System.Collections; 22 | 23 | namespace RedBlueTools 24 | { 25 | class RBPaletteMapperWindow : EditorWindow 26 | { 27 | Object sourceTexture = null; 28 | Object lastSourceTexture; 29 | string paletteKeyFilename; 30 | string paletteMapFilename; 31 | Object suppliedPalleteKey = null; 32 | bool overwriteExistingFiles = true; 33 | bool sortPalette = false; 34 | PaletteKeyOption paletteKeyOption; 35 | 36 | enum PaletteKeyOption 37 | { 38 | GenerateNewPaletteKey, 39 | SupplyCustomPaletteKey 40 | } 41 | 42 | [MenuItem ("RedBlueTools/Palette Mapper")] 43 | public static void ShowWindow () 44 | { 45 | EditorWindow.GetWindow ("Palette Mapper"); 46 | } 47 | 48 | void OnGUI () 49 | { 50 | GUILayout.Label ("Palette Map", EditorStyles.boldLabel); 51 | sourceTexture = EditorGUILayout.ObjectField ("Source Texture", sourceTexture, typeof(Texture2D), false); 52 | 53 | bool sourceTextureChanged = lastSourceTexture != sourceTexture; 54 | if(sourceTextureChanged) { 55 | lastSourceTexture = sourceTexture; 56 | 57 | paletteMapFilename = sourceTexture.name + "_PaletteMap"; 58 | paletteKeyFilename = sourceTexture.name + "_PaletteGroup"; 59 | } 60 | 61 | if(sourceTexture != null) { 62 | paletteMapFilename = EditorGUILayout.TextField("Output Filename", paletteMapFilename); 63 | } 64 | 65 | GUILayout.Label ("Palette Key", EditorStyles.boldLabel); 66 | paletteKeyOption = (PaletteKeyOption)EditorGUILayout.EnumPopup ("Palette Key Creation: ", paletteKeyOption); 67 | switch (paletteKeyOption) { 68 | case PaletteKeyOption.GenerateNewPaletteKey: 69 | suppliedPalleteKey = null; 70 | if(sourceTexture != null) { 71 | paletteKeyFilename = EditorGUILayout.TextField("Output Filename", paletteKeyFilename); 72 | } 73 | sortPalette = EditorGUILayout.Toggle ("Sort PaletteKey", sortPalette); 74 | break; 75 | case PaletteKeyOption.SupplyCustomPaletteKey: 76 | suppliedPalleteKey = EditorGUILayout.ObjectField ("Linked Palette Group", suppliedPalleteKey, typeof(RBPaletteGroup), false); 77 | sortPalette = false; 78 | break; 79 | } 80 | 81 | GUILayout.Label ("Options", EditorStyles.boldLabel); 82 | overwriteExistingFiles = EditorGUILayout.Toggle ("Overwite Existing files", overwriteExistingFiles); 83 | 84 | if (GUILayout.Button ("Build")) { 85 | if (sourceTexture == null) { 86 | Debug.LogError ("RBPaletteMapper Error: No source texture specified"); 87 | return; 88 | } 89 | 90 | // Validate source texture 91 | Texture2D inTexture = (Texture2D)sourceTexture; 92 | try { 93 | RBPaletteMapper.ValidateSourceTexture (inTexture); 94 | } catch (System.BadImageFormatException e) { 95 | Debug.LogError ("RBPaletteMapper Error: " + e.Message); 96 | return; 97 | } 98 | 99 | // Validate or skip Palette Key 100 | RBPaletteGroup inPaletteKey = null; 101 | if (paletteKeyOption == PaletteKeyOption.SupplyCustomPaletteKey) { 102 | if (suppliedPalleteKey == null) { 103 | Debug.LogError ("RBPaletteMapper Error: Trying to use custom palette key but no palette key specified." + 104 | "\nPlease select a RBPaletteGroup to use as the Palette Key."); 105 | return; 106 | } 107 | inPaletteKey = (RBPaletteGroup)suppliedPalleteKey; 108 | try { 109 | RBPaletteMapper.ValidatePaletteGroup (inPaletteKey); 110 | } catch { 111 | Debug.LogError ("Unknown PaletteMap Error encountered while Validating supplied PaletteGroup."); 112 | return; 113 | } 114 | } 115 | 116 | string path = AssetDatabaseUtility.GetAssetDirectory (inTexture); 117 | try { 118 | RBPaletteMapper.CreatePaletteMapAndKey (path, inTexture, inPaletteKey, overwriteExistingFiles, paletteKeyFilename, paletteMapFilename); 119 | 120 | Debug.Log ("Palette Map and Key for file " + inTexture.name + " created successfully"); 121 | // TODO: Better error handling messages 122 | } catch (System.NotSupportedException e) { 123 | LogError (e.Message, e); 124 | } catch (System.ArgumentException e) { 125 | LogError (e.Message, e); 126 | } catch (System.AccessViolationException e) { 127 | LogError (e.Message, e); 128 | } catch (System.IO.IOException e) { 129 | LogError ("Encountered IO Exception: " + e.Message, e); 130 | } catch (System.Exception e) { 131 | LogError ("Encountered unknown error: " + e.Message, e); 132 | } 133 | } 134 | } 135 | 136 | void LogError (string message, System.Exception e) 137 | { 138 | Debug.LogError ("PaletteMap Error: " + message + "Error: " + e); 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Editor/RBPaletteMapperWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4678b59c392c42aabc4208668a0b817 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 00a35113602ed4bc986966a9238bc100 3 | folderAsset: yes 4 | timeCreated: 1438701929 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Animations.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 920a25b2d7da043d4a4974ccd355475e 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Animations/Knight.controller: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Animations/Knight.controller -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Animations/Knight.controller.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4cd81252594943d2aa7a0840a951f54 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Animations/Knight_Idle.anim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Animations/Knight_Idle.anim -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Animations/Knight_Idle.anim.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0c314b993d954495bb71b8ad80ad332 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Demo.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Demo.unity -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Demo.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a71017bc315b4f39b4db8c5e1452f10 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ba6551c2ea254f8e9dbf24b6a505875 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt1.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt1.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3625d8798dc046bf8df86a05bafdf14 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt2.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Alt2.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d703e13e42e1a486b8c1973aaa7062ab 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_MultiPalette.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_MultiPalette.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_MultiPalette.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4d3c7cced6a646f0885b562a4bd2ab7 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_PaletteKey.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_PaletteKey.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_PaletteKey.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c1d862e45f9848189886dfd38221a2d 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt1.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt1.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e556cd38bbfc4555863c016e0778837 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt2.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Alt2.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d201dafa31b3a4e2b8c9bee596d2005b 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Multi.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Multi.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palette_Multi.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99f700eb0cdf941c5ac27ea4d6aabaa0 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cc483eb4a2fd43dcb294534c02b9479 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized_Transparent.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized_Transparent.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Knight_Palettized_Transparent.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 131012cc2b8a54ce69b55dd09c75d1cd 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Waterfall.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/Waterfall.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/Waterfall.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b22126f59eae4c0aa46c8a3398cb59b 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Original.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_Original.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Original.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09bb2e7dd0aaf4b95a83d24b4b5ce9bb 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_PaletteKey.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_PaletteKey.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_PaletteKey.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9df7331da49947d7af9f0ae51ef952a 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_PaletteMap.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_PaletteMap.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_PaletteMap.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cd68f109fdfa740a8adda04560c24021 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palette_Blue.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_Palette_Blue.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palette_Blue.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1d734af8c0bb42c7b24c8b12ee3c6d7 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palettized.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_Palettized.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palettized.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51c6ef463b8be4782b4004213150fa5e 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palettized_Blue.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Materials/World_Palettized_Blue.mat -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Materials/World_Palettized_Blue.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61a4fde2466674204bc5ea8cbb242ab7 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd327a7c85d1745a68a76440c329a8d9 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b4dab76a320846abaa7e6f9b0cd4fa1 3 | TextureImporter: 4 | fileIDToRecycleName: 5 | 21300000: Knight 6 | 21300002: Knight_0 7 | 21300004: Knight_1 8 | 21300006: Knight_2 9 | 21300008: Knight_3 10 | serializedVersion: 2 11 | mipmaps: 12 | mipMapMode: 0 13 | enableMipMap: 0 14 | linearTexture: 0 15 | correctGamma: 0 16 | fadeOut: 0 17 | borderMipMap: 0 18 | mipMapFadeDistanceStart: 1 19 | mipMapFadeDistanceEnd: 3 20 | bumpmap: 21 | convertToNormalMap: 0 22 | externalNormalMap: 0 23 | heightScale: .25 24 | normalMapFilter: 0 25 | isReadable: 1 26 | grayScaleToAlpha: 0 27 | generateCubemap: 0 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 1024 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | compressionQuality: 50 39 | spriteMode: 2 40 | spriteExtrude: 1 41 | spriteMeshType: 1 42 | alignment: 0 43 | spritePivot: {x: .5, y: .5} 44 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 45 | spritePixelsToUnits: 1 46 | alphaIsTransparency: 1 47 | textureType: 5 48 | buildTargetSettings: [] 49 | spriteSheet: 50 | sprites: 51 | - name: Knight_0 52 | rect: 53 | serializedVersion: 2 54 | x: 0 55 | y: 0 56 | width: 16 57 | height: 16 58 | alignment: 0 59 | pivot: {x: 0, y: 0} 60 | border: {x: 0, y: 0, z: 0, w: 0} 61 | - name: Knight_1 62 | rect: 63 | serializedVersion: 2 64 | x: 16 65 | y: 0 66 | width: 16 67 | height: 16 68 | alignment: 0 69 | pivot: {x: 0, y: 0} 70 | border: {x: 0, y: 0, z: 0, w: 0} 71 | - name: Knight_2 72 | rect: 73 | serializedVersion: 2 74 | x: 32 75 | y: 0 76 | width: 16 77 | height: 16 78 | alignment: 0 79 | pivot: {x: 0, y: 0} 80 | border: {x: 0, y: 0, z: 0, w: 0} 81 | - name: Knight_3 82 | rect: 83 | serializedVersion: 2 84 | x: 48 85 | y: 0 86 | width: 16 87 | height: 16 88 | alignment: 0 89 | pivot: {x: 0, y: 0} 90 | border: {x: 0, y: 0, z: 0, w: 0} 91 | spritePackingTag: 92 | userData: 93 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 235119245f7f94151b17c23e3909c959 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey_CustomSort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey_CustomSort.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteKey_CustomSort.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d55e8452862fe4b91959341eed4c5fb8 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 1 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: 5 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteMap.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_PaletteMap.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e2dd9bcfc2164dadb2127f0f6b09168 3 | TextureImporter: 4 | fileIDToRecycleName: 5 | 21300000: Knight_PaletteMap_0 6 | 21300002: Knight_PaletteMap_1 7 | 21300004: Knight_PaletteMap_2 8 | 21300006: Knight_PaletteMap_3 9 | serializedVersion: 2 10 | mipmaps: 11 | mipMapMode: 0 12 | enableMipMap: 0 13 | linearTexture: 0 14 | correctGamma: 0 15 | fadeOut: 0 16 | borderMipMap: 0 17 | mipMapFadeDistanceStart: 1 18 | mipMapFadeDistanceEnd: 3 19 | bumpmap: 20 | convertToNormalMap: 0 21 | externalNormalMap: 0 22 | heightScale: .25 23 | normalMapFilter: 0 24 | isReadable: 0 25 | grayScaleToAlpha: 0 26 | generateCubemap: 0 27 | seamlessCubemap: 0 28 | textureFormat: 1 29 | maxTextureSize: 1024 30 | textureSettings: 31 | filterMode: 0 32 | aniso: -1 33 | mipBias: -1 34 | wrapMode: -1 35 | nPOTScale: 0 36 | lightmap: 0 37 | compressionQuality: 50 38 | spriteMode: 2 39 | spriteExtrude: 1 40 | spriteMeshType: 1 41 | alignment: 0 42 | spritePivot: {x: .5, y: .5} 43 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 44 | spritePixelsToUnits: 1 45 | alphaIsTransparency: 0 46 | textureType: 5 47 | buildTargetSettings: [] 48 | spriteSheet: 49 | sprites: 50 | - name: Knight_PaletteMap_0 51 | rect: 52 | serializedVersion: 2 53 | x: 0 54 | y: 0 55 | width: 16 56 | height: 16 57 | alignment: 0 58 | pivot: {x: 0, y: 0} 59 | border: {x: 0, y: 0, z: 0, w: 0} 60 | - name: Knight_PaletteMap_1 61 | rect: 62 | serializedVersion: 2 63 | x: 16 64 | y: 0 65 | width: 16 66 | height: 16 67 | alignment: 0 68 | pivot: {x: 0, y: 0} 69 | border: {x: 0, y: 0, z: 0, w: 0} 70 | - name: Knight_PaletteMap_2 71 | rect: 72 | serializedVersion: 2 73 | x: 32 74 | y: 0 75 | width: 16 76 | height: 16 77 | alignment: 0 78 | pivot: {x: 0, y: 0} 79 | border: {x: 0, y: 0, z: 0, w: 0} 80 | - name: Knight_PaletteMap_3 81 | rect: 82 | serializedVersion: 2 83 | x: 48 84 | y: 0 85 | width: 16 86 | height: 16 87 | alignment: 0 88 | pivot: {x: 0, y: 0} 89 | border: {x: 0, y: 0, z: 0, w: 0} 90 | spritePackingTag: 91 | userData: 92 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt1.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8606d3bf7388b49beac1638b705d0ef7 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt2.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Alt2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06134f628bf93481487cdb7f9591b804 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Multi.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Knight_Palette_Multi.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb15f8d530c02408eac129594ce76380 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: 5 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Waterfall.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f75303190bc64973b98f8f424c00536 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 1 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 1 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: 5 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_AnimatingKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Waterfall_AnimatingKey.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_AnimatingKey.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: edc49910b60ec434d90e84b3b652f4a5 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteKey.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteKey.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f84578c4673043d28944d8d4709d8ec 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteMap.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_PaletteMap.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51ab896ed75874a06abd65c716a38358 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 1 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: 5 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_SourceFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/Waterfall_SourceFile.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/Waterfall_SourceFile.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 754d1c216b042433aa05b55ddc46ac4a 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: -1 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: -1 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 1 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/World.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93fc52e79b2384c739c68471e1feb808 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 1 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: 5 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_PaletteKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/World_PaletteKey.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_PaletteKey.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1aaaa085a9c884f27910c65970aeeb05 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 1 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_PaletteMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/World_PaletteMap.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_PaletteMap.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 948b0142920ab48ffbfe5dbe3bae4532 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 1 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_Palette_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/RBPixelPalettemap/Examples/Textures/World_Palette_blue.png -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Examples/Textures/World_Palette_blue.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc6e91047ce514b4e8ce4edc325b788d 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 0 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: .25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | seamlessCubemap: 0 24 | textureFormat: 4 25 | maxTextureSize: 256 26 | textureSettings: 27 | filterMode: 0 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 0 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 1 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64ade3250005040e3a002855f7f1b845 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/MaterialTween.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright (C) 2014 Red Blue Games, LLC 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | using UnityEngine; 18 | using System.Collections; 19 | 20 | namespace RedBlueTools 21 | { 22 | /// 23 | /// MaterialTween is a RedBlueTool used to swap between materials on a gameobject. 24 | /// 25 | public class MaterialTween : MonoBehaviour 26 | { 27 | public Material[] tweenMaterials; 28 | public float swapInterval; 29 | public float duration; 30 | public bool TweenOnAwake; 31 | bool IsTweening; 32 | float timeTweening; 33 | public static float INFINITE_DURATION = -1.0f; 34 | 35 | // State tracking members 36 | Material originalMaterial; 37 | int currentIndex = 0; 38 | 39 | IEnumerator tweenCoroutine; 40 | 41 | void Awake () 42 | { 43 | if(TweenOnAwake) { 44 | BeginTweening (); 45 | } 46 | } 47 | 48 | public void BeginTweening () 49 | { 50 | if (tweenMaterials == null || tweenMaterials.Length <= 0) { 51 | Debug.LogError ("No textures assigned to Material Tween on GameObject: " + gameObject.name 52 | + "\nMust have at least one texture."); 53 | enabled = false; 54 | return; 55 | } 56 | 57 | if(Mathf.Approximately(duration, 0.0f)) { 58 | Debug.LogWarning("Trying to begin a material tween with no duration. Please assign a duration."); 59 | enabled = false; 60 | return; 61 | } 62 | 63 | // If told to tween while already tweening, reset duration. 64 | if(IsTweening) { 65 | timeTweening = 0.0f; 66 | return; 67 | } 68 | 69 | tweenCoroutine = TweenForDuration(); 70 | StartCoroutine(tweenCoroutine); 71 | } 72 | 73 | IEnumerator TweenForDuration () 74 | { 75 | IsTweening = true; 76 | 77 | currentIndex = 0; 78 | originalMaterial = GetComponent().material; 79 | GetComponent().material = tweenMaterials [currentIndex]; 80 | 81 | float timeUntilSwap = swapInterval; 82 | timeTweening = 0.0f; 83 | while (true) { 84 | 85 | timeUntilSwap -= Time.deltaTime; 86 | // Every swap interval, go to the next Material 87 | if (timeUntilSwap <= 0.0f) { 88 | IncrementMaterial (); 89 | // Reset timer, carrying over extra deltaTime 90 | timeUntilSwap += swapInterval; 91 | } 92 | 93 | // Check if duration time has elapsed 94 | if(duration > 0.0f) { 95 | timeTweening += Time.deltaTime; 96 | if(timeTweening >= duration) { 97 | break; 98 | } 99 | } 100 | 101 | yield return null; 102 | } 103 | 104 | FinishTween (); 105 | } 106 | void IncrementMaterial () 107 | { 108 | currentIndex = currentIndex + 1; 109 | // Wrap back around when done looping through materials. 110 | if (currentIndex >= tweenMaterials.Length) { 111 | currentIndex = 0; 112 | } 113 | GetComponent().material = tweenMaterials [currentIndex]; 114 | } 115 | 116 | void FinishTween () 117 | { 118 | StopTweening (); 119 | } 120 | 121 | public void StopTweening () 122 | { 123 | IsTweening = false; 124 | 125 | // Restore original material 126 | GetComponent().material = originalMaterial; 127 | 128 | StopCoroutine(tweenCoroutine); 129 | tweenCoroutine = null; 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/MaterialTween.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a569a447b0824db9b57d9dd5c0e700a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/PaletteScroll.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright (C) 2014 Red Blue Games, LLC 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | 18 | using UnityEngine; 19 | using System.Collections; 20 | 21 | namespace RedBlueTools 22 | { 23 | /// 24 | /// PaletteScroll scrolls a Material's PaletteY offset at a specified rate during Update. 25 | /// 26 | public class PaletteScroll : MonoBehaviour 27 | { 28 | 29 | string paletteTexture = "_Palette"; 30 | public float scrollRate; 31 | 32 | void Update () 33 | { 34 | float deltaY = scrollRate * Time.deltaTime; 35 | float currentPaletteY = GetComponent().material.GetTextureOffset(paletteTexture).y; 36 | float newPaletteY = (currentPaletteY + deltaY) % 1.0f; 37 | 38 | // Set the paletteYOffset for the given material. 39 | GetComponent().material.SetTextureOffset(paletteTexture, new Vector2(0.0f,newPaletteY)); 40 | } 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/PaletteScroll.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52f89e4961f0d4cda8537a3bc4b80d4d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/RBPalette.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | using System.Collections; 5 | 6 | [System.Serializable] 7 | public class RBPalette 8 | { 9 | public string PaletteName; 10 | [SerializeField] 11 | List ColorsInPalette; 12 | string defaultColorName = "Color"; 13 | 14 | [System.Serializable] 15 | class RBPaletteColor 16 | { 17 | public Color Color; 18 | public string Name; 19 | 20 | public RBPaletteColor (Color color, string name) 21 | { 22 | this.Color = color; 23 | this.Name = name; 24 | } 25 | } 26 | 27 | public Color this [int index] { 28 | get { 29 | return GetColor (index); 30 | } 31 | set { 32 | SetColor (index, value); 33 | } 34 | } 35 | 36 | public int Count { 37 | get { 38 | return ColorsInPalette.Count; 39 | } 40 | } 41 | 42 | Color GetColor (int index) 43 | { 44 | return ColorsInPalette [index].Color; 45 | } 46 | 47 | void SetColor (int index, Color color) 48 | { 49 | ColorsInPalette [index].Color = color; 50 | } 51 | 52 | public RBPalette () : this ("RBPalette") 53 | { 54 | } 55 | 56 | public RBPalette (string paletteName) 57 | { 58 | this.PaletteName = paletteName; 59 | this.ColorsInPalette = new List (); 60 | } 61 | 62 | public RBPalette (RBPalette paletteToCopy) 63 | { 64 | this.PaletteName = paletteToCopy.PaletteName; 65 | this.ColorsInPalette = new List (); 66 | this.ColorsInPalette.AddRange (paletteToCopy.ColorsInPalette); 67 | } 68 | 69 | public void AddColor (Color color) 70 | { 71 | ColorsInPalette.Add (new RBPaletteColor (color, defaultColorName + ColorsInPalette.Count)); 72 | } 73 | 74 | public void RemoveColorAtIndex (int index) 75 | { 76 | ColorsInPalette.RemoveAt (index); 77 | } 78 | 79 | public bool ContainsColor (Color colorToFind) 80 | { 81 | return IndexOf (colorToFind) >= 0; 82 | } 83 | 84 | public int IndexOf (Color colorToFind) 85 | { 86 | int index = -1; 87 | for (int i = 0; i < ColorsInPalette.Count; i++) { 88 | bool colorToFindIsZeroAlpha = Mathf.Approximately (colorToFind.a, 0.0f); 89 | bool currentColorIsZeroAlpha = Mathf.Approximately (ColorsInPalette [i].Color.a, 0.0f); 90 | if ((colorToFindIsZeroAlpha && currentColorIsZeroAlpha) || ColorsInPalette [i].Color == colorToFind) { 91 | index = i; 92 | break; 93 | } 94 | } 95 | 96 | return index; 97 | } 98 | 99 | public static RBPalette CreatePaletteFromTexture (Texture2D sourceTexture) 100 | { 101 | Color[] sourcePixels = sourceTexture.GetPixels (); 102 | RBPalette palette = new RBPalette (); 103 | palette.PaletteName = sourceTexture.name; 104 | 105 | // Get all unique colors 106 | for (int i = 0; i < sourcePixels.Length; i++) { 107 | Color colorAtSource = ClearRGBIfNoAlpha (sourcePixels [i]); 108 | if (!palette.ContainsColor (colorAtSource)) { 109 | palette.AddColor (colorAtSource); 110 | } 111 | } 112 | 113 | return palette; 114 | } 115 | 116 | 117 | /// 118 | /// Clears the RGB if there is no alpha. This is useful to keep duplicate full-transparent colors out of the palette 119 | /// 120 | /// If color has no alpha returns black with 0 alpha, otherwise returns the original color. 121 | /// Color to clear. 122 | static Color ClearRGBIfNoAlpha (Color colorToClear) 123 | { 124 | Color clearedColor = colorToClear; 125 | if (Mathf.Approximately (clearedColor.a, 0.0f)) { 126 | clearedColor = Color.clear; 127 | } 128 | return clearedColor; 129 | } 130 | 131 | public override string ToString () 132 | { 133 | string fullString = ""; 134 | fullString += "[RBPalette: Name=" + PaletteName + " Count=" + Count + " Colors="; 135 | for (int i =0; i < Count; i++) { 136 | string colorString = "{"; 137 | colorString += (Color32) ColorsInPalette[i].Color; 138 | colorString += "}"; 139 | fullString += colorString; 140 | } 141 | return fullString; 142 | } 143 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/RBPalette.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e30526a61fd44c28b2cb94d27a51476 3 | timeCreated: 1435522619 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/RBPaletteDiff.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | [System.Serializable] 6 | public class RBPaletteDiff 7 | { 8 | public List Insertions; 9 | public List Deletions; 10 | 11 | public int NumChanges 12 | { 13 | get { 14 | return Insertions.Count + Deletions.Count; 15 | } 16 | } 17 | 18 | public RBPaletteDiff () 19 | { 20 | Insertions = new List (); 21 | Deletions = new List (); 22 | } 23 | 24 | public static RBPaletteDiff Diff (RBPalette paletteA, RBPalette paletteB) 25 | { 26 | RBPaletteDiff diffResults = new RBPaletteDiff (); 27 | 28 | // Find deletions (colors in A that aren't in B) 29 | for (int i = 0; i < paletteA.Count; i++) { 30 | if (!paletteB.ContainsColor (paletteA[i])) { 31 | diffResults.Deletions.Add (paletteA[i]); 32 | } 33 | } 34 | 35 | // Find insertions (colors in B that aren't in A) 36 | for (int i = 0; i < paletteB.Count; i++) { 37 | if (!paletteA.ContainsColor (paletteB[i])) { 38 | diffResults.Insertions.Add (paletteB[i]); 39 | } 40 | } 41 | 42 | return diffResults; 43 | } 44 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/RBPaletteDiff.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ac0fd25045ed4cd0ad743d4fdf54c90 3 | timeCreated: 1441628973 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/SetTextureVariableExample.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright (C) 2014 Red Blue Games, LLC 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | using UnityEngine; 18 | using System.Collections; 19 | 20 | namespace RedBlueTools 21 | { 22 | /// 23 | /// SetTextureVariableExample is simply an example of how to set a shader variable from script. 24 | /// 25 | public class SetTextureVariableExample : MonoBehaviour 26 | { 27 | 28 | public Texture[] palettes; 29 | public int currentIndex = 0; 30 | string paletteVariable = "_Palette"; 31 | 32 | void OnEnable () 33 | { 34 | if (palettes.Length == 0) { 35 | Debug.LogError ("No Palette textures assigned to GameObject: " + gameObject.name); 36 | enabled = false; 37 | } 38 | } 39 | 40 | void Update () 41 | { 42 | if (currentIndex > palettes.Length || currentIndex < 0) { 43 | Debug.LogError ("Tried to set palette index beyond the number of supplied Palettes."); 44 | currentIndex = 0; 45 | } 46 | 47 | // Set the palette for the given material. 48 | GetComponent().material.SetTexture (paletteVariable, palettes [currentIndex]); 49 | 50 | // This would change the palette for all objects using this material. Careful with this, 51 | // since changes will persist across Play mode. 52 | //renderer.sharedMaterial.SetTexture(paletteVariable, palettes[currentIndex]); 53 | 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Scripts/SetTextureVariableExample.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f9aa023148364380b1c2b402dcafb1b 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0972a2be079d341dd9cbfe7306226adc 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5cf2d0c29eb145f2bb01a1cea08c8db 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Sprites-Default.shader: -------------------------------------------------------------------------------- 1 | Shader "Sprites/Default" 2 | { 3 | Properties 4 | { 5 | [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} 6 | _Color ("Tint", Color) = (1,1,1,1) 7 | [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 8 | } 9 | 10 | SubShader 11 | { 12 | Tags 13 | { 14 | "Queue"="Transparent" 15 | "IgnoreProjector"="True" 16 | "RenderType"="Transparent" 17 | "PreviewType"="Plane" 18 | "CanUseSpriteAtlas"="True" 19 | } 20 | 21 | Cull Off 22 | Lighting Off 23 | ZWrite Off 24 | Fog { Mode Off } 25 | Blend One OneMinusSrcAlpha 26 | 27 | Pass 28 | { 29 | CGPROGRAM 30 | #pragma vertex vert 31 | #pragma fragment frag 32 | #pragma multi_compile DUMMY PIXELSNAP_ON 33 | #include "UnityCG.cginc" 34 | 35 | struct appdata_t 36 | { 37 | float4 vertex : POSITION; 38 | float4 color : COLOR; 39 | float2 texcoord : TEXCOORD0; 40 | }; 41 | 42 | struct v2f 43 | { 44 | float4 vertex : SV_POSITION; 45 | fixed4 color : COLOR; 46 | half2 texcoord : TEXCOORD0; 47 | }; 48 | 49 | fixed4 _Color; 50 | 51 | v2f vert(appdata_t IN) 52 | { 53 | v2f OUT; 54 | OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); 55 | OUT.texcoord = IN.texcoord; 56 | OUT.color = IN.color * _Color; 57 | #ifdef PIXELSNAP_ON 58 | OUT.vertex = UnityPixelSnap (OUT.vertex); 59 | #endif 60 | 61 | return OUT; 62 | } 63 | 64 | sampler2D _MainTex; 65 | 66 | fixed4 frag(v2f IN) : SV_Target 67 | { 68 | fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color; 69 | c.rgb *= c.a; 70 | return c; 71 | } 72 | ENDCG 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Sprites-Default.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abcec6bbcd2b9440d8b8408dd7e73c90 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Unlit-Alpha.shader: -------------------------------------------------------------------------------- 1 | // Unlit alpha-blended shader. 2 | // - no lighting 3 | // - no lightmap support 4 | // - no per-material color 5 | 6 | Shader "Unlit/Transparent" { 7 | Properties { 8 | _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} 9 | } 10 | 11 | SubShader { 12 | Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} 13 | LOD 100 14 | 15 | ZWrite Off 16 | Blend SrcAlpha OneMinusSrcAlpha 17 | 18 | Pass { 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | 25 | struct appdata_t { 26 | float4 vertex : POSITION; 27 | float2 texcoord : TEXCOORD0; 28 | }; 29 | 30 | struct v2f { 31 | float4 vertex : SV_POSITION; 32 | half2 texcoord : TEXCOORD0; 33 | }; 34 | 35 | sampler2D _MainTex; 36 | float4 _MainTex_ST; 37 | 38 | v2f vert (appdata_t v) 39 | { 40 | v2f o; 41 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 42 | o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); 43 | return o; 44 | } 45 | 46 | fixed4 frag (v2f i) : SV_Target 47 | { 48 | fixed4 col = tex2D(_MainTex, i.texcoord); 49 | return col; 50 | } 51 | ENDCG 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Unlit-Alpha.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad526a42155f243b69aed1c183c9ebc2 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Unlit-Normal.shader: -------------------------------------------------------------------------------- 1 | // Unlit shader. Simplest possible textured shader. 2 | // - no lighting 3 | // - no lightmap support 4 | // - no per-material color 5 | 6 | Shader "Unlit/Texture" { 7 | Properties { 8 | _MainTex ("Base (RGB)", 2D) = "white" {} 9 | } 10 | 11 | SubShader { 12 | Tags { "RenderType"="Opaque" } 13 | LOD 100 14 | 15 | Pass { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "UnityCG.cginc" 21 | 22 | struct appdata_t { 23 | float4 vertex : POSITION; 24 | float2 texcoord : TEXCOORD0; 25 | }; 26 | 27 | struct v2f { 28 | float4 vertex : SV_POSITION; 29 | half2 texcoord : TEXCOORD0; 30 | }; 31 | 32 | sampler2D _MainTex; 33 | float4 _MainTex_ST; 34 | 35 | v2f vert (appdata_t v) 36 | { 37 | v2f o; 38 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 39 | o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); 40 | return o; 41 | } 42 | 43 | fixed4 frag (v2f i) : SV_Target 44 | { 45 | fixed4 col = tex2D(_MainTex, i.texcoord); 46 | return col; 47 | } 48 | ENDCG 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/DefaultShaders/Unlit-Normal.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c52d943973c04c0f9caf88d9403bfd1 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteSprite.shader: -------------------------------------------------------------------------------- 1 | // Default Sprite Shader combined with an indexed color texture (Palette) 2 | Shader "RBTools/Palettized Image/Palette Sprite" 3 | { 4 | Properties 5 | { 6 | [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} 7 | _Palette ("Palette Texture", 2D) = "white" {} 8 | _Tint ("Tint", Color) = (1,1,1,1) 9 | [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 10 | } 11 | 12 | SubShader 13 | { 14 | Tags 15 | { 16 | "Queue"="Transparent" 17 | "IgnoreProjector"="True" 18 | "RenderType"="Transparent" 19 | "PreviewType"="Plane" 20 | "CanUseSpriteAtlas"="True" 21 | } 22 | 23 | Cull Off 24 | Lighting Off 25 | ZWrite Off 26 | Fog { Mode Off } 27 | Blend One OneMinusSrcAlpha 28 | 29 | Pass 30 | { 31 | CGPROGRAM 32 | #pragma vertex vert 33 | #pragma fragment frag 34 | #pragma multi_compile DUMMY PIXELSNAP_ON 35 | #include "UnityCG.cginc" 36 | 37 | struct appdata_t 38 | { 39 | float4 vertex : POSITION; 40 | float4 color : COLOR; 41 | float2 texcoord : TEXCOORD0; 42 | }; 43 | 44 | struct v2f 45 | { 46 | float4 vertex : SV_POSITION; 47 | fixed4 color : COLOR; 48 | half2 texcoord : TEXCOORD0; 49 | }; 50 | 51 | fixed4 _Tint; 52 | 53 | v2f vert(appdata_t IN) 54 | { 55 | v2f OUT; 56 | OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); 57 | OUT.texcoord = IN.texcoord; 58 | // Removed the tinting here, since it would tint the palette map 59 | OUT.color = IN.color; 60 | #ifdef PIXELSNAP_ON 61 | OUT.vertex = UnityPixelSnap (OUT.vertex); 62 | #endif 63 | 64 | return OUT; 65 | } 66 | 67 | sampler2D _MainTex; 68 | sampler2D _Palette; 69 | float4 _Palette_ST; // Stores the tiling and offset information 70 | 71 | fixed4 frag(v2f IN) : SV_Target 72 | { 73 | fixed4 paletteMapColor = tex2D(_MainTex, IN.texcoord) * IN.color; 74 | 75 | // The alpha channel of the palette map points to UVs in the palette key. 76 | float paletteX = paletteMapColor.a; 77 | float2 paletteUV = float2(paletteX, 0.0f); 78 | // Get the palette's UV accounting for texture tiling and offset 79 | float2 paletteUVTransformed = TRANSFORM_TEX(paletteUV, _Palette); 80 | 81 | // Get the color from the palette key 82 | fixed4 outColor = tex2D(_Palette, paletteUVTransformed); 83 | 84 | // Apply the tint to the final color 85 | outColor *= _Tint; 86 | return outColor; 87 | } 88 | ENDCG 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteSprite.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9c4ffd706de14167801487ee260553e 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteTexture-Normal.shader: -------------------------------------------------------------------------------- 1 | // Unlit shader, combined with a color index (palette) texture. 2 | // - no lighting 3 | // - no lightmap support 4 | // - no per-material color 5 | 6 | Shader "RBTools/Palettized Image/Palette Texture (Unlit)" { 7 | Properties { 8 | _MainTex ("Base (RGB)", 2D) = "white" {} 9 | _Palette ("Palette Texture", 2D) = "white" {} 10 | } 11 | 12 | SubShader { 13 | Tags { "RenderType"="Opaque" } 14 | LOD 100 15 | 16 | Pass { 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | 23 | struct appdata_t { 24 | float4 vertex : POSITION; 25 | float2 texcoord : TEXCOORD0; 26 | }; 27 | 28 | struct v2f { 29 | float4 vertex : SV_POSITION; 30 | half2 texcoord : TEXCOORD0; 31 | }; 32 | 33 | sampler2D _MainTex; 34 | float4 _MainTex_ST; 35 | sampler2D _Palette; 36 | 37 | v2f vert (appdata_t v) 38 | { 39 | v2f o; 40 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 41 | o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); 42 | return o; 43 | } 44 | float4 _Palette_ST; 45 | 46 | fixed4 frag (v2f i) : SV_Target 47 | { 48 | fixed4 paletteMapColor = tex2D(_MainTex, i.texcoord); 49 | 50 | // The alpha channel of the palette map points to UVs in the palette key. 51 | float paletteIndex = paletteMapColor.a; 52 | float2 paletteUV = float2(paletteIndex, 0.0f); 53 | // Get the palette's UV accounting for texture tiling and offset 54 | float2 paletteUVTransformed = TRANSFORM_TEX(paletteUV, _Palette); 55 | 56 | // Get the color from the palette key 57 | fixed4 outColor = tex2D(_Palette, paletteUVTransformed); 58 | 59 | return outColor; 60 | } 61 | ENDCG 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteTexture-Normal.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f3504ccc75624ba3b7d77ecbb63ab66 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteTexture-Transparent.shader: -------------------------------------------------------------------------------- 1 | // Unlit alpha-blended shader, combined with a color index (palette) texture. 2 | // - no lighting 3 | // - no lightmap support 4 | // - no per-material color 5 | 6 | Shader "RBTools/Palettized Image/Palette Texture (UnlitTransparent)" { 7 | Properties { 8 | _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} 9 | _Palette ("Palette Texture", 2D) = "white" {} 10 | } 11 | 12 | SubShader { 13 | Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} 14 | LOD 100 15 | 16 | ZWrite Off 17 | Blend SrcAlpha OneMinusSrcAlpha 18 | 19 | Pass { 20 | CGPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | #include "UnityCG.cginc" 25 | 26 | struct appdata_t { 27 | float4 vertex : POSITION; 28 | float2 texcoord : TEXCOORD0; 29 | }; 30 | 31 | struct v2f { 32 | float4 vertex : SV_POSITION; 33 | half2 texcoord : TEXCOORD0; 34 | }; 35 | 36 | sampler2D _MainTex; 37 | float4 _MainTex_ST; 38 | sampler2D _Palette; 39 | 40 | v2f vert (appdata_t v) 41 | { 42 | v2f o; 43 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 44 | o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); 45 | return o; 46 | } 47 | 48 | float4 _Palette_ST; 49 | 50 | fixed4 frag (v2f i) : SV_Target 51 | { 52 | fixed4 paletteMapColor = tex2D(_MainTex, i.texcoord); 53 | 54 | // The alpha channel of the palette map points to UVs in the palette key. 55 | float paletteX = paletteMapColor.a; 56 | float2 paletteUV = float2(paletteX, 0.0f); 57 | // Get the palette's UV accounting for texture tiling and offset 58 | float2 paletteUVTransformed = TRANSFORM_TEX(paletteUV, _Palette); 59 | 60 | // Get the color from the palette key 61 | fixed4 outColor = tex2D(_Palette, paletteUVTransformed); 62 | 63 | return outColor; 64 | } 65 | ENDCG 66 | } 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Assets/RBPixelPalettemap/Shaders/PaletteTexture-Transparent.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84b1d335742884bdb83762967dec27a7 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09f0044db5a8849d4b16456bb4eb5053 3 | folderAsset: yes 4 | timeCreated: 1438923269 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Tests/FourColors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/FourColors.png -------------------------------------------------------------------------------- /Assets/Tests/FourColors.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d40ae0ed8913141779016ddfc4333f82 3 | timeCreated: 1438923269 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Tests/Rectangular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/Rectangular.png -------------------------------------------------------------------------------- /Assets/Tests/Rectangular.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91d8bb068abf34ed3b515a61951511ca 3 | timeCreated: 1438982722 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Tests/ThreeColors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/ThreeColors.png -------------------------------------------------------------------------------- /Assets/Tests/ThreeColors.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6415618529b774135a340de1f0838c46 3 | timeCreated: 1438923269 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Tests/ThreeColorsAndAlpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/ThreeColorsAndAlpha.png -------------------------------------------------------------------------------- /Assets/Tests/ThreeColorsAndAlpha.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c515623d729e44d1bf557fecf216053 3 | timeCreated: 1438923269 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Tests/ThreeColorsOrderSwap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/ThreeColorsOrderSwap.png -------------------------------------------------------------------------------- /Assets/Tests/ThreeColorsOrderSwap.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6107559969384c468d26d0021451b27 3 | timeCreated: 1438923269 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Tests/TwoColors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/Assets/Tests/TwoColors.png -------------------------------------------------------------------------------- /Assets/Tests/TwoColors.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e08b77d068744fc2896e99b87d2aa51 3 | timeCreated: 1438923269 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: .25 21 | normalMapFilter: 0 22 | isReadable: 1 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 8 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: 4 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 0 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | spriteMode: 0 41 | spriteExtrude: 1 42 | spriteMeshType: 1 43 | alignment: 0 44 | spritePivot: {x: .5, y: .5} 45 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 46 | spritePixelsToUnits: 100 47 | alphaIsTransparency: 0 48 | textureType: 5 49 | buildTargetSettings: [] 50 | spriteSheet: 51 | sprites: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.1.1f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /RBPixelPalettemap.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/RBPixelPalettemap.unitypackage -------------------------------------------------------------------------------- /RBPixelPalettemapDebug.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redbluegames/unity-pixel-palettemap/7773fc8412698da6d72cd48bafd29d303b30fdc8/RBPixelPalettemapDebug.unitypackage -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Unity-Pixel-Palettemap 2 | ================ 3 | Pixel Palettemap "palettizes" textures, allowing them to be used with a shader for alternate color schemes and palette swapping. 4 | 5 | NOTE This read me is out of date. I will update it when I'm finished with major outstanding features and I've figured out the final workflow. 6 | 7 | Overview 8 | ================ 9 | In games we often want to colorize the same 2D image many different ways. Maybe we want to have several color variants for playable characters, like in Super Smash Brothers. Or maybe we want to let players dye parts of their armor. One solution to this is to draw separate sprite sheets for each color variation, but that has the con of using more memory and more importantly, difficult upkeep. When you want to make a change you have to change every version of the texture. And if we want to allow many combinations, like a custom hat color, custom cape color, and custom armor color, it would be virtually impossible to draw every permutation. You could instead use color tinting on a black and white texture but that will only allow you to make all colors in the image a shade of one color. Maybe you want blonde hair and a blue cape. To solve these issues, we can use a color indexed image. 10 | 11 | ##Color Indexing and Palettes 12 | A color indexed image is made up of two structures - an indexed image and a palette of all the unique colors in the image. A typical image stores pixels as colors, which consist of 4 bytes, one for each color channel and the alpha value. In a color indexed image, instead of storing color information each pixel points to its corresponding color’s index in a palette of colors. This reduces redundant information resulting in a smaller file size. Typically the palette size is a byte, allowing for 256 unique colors, which is what this tool uses. With each pixel storing only one byte instead of four, a color indexed image should be quarter the size of its uncompressed source image. 13 | 14 | ![Color Indexing] 15 | (https://docs.google.com/drawings/d/1DGYJIlG9qPU6PZ9Un4MGe50YfI0802PhoML57Rz6ECY/pub?w=666&h=319) 16 | 17 | With the color information split out into another structure, you can easily change all colors in the image simply by changing out the palette. This is shown in the next diagram. 18 | 19 | ![Swapping Palettes A] 20 | (https://docs.google.com/drawings/d/1MQ3mVvWj5AGfNh0hLXJqljNCOePI5OxOAC9_pgCdGCA/pub?w=460&h=347) 21 | 22 | ##RBPaletteMapper Overview 23 | It is possible to create color indexed images by hand in a drawing program, but it is tedious and prone to error. This tool is designed to help you quickly create a color indexed image from your source image. Given a source image it creates two other texture files: a palette map (the color indexed image) and a palette key. The palette map is the color indexed texture, pointing to coordinates in the palette key. You then create new palettes for the image by copying the generated palette key. The package also contains custom shaders, used to render palettized images as sprites or as textures on meshes. There are also a few sample scripts that show how to swap out palettes at runtime. 24 | 25 | Using the Tool and Workflows 26 | ======= 27 | ###Quick Workflow 28 | Create a palettized image: 29 | 30 | 1. Create your source texture 31 | 1. Draw everything that you want to color separately as a different color. This makes sure that they get assigned as new entries in the palette 32 | 2. Import texture into Unity and set up its settings as follows: 33 | 1. Texture Type: Advanced 34 | 2. Read / Write enabled 35 | 3. Point filter 36 | 4. RGBA32 format 37 | 3. Select the PaletteMapper tool under RedBlueTools in the menu bar 38 | 4. Drop the texture into the texture slot 39 | 5. Click Build Texture to create a PaletteMap texture and PaletteKey texture 40 | 41 | For each sprite you want to palettize: 42 | 43 | 1. Create a new material 44 | 2. Select the custom shader for the new material 45 | 1. For a sprite choose RBTools / Palettized Image / PaletteSprite 46 | 2. For a texture with transparency choose RBTools / Palettized Image / Palette Texture (Until/Transparent) 47 | 3. For a texture without transparency choose RBTools / Palettized Image / Palette Texture (Until) 48 | 3. If you are needing a new palette for the sprite, duplicate the key that corresponds to the palette map and colorize it how you want in an image editing program 49 | 4. Assign the new palette key to the material 50 | 5. For a sprite: 51 | 1. Create sprites from your generated PaletteMap texture and use one of those sprites on your game object. You can find more information on creating sprites in the Unity Documentation here. 52 | 2. Assign the new material to the sprite renderer. 53 | 6. For a texture: 54 | 1. Assign the palette map into the Material as the Base texture 55 | 2. Assign the newly created palette texture into the Material as the Palette texture 56 | 57 | ###Creating Palette Swapping 58 | There are many ways to achieve a palette swapping effect. Each method is just a different way of changing out the sprite or texture’s palette, while using the same palette map. You can change the object’s Material to a material that uses another palette, you can change the specific Palette texture used by a particular material, or if you have multiple palettes in one palette image, you can change the texture’s Y offset of your material. I’ve included several scripts that provide examples of this. MaterialTween.cs swaps between materials, PaletteScroll.cs scrolls through the palettes in a multi-palette texture by setting texture offset, and SetTextureVariableExample.cs swaps out the textures supplied as the palette to a material. 59 | 60 | ###Advanced Workflow and Best Practices 61 | The tool works great for quick and dirty palettized sprites. But if you have a large project where the sprites you are using change frequently, you will want to use these advanced workflow recommendations. 62 | 63 | 1. Create your own palette key based on the source texture. This lets you put the colors in the order you want, so that it is easier to create new palettes. It also helps when you insert or remove colors from the source image. If you insert a color in your original image, a generated key will insert a color somewhere. You would have to figure out where it entered that color and add one to all the palettes you’ve created. By providing your own key, you can insert that color where you want it and immediately do the same to all your palettes. You can also label your custom key to help you with organization. As long as the font you use is made up of colors in the palette, it won’t even create unused colors in the key. Here is a custom palette key I am using in our project at Red Blue Games: TODO: Publish my key 64 | 65 | 2. Use one texture file for all your color palettes for a specific palette map texture. This lets you modify all palettes easily at one time. For example, if you insert a new color into the palette key, you can easily insert a column of new pixels into all palettes. 66 | 67 | To specify which palette to use on your material, you need to use the Texture Offset on the Palette’s texture. The value is 0.0 - 1.0, bottom to top. Divide the index of the row you want by the number of palette rows in the texture to find the y offset. For example, to get the 3rd row from the bottom in a texure with 4 palettes, divide 2 (0 based index) by 4 to get 0.5. The row spans the texture from 0.5 to 0.75 so any number in between the two will give you that palette. 68 | 69 | Code Explanation 70 | ================ 71 | * The tool first creates a palette key from the provided source image. If you supply your own palette key image it still creates a new palette key, but instead of creating a palette key from the source image it uses the supplied palette key image to create a palette key. 72 | * To create the palette key, the tool simply iterates through the pixels in the source image and inserts unique colors into a palette. If you choose to sort the palette, it will sort the colors after they’ve been identified. 73 | * It then creates the palette map from the source texture using the generated palette key. For each color it finds in the source texture it finds the corresponding index for that color in the palette key. It then writes that new value into the alpha channel of a new texture. 74 | * The alpha values are normalized to the size of the texture. So a palette with 4 colors will have alpha values from [0, .25), [.25, .5), [.5, .75), and [.75, 1.0f). This lets us keep the palette image small and also makes it so that the content of the palette map is discernable when viewing the alpha channel. 75 | * When it’s finished, it writes both the palette key and the palette map out to disk at the same directory as the source image. 76 | 77 | ####The Shaders 78 | Each shader simply uses the alpha values at each pixel in the Palette Map to point into coordinates of the Palette. Instead of using the color value from the primary texture, it uses the color values found in the Palette. 79 | 80 | FAQ 81 | ====== 82 | * When I change the Source texture, do I have to update all of the custom alternate palettes that I’ve made? 83 | * If you add or remove a color to the source image, it can change the order of the colors in the palette since they are sorted by grayscale. Therefore, you have to re-create your palettes if you do this. 84 | * Note, even if I go to a method of First Color found, first added, it won’t fix this since you could change the order in which the colors are found in the image. 85 | * The only fix is to support supplying custom palette keys as input. This would let users add new colors to the end of their palette, so that they’d just have to adjust those two colors in all their palettes. 86 | * Therefore it is recommended that you define the palette beforehand so that it’s unlikely to change. 87 | * What are some uses for this tool? 88 | * Allows for easily created alternate color schemes for player characters or enemies 89 | * Allows for players to customize their character 90 | * Can be used in combination with Palette Swapping for hit flashing or animations 91 | * Why would I use this instead of just creating new textures for each color? 92 | * Saves texture memory 93 | * Saves time repainting textures every time you want to change or add animations to an existing character 94 | * Why is it so slow? 95 | * I did not optimize the algorithms, so it will take a while to convert large textures. 96 | * I’ve split my character into several spritesheets. How do I create a palette map for them? 97 | You should create your own palette key that includes all the colors from each spritesheet. Then generate a palette map for each spritesheet providing the same palette key to each. This will make sure your indexed values for each palette map point to the same set of colors found in the palette key. 98 | 99 | Troubleshooting 100 | ============== 101 | * PaletteMap Error: Tried to Add more colors to palette key than are currently supported due to PaletteMap's Alpha8 format 102 | * This error occurs when either the source texture contains more colors than a palette can store ( > 256 ), or a supplied custom palette key contains more colors than a palette can store. This is typically due to compression, which can be caused from any of the following: 103 | * If the texture is not a power of 2 in size, make sure it is not flagged to round. (Non Power of 2: None) 104 | * Filter mode should be point 105 | * Make sure Max Size is bigger than the texture size 106 | * Format: RGBA 32 bit 107 | 108 | Further Reading 109 | ============= 110 | 111 | Indexed Colors 112 | 113 | http://en.wikipedia.org/wiki/Indexed_color 114 | 115 | http://en.wikipedia.org/wiki/Palette_swap 116 | 117 | Shaders 118 | 119 | http://gamedev.stackexchange.com/questions/43294/creating-a-retro-style-palette-swapping-effect-in-opengl 120 | 121 | Attribution 122 | ================ 123 | Demo world image by Lanea Zimmerman, used under license CC-BY 3.0 (http://creativecommons.org/licenses/by/3.0/) 124 | 125 | Get the image here: http://opengameart.org/content/tiny-16-basic 126 | --------------------------------------------------------------------------------