├── .gitignore ├── Assets ├── IndexColorShader.meta └── IndexColorShader │ ├── Editor.meta │ ├── Editor │ ├── Import.meta │ ├── Import │ │ ├── Image.cs │ │ ├── Image.cs.meta │ │ ├── Setting.cs │ │ └── Setting.cs.meta │ ├── Inspector.meta │ ├── Inspector │ │ ├── Inspector_IndexColorShader_Sprite.cs │ │ ├── Inspector_IndexColorShader_Sprite.cs.meta │ │ ├── Inspector_IndexColorShader_UIImage.cs │ │ └── Inspector_IndexColorShader_UIImage.cs.meta │ ├── LibraryEditor_IndexColorShader.cs │ ├── LibraryEditor_IndexColorShader.cs.meta │ ├── Plugins.meta │ ├── Plugins │ │ ├── MacOSX.meta │ │ ├── MacOSX │ │ │ ├── ICS_LoaderImage.bundle │ │ │ └── ICS_LoaderImage.bundle.meta │ │ ├── Windows.meta │ │ └── Windows │ │ │ ├── x86_64.meta │ │ │ └── x86_64 │ │ │ ├── ICS_LoaderImage.dll │ │ │ ├── ICS_LoaderImage.dll.meta │ │ │ ├── vcruntime140.dll │ │ │ ├── vcruntime140.dll.meta │ │ │ ├── vcruntime140_1d.dll │ │ │ └── vcruntime140_1d.dll.meta │ ├── Tools.meta │ └── Tools │ │ ├── About.cs │ │ ├── About.cs.meta │ │ ├── Importer.cs │ │ └── Importer.cs.meta │ ├── Library.meta │ ├── Library │ ├── Library_IndexColorShader.cs │ └── Library_IndexColorShader.cs.meta │ ├── Material.meta │ ├── Material │ ├── Default_Palette256.mat │ ├── Default_Palette256.mat.meta │ ├── Default_UIPalette256.mat │ └── Default_UIPalette256.mat.meta │ ├── Script.meta │ ├── Script │ ├── Script_IndexColorShader_Palette.cs │ ├── Script_IndexColorShader_Palette.cs.meta │ ├── Script_IndexColorShader_Sprite.cs │ ├── Script_IndexColorShader_Sprite.cs.meta │ ├── Script_IndexColorShader_SpritePalette.cs │ ├── Script_IndexColorShader_SpritePalette.cs.meta │ ├── Script_IndexColorShader_UIImage.cs │ └── Script_IndexColorShader_UIImage.cs.meta │ ├── Shader.meta │ └── Shader │ ├── Base.meta │ ├── Base │ ├── Data_IndexColorShader.cginc │ ├── Data_IndexColorShader.cginc.meta │ ├── Data_IndexColorShaderUI.cginc │ ├── Data_IndexColorShaderUI.cginc.meta │ ├── Pixel_Palette256.cginc │ ├── Pixel_Palette256.cginc.meta │ ├── Pixel_UIPalette256.cginc │ ├── Pixel_UIPalette256.cginc.meta │ ├── Vertex_Palette256.cginc │ ├── Vertex_Palette256.cginc.meta │ ├── Vertex_UIPalette256.cginc │ └── Vertex_UIPalette256.cginc.meta │ ├── IndexColorShader_Palette256.shader │ ├── IndexColorShader_Palette256.shader.meta │ ├── IndexColorShader_UIPalette256.shader │ └── IndexColorShader_UIPalette256.shader.meta ├── ICS_for_Unity.unitypackage ├── ICS_for_Unity_Sample.unitypackage ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | # *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Assets/IndexColorShader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f426654cc5e93574fb3db34203836454 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8e09fc1d5e62e042a8191e2fcd1a8df 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Import.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfef7c0c09f0f6c4fa6d70486e077369 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Import/Image.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using System; 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | using System.Runtime.InteropServices; 13 | using UnityEngine; 14 | using UnityEditor; 15 | 16 | public static partial class LibraryEditor_IndexColorShader 17 | { 18 | public static partial class Image 19 | { 20 | /* ----------------------------------------------- Variables & Properties */ 21 | #region Variables & Properties 22 | #endregion Variables & Properties 23 | 24 | /* ----------------------------------------------- Functions */ 25 | #region Functions 26 | internal static InformationDecode Decode(byte[] dataTextureOriginal, string messageSuffix) 27 | { 28 | const string messageLogPrefix = "Decode"; 29 | 30 | InformationDecode informationDecode = new InformationDecode(); 31 | if(null == informationDecode) 32 | { 33 | LogError(messageLogPrefix, "Not Enough Memory(Information)" + messageSuffix); 34 | goto Decode_ErrorEnd; 35 | } 36 | 37 | /* Decode Image-Data */ 38 | informationDecode.Image = Loader.ImageCreate(); 39 | if(null == informationDecode.Image) 40 | { 41 | LogError(messageLogPrefix, "Not Enough Memory(Image)" + messageSuffix); 42 | goto Decode_ErrorEnd; 43 | } 44 | IntPtr image = informationDecode.Image; 45 | 46 | informationDecode.HandleDataTexture = GCHandle.Alloc(dataTextureOriginal, GCHandleType.Pinned); 47 | informationDecode.PointerDataTexture = informationDecode.HandleDataTexture.AddrOfPinnedObject(); 48 | if(0 == Loader.ImageDecode(image, informationDecode.PointerDataTexture, dataTextureOriginal.Length)) 49 | { /* Failure */ 50 | LogError(messageLogPrefix, "Invalid Image-Data" + messageSuffix); 51 | goto Decode_ErrorEnd; 52 | } 53 | 54 | /* Check Image */ 55 | int sizePixelX = Loader.WidthGetImage(image); 56 | int sizePixelY = Loader.HeightGetImage(image); 57 | int depthPixel = Loader.DepthGetImage(image); 58 | int countPalette = Loader.CountGetImageCLUT(image); 59 | if(false == SizeCheck(sizePixelX, sizePixelY)) 60 | { /* Invalid */ 61 | LogError(messageLogPrefix, "Invalid Textuer's size" + messageSuffix); 62 | goto Decode_ErrorEnd; 63 | } 64 | if(8 != depthPixel) 65 | { /* Invalid */ 66 | LogError(messageLogPrefix, "Invalid Texture's Pixel-Depth" + messageSuffix); 67 | goto Decode_ErrorEnd; 68 | } 69 | if(0 >= countPalette) 70 | { /* Invalid */ 71 | LogError(messageLogPrefix, "Texture has no CLUT" + messageSuffix); 72 | goto Decode_ErrorEnd; 73 | } 74 | 75 | return(informationDecode); 76 | 77 | Decode_ErrorEnd:; 78 | informationDecode.Release(); 79 | 80 | return(null); 81 | } 82 | private static bool SizeCheck(int sizePixelX, int sizePixelY) 83 | { 84 | const int sizePixelMinimum = 64; 85 | 86 | if((sizePixelMinimum > sizePixelX) || (sizePixelMinimum > sizePixelY)) 87 | { 88 | return(false); 89 | } 90 | 91 | /* MEMO: Should check POT ?? */ 92 | 93 | return(true); 94 | } 95 | 96 | internal static Color[] PaletteConvert(InformationDecode informationDecode, string messageSuffix) 97 | { 98 | const string messageLogPrefix = "Convert-Palette"; 99 | 100 | /* Generate Palette */ 101 | int sizePalette = Library_IndexColorShader.Data.Palette.CountColorMax; 102 | Color[] palette = new Color[sizePalette]; 103 | if(null == palette) 104 | { 105 | LogError(messageLogPrefix, "Not Enough Memory(Palette)" + messageSuffix); 106 | return(null); 107 | } 108 | 109 | /* Clear */ 110 | for(int i=0; i> 24) & 0x000000ff) / 255.0f; 122 | palette[i].r = (float)((colorPalette >> 16) & 0x000000ff) / 255.0f; 123 | palette[i].g = (float)((colorPalette >> 8) & 0x000000ff) / 255.0f; 124 | palette[i].b = (float)(colorPalette & 0x000000ff) / 255.0f; 125 | } 126 | 127 | return(palette); 128 | } 129 | 130 | internal static Texture2D PixelConvert(InformationDecode informationDecode, string messageSuffix) 131 | { 132 | const string messageLogPrefix = "Convert-Pixel"; 133 | 134 | /* Create Texture2D */ 135 | IntPtr image = informationDecode.Image; 136 | int sizePixelX = Loader.WidthGetImage(image); 137 | int sizePixelY = Loader.HeightGetImage(image); 138 | // int depthPixel = Loader.DepthGetImage(image); 139 | Texture2D textureIndexed = new Texture2D(sizePixelX, sizePixelY, TextureFormat.Alpha8, 0, true); /* Has no mips / ColorSpace is Linear */ 140 | if(null == textureIndexed) 141 | { 142 | LogError(messageLogPrefix, "Not Enough Memory(Texture)" + messageSuffix); 143 | return(null); 144 | } 145 | 146 | /* Setting */ 147 | textureIndexed.alphaIsTransparency = false; 148 | 149 | /* Decode */ 150 | Color32 colorPixel32 = new Color32(); 151 | for(int y=0; y(nameMaterialSource); 138 | 139 | FlagCreatePrefabSprite = flagCreatePrefabSprite; 140 | 141 | FlagCreatePrefabUI = flagCreatePrefabUI; 142 | MaterialSourceUI = Utility.Asset.AssetLoadPath(nameMaterialSourcePrefabUI); 143 | } 144 | 145 | public void CleanUp() 146 | { 147 | this = Default; 148 | } 149 | 150 | public bool Load() 151 | { 152 | { /* "Create Material" */ 153 | FlagCreateMaterial = EditorPrefs.GetBool(PrefsKeyFlagCreateMaterial, Default.FlagCreateMaterial); 154 | string textDefault = Utility.Asset.PathGetAsset(Default.MaterialSource); 155 | string text = Utility.Prefs.StringLoad(PrefsKeyMaterialSource, textDefault); 156 | if(true == string.IsNullOrEmpty(text)) 157 | { 158 | MaterialSource = null; 159 | } 160 | else 161 | { 162 | MaterialSource = Utility.Asset.AssetLoadPath(text); 163 | } 164 | } 165 | 166 | { /* "Create PrefabSprite" */ 167 | FlagCreatePrefabSprite = EditorPrefs.GetBool(PrefsKeyFlagCreatePrefabSprite, Default.FlagCreatePrefabSprite); 168 | } 169 | 170 | { /* "Create Prefab-UI" */ 171 | FlagCreatePrefabUI = EditorPrefs.GetBool(PrefsKeyFlagCreatePrefabUI, Default.FlagCreatePrefabUI); 172 | string textDefault = Utility.Asset.PathGetAsset(Default.MaterialSourceUI); 173 | string text = Utility.Prefs.StringLoad(PrefsKeyMaterialSourcePrefabUI, textDefault); 174 | if(true == string.IsNullOrEmpty(text)) 175 | { 176 | MaterialSourceUI = null; 177 | } 178 | else 179 | { 180 | MaterialSourceUI = Utility.Asset.AssetLoadPath(text); 181 | } 182 | } 183 | 184 | 185 | return(true); 186 | } 187 | 188 | public bool Save() 189 | { 190 | { /* "Create Material" */ 191 | EditorPrefs.SetBool(PrefsKeyFlagCreateMaterial, FlagCreateMaterial); 192 | string text = string.Empty; 193 | if(null != MaterialSource) 194 | { 195 | text = Utility.Asset.PathGetAsset(MaterialSource); 196 | } 197 | Utility.Prefs.StringSave(PrefsKeyMaterialSource, text); 198 | } 199 | 200 | { /* "Create PrefabSprite" */ 201 | EditorPrefs.SetBool(PrefsKeyFlagCreatePrefabSprite, FlagCreatePrefabSprite); 202 | } 203 | 204 | { /* "Create Prefab-UI" */ 205 | EditorPrefs.SetBool(PrefsKeyFlagCreatePrefabUI, FlagCreatePrefabUI); 206 | string text = string.Empty; 207 | if(null != MaterialSourceUI) 208 | { 209 | text = Utility.Asset.PathGetAsset(MaterialSourceUI); 210 | } 211 | Utility.Prefs.StringSave(PrefsKeyMaterialSourcePrefabUI, text); 212 | } 213 | 214 | return(true); 215 | } 216 | #endregion Functions 217 | 218 | /* ----------------------------------------------- Enums & Constants */ 219 | #region Enums & Constants 220 | public enum KindNoCreateMaterialUnreferenced 221 | { 222 | NONE = 0, 223 | BLENDING, 224 | BLENDING_CELLMAP, 225 | 226 | TERMINATOR 227 | } 228 | 229 | private const string KeyFlagCreateMaterial = "FlagCreateMaterial"; 230 | private const string KeyMaterialSource = "MaterialSource"; 231 | private const string KeyFlagCreatePrefabSprite = "FlagCreatePrefabSprite"; 232 | private const string KeyFlagCreatePrefabUI = "FlagCreatePrefabUI"; 233 | private const string KeyMaterialSourcePrefabUI = "MaterialSourcePrefabUI"; 234 | 235 | private const string TextKeyPrefix = "Basic_"; 236 | private const string TextKeyFlagCreateMaterial = TextKeyPrefix + KeyFlagCreateMaterial; 237 | private const string TextKeyMaterialSource = TextKeyPrefix + KeyMaterialSource; 238 | private const string TextKeyFlagCreatePrefabSprite = TextKeyPrefix + KeyFlagCreatePrefabSprite; 239 | private const string TextKeyFlagCreatePrefabUI = TextKeyPrefix + KeyFlagCreatePrefabUI; 240 | private const string TextKeyMaterialSourcePrefabUI = TextKeyPrefix + KeyMaterialSourcePrefabUI; 241 | 242 | private const string PrefsKeyPrefix = Import.PrefsKeyPrefix + TextKeyPrefix; 243 | private const string PrefsKeyFlagCreateMaterial = PrefsKeyPrefix + KeyFlagCreateMaterial; 244 | private const string PrefsKeyMaterialSource = PrefsKeyPrefix + KeyMaterialSource; 245 | private const string PrefsKeyFlagCreatePrefabSprite = PrefsKeyPrefix + KeyFlagCreatePrefabSprite; 246 | private const string PrefsKeyFlagCreatePrefabUI = PrefsKeyPrefix + KeyFlagCreatePrefabUI; 247 | private const string PrefsKeyMaterialSourcePrefabUI = PrefsKeyPrefix + KeyMaterialSourcePrefabUI; 248 | 249 | private readonly static GroupBasic Default = new GroupBasic( 250 | true, /* FlagCreateMaterial */ 251 | "Assets/IndexColorShader/Material/Default_Palette256" + ExtentionMaterial, /* MaterialSource */ 252 | true, /* FlagCreatePrefabSprite */ 253 | true, /* FlagCreatePrefabUI */ 254 | "Assets/IndexColorShader/Material/Default_UIPalette256" + ExtentionMaterial /* MaterialSourceUI */ 255 | ); 256 | #endregion Enums & Constants 257 | 258 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 259 | #region Classes, Structs & Interfaces 260 | #endregion Classes, Structs & Interfaces 261 | 262 | /* ----------------------------------------------- Delegates */ 263 | #region Delegates 264 | #endregion Delegates 265 | } 266 | 267 | public struct GroupConfirmOverWrite 268 | { 269 | /* ----------------------------------------------- Variables & Properties */ 270 | #region Variables & Properties 271 | public bool FlagTexture; 272 | public bool FlagPalette; 273 | public bool FlagMaterial; 274 | 275 | public bool FlagPrefabSprite; 276 | 277 | public bool FlagPrefabUI; 278 | public bool FlagMaterialUI; 279 | #endregion Variables & Properties 280 | 281 | /* ----------------------------------------------- Functions */ 282 | #region Functions 283 | public GroupConfirmOverWrite( bool flagTexture, 284 | bool flagPalette, 285 | bool flagMaterial, 286 | bool flagPrefabSprite, 287 | bool flagPrefabUI, 288 | bool flagMaterialUI 289 | ) 290 | { 291 | FlagTexture = flagTexture; 292 | FlagPalette = flagPalette; 293 | FlagMaterial = flagMaterial; 294 | 295 | FlagPrefabSprite = flagPrefabSprite; 296 | 297 | FlagPrefabUI = flagPrefabUI; 298 | FlagMaterialUI = flagMaterialUI; 299 | } 300 | 301 | public void CleanUp() 302 | { 303 | this = Default; 304 | } 305 | 306 | public bool Load() 307 | { 308 | FlagTexture = EditorPrefs.GetBool(PrefsKeyFlagTexture, Default.FlagTexture); 309 | FlagPalette = EditorPrefs.GetBool(PrefsKeyFlagPalette, Default.FlagPalette); 310 | FlagMaterial = EditorPrefs.GetBool(PrefsKeyFlagMaterial, Default.FlagMaterial); 311 | 312 | FlagPrefabSprite = EditorPrefs.GetBool(PrefsKeyFlagPrefabSprite, Default.FlagPrefabSprite); 313 | 314 | FlagPrefabUI = EditorPrefs.GetBool(PrefsKeyFlagPrefabUI, Default.FlagPrefabUI); 315 | FlagMaterialUI = EditorPrefs.GetBool(PrefsKeyFlagMaterialUI, Default.FlagMaterialUI); 316 | 317 | return(true); 318 | } 319 | 320 | public bool Save() 321 | { 322 | EditorPrefs.SetBool(PrefsKeyFlagTexture, FlagTexture); 323 | EditorPrefs.SetBool(PrefsKeyFlagPalette, FlagPalette); 324 | EditorPrefs.SetBool(PrefsKeyFlagMaterial, FlagMaterial); 325 | 326 | EditorPrefs.SetBool(PrefsKeyFlagPrefabSprite, FlagPrefabSprite); 327 | 328 | EditorPrefs.SetBool(PrefsKeyFlagPrefabUI, FlagPrefabUI); 329 | EditorPrefs.SetBool(PrefsKeyFlagMaterialUI, FlagMaterialUI); 330 | 331 | return(true); 332 | } 333 | #endregion Functions 334 | 335 | /* ----------------------------------------------- Enums & Constants */ 336 | #region Enums & Constants 337 | private const string KeyFlagTexture = "FlagTexture"; 338 | private const string KeyFlagPalette = "FlagPalette"; 339 | private const string KeyFlagMaterial = "FlagMaterial"; 340 | private const string KeyFlagPrefabSprite = "FlagPrefabSprite"; 341 | private const string KeyFlagPrefabUI = "FlagPrefabUI"; 342 | private const string KeyFlagMaterialUI = "FlagMaterialUI"; 343 | 344 | private const string TextKeyPrefix = "ConfirmOverWrite_"; 345 | private const string TextKeyFlagTexture = TextKeyPrefix + KeyFlagTexture; 346 | private const string TextKeyFlagPalette = TextKeyPrefix + KeyFlagPalette; 347 | private const string TextKeyFlagMaterial = TextKeyPrefix + KeyFlagMaterial; 348 | private const string TextKeyFlagPrefabSprite = TextKeyPrefix + KeyFlagPrefabSprite; 349 | private const string TextKeyFlagPrefabUI = TextKeyPrefix + KeyFlagPrefabUI; 350 | private const string TextKeyFlagMaterialUI = TextKeyPrefix + KeyFlagMaterialUI; 351 | 352 | private const string PrefsKeyPrefix = Import.PrefsKeyPrefix + TextKeyPrefix; 353 | private const string PrefsKeyFlagTexture = PrefsKeyPrefix + KeyFlagTexture; 354 | private const string PrefsKeyFlagPalette = PrefsKeyPrefix + KeyFlagPalette; 355 | private const string PrefsKeyFlagMaterial = PrefsKeyPrefix + KeyFlagMaterial; 356 | private const string PrefsKeyFlagPrefabSprite = PrefsKeyPrefix + KeyFlagPrefabSprite; 357 | private const string PrefsKeyFlagPrefabUI = PrefsKeyPrefix + KeyFlagPrefabUI; 358 | private const string PrefsKeyFlagMaterialUI = PrefsKeyPrefix + KeyFlagMaterialUI; 359 | 360 | internal readonly static GroupConfirmOverWrite Default = new GroupConfirmOverWrite( 361 | false, /* FlagTexture */ 362 | false, /* FlagPalette */ 363 | false, /* FlagMaterial */ 364 | false, /* FlagPrefabSprite */ 365 | false, /* FlagPrefabUI */ 366 | false /* FlagMaterialUI */ 367 | ); 368 | #endregion Enums & Constants 369 | 370 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 371 | #region Classes, Structs & Interfaces 372 | #endregion Classes, Structs & Interfaces 373 | 374 | /* ----------------------------------------------- Delegates */ 375 | #region Delegates 376 | #endregion Delegates 377 | } 378 | 379 | public struct GroupRuleNameAsset 380 | { 381 | /* ----------------------------------------------- Variables & Properties */ 382 | #region Variables & Properties 383 | /* Prefix */ 384 | public string NamePrefixTexture; 385 | public string NamePrefixPalette; 386 | public string NamePrefixMaterial; 387 | 388 | public string NamePrefixPrefabSprite; 389 | 390 | public string NamePrefixPrefabUI; 391 | public string NamePrefixMaterialUI; 392 | #endregion Variables & Properties 393 | 394 | /* ----------------------------------------------- Functions */ 395 | #region Functions 396 | public GroupRuleNameAsset( string namePrefixTexture, 397 | string namePrefixPalette, 398 | string namePrefixMaterial, 399 | string namePrefixPrefabSprite, 400 | string namePrefixPrefabUI, 401 | string namePrefixMaterialUI 402 | ) 403 | { 404 | NamePrefixTexture = namePrefixTexture; 405 | NamePrefixPalette = namePrefixPalette; 406 | NamePrefixMaterial = namePrefixMaterial; 407 | 408 | NamePrefixPrefabSprite = namePrefixPrefabSprite; 409 | 410 | NamePrefixPrefabUI = namePrefixPrefabUI; 411 | NamePrefixMaterialUI = namePrefixMaterialUI; 412 | } 413 | 414 | public void CleanUp() 415 | { 416 | this = Default; 417 | } 418 | 419 | public bool Load() 420 | { 421 | NamePrefixTexture = Utility.Prefs.StringLoad(PrefsKeyNamePrefixTexture, Default.NamePrefixTexture); 422 | NamePrefixPalette = Utility.Prefs.StringLoad(PrefsKeyNamePrefixPalette, Default.NamePrefixPalette); 423 | NamePrefixMaterial = Utility.Prefs.StringLoad(PrefsKeyNamePrefixMaterial, Default.NamePrefixMaterial); 424 | 425 | NamePrefixPrefabSprite = Utility.Prefs.StringLoad(PrefsKeyNamePrefixPrefabSprite, Default.NamePrefixPrefabSprite); 426 | 427 | NamePrefixPrefabUI = Utility.Prefs.StringLoad(PrefsKeyNamePrefixPrefabUI, Default.NamePrefixPrefabUI); 428 | NamePrefixMaterialUI = Utility.Prefs.StringLoad(PrefsKeyNamePrefixMaterialUI, Default.NamePrefixMaterialUI); 429 | 430 | return(true); 431 | } 432 | 433 | public bool Save() 434 | { 435 | Utility.Prefs.StringSave(PrefsKeyNamePrefixTexture, NamePrefixTexture); 436 | Utility.Prefs.StringSave(PrefsKeyNamePrefixPalette, NamePrefixPalette); 437 | Utility.Prefs.StringSave(PrefsKeyNamePrefixMaterial, NamePrefixMaterial); 438 | 439 | Utility.Prefs.StringSave(PrefsKeyNamePrefixPrefabSprite, NamePrefixPrefabSprite); 440 | 441 | Utility.Prefs.StringSave(PrefsKeyNamePrefixPrefabUI, NamePrefixPrefabUI); 442 | Utility.Prefs.StringSave(PrefsKeyNamePrefixMaterialUI, NamePrefixMaterialUI); 443 | 444 | return(true); 445 | } 446 | 447 | public void Adjust() 448 | { 449 | NamePrefixTexture = Adjust(NamePrefixTexture); 450 | NamePrefixPalette = Adjust(NamePrefixPalette); 451 | NamePrefixMaterial = Adjust(NamePrefixMaterial); 452 | 453 | NamePrefixPrefabSprite = Adjust(NamePrefixPrefabSprite); 454 | 455 | NamePrefixPrefabUI = Adjust(NamePrefixPrefabUI); 456 | NamePrefixMaterialUI = Adjust(NamePrefixMaterialUI); 457 | } 458 | private static string Adjust(string text) 459 | { 460 | return(Setting.NameNormalize(text)); 461 | } 462 | 463 | public string NameGetAssetTexture(string nameBase) 464 | { 465 | string nameNormalize = nameBase; 466 | if(false == string.IsNullOrEmpty(NamePrefixTexture)) 467 | { 468 | nameNormalize = NamePrefixTexture + nameNormalize; 469 | } 470 | return(nameNormalize); 471 | } 472 | public string NameGetAssetPalette(string nameBase) 473 | { 474 | string nameNormalize = nameBase; 475 | if(false == string.IsNullOrEmpty(NamePrefixPalette)) 476 | { 477 | nameNormalize = NamePrefixPalette + nameNormalize; 478 | } 479 | return(nameNormalize); 480 | } 481 | public string NameGetAssetMaterial(string nameBase) 482 | { 483 | string nameNormalize = nameBase; 484 | if(false == string.IsNullOrEmpty(NamePrefixMaterial)) 485 | { 486 | nameNormalize = NamePrefixMaterial + nameNormalize; 487 | } 488 | return(nameNormalize); 489 | } 490 | public string NameGetAssetPrefabSprite(string nameBase) 491 | { 492 | string nameNormalize = nameBase; 493 | if(false == string.IsNullOrEmpty(NamePrefixPrefabSprite)) 494 | { 495 | nameNormalize = NamePrefixPrefabSprite + nameNormalize; 496 | } 497 | return(nameNormalize); 498 | } 499 | public string NameGetAssetPrefabUI(string nameBase) 500 | { 501 | string nameNormalize = nameBase; 502 | if(false == string.IsNullOrEmpty(NamePrefixPrefabUI)) 503 | { 504 | nameNormalize = NamePrefixPrefabUI + nameNormalize; 505 | } 506 | return(nameNormalize); 507 | } 508 | public string NameGetAssetMaterialUI(string nameBase) 509 | { 510 | string nameNormalize = nameBase; 511 | if(false == string.IsNullOrEmpty(NamePrefixMaterialUI)) 512 | { 513 | nameNormalize = NamePrefixMaterialUI + nameNormalize; 514 | } 515 | return(nameNormalize); 516 | } 517 | #endregion Functions 518 | 519 | /* ----------------------------------------------- Enums & Constants */ 520 | #region Enums & Constants 521 | private const string KeyNamePrefixTexture = "NamePrefixTexture"; 522 | private const string KeyNamePrefixPalette = "NamePrefixPalette"; 523 | private const string KeyNamePrefixMaterial = "NamePrefixMaterial"; 524 | private const string KeyNamePrefixPrefabSprite = "NamePrefixPrefabSprite"; 525 | private const string KeyNamePrefixPrefabUI = "NamePrefixPrefabUI"; 526 | private const string KeyNamePrefixMaterialUI = "NamePrefixMaterialUI"; 527 | 528 | private const string TextKeyPrefix = "RuleNameAsset_"; 529 | private const string TextKeyNamePrefixTexture = TextKeyPrefix + KeyNamePrefixTexture; 530 | private const string TextKeyNamePrefixPalette = TextKeyPrefix + KeyNamePrefixPalette; 531 | private const string TextKeyNamePrefixMaterial = TextKeyPrefix + KeyNamePrefixMaterial; 532 | private const string TextKeyNamePrefixPrefabSprite = TextKeyPrefix + KeyNamePrefixPrefabSprite; 533 | private const string TextKeyNamePrefixPrefabUI = TextKeyPrefix + KeyNamePrefixPrefabUI; 534 | private const string TextKeyNamePrefixMaterialUI = TextKeyPrefix + KeyNamePrefixMaterialUI; 535 | 536 | private const string PrefsKeyPrefix = Import.PrefsKeyPrefix + TextKeyPrefix; 537 | private const string PrefsKeyNamePrefixTexture = PrefsKeyPrefix + KeyNamePrefixTexture; 538 | private const string PrefsKeyNamePrefixPalette = PrefsKeyPrefix + KeyNamePrefixPalette; 539 | private const string PrefsKeyNamePrefixMaterial = PrefsKeyPrefix + KeyNamePrefixMaterial; 540 | private const string PrefsKeyNamePrefixPrefabSprite = PrefsKeyPrefix + KeyNamePrefixPrefabSprite; 541 | private const string PrefsKeyNamePrefixPrefabUI = PrefsKeyPrefix + KeyNamePrefixPrefabUI; 542 | private const string PrefsKeyNamePrefixMaterialUI = PrefsKeyPrefix + KeyNamePrefixMaterialUI; 543 | 544 | private readonly static GroupRuleNameAsset Default = new GroupRuleNameAsset( 545 | /* NamePrefixTexture */ "", 546 | /* NamePrefixPalette */ "icsp_", 547 | /* NamePrefixMaterial */ "icsm_", 548 | /* NamePrefixPrefabSprite */ "icss_", 549 | /* NamePrefixPrefabUI */ "icsui_", 550 | /* NamePrefixMaterialUI */ "icsum_" 551 | ); 552 | #endregion Enums & Constants 553 | } 554 | 555 | public struct GroupRuleNameAssetFolder 556 | { 557 | /* ----------------------------------------------- Variables & Properties */ 558 | #region Variables & Properties 559 | /* Folder Names (Common) */ 560 | public string NameFolderTexture; 561 | public string NameFolderPalette; 562 | public string NameFolderMaterial; 563 | 564 | public string NameFolderPrefabSprite; 565 | 566 | public string NameFolderPrefabUI; 567 | public string NameFolderMaterialUI; 568 | #endregion Variables & Properties 569 | 570 | /* ----------------------------------------------- Functions */ 571 | #region Functions 572 | public GroupRuleNameAssetFolder( string nameFolderTexture, 573 | string nameFolderPalette, 574 | string nameFolderMaterial, 575 | string nameFolderPrefabSprite, 576 | string nameFolderPrefabUI, 577 | string nameFolderMaterialUI 578 | ) 579 | { 580 | NameFolderTexture = nameFolderTexture; 581 | NameFolderPalette = nameFolderPalette; 582 | NameFolderMaterial = nameFolderMaterial; 583 | 584 | NameFolderPrefabSprite = nameFolderPrefabSprite; 585 | 586 | NameFolderPrefabUI = nameFolderPrefabUI; 587 | NameFolderMaterialUI = nameFolderMaterialUI; 588 | } 589 | 590 | public void CleanUp() 591 | { 592 | this = Default; 593 | } 594 | 595 | public bool Load() 596 | { 597 | NameFolderTexture = Utility.Prefs.StringLoad(PrefsKeyNameFolderTexture, Default.NameFolderTexture); 598 | NameFolderPalette = Utility.Prefs.StringLoad(PrefsKeyNameFolderPalette, Default.NameFolderPalette); 599 | NameFolderMaterial = Utility.Prefs.StringLoad(PrefsKeyNameFolderMaterial, Default.NameFolderMaterial); 600 | 601 | NameFolderPrefabSprite = Utility.Prefs.StringLoad(PrefsKeyNameFolderPrefabSprite, Default.NameFolderPrefabSprite); 602 | 603 | NameFolderPrefabUI = Utility.Prefs.StringLoad(PrefsKeyNameFolderPrefabUI, Default.NameFolderPrefabUI); 604 | NameFolderMaterialUI = Utility.Prefs.StringLoad(PrefsKeyNameFolderMaterialUI, Default.NameFolderMaterialUI); 605 | 606 | Adjust(); 607 | 608 | return(true); 609 | } 610 | 611 | public bool Save() 612 | { 613 | Adjust(); 614 | 615 | Utility.Prefs.StringSave(PrefsKeyNameFolderTexture, NameFolderTexture); 616 | Utility.Prefs.StringSave(PrefsKeyNameFolderPalette, NameFolderPalette); 617 | Utility.Prefs.StringSave(PrefsKeyNameFolderMaterial, NameFolderMaterial); 618 | 619 | Utility.Prefs.StringSave(PrefsKeyNameFolderPrefabSprite, NameFolderPrefabSprite); 620 | 621 | Utility.Prefs.StringSave(PrefsKeyNameFolderPrefabUI, NameFolderPrefabUI); 622 | Utility.Prefs.StringSave(PrefsKeyNameFolderMaterialUI, NameFolderMaterialUI); 623 | 624 | return(true); 625 | } 626 | 627 | public void Adjust() 628 | { 629 | NameFolderTexture = Adjust(NameFolderTexture); 630 | NameFolderPalette = Adjust(NameFolderPalette); 631 | NameFolderMaterial = Adjust(NameFolderMaterial); 632 | 633 | NameFolderPrefabSprite = Adjust(NameFolderPrefabSprite); 634 | 635 | NameFolderPrefabUI = Adjust(NameFolderPrefabUI); 636 | NameFolderMaterialUI = Adjust(NameFolderMaterialUI); 637 | } 638 | private static string Adjust(string text) 639 | { 640 | return(Setting.NameNormalize(text)); 641 | } 642 | #endregion Functions 643 | 644 | /* ----------------------------------------------- Enums & Constants */ 645 | #region Enums & Constants 646 | private const string KeyNameFolderTexture = "NameFolderTexture"; 647 | private const string KeyNameFolderPalette = "NameFolderPalette"; 648 | private const string KeyNameFolderMaterial = "NameFolderMaterial"; 649 | private const string KeyNameFolderPrefabSprite = "NameFolderPrefabSprite"; 650 | private const string KeyNameFolderPrefabUI = "NameFolderPrefabUI"; 651 | private const string KeyNameFolderMaterialUI = "NameFolderMaterialUI"; 652 | 653 | private const string TextKeyPrefix = "RuleNameAssetFolder_"; 654 | private const string TextKeyNameFolderTexture = TextKeyPrefix + KeyNameFolderTexture; 655 | private const string TextKeyNameFolderPalette = TextKeyPrefix + KeyNameFolderPalette; 656 | private const string TextKeyNameFolderMaterial = TextKeyPrefix + KeyNameFolderMaterial; 657 | private const string TextKeyNameFolderPrefabSprite = TextKeyPrefix + KeyNameFolderPrefabSprite; 658 | private const string TextKeyNameFolderPrefabUI = TextKeyPrefix + KeyNameFolderPrefabUI; 659 | private const string TextKeyNameFolderMaterialUI = TextKeyPrefix + KeyNameFolderMaterialUI; 660 | 661 | private const string PrefsKeyPrefix = Import.PrefsKeyPrefix + TextKeyPrefix; 662 | private const string PrefsKeyNameFolderTexture = PrefsKeyPrefix + KeyNameFolderTexture; 663 | private const string PrefsKeyNameFolderPalette = PrefsKeyPrefix + KeyNameFolderPalette; 664 | private const string PrefsKeyNameFolderMaterial = PrefsKeyPrefix + KeyNameFolderMaterial; 665 | private const string PrefsKeyNameFolderPrefabSprite = PrefsKeyPrefix + KeyNameFolderPrefabSprite; 666 | private const string PrefsKeyNameFolderPrefabUI = PrefsKeyPrefix + KeyNameFolderPrefabUI; 667 | private const string PrefsKeyNameFolderMaterialUI = PrefsKeyPrefix + KeyNameFolderMaterialUI; 668 | 669 | private readonly static GroupRuleNameAssetFolder Default = new GroupRuleNameAssetFolder( 670 | "Texture", /* NameFolderTexture */ 671 | "Palette", /* NameFolderPalette */ 672 | "Material", /* NameFolderMaterial */ 673 | "PrefabSprite", /* NameFolderPrefabSprite */ 674 | "PrefabUI", /* NameFolderPrefabUI */ 675 | "MaterialUI" /* NameFolderMaterialUI */ 676 | ); 677 | #endregion Enums & Constants 678 | 679 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 680 | #region Classes, Structs & Interfaces 681 | #endregion Classes, Structs & Interfaces 682 | 683 | /* ----------------------------------------------- Delegates */ 684 | #region Delegates 685 | #endregion Delegates 686 | } 687 | #endregion Classes, Structs & Interfaces 688 | 689 | /* ----------------------------------------------- Delegates */ 690 | #region Delegates 691 | #endregion Delegates 692 | } 693 | #endregion Classes, Structs & Interfaces 694 | } 695 | } 696 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Import/Setting.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4eba81f50f4abe4b8af03945a201d41 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Inspector.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40c6dce7c2f89524d8972f35ce383cf8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Inspector/Inspector_IndexColorShader_Sprite.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using UnityEngine; 10 | using UnityEditor; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | 14 | [CustomEditor(typeof(Script_IndexColorShader_Sprite))] 15 | public class Inspector_IndexColorShader_Sprite : Editor 16 | { 17 | /* ----------------------------------------------- Variables & Properties */ 18 | #region Variables & Properties 19 | /* WorkArea (for Inspector) */ 20 | private Script_IndexColorShader_Sprite InstanceObject; 21 | 22 | /* WorkArea (for Preview) */ 23 | private UnityEngine.Material InstanceMaterial = null; 24 | #endregion Variables & Properties 25 | 26 | /* ----------------------------------------------- Functions */ 27 | #region Functions 28 | private void OnEnable() 29 | { 30 | InstanceObject = (Script_IndexColorShader_Sprite)target; 31 | 32 | // serializedObject.FindProperty("__DUMMY__"); 33 | } 34 | 35 | // public override void OnInspectorGUI() 36 | // { 37 | // serializedObject.Update(); 38 | // } 39 | 40 | // private void OnDisable() 41 | // { 42 | // } 43 | #endregion Functions 44 | 45 | /* ----------------------------------------------- Functions-forPreview */ 46 | #region Functions-forPreview 47 | public override bool HasPreviewGUI() 48 | { 49 | return(true); 50 | } 51 | 52 | // public override GUIContent GetPreviewTitle() 53 | // { 54 | // return(TitlePreview); 55 | // } 56 | 57 | public override bool RequiresConstantRepaint() 58 | { 59 | return(false); 60 | } 61 | 62 | // public override void OnPreviewSettings() 63 | // { 64 | // } 65 | 66 | public override void OnPreviewGUI(Rect rect, GUIStyle background) 67 | { 68 | if(null == InstanceObject) 69 | { 70 | return; 71 | } 72 | if(null == InstanceObject.DataPalette) 73 | { 74 | return; 75 | } 76 | 77 | if(null == InstanceMaterial) 78 | { 79 | if(null == InstanceObject.MaterialMaster) 80 | { 81 | return; 82 | } 83 | InstanceMaterial = new Material(InstanceObject.MaterialMaster); 84 | } 85 | Vector4[] dataLUT = InstanceObject.LUT; 86 | if(null == dataLUT) 87 | { 88 | return; 89 | } 90 | 91 | /* Update Material */ 92 | UnityEngine.Texture texture = InstanceObject.Texture; 93 | UnityEngine.Color color = (null != InstanceObject.SpriteRenderer) ? InstanceObject.SpriteRenderer.color : UnityEngine.Color.white; 94 | Library_IndexColorShader.Data.ControlMaterialPalette.Update( InstanceMaterial, 95 | dataLUT, 96 | color, 97 | InstanceObject.Interpolation, 98 | texture, 99 | null 100 | ); 101 | 102 | /* Draw */ 103 | base.OnPreviewGUI(rect, background); 104 | Graphics.DrawTexture(rect, texture, InstanceMaterial); 105 | } 106 | #endregion Functions-forPreview 107 | 108 | /* ----------------------------------------------- Enums & Constants */ 109 | #region Enums & Constants 110 | // private readonly static GUIContent TitlePreview = new GUIContent("Preview [Script_IndexColorShader_Sprite]"); 111 | #endregion Enums & Constants 112 | } 113 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Inspector/Inspector_IndexColorShader_Sprite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43834949ee45af74986c3e0ff02107d4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Inspector/Inspector_IndexColorShader_UIImage.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using UnityEngine; 10 | using UnityEditor; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | 14 | [CustomEditor(typeof(Script_IndexColorShader_UIImage))] 15 | public class Inspector_IndexColorShader_UIImage : Editor 16 | { 17 | /* ----------------------------------------------- Variables & Properties */ 18 | #region Variables & Properties 19 | /* WorkArea (for Inspector) */ 20 | private Script_IndexColorShader_UIImage InstanceObject; 21 | 22 | /* WorkArea (for Preview) */ 23 | private UnityEngine.Material InstanceMaterial = null; 24 | #endregion Variables & Properties 25 | 26 | /* ----------------------------------------------- Functions */ 27 | #region Functions 28 | private void OnEnable() 29 | { 30 | InstanceObject = (Script_IndexColorShader_UIImage)target; 31 | 32 | // serializedObject.FindProperty("__DUMMY__"); 33 | } 34 | 35 | // public override void OnInspectorGUI() 36 | // { 37 | // serializedObject.Update(); 38 | // } 39 | 40 | // private void OnDisable() 41 | // { 42 | // } 43 | #endregion Functions 44 | 45 | /* ----------------------------------------------- Functions-forPreview */ 46 | #region Functions-forPreview 47 | public override bool HasPreviewGUI() 48 | { 49 | return(true); 50 | } 51 | 52 | // public override GUIContent GetPreviewTitle() 53 | // { 54 | // return(TitlePreview); 55 | // } 56 | 57 | public override bool RequiresConstantRepaint() 58 | { 59 | return(false); 60 | } 61 | 62 | // public override void OnPreviewSettings() 63 | // { 64 | // } 65 | 66 | public override void OnPreviewGUI(Rect rect, GUIStyle background) 67 | { 68 | if(null == InstanceObject) 69 | { 70 | return; 71 | } 72 | if(null == InstanceObject.DataPalette) 73 | { 74 | return; 75 | } 76 | 77 | if(null == InstanceMaterial) 78 | { 79 | if(null == InstanceObject.material) 80 | { 81 | return; 82 | } 83 | InstanceMaterial = new Material(InstanceObject.material); 84 | } 85 | Vector4[] dataLUT = InstanceObject.LUT; 86 | if(null == dataLUT) 87 | { 88 | return; 89 | } 90 | 91 | /* Update Material */ 92 | Rect uvRect = InstanceObject.uvRect; 93 | UnityEngine.Texture texture = InstanceObject.mainTexture; 94 | Library_IndexColorShader.Data.ControlMaterialPalette.Update( InstanceMaterial, 95 | dataLUT, 96 | InstanceObject.color, 97 | InstanceObject.Interpolation, 98 | texture, 99 | new Vector4(uvRect.width, uvRect.height, uvRect.x, uvRect.y) 100 | ); 101 | 102 | /* Draw */ 103 | base.OnPreviewGUI(rect, background); 104 | Graphics.DrawTexture(rect, texture, uvRect, 0, 0, 0, 0, Color.white, InstanceMaterial); 105 | } 106 | #endregion Functions-forPreview 107 | 108 | /* ----------------------------------------------- Enums & Constants */ 109 | #region Enums & Constants 110 | // private readonly static GUIContent TitlePreview = new GUIContent("Preview [Script_IndexColorShader_UIImage]"); 111 | #endregion Enums & Constants 112 | } 113 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Inspector/Inspector_IndexColorShader_UIImage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69ed763523f6f6c4d91eb1b07596f085 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/LibraryEditor_IndexColorShader.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using UnityEngine; 12 | using UnityEditor; 13 | 14 | public static partial class LibraryEditor_IndexColorShader 15 | { 16 | /* ----------------------------------------------- Variables & Properties */ 17 | #region Variables & Properties 18 | #endregion Variables & Properties 19 | 20 | /* ----------------------------------------------- Functions */ 21 | #region Functions 22 | private static void LogError(string messagePrefix, string message) 23 | { 24 | LibraryEditor_IndexColorShader.Utility.Log.Error(messagePrefix + ": " + message); 25 | } 26 | 27 | private static void LogWarning(string messagePrefix, string message) 28 | { 29 | LibraryEditor_IndexColorShader.Utility.Log.Warning(messagePrefix + ": " + message); 30 | } 31 | #endregion Functions 32 | 33 | /* ----------------------------------------------- Enums & Constants */ 34 | #region Enums & Constants 35 | #endregion Enums & Constants 36 | 37 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 38 | #region Classes, Structs & Interfaces 39 | public static partial class Import 40 | { 41 | /* ----------------------------------------------- Variables & Properties */ 42 | #region Variables & Properties 43 | #endregion Variables & Properties 44 | 45 | /* ----------------------------------------------- Functions */ 46 | #region Functions 47 | public static bool Exec( ref Setting setting, 48 | string nameInputFullPathImage, 49 | string nameOutputAssetFolderBase, 50 | bool flagDisplayProgressBar = true 51 | ) 52 | { 53 | const string messageLogPrefix = "Main"; 54 | const string titleProgressBar = Library_IndexColorShader.SignatureNameAsset; 55 | 56 | string nameDirectory = ""; 57 | string nameFileBody = ""; 58 | string nameFileExtension = ""; 59 | nameInputFullPathImage = Utility.File.PathNormalize(nameInputFullPathImage); 60 | string messageLogSuffix = " [" + nameInputFullPathImage + "]"; 61 | 62 | const int stepLoad = 2; /* Load / Decode */ 63 | const int stepConvert = 1; /* Convert(Palette, Pixel) */ 64 | const int stepOutputBasic = 3; /* Output-Basic(Palette, Texture, Material) */ 65 | const int stepOutputSprite = 1; /* Output-Sprite(Prefab) */ 66 | const int stepOutputUI = 2; /* Output-UI(Material, Prefab) */ 67 | int stepFull = stepLoad 68 | + stepConvert 69 | + stepOutputBasic 70 | + stepOutputSprite 71 | + stepOutputUI; 72 | int countStep = 0; 73 | 74 | // Utility.Log.Message("Importing Start" + messageLogSuffix, true, false); /* External-File only, no indent */ 75 | 76 | /* Load Image */ 77 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Loading Image", flagDisplayProgressBar, countStep, stepFull); 78 | if(false == System.IO.File.Exists(nameInputFullPathImage)) 79 | { /* Not Found */ 80 | LogError(messageLogPrefix, "File Not Found" + messageLogSuffix); 81 | goto Exec_ErrorEnd; 82 | } 83 | 84 | Utility.File.PathSplit(out nameDirectory, out nameFileBody, out nameFileExtension, nameInputFullPathImage); 85 | byte[] dataTexture = System.IO.File.ReadAllBytes(nameInputFullPathImage); 86 | if(null == dataTexture) 87 | { 88 | LogError(messageLogPrefix, "Failed to read file" + messageLogSuffix); 89 | goto Exec_ErrorEnd; 90 | } 91 | countStep++; 92 | 93 | /* Decode Image */ 94 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Deocoding Image", flagDisplayProgressBar, countStep, stepFull); 95 | Image.InformationDecode informationDecode = Image.Decode(dataTexture, messageLogSuffix); 96 | if(null == informationDecode) 97 | { 98 | goto Exec_ErrorEnd; 99 | } 100 | countStep++; 101 | 102 | /* Convert */ 103 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Converting Palette", flagDisplayProgressBar, countStep, stepFull); 104 | Color[] palette = Image.PaletteConvert(informationDecode, messageLogSuffix); 105 | if(null == palette) 106 | { 107 | informationDecode.Release(); 108 | goto Exec_ErrorEnd; 109 | } 110 | countStep++; 111 | 112 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Converting Pixel", flagDisplayProgressBar, countStep, stepFull); 113 | Texture2D textureIndexed = Image.PixelConvert(informationDecode, messageLogSuffix); 114 | if(null == textureIndexed) 115 | { 116 | informationDecode.Release(); 117 | goto Exec_ErrorEnd; 118 | } 119 | countStep++; 120 | 121 | /* MEMO: Image has been converted, no-need decoding-information anymore. */ 122 | informationDecode.Release(); 123 | 124 | /* Output Assets */ 125 | bool flagIgnoreConfirmOverwrite = false; 126 | 127 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Pallete asset", flagDisplayProgressBar, countStep, stepFull); 128 | Script_IndexColorShader_Palette assetDataPalette; 129 | if(false == AssetOutputPalette(out assetDataPalette, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, palette)) 130 | { 131 | goto Exec_ErrorEnd; 132 | } 133 | countStep++; 134 | 135 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Texture asset", flagDisplayProgressBar, countStep, stepFull); 136 | Texture2D assetTextureIndexed; 137 | if(false == AssetOutputTextureIndexed(out assetTextureIndexed, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, textureIndexed)) 138 | { 139 | goto Exec_ErrorEnd; 140 | } 141 | countStep++; 142 | 143 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Material asset", flagDisplayProgressBar, countStep, stepFull); 144 | Material assetMaterial; 145 | if(false == AssetOutputMaterial(out assetMaterial, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, assetTextureIndexed)) 146 | { 147 | goto Exec_ErrorEnd; 148 | } 149 | countStep++; 150 | 151 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Prefab-Sprite asset", flagDisplayProgressBar, countStep, stepFull); 152 | GameObject assetPrefabSprite; 153 | if(false == AssetOutputPrefabSprite(out assetPrefabSprite, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, assetMaterial, assetDataPalette)) 154 | { 155 | goto Exec_ErrorEnd; 156 | } 157 | countStep++; 158 | 159 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Material-UI asset", flagDisplayProgressBar, countStep, stepFull); 160 | Material assetMaterialUI; 161 | if(false == AssetOutputMaterialUI(out assetMaterialUI, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, assetTextureIndexed)) 162 | { 163 | goto Exec_ErrorEnd; 164 | } 165 | countStep++; 166 | 167 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, "Output Prefab-UI asset", flagDisplayProgressBar, countStep, stepFull); 168 | GameObject assetPrefabUI; 169 | if(false == AssetOutputPrefabUI(out assetPrefabUI, ref flagIgnoreConfirmOverwrite, ref setting, nameFileBody, nameOutputAssetFolderBase, assetMaterialUI, assetDataPalette)) 170 | { 171 | goto Exec_ErrorEnd; 172 | } 173 | countStep++; 174 | 175 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, string.Empty, flagDisplayProgressBar, -1, -1); 176 | // Utility.Log.Message("Importing Complete" + messageLogSuffix, true, false); /* External-File only, no indent */ 177 | 178 | return(true); 179 | 180 | Exec_ErrorEnd:; 181 | Utility.Miscellaneous.ProgressBarUpdate(titleProgressBar, string.Empty, flagDisplayProgressBar, -1, -1); 182 | // Utility.Log.Message("Importing Failed" + messageLogSuffix, true, false); /* External-File only, no indent */ 183 | 184 | return(false); 185 | } 186 | 187 | internal static bool AssetOutputPalette( out Script_IndexColorShader_Palette assetDataPalette, 188 | ref bool flagIgnoreConfirmOverwrite, 189 | ref Setting setting, 190 | string nameAsset, 191 | string nameOutputAssetFolderBase, 192 | Color[] palette 193 | ) 194 | { 195 | assetDataPalette = null; 196 | 197 | /* Get Assets Full-Path */ 198 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 199 | setting.RuleNameAssetFolder.NameFolderPalette, 200 | setting.RuleNameAsset.NameGetAssetPalette(nameAsset), 201 | ExtentionScriptableObject 202 | ); 203 | if(null == pathAssetFull) 204 | { 205 | return(false); 206 | } 207 | 208 | /* Get asset to save */ 209 | bool flagEnableUpdate; 210 | assetDataPalette = AssetGetPalette( out flagEnableUpdate, 211 | ref flagIgnoreConfirmOverwrite, 212 | ref setting, 213 | pathAssetFull 214 | ); 215 | if(null == assetDataPalette) 216 | { /* Error */ 217 | return(false); 218 | } 219 | 220 | /* Update asset */ 221 | if(true == flagEnableUpdate) 222 | { 223 | /* Write palette */ 224 | if(null != palette) 225 | { 226 | /* Clear & Set palettes */ 227 | int countPalette = assetDataPalette.Color.Length; 228 | for(int i=0; i(pathAsset); 266 | if(null == assetDataPalette) 267 | { /* Not Exist (Create New) */ 268 | /* Creagte Asset-Folder */ 269 | string nameAssetFolder = ""; 270 | string nameAssetFileBody = ""; 271 | string nameAssetFileExtension = ""; 272 | 273 | Utility.File.PathSplit(out nameAssetFolder, out nameAssetFileBody, out nameAssetFileExtension, pathAsset); 274 | if(true == string.IsNullOrEmpty(Utility.File.AssetFolderCreate(nameAssetFolder))) 275 | { 276 | LogError(messageLogPrefix, "Asset-Folder \"" + nameAssetFolder + "\" could not be created"); 277 | return(null); 278 | } 279 | 280 | /* Create Asset */ 281 | assetDataPalette = ScriptableObject.CreateInstance(); 282 | AssetDatabase.CreateAsset(assetDataPalette, pathAsset); 283 | 284 | /* Boot up Data */ 285 | assetDataPalette.BootUp(); 286 | } 287 | else 288 | { /* Exist (Overwrite) */ 289 | /* Check overwrite */ 290 | if(false == Utility.File.PermissionGetConfirmDialogueOverwrite( ref flagIgnoreConfirmOverwrite, 291 | setting.ConfirmOverWrite.FlagPalette, 292 | pathAsset, 293 | "Palette" 294 | ) 295 | ) 296 | { /* Not overwrite (Cancel) */ 297 | /* MEMO: No message */ 298 | // flagEnableUpdate = false; 299 | 300 | return(assetDataPalette); 301 | } 302 | } 303 | 304 | flagEnableUpdate = true; 305 | 306 | return(assetDataPalette); 307 | } 308 | 309 | internal static bool AssetOutputTextureIndexed( out Texture2D assetTexture, 310 | ref bool flagIgnoreConfirmOverwrite, 311 | ref Setting setting, 312 | string nameAsset, 313 | string nameOutputAssetFolderBase, 314 | Texture2D textureIndexed 315 | ) 316 | { 317 | assetTexture = null; 318 | 319 | /* Get Assets Full-Path */ 320 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 321 | setting.RuleNameAssetFolder.NameFolderTexture, 322 | setting.RuleNameAsset.NameGetAssetTexture(nameAsset), 323 | ExtentionTextureIndexed 324 | ); 325 | if(null == pathAssetFull) 326 | { 327 | return(false); 328 | } 329 | 330 | /* Get asset to save */ 331 | bool flagEnableUpdate; 332 | assetTexture = AssetGetTextureImporter( out flagEnableUpdate, 333 | ref flagIgnoreConfirmOverwrite, 334 | ref setting, 335 | pathAssetFull, 336 | textureIndexed 337 | ); 338 | if(null == assetTexture) 339 | { /* Error */ 340 | return(false); 341 | } 342 | 343 | /* Update asset */ 344 | if(true == flagEnableUpdate) 345 | { 346 | /* Dirty data */ 347 | EditorUtility.SetDirty(assetTexture); 348 | AssetDatabase.SaveAssets(); 349 | } 350 | 351 | return(assetTexture); 352 | } 353 | private static Texture2D AssetGetTextureImporter( out bool flagEnableUpdate, 354 | ref bool flagIgnoreConfirmOverwrite, 355 | ref Setting setting, 356 | string pathAsset, 357 | Texture2D textureIndexed 358 | ) 359 | { 360 | const string messageLogPrefix = "Asset-Create (Texture-Encode)"; 361 | flagEnableUpdate = false; 362 | 363 | bool optionIsSRGB = false; 364 | bool optionIsReadable = false; 365 | bool optionMipmapEnabled = false; 366 | int optionMaxTextureSize = 2048; 367 | TextureImporterAlphaSource optionAlphaSource = TextureImporterAlphaSource.FromInput; 368 | bool optionAlphaIsTransparency = false; 369 | TextureImporterNPOTScale optionNpotScale = TextureImporterNPOTScale.None; 370 | TextureImporterType optionTextureType = TextureImporterType.Sprite; 371 | SpriteImportMode optionSpriteImportMode = SpriteImportMode.Multiple; 372 | 373 | /* Check existing */ 374 | TextureImporter importer = TextureImporter.GetAtPath(pathAsset) as TextureImporter; 375 | if(null == importer) 376 | { /* Not Exist (Create New) */ 377 | /* Creagte Asset-Folder */ 378 | string nameAssetFolder = ""; 379 | string nameAssetFileBody = ""; 380 | string nameAssetFileExtension = ""; 381 | 382 | Utility.File.PathSplit(out nameAssetFolder, out nameAssetFileBody, out nameAssetFileExtension, pathAsset); 383 | if(true == string.IsNullOrEmpty(Utility.File.AssetFolderCreate(nameAssetFolder))) 384 | { 385 | LogError(messageLogPrefix, "Asset-Folder \"" + nameAssetFolder + "\" could not be created"); 386 | return(null); 387 | } 388 | } 389 | else 390 | { /* Exist (Overwrite) */ 391 | /* Check overwrite */ 392 | if(false == Utility.File.PermissionGetConfirmDialogueOverwrite( ref flagIgnoreConfirmOverwrite, 393 | setting.ConfirmOverWrite.FlagTexture, 394 | pathAsset, 395 | "Texture" 396 | ) 397 | ) 398 | { /* Not overwrite (Cancel) */ 399 | /* MEMO: No message */ 400 | // flagEnableUpdate = false; 401 | 402 | return(Utility.Asset.AssetLoadPath(pathAsset)); 403 | } 404 | 405 | /* Back up importer's setting */ 406 | optionIsSRGB = importer.sRGBTexture; 407 | optionIsReadable = importer.isReadable; 408 | optionMipmapEnabled = importer.mipmapEnabled; 409 | optionMaxTextureSize = importer.maxTextureSize; 410 | optionAlphaSource = importer.alphaSource; 411 | optionAlphaIsTransparency = importer.alphaIsTransparency; 412 | optionNpotScale = importer.npotScale; 413 | optionTextureType = importer.textureType; 414 | optionSpriteImportMode = importer.spriteImportMode; 415 | } 416 | 417 | flagEnableUpdate = true; 418 | 419 | /* Texture output */ 420 | string pathAssetNative = Utility.File.PathGetAssetNative(pathAsset); 421 | byte[] dataTexture = textureIndexed.EncodeToPNG(); 422 | if(null == dataTexture) 423 | { 424 | LogError(messageLogPrefix, "Texturer \"" + pathAsset + "\" could not encode"); 425 | return(null); 426 | } 427 | System.IO.File.WriteAllBytes(pathAssetNative, dataTexture); 428 | /* MEMO: After storing the Texture-File, cannot be gotten TextureImporter unless import & save once. */ 429 | AssetDatabase.ImportAsset(pathAsset, ImportAssetOptions.ForceUpdate); 430 | AssetDatabase.SaveAssets(); 431 | 432 | /* Re-get TextureImporter */ 433 | importer = TextureImporter.GetAtPath(pathAsset) as TextureImporter; 434 | 435 | /* Overwrite importer's setting */ 436 | importer.textureShape = TextureImporterShape.Texture2D; 437 | importer.textureCompression = TextureImporterCompression.Uncompressed; 438 | importer.filterMode = FilterMode.Point; 439 | importer.isReadable = optionIsReadable; 440 | importer.mipmapEnabled = optionMipmapEnabled; 441 | importer.maxTextureSize = optionMaxTextureSize; 442 | importer.npotScale = optionNpotScale; 443 | importer.textureType = optionTextureType; 444 | importer.spriteImportMode = optionSpriteImportMode; 445 | importer.sRGBTexture = optionIsSRGB; 446 | importer.alphaIsTransparency = false; // optionAlphaIsTransparency; 447 | importer.alphaSource = optionAlphaSource; 448 | 449 | // AssetDatabase.ImportAsset(pathAsset, ImportAssetOptions.ForceUpdate); 450 | EditorUtility.SetDirty(importer); 451 | importer.SaveAndReimport(); 452 | AssetDatabase.SaveAssets(); 453 | AssetDatabase.Refresh(); 454 | 455 | /* Get asset */ 456 | Texture2D assetTexture = Utility.Asset.AssetLoadPath(pathAsset); 457 | 458 | return(assetTexture); 459 | } 460 | 461 | internal static bool AssetOutputMaterial( out Material assetMaterial, 462 | ref bool flagIgnoreConfirmOverwrite, 463 | ref Setting setting, 464 | string nameAsset, 465 | string nameOutputAssetFolderBase, 466 | Texture2D textureIndexed 467 | ) 468 | { 469 | assetMaterial = null; 470 | 471 | if(false == setting.Basic.FlagCreateMaterial) 472 | { 473 | return(true); 474 | } 475 | 476 | /* Get Assets Full-Path */ 477 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 478 | setting.RuleNameAssetFolder.NameFolderMaterial, 479 | setting.RuleNameAsset.NameGetAssetMaterial(nameAsset), 480 | ExtentionMaterial 481 | ); 482 | if(null == pathAssetFull) 483 | { 484 | return(false); 485 | } 486 | 487 | /* Get asset to save */ 488 | bool flagEnableUpdate; 489 | assetMaterial = AssetGetMaterial( out flagEnableUpdate, 490 | ref flagIgnoreConfirmOverwrite, 491 | pathAssetFull, 492 | setting.ConfirmOverWrite.FlagMaterial, 493 | setting.Basic.MaterialSource, 494 | "Material" 495 | ); 496 | if(null == assetMaterial) 497 | { /* Error */ 498 | return(false); 499 | } 500 | 501 | /* Update asset */ 502 | if(true == flagEnableUpdate) 503 | { 504 | /* Set Texture */ 505 | assetMaterial.mainTexture = textureIndexed; 506 | 507 | /* Dirty data */ 508 | EditorUtility.SetDirty(assetMaterial); 509 | AssetDatabase.SaveAssets(); 510 | } 511 | 512 | return(true); 513 | } 514 | private static Material AssetGetMaterial( out bool flagEnableUpdate, 515 | ref bool flagIgnoreConfirmOverwrite, 516 | string pathAsset, 517 | bool flagConfirmOverwrite, 518 | Material assetSource, 519 | string textKindMaterial 520 | ) 521 | { 522 | string messageLogPrefix = "Asset-Create " + textKindMaterial; 523 | flagEnableUpdate = false; 524 | 525 | /* Check existing */ 526 | Material assetMaterial = AssetDatabase.LoadAssetAtPath(pathAsset); 527 | if(null == assetMaterial) 528 | { /* Not Exist (Create New) */ 529 | /* Creagte Asset-Folder */ 530 | string nameAssetFolder = ""; 531 | string nameAssetFileBody = ""; 532 | string nameAssetFileExtension = ""; 533 | 534 | Utility.File.PathSplit(out nameAssetFolder, out nameAssetFileBody, out nameAssetFileExtension, pathAsset); 535 | if(true == string.IsNullOrEmpty(Utility.File.AssetFolderCreate(nameAssetFolder))) 536 | { 537 | LogError(messageLogPrefix, "Asset-Folder \"" + nameAssetFolder + "\" could not be created"); 538 | return(null); 539 | } 540 | 541 | /* Create Asset */ 542 | assetMaterial = new Material(assetSource); 543 | AssetDatabase.CreateAsset(assetMaterial, pathAsset); 544 | } 545 | else 546 | { /* Exist (Overwrite) */ 547 | /* Check overwrite */ 548 | if(false == Utility.File.PermissionGetConfirmDialogueOverwrite( ref flagIgnoreConfirmOverwrite, 549 | flagConfirmOverwrite, 550 | pathAsset, 551 | textKindMaterial 552 | ) 553 | ) 554 | { /* Not overwrite (Cancel) */ 555 | /* MEMO: No message */ 556 | // flagEnableUpdate = true; 557 | 558 | return(assetMaterial); 559 | } 560 | } 561 | 562 | flagEnableUpdate = true; 563 | 564 | return(assetMaterial); 565 | } 566 | 567 | internal static bool AssetOutputPrefabSprite( out GameObject assetPrefabSprite, 568 | ref bool flagIgnoreConfirmOverwrite, 569 | ref Setting setting, 570 | string nameAsset, 571 | string nameOutputAssetFolderBase, 572 | Material material, 573 | Script_IndexColorShader_Palette dataPalette 574 | ) 575 | { 576 | assetPrefabSprite = null; 577 | 578 | if(false == setting.Basic.FlagCreatePrefabSprite) 579 | { 580 | return(true); 581 | } 582 | 583 | /* Get Assets Full-Path */ 584 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 585 | setting.RuleNameAssetFolder.NameFolderPrefabSprite, 586 | setting.RuleNameAsset.NameGetAssetPrefabSprite(nameAsset), 587 | ExtentionPrefab 588 | ); 589 | if(null == pathAssetFull) 590 | { 591 | return(false); 592 | } 593 | 594 | /* Get asset to save */ 595 | bool flagEnableUpdate; 596 | assetPrefabSprite = AssetGetPrefabSprite( out flagEnableUpdate, 597 | ref flagIgnoreConfirmOverwrite, 598 | ref setting, 599 | pathAssetFull 600 | ); 601 | if(null == assetPrefabSprite) 602 | { /* Error */ 603 | return(false); 604 | } 605 | 606 | /* Update asset */ 607 | if(true == flagEnableUpdate) 608 | { 609 | Script_IndexColorShader_Sprite assetSprite = assetPrefabSprite.GetComponent(); 610 | UnityEngine.SpriteRenderer assetSpriteRenderer = assetPrefabSprite.GetComponent(); 611 | 612 | /* Set other assets: Script_IndexColorShader_Sprite */ 613 | assetSprite.DataPalette = dataPalette; 614 | assetSprite.Texture = (null != material) ? (Texture2D)material.mainTexture : null; 615 | assetSprite.MaterialMaster = setting.Basic.MaterialSource; // material; 616 | 617 | /* Set other assets: UnityEngine.SpriteRenderer */ 618 | assetSpriteRenderer.material = material; 619 | assetSpriteRenderer.sprite = null; 620 | 621 | /* Dirty data */ 622 | EditorUtility.SetDirty(assetPrefabSprite); 623 | AssetDatabase.SaveAssets(); 624 | } 625 | 626 | return(true); 627 | } 628 | private static GameObject AssetGetPrefabSprite( out bool flagEnableUpdate, 629 | ref bool flagIgnoreConfirmOverwrite, 630 | ref Setting setting, 631 | string pathAsset 632 | ) 633 | { 634 | const string messageLogPrefix = "Asset-Create (Prefab-Sprite)"; 635 | flagEnableUpdate = false; 636 | 637 | /* Check existing : GameObject & Script-Sprite */ 638 | GameObject gameObjectSprite = AssetDatabase.LoadAssetAtPath(pathAsset); 639 | Script_IndexColorShader_Sprite assetPrefabSprite = null; 640 | if(null == gameObjectSprite) 641 | { /* Not Exist (Create New) */ 642 | /* Creagte Asset-Folder */ 643 | string nameAssetFolder = ""; 644 | string nameAssetFileBody = ""; 645 | string nameAssetFileExtension = ""; 646 | 647 | Utility.File.PathSplit(out nameAssetFolder, out nameAssetFileBody, out nameAssetFileExtension, pathAsset); 648 | if(true == string.IsNullOrEmpty(Utility.File.AssetFolderCreate(nameAssetFolder))) 649 | { 650 | LogError(messageLogPrefix, "Asset-Folder \"" + nameAssetFolder + "\" could not be created"); 651 | return(null); 652 | } 653 | 654 | /* Create GameObject */ 655 | gameObjectSprite = new GameObject(); 656 | assetPrefabSprite = gameObjectSprite.AddComponent(); 657 | if(null == assetPrefabSprite) 658 | { 659 | return(null); 660 | } 661 | 662 | /* Clean up component */ 663 | AssetResetPrefabSpriteScript(assetPrefabSprite); 664 | } 665 | else 666 | { /* Exist (Overwrite) */ 667 | /* Check overwrite */ 668 | if(false == Utility.File.PermissionGetConfirmDialogueOverwrite( ref flagIgnoreConfirmOverwrite, 669 | setting.ConfirmOverWrite.FlagPrefabUI, 670 | pathAsset, 671 | "Prefab-Sprite" 672 | ) 673 | ) 674 | { /* Not overwrite (Cancel) */ 675 | /* MEMO: No message */ 676 | // flagEnableUpdate = false; 677 | 678 | return(gameObjectSprite); 679 | } 680 | 681 | /* Instantiate & Update */ 682 | GameObject gameObjectUIPrefab = gameObjectSprite; 683 | gameObjectSprite = UnityEngine.Object.Instantiate(gameObjectUIPrefab); 684 | assetPrefabSprite = gameObjectSprite.GetComponent(); 685 | if(null == assetPrefabSprite) 686 | { /* Component missing */ 687 | assetPrefabSprite = gameObjectSprite.AddComponent(); 688 | 689 | /* Clean up component */ 690 | AssetResetPrefabSpriteScript(assetPrefabSprite); 691 | } 692 | } 693 | 694 | /* Check existing : GameObject & Script-Sprite */ 695 | UnityEngine.SpriteRenderer assetSpriteRenderer = gameObjectSprite.GetComponent(); 696 | if(null == assetSpriteRenderer) 697 | { 698 | assetSpriteRenderer = gameObjectSprite.AddComponent(); 699 | if(null == assetSpriteRenderer) 700 | { 701 | return(null); 702 | } 703 | 704 | AssetResetPrefabSpriteRenderer(assetSpriteRenderer); 705 | } 706 | 707 | /* Save assets */ 708 | GameObject prefabUI = PrefabUtility.SaveAsPrefabAsset(gameObjectSprite, pathAsset); 709 | AssetDatabase.SaveAssets(); 710 | 711 | /* Destroy Temporary */ 712 | UnityEngine.Object.DestroyImmediate(gameObjectSprite); 713 | 714 | flagEnableUpdate = true; 715 | 716 | return(prefabUI); 717 | } 718 | private static void AssetResetPrefabSpriteScript(Script_IndexColorShader_Sprite scriptSprite) 719 | { 720 | scriptSprite.Interpolation = Library_IndexColorShader.KindInterpolation.LINEAR; 721 | scriptSprite.Texture = null; /* Crear */ 722 | scriptSprite.RectDraw = new Rect(Vector2.zero, -Vector2.one); /* Rect.zero; */ 723 | scriptSprite.RatePivot = new Vector2(0.5f, 0.5f); 724 | scriptSprite.PixelsPerUnit = 0.0f; 725 | } 726 | private static void AssetResetPrefabSpriteRenderer(UnityEngine.SpriteRenderer renderer) 727 | { 728 | /* MEMO: Now, nothing to set. */ 729 | } 730 | 731 | internal static bool AssetOutputMaterialUI( out Material assetMaterial, 732 | ref bool flagIgnoreConfirmOverwrite, 733 | ref Setting setting, 734 | string nameAsset, 735 | string nameOutputAssetFolderBase, 736 | Texture2D textureIndexed 737 | ) 738 | { 739 | assetMaterial = null; 740 | 741 | if(false == setting.Basic.FlagCreatePrefabUI) 742 | { 743 | return(false); 744 | } 745 | 746 | /* Get Assets Full-Path */ 747 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 748 | setting.RuleNameAssetFolder.NameFolderMaterialUI, 749 | setting.RuleNameAsset.NameGetAssetMaterialUI(nameAsset), 750 | ExtentionMaterial 751 | ); 752 | if(null == pathAssetFull) 753 | { 754 | return(false); 755 | } 756 | 757 | /* Get asset to save */ 758 | bool flagEnableUpdate; 759 | assetMaterial = AssetGetMaterial( out flagEnableUpdate, 760 | ref flagIgnoreConfirmOverwrite, 761 | pathAssetFull, 762 | setting.ConfirmOverWrite.FlagMaterialUI, 763 | setting.Basic.MaterialSourceUI, 764 | "Material-UI" 765 | ); 766 | if(null == assetMaterial) 767 | { /* Error */ 768 | return(false); 769 | } 770 | 771 | /* Update asset */ 772 | if(true == flagEnableUpdate) 773 | { 774 | /* Set Texture */ 775 | assetMaterial.mainTexture = textureIndexed; 776 | 777 | /* Dirty data */ 778 | EditorUtility.SetDirty(assetMaterial); 779 | AssetDatabase.SaveAssets(); 780 | } 781 | 782 | return(true); 783 | } 784 | 785 | internal static bool AssetOutputPrefabUI( out GameObject assetPrefabUI, 786 | ref bool flagIgnoreConfirmOverwrite, 787 | ref Setting setting, 788 | string nameAsset, 789 | string nameOutputAssetFolderBase, 790 | Material material, 791 | Script_IndexColorShader_Palette dataPalette 792 | ) 793 | { 794 | assetPrefabUI = null; 795 | 796 | if(false == setting.Basic.FlagCreatePrefabUI) 797 | { 798 | return(true); 799 | } 800 | 801 | /* Get Assets Full-Path */ 802 | string pathAssetFull = AssetPathGetFull( nameOutputAssetFolderBase, 803 | setting.RuleNameAssetFolder.NameFolderPrefabUI, 804 | setting.RuleNameAsset.NameGetAssetPrefabUI(nameAsset), 805 | ExtentionPrefab 806 | ); 807 | if(null == pathAssetFull) 808 | { 809 | return(false); 810 | } 811 | 812 | /* Get asset to save */ 813 | bool flagEnableUpdate; 814 | assetPrefabUI = AssetGetPrefabUI( out flagEnableUpdate, 815 | ref flagIgnoreConfirmOverwrite, 816 | ref setting, 817 | pathAssetFull 818 | ); 819 | if(null == assetPrefabUI) 820 | { /* Error */ 821 | return(false); 822 | } 823 | 824 | /* Update asset */ 825 | if(true == flagEnableUpdate) 826 | { 827 | Script_IndexColorShader_UIImage assetUIImage = assetPrefabUI.GetComponent(); 828 | 829 | /* Set other assets */ 830 | assetUIImage.DataPalette = dataPalette; 831 | assetUIImage.material = material; 832 | 833 | /* Dirty data */ 834 | EditorUtility.SetDirty(assetPrefabUI); 835 | AssetDatabase.SaveAssets(); 836 | } 837 | 838 | return(true); 839 | } 840 | private static GameObject AssetGetPrefabUI( out bool flagEnableUpdate, 841 | ref bool flagIgnoreConfirmOverwrite, 842 | ref Setting setting, 843 | string pathAsset 844 | ) 845 | { 846 | const string messageLogPrefix = "Asset-Create (Prefab-UI)"; 847 | flagEnableUpdate = false; 848 | 849 | /* Check existing */ 850 | GameObject gameObjectUI = AssetDatabase.LoadAssetAtPath(pathAsset); 851 | Script_IndexColorShader_UIImage assetPrefabUI = null; 852 | if(null == gameObjectUI) 853 | { /* Not Exist (Create New) */ 854 | /* Creagte Asset-Folder */ 855 | string nameAssetFolder = ""; 856 | string nameAssetFileBody = ""; 857 | string nameAssetFileExtension = ""; 858 | 859 | Utility.File.PathSplit(out nameAssetFolder, out nameAssetFileBody, out nameAssetFileExtension, pathAsset); 860 | if(true == string.IsNullOrEmpty(Utility.File.AssetFolderCreate(nameAssetFolder))) 861 | { 862 | LogError(messageLogPrefix, "Asset-Folder \"" + nameAssetFolder + "\" could not be created"); 863 | return(null); 864 | } 865 | 866 | /* Create GameObject */ 867 | gameObjectUI = new GameObject(); 868 | assetPrefabUI = gameObjectUI.AddComponent(); 869 | if(null == assetPrefabUI) 870 | { 871 | return(null); 872 | } 873 | 874 | /* Clean up component */ 875 | AssetResetPrefabUIScript(assetPrefabUI); 876 | } 877 | else 878 | { /* Exist (Overwrite) */ 879 | /* Check overwrite */ 880 | if(false == Utility.File.PermissionGetConfirmDialogueOverwrite( ref flagIgnoreConfirmOverwrite, 881 | setting.ConfirmOverWrite.FlagPrefabUI, 882 | pathAsset, 883 | "Prefab-UI" 884 | ) 885 | ) 886 | { /* Not overwrite (Cancel) */ 887 | /* MEMO: No message */ 888 | // flagEnableUpdate = false; 889 | 890 | return(gameObjectUI); 891 | } 892 | 893 | /* Instantiate & Update */ 894 | GameObject gameObjectUIPrefab = gameObjectUI; 895 | gameObjectUI = UnityEngine.Object.Instantiate(gameObjectUIPrefab); 896 | assetPrefabUI = gameObjectUI.GetComponent(); 897 | if(null == assetPrefabUI) 898 | { /* Component missing */ 899 | assetPrefabUI = gameObjectUI.AddComponent(); 900 | 901 | /* Clean up component */ 902 | AssetResetPrefabUIScript(assetPrefabUI); 903 | } 904 | } 905 | 906 | /* Save assets */ 907 | GameObject prefabUI = PrefabUtility.SaveAsPrefabAsset(gameObjectUI, pathAsset); 908 | AssetDatabase.SaveAssets(); 909 | 910 | /* Destroy Temporary */ 911 | UnityEngine.Object.DestroyImmediate(gameObjectUI); 912 | 913 | flagEnableUpdate = true; 914 | 915 | return(prefabUI); 916 | } 917 | private static void AssetResetPrefabUIScript(Script_IndexColorShader_UIImage scriptUIImage) 918 | { 919 | scriptUIImage.color = Color.white; 920 | scriptUIImage.raycastTarget = true; 921 | scriptUIImage.maskable = true; 922 | scriptUIImage.Interpolation = Library_IndexColorShader.KindInterpolation.LINEAR; 923 | scriptUIImage.FlagHideForce = false; 924 | scriptUIImage.uvRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); 925 | scriptUIImage.SizeImageForce = -Vector2.one; 926 | scriptUIImage.StencilCompare = UnityEngine.Rendering.CompareFunction.Disabled; 927 | scriptUIImage.StencilID = 0; 928 | } 929 | 930 | private static string AssetPathGetFull(string nameBase, string nameFolderSub, string nameAsset, string extention) 931 | { 932 | if(true == string.IsNullOrEmpty(nameAsset)) 933 | { /* Error */ 934 | return(null); 935 | } 936 | 937 | string pathAssetFull = nameBase; 938 | if(true == string.IsNullOrEmpty(pathAssetFull)) 939 | { 940 | pathAssetFull = string.Empty; 941 | } 942 | if(false == pathAssetFull.EndsWith("/")) 943 | { 944 | pathAssetFull += "/"; 945 | } 946 | 947 | if(false == string.IsNullOrEmpty(nameFolderSub)) 948 | { 949 | pathAssetFull += nameFolderSub; 950 | if(false == pathAssetFull.EndsWith("/")) 951 | { 952 | pathAssetFull += "/"; 953 | } 954 | } 955 | 956 | pathAssetFull += nameAsset; 957 | if(false == string.IsNullOrEmpty(extention)) 958 | { 959 | pathAssetFull += extention; 960 | } 961 | 962 | return(pathAssetFull); 963 | } 964 | #endregion Functions 965 | 966 | /* ----------------------------------------------- Enums & Constants */ 967 | #region Enums & Constants 968 | internal const string ExtentionPrefab = ".prefab"; 969 | internal const string ExtentionScriptableObject = ".asset"; 970 | internal const string ExtentionTextureIndexed = ".png"; 971 | internal const string ExtentionMaterial = ".mat"; 972 | internal const string ExtentionSprite = ".png"; 973 | #endregion Enums & Constants 974 | 975 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 976 | #region Classes, Structs & Interfaces 977 | #endregion Classes, Structs & Interfaces 978 | 979 | /* ----------------------------------------------- Delegates */ 980 | #region Delegates 981 | #endregion Delegates 982 | } 983 | 984 | public static partial class Utility 985 | { 986 | /* ----------------------------------------------- Variables & Properties */ 987 | #region Variables & Properties 988 | #endregion Variables & Properties 989 | 990 | /* ----------------------------------------------- Functions */ 991 | #region Functions 992 | #endregion Functions 993 | 994 | /* ----------------------------------------------- Enums & Constants */ 995 | #region Enums & Constants 996 | #endregion Enums & Constants 997 | 998 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 999 | #region Classes, Structs & Interfaces 1000 | public static partial class File 1001 | { 1002 | /* ----------------------------------------------- Variables & Properties */ 1003 | #region Variables & Properties 1004 | #endregion Variables & Properties 1005 | 1006 | /* ----------------------------------------------- Functions */ 1007 | #region Functions 1008 | public static bool NamesGetFileDialogLoad( out string nameDirectory, 1009 | out string nameFileBody, 1010 | out string nameFileExtension, 1011 | string nameDirectoryPrevious, 1012 | string textTitleDialog, 1013 | string filterExtension 1014 | ) 1015 | { 1016 | if(true == string.IsNullOrEmpty(nameDirectoryPrevious)) 1017 | { 1018 | nameDirectoryPrevious = ""; 1019 | } 1020 | 1021 | /* Choose file */ 1022 | string fileNameFullPath = EditorUtility.OpenFilePanel(textTitleDialog, nameDirectoryPrevious, filterExtension); 1023 | if(0 == fileNameFullPath.Length) 1024 | { /* Cancelled */ 1025 | nameDirectory = ""; 1026 | nameFileBody = ""; 1027 | nameFileExtension = ""; 1028 | 1029 | return(false); 1030 | } 1031 | 1032 | return(PathSplit(out nameDirectory, out nameFileBody, out nameFileExtension, fileNameFullPath)); 1033 | } 1034 | 1035 | public static bool NamesGetFileDialogSave( out string nameDirectory, 1036 | out string nameFileBody, 1037 | out string nameFileExtension, 1038 | string nameDirectoryPrevious, 1039 | string nameFilePrevious, 1040 | string textTitleDialog, 1041 | string nameExtension 1042 | ) 1043 | { 1044 | /* Choose file */ 1045 | string fileNameFullPath = EditorUtility.SaveFilePanel(textTitleDialog, nameDirectoryPrevious, nameFilePrevious, nameExtension); 1046 | if(0 == fileNameFullPath.Length) 1047 | { /* Cancelled */ 1048 | nameDirectory = ""; 1049 | nameFileBody = ""; 1050 | nameFileExtension = ""; 1051 | 1052 | return(false); 1053 | } 1054 | 1055 | return(PathSplit(out nameDirectory, out nameFileBody, out nameFileExtension, fileNameFullPath)); 1056 | } 1057 | 1058 | internal static bool PermissionGetConfirmDialogueOverwrite( ref bool flagIgnoewConfirm, 1059 | bool flagSwitchSetting, 1060 | string nameAsset, 1061 | string nameTypeAsset 1062 | ) 1063 | { 1064 | if((false == flagSwitchSetting) || (true == flagIgnoewConfirm)) 1065 | { /* No-Confirm */ 1066 | return(true); 1067 | } 1068 | 1069 | bool rv = false; 1070 | int KindResult = EditorUtility.DisplayDialogComplex( "Asset already exists.", 1071 | "Do you want to overwrite?\n" + nameAsset, 1072 | "Yes", 1073 | "Yes, all \"" + nameTypeAsset +"\"s", 1074 | "No" 1075 | ); 1076 | switch(KindResult) 1077 | { 1078 | case 0: /* Yes */ 1079 | rv = true; 1080 | break; 1081 | 1082 | case 1: /* All */ 1083 | flagIgnoewConfirm = false; 1084 | rv = true; 1085 | break; 1086 | 1087 | case 2: /* No */ 1088 | rv = false; 1089 | break; 1090 | 1091 | } 1092 | 1093 | return(rv); 1094 | } 1095 | 1096 | public static string AssetFolderCreate(string namePath) 1097 | { 1098 | if(true == string.IsNullOrEmpty(namePath)) 1099 | { 1100 | return(null); 1101 | } 1102 | 1103 | /* MEMO: Originally, way that should not take. Use "System.IO.Directory.CreateDirectory" to create folders. */ 1104 | string[] namePathSplit = namePath.Split(TextSplitFolder); 1105 | int count = namePathSplit.Length; 1106 | if(0 >= count) 1107 | { 1108 | return(null); 1109 | } 1110 | 1111 | /* Reconstruct path */ 1112 | int indexTop = (NamePathRootAsset.ToLower() == namePathSplit[0].ToLower()) ? 1 : 0; 1113 | string namePathAsset = string.Copy(NamePathRootAsset); 1114 | string namePathNative = string.Copy(NamePathRootNative); 1115 | string namePathChild = null; 1116 | for(int i=indexTop; i "/" */ 1200 | return(namePathNew); 1201 | } 1202 | 1203 | public static string PathGetAbsolute(string namePath, string nameBase) 1204 | { 1205 | string nameCurrent = System.Environment.CurrentDirectory; 1206 | System.Environment.CurrentDirectory = nameBase; 1207 | 1208 | string rv = System.IO.Path.GetFullPath(namePath); 1209 | rv = PathNormalize(rv); 1210 | 1211 | System.Environment.CurrentDirectory = nameCurrent; 1212 | return(rv); 1213 | } 1214 | 1215 | public static string PathGetAssetNative(string namePathAsset) 1216 | { 1217 | string namePathNative = string.Copy(NamePathRootNative); 1218 | if(false == string.IsNullOrEmpty(namePathAsset)) 1219 | { 1220 | namePathNative += "/" + namePathAsset.Substring(NamePathRootAsset.Length + 1); 1221 | namePathNative = PathNormalize(namePathNative); 1222 | } 1223 | return(namePathNative); 1224 | } 1225 | 1226 | public static bool PathCheckRoot(string namePath) 1227 | { /* MEMO: Create another function separately, since possibility that can not be checked with IsPathRooted. */ 1228 | return(System.IO.Path.IsPathRooted(namePath)); 1229 | } 1230 | #endregion Functions 1231 | 1232 | /* ----------------------------------------------- Enums & Constants */ 1233 | #region Enums & Constants 1234 | private readonly static char[] TextSplitFolder = 1235 | { 1236 | '/', 1237 | '\\', 1238 | }; 1239 | 1240 | internal readonly static string NamePathRootNative = Application.dataPath; 1241 | internal const string NamePathRootAsset = "Assets"; 1242 | #endregion Enums & Constants 1243 | 1244 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 1245 | #region Classes, Structs & Interfaces 1246 | #endregion Classes, Structs & Interfaces 1247 | 1248 | /* ----------------------------------------------- Delegates */ 1249 | #region Delegates 1250 | #endregion Delegates 1251 | } 1252 | 1253 | public static partial class Prefs 1254 | { 1255 | /* ----------------------------------------------- Variables & Properties */ 1256 | #region Variables & Properties 1257 | #endregion Variables & Properties 1258 | 1259 | /* ----------------------------------------------- Functions */ 1260 | #region Functions 1261 | public static void StringSave(string prefsKey, string text) 1262 | { 1263 | string text64 = System.Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(text)); 1264 | EditorPrefs.SetString(prefsKey, text64); 1265 | } 1266 | 1267 | public static string StringLoad(string prefsKey, string textDefault) 1268 | { 1269 | string textDefault64 = System.Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(textDefault)); 1270 | string text64 = EditorPrefs.GetString(prefsKey, textDefault64); 1271 | return(System.Text.UTF8Encoding.UTF8.GetString(System.Convert.FromBase64String(text64))); 1272 | } 1273 | #endregion Functions 1274 | 1275 | /* ----------------------------------------------- Enums & Constants */ 1276 | #region Enums & Constants 1277 | #endregion Enums & Constants 1278 | 1279 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 1280 | #region Classes, Structs & Interfaces 1281 | #endregion Classes, Structs & Interfaces 1282 | 1283 | /* ----------------------------------------------- Delegates */ 1284 | #region Delegates 1285 | #endregion Delegates 1286 | } 1287 | 1288 | public static partial class Asset 1289 | { 1290 | /* ----------------------------------------------- Variables & Properties */ 1291 | #region Variables & Properties 1292 | #endregion Variables & Properties 1293 | 1294 | /* ----------------------------------------------- Functions */ 1295 | #region Functions 1296 | public static _Type AssetLoadPath<_Type>(string path) 1297 | where _Type : class 1298 | { 1299 | _Type asset = AssetDatabase.LoadAssetAtPath(path, typeof(_Type)) as _Type; 1300 | return(asset); 1301 | } 1302 | 1303 | public static string PathGetAsset(UnityEngine.Object asset) 1304 | { 1305 | return(AssetDatabase.GetAssetPath(asset)); 1306 | } 1307 | #endregion Functions 1308 | 1309 | /* ----------------------------------------------- Enums & Constants */ 1310 | #region Enums & Constants 1311 | #endregion Enums & Constants 1312 | 1313 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 1314 | #region Classes, Structs & Interfaces 1315 | #endregion Classes, Structs & Interfaces 1316 | 1317 | /* ----------------------------------------------- Delegates */ 1318 | #region Delegates 1319 | #endregion Delegates 1320 | } 1321 | 1322 | public static partial class Log 1323 | { 1324 | /* ----------------------------------------------- Variables & Properties */ 1325 | #region Variables & Properties 1326 | public static System.IO.StreamWriter StreamExternal = null; 1327 | #endregion Variables & Properties 1328 | 1329 | /* ----------------------------------------------- Functions */ 1330 | #region Functions 1331 | public static void Error(string message, bool flagExternalOnly=false, bool flagIndentExternal=true) 1332 | { 1333 | string text = "IndexColorShader Error: " + message; 1334 | if(false == flagExternalOnly) 1335 | { 1336 | Debug.LogError(text); 1337 | } 1338 | if(null != StreamExternal) 1339 | { 1340 | if(true == flagIndentExternal) 1341 | { 1342 | text = "\t" + text; 1343 | } 1344 | StreamExternal.WriteLine(text); 1345 | } 1346 | } 1347 | 1348 | public static void Warning(string message, bool flagExternalOnly=false, bool flagIndentExternal=true) 1349 | { 1350 | string text = "IndexColorShader Warning: " + message; 1351 | if(false == flagExternalOnly) 1352 | { 1353 | Debug.LogWarning(text); 1354 | } 1355 | if(null != StreamExternal) 1356 | { 1357 | if(true == flagIndentExternal) 1358 | { 1359 | text = "\t" + text; 1360 | } 1361 | StreamExternal.WriteLine(text); 1362 | } 1363 | } 1364 | 1365 | public static void Message(string message, bool flagExternalOnly=false, bool flagIndentExternal=true) 1366 | { 1367 | string text = "IndexColorShader Message: " + message; 1368 | if(false == flagExternalOnly) 1369 | { 1370 | Debug.Log(text); 1371 | } 1372 | if(null != StreamExternal) 1373 | { 1374 | if(true == flagIndentExternal) 1375 | { 1376 | text = "\t" + text; 1377 | } 1378 | StreamExternal.WriteLine(text); 1379 | } 1380 | } 1381 | #endregion Functions 1382 | 1383 | /* ----------------------------------------------- Enums & Constants */ 1384 | #region Enums & Constants 1385 | #endregion Enums & Constants 1386 | 1387 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 1388 | #region Classes, Structs & Interfaces 1389 | #endregion Classes, Structs & Interfaces 1390 | 1391 | /* ----------------------------------------------- Delegates */ 1392 | #region Delegates 1393 | #endregion Delegates 1394 | } 1395 | 1396 | public static partial class Miscellaneous 1397 | { 1398 | /* ----------------------------------------------- Variables & Properties */ 1399 | #region Variables & Properties 1400 | #endregion Variables & Properties 1401 | 1402 | /* ----------------------------------------------- Functions */ 1403 | #region Functions 1404 | public static void ProgressBarUpdate(string title, string nameTask, bool flagSwitch, int step, int stepFull) 1405 | { 1406 | if(false == flagSwitch) 1407 | { 1408 | return; 1409 | } 1410 | 1411 | if((-1 == step) || (-1 == stepFull)) 1412 | { 1413 | EditorUtility.ClearProgressBar(); 1414 | return; 1415 | } 1416 | 1417 | EditorUtility.DisplayProgressBar(title, nameTask, ((float)step / (float)stepFull)); 1418 | } 1419 | 1420 | public static void GarbageCollect() 1421 | { 1422 | System.GC.Collect(); 1423 | System.GC.WaitForPendingFinalizers(); 1424 | System.GC.Collect(); 1425 | } 1426 | #endregion Functions 1427 | 1428 | /* ----------------------------------------------- Enums & Constants */ 1429 | #region Enums & Constants 1430 | #endregion Enums & Constants 1431 | 1432 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 1433 | #region Classes, Structs & Interfaces 1434 | #endregion Classes, Structs & Interfaces 1435 | 1436 | /* ----------------------------------------------- Delegates */ 1437 | #region Delegates 1438 | #endregion Delegates 1439 | } 1440 | #endregion Classes, Structs & Interfaces 1441 | 1442 | /* ----------------------------------------------- Delegates */ 1443 | #region Delegates 1444 | #endregion Delegates 1445 | } 1446 | #endregion Classes, Structs & Interfaces 1447 | 1448 | /* ----------------------------------------------- Delegates */ 1449 | #region Delegates 1450 | #endregion Delegates 1451 | } 1452 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/LibraryEditor_IndexColorShader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83ab3e856ab51054aabaececee33a0c1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6896281e16d26584681d5f5668e3d0c9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/MacOSX.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e380b0cce78c4431a00d1b4dbbdc31c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/MacOSX/ICS_LoaderImage.bundle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/Assets/IndexColorShader/Editor/Plugins/MacOSX/ICS_LoaderImage.bundle -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/MacOSX/ICS_LoaderImage.bundle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c43a9dc9ee1447142b853f0478daca54 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38290f87c36a2ff4d9094dfc7b47016d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5f7b6ddf701dea4a9b86e61778c09c5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/ICS_LoaderImage.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/ICS_LoaderImage.dll -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/ICS_LoaderImage.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b209ea59089135a4cb1e60004bc387f1 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude Lumin: 1 23 | Exclude OSXUniversal: 1 24 | Exclude WebGL: 1 25 | Exclude Win: 1 26 | Exclude Win64: 1 27 | Exclude WindowsStoreApps: 1 28 | Exclude iOS: 1 29 | - first: 30 | Android: Android 31 | second: 32 | enabled: 0 33 | settings: 34 | CPU: ARMv7 35 | - first: 36 | Any: 37 | second: 38 | enabled: 0 39 | settings: {} 40 | - first: 41 | Editor: Editor 42 | second: 43 | enabled: 1 44 | settings: 45 | CPU: x86_64 46 | DefaultValueInitialized: true 47 | OS: Windows 48 | - first: 49 | Standalone: Linux64 50 | second: 51 | enabled: 0 52 | settings: 53 | CPU: AnyCPU 54 | - first: 55 | Standalone: OSXUniversal 56 | second: 57 | enabled: 0 58 | settings: 59 | CPU: x86_64 60 | - first: 61 | Standalone: Win 62 | second: 63 | enabled: 0 64 | settings: 65 | CPU: x86 66 | - first: 67 | Standalone: Win64 68 | second: 69 | enabled: 0 70 | settings: 71 | CPU: x86_64 72 | - first: 73 | Windows Store Apps: WindowsStoreApps 74 | second: 75 | enabled: 0 76 | settings: 77 | CPU: AnyCPU 78 | DontProcess: false 79 | PlaceholderPath: 80 | SDK: AnySDK 81 | ScriptingBackend: AnyScriptingBackend 82 | - first: 83 | iPhone: iOS 84 | second: 85 | enabled: 0 86 | settings: 87 | AddToEmbeddedBinaries: false 88 | CPU: AnyCPU 89 | CompileFlags: 90 | FrameworkDependencies: 91 | userData: 92 | assetBundleName: 93 | assetBundleVariant: 94 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140.dll -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ded4f9ea57b80c64893952b787aec82f 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140_1d.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140_1d.dll -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Plugins/Windows/x86_64/vcruntime140_1d.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a2ddea0ae41a5a4ca1351ab66ea205a 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | userData: 26 | assetBundleName: 27 | assetBundleVariant: 28 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Tools.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93bcf388a72fd5649912e44397523d67 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Tools/About.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using UnityEngine; 10 | using UnityEditor; 11 | 12 | public sealed class MenuItem_IndexColorShader_About : EditorWindow 13 | { 14 | /* ----------------------------------------------- Variables & Properties */ 15 | #region Variables & Properties 16 | #endregion Variables & Properties 17 | 18 | /* ----------------------------------------------- Functions */ 19 | #region Functions 20 | [MenuItem("Tools/IndexColorShader/About")] 21 | static void About() 22 | { 23 | EditorUtility.DisplayDialog( Library_IndexColorShader.SignatureNameAsset, 24 | Library_IndexColorShader.SignatureNameAsset 25 | + "\n\n" 26 | + "Version: " + Library_IndexColorShader.SignatureVersionAsset 27 | + "\n\n" 28 | + "Copyright(C) " + Library_IndexColorShader.SignatureNameDistributor, 29 | "OK" 30 | ); 31 | } 32 | #endregion Functions 33 | 34 | /* ----------------------------------------------- Enums & Constants */ 35 | #region Enums & Constants 36 | #endregion Enums & Constants 37 | 38 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 39 | #region Classes, Structs & Interfaces 40 | #endregion Classes, Structs & Interfaces 41 | 42 | /* ----------------------------------------------- Delegates */ 43 | #region Delegates 44 | #endregion Delegates 45 | } 46 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Tools/About.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8d513d426751744ea51a6762f770fa1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Tools/Importer.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using UnityEngine; 12 | using UnityEditor; 13 | 14 | public sealed class MenuItem_IndexColorShader_ImportTexture : EditorWindow 15 | { 16 | /* ----------------------------------------------- Variables & Properties */ 17 | #region Variables & Properties 18 | private static LibraryEditor_IndexColorShader.Import.Setting SettingImport; 19 | private static Setting SettingOption; 20 | #endregion Variables & Properties 21 | 22 | /* ----------------------------------------------- Functions */ 23 | #region Functions 24 | [MenuItem("Tools/IndexColorShader/Importer")] 25 | static void OpenWindow() 26 | { 27 | EditorWindow.GetWindow(true, Library_IndexColorShader.SignatureNameAsset + " Import-Settings"); 28 | SettingImport.CleanUp(); 29 | SettingOption.CleanUp(); 30 | SettingImport.Load(); 31 | SettingOption.Load(); 32 | } 33 | void OnGUI() 34 | { 35 | int levelIndent = EditorGUI.indentLevel; 36 | 37 | /* Fold Out: Commons */ 38 | EditorGUILayout.Space(); 39 | 40 | SettingOption.FlagFoldOutBasic = EditorGUILayout.Foldout(SettingOption.FlagFoldOutBasic, "Options: Basic"); 41 | if(true == SettingOption.FlagFoldOutBasic) 42 | { 43 | FoldOutExecBasic(levelIndent + 1); 44 | EditorGUI.indentLevel = levelIndent; 45 | } 46 | 47 | SettingOption.FlagFoldOutConfirmOverWrite = EditorGUILayout.Foldout(SettingOption.FlagFoldOutConfirmOverWrite, "Options: Overwrite Confirm"); 48 | if(true == SettingOption.FlagFoldOutConfirmOverWrite) 49 | { 50 | FoldOutExecConfirmOverWrite(levelIndent + 1); 51 | EditorGUI.indentLevel = levelIndent; 52 | } 53 | 54 | /* Button: Import */ 55 | EditorGUILayout.Space(); 56 | 57 | if(true == GUILayout.Button("Import")) 58 | { 59 | /* Single File Import */ 60 | string nameBaseAssetPath = LibraryEditor_IndexColorShader.Utility.File.AssetPathGetSelected(); 61 | if((false == string.IsNullOrEmpty(nameBaseAssetPath)) && (true == LibraryEditor_IndexColorShader.Utility.File.AssetCheckFolder(nameBaseAssetPath))) 62 | { 63 | string nameDirectory; 64 | string nameFileBody; 65 | string nameFileExtension; 66 | if(true == LibraryEditor_IndexColorShader.Utility.File.NamesGetFileDialogLoad( out nameDirectory, 67 | out nameFileBody, 68 | out nameFileExtension, 69 | SettingOption.NameFolderImportPrevious, 70 | "Select Image-File to import", 71 | "png" 72 | ) 73 | ) 74 | { 75 | string nameFile = LibraryEditor_IndexColorShader.Utility.File.PathNormalize(nameDirectory + "/" + nameFileBody + nameFileExtension); 76 | SettingOption.NameFolderImportPrevious = nameDirectory; 77 | 78 | SettingOption.Save(); 79 | SettingImport.Save(); 80 | 81 | /* Import */ 82 | if(false == LibraryEditor_IndexColorShader.Import.Exec( ref SettingImport, 83 | nameFile, 84 | nameBaseAssetPath, 85 | true 86 | ) 87 | ) 88 | { 89 | EditorUtility.DisplayDialog( Library_IndexColorShader.SignatureNameAsset, 90 | "Import Interrupted! Check Error on Console.", 91 | "OK" 92 | ); 93 | } 94 | 95 | Close(); 96 | } 97 | } 98 | else 99 | { /* Error (No selected) */ 100 | EditorUtility.DisplayDialog( Library_IndexColorShader.SignatureNameAsset, 101 | "Select Asset-Folder you want to store in before import, on the \"Project\" window.", 102 | "OK" 103 | ); 104 | } 105 | } 106 | 107 | /* Fold Out: Advanced Options */ 108 | EditorGUILayout.Space(); 109 | 110 | SettingOption.FlagFoldOutAdvancedOprions = EditorGUILayout.Foldout(SettingOption.FlagFoldOutAdvancedOprions, "Advanced Options"); 111 | if(true == SettingOption.FlagFoldOutAdvancedOprions) 112 | { 113 | levelIndent++; 114 | EditorGUI.indentLevel = levelIndent; 115 | 116 | SettingOption.FlagFoldOutRuleNameAsset = EditorGUILayout.Foldout(SettingOption.FlagFoldOutRuleNameAsset, "Advanced Options: Naming Assets"); 117 | if(true == SettingOption.FlagFoldOutRuleNameAsset) 118 | { 119 | FoldOutExecRuleNameAsset(levelIndent + 1); 120 | EditorGUI.indentLevel = levelIndent; 121 | } 122 | 123 | SettingOption.FlagFoldOutRuleNameAssetFolder = EditorGUILayout.Foldout(SettingOption.FlagFoldOutRuleNameAssetFolder, "Advanced Options: Naming Asset-Foldes"); 124 | if(true == SettingOption.FlagFoldOutRuleNameAssetFolder) 125 | { 126 | FoldOutExecRuleNameAssetFolder(levelIndent + 1); 127 | EditorGUI.indentLevel = levelIndent; 128 | } 129 | 130 | levelIndent--; 131 | EditorGUI.indentLevel = levelIndent; 132 | } 133 | } 134 | private void FoldOutExecBasic(int levelIndent) 135 | { 136 | EditorGUI.indentLevel = levelIndent; 137 | 138 | SettingImport.Basic.FlagCreateMaterial = EditorGUILayout.ToggleLeft("Create Material", SettingImport.Basic.FlagCreateMaterial); 139 | EditorGUI.indentLevel = levelIndent + 1; 140 | EditorGUILayout.LabelField("Create material with textures and shaders assigned."); 141 | if(true == SettingImport.Basic.FlagCreateMaterial) 142 | { 143 | EditorGUILayout.Space(); 144 | SettingImport.Basic.MaterialSource = EditorGUILayout.ObjectField("Source Material", SettingImport.Basic.MaterialSource, typeof(Material), true) as Material; 145 | } 146 | 147 | EditorGUILayout.Space(); 148 | EditorGUI.indentLevel = levelIndent; 149 | 150 | SettingImport.Basic.FlagCreatePrefabSprite = EditorGUILayout.ToggleLeft("Create Prefav for Sprite", SettingImport.Basic.FlagCreatePrefabSprite); 151 | EditorGUI.indentLevel = levelIndent + 1; 152 | EditorGUILayout.LabelField("Create prefabl assigned for Sprite."); 153 | EditorGUILayout.LabelField("Material will be the created in \"Create Material\"."); 154 | 155 | EditorGUILayout.Space(); 156 | EditorGUI.indentLevel = levelIndent; 157 | 158 | SettingImport.Basic.FlagCreatePrefabUI = EditorGUILayout.ToggleLeft("Create Prefab for UI", SettingImport.Basic.FlagCreatePrefabUI); 159 | EditorGUI.indentLevel = levelIndent + 1; 160 | EditorGUILayout.LabelField("Create prefab & material assigned for UI (Canvas)."); 161 | if(true == SettingImport.Basic.FlagCreatePrefabUI) 162 | { 163 | EditorGUILayout.Space(); 164 | SettingImport.Basic.MaterialSourceUI = EditorGUILayout.ObjectField("Source Material", SettingImport.Basic.MaterialSourceUI, typeof(Material), true) as Material; 165 | } 166 | 167 | EditorGUILayout.Space(); 168 | EditorGUILayout.Space(); 169 | EditorGUI.indentLevel = levelIndent; 170 | } 171 | private void FoldOutExecConfirmOverWrite(int levelIndent) 172 | { 173 | EditorGUI.indentLevel = levelIndent; 174 | 175 | EditorGUILayout.LabelField("Confirm when overwrite existing data."); 176 | EditorGUILayout.Space(); 177 | 178 | SettingImport.ConfirmOverWrite.FlagTexture = EditorGUILayout.ToggleLeft("Textures", SettingImport.ConfirmOverWrite.FlagTexture); 179 | SettingImport.ConfirmOverWrite.FlagPalette = EditorGUILayout.ToggleLeft("Palette", SettingImport.ConfirmOverWrite.FlagPalette); 180 | SettingImport.ConfirmOverWrite.FlagMaterial = EditorGUILayout.ToggleLeft("Material", SettingImport.ConfirmOverWrite.FlagMaterial); 181 | SettingImport.ConfirmOverWrite.FlagPrefabSprite = EditorGUILayout.ToggleLeft("Prefab-Sprite", SettingImport.ConfirmOverWrite.FlagPrefabSprite); 182 | SettingImport.ConfirmOverWrite.FlagPrefabUI = EditorGUILayout.ToggleLeft("Prefab-UI", SettingImport.ConfirmOverWrite.FlagPrefabUI); 183 | SettingImport.ConfirmOverWrite.FlagMaterialUI = EditorGUILayout.ToggleLeft("Material-UI", SettingImport.ConfirmOverWrite.FlagMaterialUI); 184 | 185 | EditorGUILayout.Space(); 186 | EditorGUILayout.Space(); 187 | } 188 | private void FoldOutExecRuleNameAsset(int levelIndent) 189 | { 190 | EditorGUI.indentLevel = levelIndent; 191 | 192 | EditorGUILayout.LabelField("So that assets' name does not conflict when stored in AssetBundle,"); 193 | EditorGUILayout.LabelField(" add the data identification string to top of file-name."); 194 | EditorGUILayout.LabelField("The prohibited characters are \":\", \"/\", \"\\\", \".\", \"*\", \"?\", Space and Tab."); 195 | EditorGUILayout.Space(); 196 | 197 | SettingImport.RuleNameAsset.NamePrefixTexture = EditorGUILayout.TextField("Texture", SettingImport.RuleNameAsset.NamePrefixTexture); 198 | SettingImport.RuleNameAsset.NamePrefixPalette = EditorGUILayout.TextField("Palette", SettingImport.RuleNameAsset.NamePrefixPalette); 199 | SettingImport.RuleNameAsset.NamePrefixMaterial = EditorGUILayout.TextField("Material", SettingImport.RuleNameAsset.NamePrefixMaterial); 200 | SettingImport.RuleNameAsset.NamePrefixPrefabSprite = EditorGUILayout.TextField("Prefab-Sprite", SettingImport.RuleNameAsset.NamePrefixPrefabSprite); 201 | SettingImport.RuleNameAsset.NamePrefixPrefabUI = EditorGUILayout.TextField("Prefab-UI", SettingImport.RuleNameAsset.NamePrefixPrefabUI); 202 | SettingImport.RuleNameAsset.NamePrefixMaterialUI = EditorGUILayout.TextField("Material-UI", SettingImport.RuleNameAsset.NamePrefixMaterialUI); 203 | 204 | SettingImport.RuleNameAsset.Adjust(); 205 | 206 | EditorGUILayout.Space(); 207 | EditorGUILayout.Space(); 208 | } 209 | private void FoldOutExecRuleNameAssetFolder(int levelIndent) 210 | { 211 | EditorGUI.indentLevel = levelIndent; 212 | 213 | EditorGUILayout.LabelField("For each type to output, you can specify name of Asset-Folder."); 214 | EditorGUILayout.LabelField("The prohibited characters are \":\", \"/\", \"\\\", \".\", \"*\", \"?\", Space and Tab."); 215 | EditorGUILayout.Space(); 216 | 217 | SettingImport.RuleNameAssetFolder.NameFolderTexture = EditorGUILayout.TextField("Texture", SettingImport.RuleNameAssetFolder.NameFolderTexture); 218 | SettingImport.RuleNameAssetFolder.NameFolderPalette = EditorGUILayout.TextField("Palette", SettingImport.RuleNameAssetFolder.NameFolderPalette); 219 | SettingImport.RuleNameAssetFolder.NameFolderMaterial = EditorGUILayout.TextField("Material", SettingImport.RuleNameAssetFolder.NameFolderMaterial); 220 | SettingImport.RuleNameAssetFolder.NameFolderPrefabSprite = EditorGUILayout.TextField("Prefab-Sprite", SettingImport.RuleNameAssetFolder.NameFolderPrefabSprite); 221 | SettingImport.RuleNameAssetFolder.NameFolderPrefabUI = EditorGUILayout.TextField("Prefab-UI", SettingImport.RuleNameAssetFolder.NameFolderPrefabUI); 222 | SettingImport.RuleNameAssetFolder.NameFolderMaterialUI = EditorGUILayout.TextField("Material-UI", SettingImport.RuleNameAssetFolder.NameFolderMaterialUI); 223 | 224 | SettingImport.RuleNameAssetFolder.Adjust(); 225 | 226 | EditorGUILayout.Space(); 227 | EditorGUILayout.Space(); 228 | } 229 | #endregion Functions 230 | 231 | /* ----------------------------------------------- Enums & Constants */ 232 | #region Enums & Constants 233 | #endregion Enums & Constants 234 | 235 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 236 | #region Classes, Structs & Interfaces 237 | private struct Setting 238 | { 239 | /* ----------------------------------------------- Variables & Properties */ 240 | #region Variables & Properties 241 | public string NameFolderImportPrevious; 242 | 243 | public bool FlagFoldOutBasic; 244 | 245 | public bool FlagFoldOutConfirmOverWrite; 246 | 247 | public bool FlagFoldOutAdvancedOprions; 248 | public bool FlagFoldOutRuleNameAsset; 249 | public bool FlagFoldOutRuleNameAssetFolder; 250 | #endregion Variables & Properties 251 | 252 | /* ----------------------------------------------- Functions */ 253 | #region Functions 254 | public Setting( string nameFolderImportPrevious, 255 | bool flagFoldOutBasic, 256 | bool flagFoldOutConfirmOverWrite, 257 | bool flagFoldOutAdvancedOprions, 258 | bool flagFoldOutRuleNameAsset, 259 | bool flagFoldOutRuleNameAssetFolder 260 | ) 261 | { 262 | NameFolderImportPrevious = nameFolderImportPrevious; 263 | 264 | FlagFoldOutBasic = flagFoldOutBasic; 265 | 266 | FlagFoldOutConfirmOverWrite = flagFoldOutConfirmOverWrite; 267 | 268 | FlagFoldOutAdvancedOprions = flagFoldOutAdvancedOprions; 269 | FlagFoldOutRuleNameAsset = flagFoldOutRuleNameAsset; 270 | FlagFoldOutRuleNameAssetFolder = flagFoldOutRuleNameAssetFolder; 271 | } 272 | 273 | public void CleanUp() 274 | { 275 | this = Default; 276 | } 277 | 278 | public bool Load() 279 | { 280 | NameFolderImportPrevious = LibraryEditor_IndexColorShader.Utility.Prefs.StringLoad(PrefsKeyNameFolderImportPrevious, Default.NameFolderImportPrevious); 281 | 282 | FlagFoldOutBasic = EditorPrefs.GetBool(PrefsKeyFlagFoldOutBasic, Default.FlagFoldOutBasic); 283 | 284 | FlagFoldOutConfirmOverWrite = EditorPrefs.GetBool(PrefsKeyFlagFoldOutConfirmOverWrite, Default.FlagFoldOutConfirmOverWrite); 285 | 286 | FlagFoldOutAdvancedOprions = EditorPrefs.GetBool(PrefsKeyFlagFoldOutAdvancedOprions, Default.FlagFoldOutAdvancedOprions); 287 | FlagFoldOutRuleNameAsset = EditorPrefs.GetBool(PrefsKeyFlagFoldOutRuleNameAsset, Default.FlagFoldOutRuleNameAsset); 288 | FlagFoldOutRuleNameAssetFolder = EditorPrefs.GetBool(PrefsKeyFlagFoldOutRuleNameAssetFolder, Default.FlagFoldOutRuleNameAssetFolder); 289 | 290 | return(true); 291 | } 292 | 293 | public bool Save() 294 | { 295 | LibraryEditor_IndexColorShader.Utility.Prefs.StringSave(PrefsKeyNameFolderImportPrevious, NameFolderImportPrevious); 296 | 297 | EditorPrefs.SetBool(PrefsKeyFlagFoldOutBasic, FlagFoldOutBasic); 298 | 299 | EditorPrefs.SetBool(PrefsKeyFlagFoldOutConfirmOverWrite, FlagFoldOutConfirmOverWrite); 300 | 301 | EditorPrefs.SetBool(PrefsKeyFlagFoldOutAdvancedOprions, FlagFoldOutAdvancedOprions); 302 | EditorPrefs.SetBool(PrefsKeyFlagFoldOutRuleNameAsset, FlagFoldOutRuleNameAsset); 303 | EditorPrefs.SetBool(PrefsKeyFlagFoldOutRuleNameAssetFolder, FlagFoldOutRuleNameAssetFolder); 304 | 305 | return(true); 306 | } 307 | #endregion Functions 308 | 309 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 310 | #region Classes, Structs & Interfaces 311 | private const string PrefsKeyPrefix = "ICS_ToolImporter_"; 312 | private const string PrefsKeyNameFolderImportPrevious = PrefsKeyPrefix + "NameFolderImportPrevious"; 313 | private const string PrefsKeyFlagFoldOutBasic = PrefsKeyPrefix + "FlagFoldOutBasic"; 314 | private const string PrefsKeyFlagFoldOutConfirmOverWrite = PrefsKeyPrefix + "FlagFoldOutConfirmOverWrite"; 315 | private const string PrefsKeyFlagFoldOutAdvancedOprions = PrefsKeyPrefix + "FlagFoldOutAdvancedOprions"; 316 | private const string PrefsKeyFlagFoldOutRuleNameAsset = PrefsKeyPrefix + "FlagFoldOutRuleNameAsset"; 317 | private const string PrefsKeyFlagFoldOutRuleNameAssetFolder = PrefsKeyPrefix + "FlagFoldOutRuleNameAssetFolder"; 318 | 319 | public readonly static Setting Default = new Setting( string.Empty, /* NameFolderImportPrevious */ 320 | true, /* FlagFoldOutBasic */ 321 | false, /* FlagFoldOutConfirmOverWrite */ 322 | false, /* FlagFoldOutAdvancedOprions */ 323 | false, /* FlagFoldOutRuleNameAsset */ 324 | false /* FlagFoldOutRuleNameAssetFolder */ 325 | ); 326 | #endregion Classes, Structs & Interfaces 327 | 328 | /* ----------------------------------------------- Delegates */ 329 | #region Delegates 330 | #endregion Delegates 331 | } 332 | #endregion Classes, Structs & Interfaces 333 | 334 | /* ----------------------------------------------- Delegates */ 335 | #region Delegates 336 | #endregion Delegates 337 | } 338 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Editor/Tools/Importer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d6a720a508373b429261fdb5a6f0f0a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Library.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3aba3460d7870ad458abdf57258bb2a9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Library/Library_IndexColorShader.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using UnityEngine; 12 | 13 | public static partial class Library_IndexColorShader 14 | { 15 | /* ----------------------------------------------- Signatures */ 16 | #region Signatures 17 | public const string SignatureNameAsset = "IndexColorShader for Unity"; 18 | public const string SignatureVersionAsset = "1.1.0"; 19 | public const string SignatureNameDistributor = "CRI Middleware Co., Ltd."; 20 | #endregion Signatures 21 | 22 | /* ----------------------------------------------- Variables & Properties */ 23 | #region Variables & Properties 24 | #endregion Variables & Properties 25 | 26 | /* ----------------------------------------------- Functions */ 27 | #region Functions 28 | #endregion Functions 29 | 30 | /* ----------------------------------------------- Enums & Constants */ 31 | #region Enums & Constants 32 | public enum KindInterpolation 33 | { 34 | NONE = 0, /* Nearest Neighbor */ 35 | LINEAR, /* Bi-Linear */ 36 | } 37 | #endregion Enums & Constants 38 | 39 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 40 | #region Classes, Structs & Interfaces 41 | public static partial class CallBack 42 | { 43 | /* ----------------------------------------------- Functions */ 44 | #region Functions 45 | #endregion Functions 46 | 47 | /* ----------------------------------------------- Enums & Constants */ 48 | #region Enums & Constants 49 | #endregion Enums & Constants 50 | 51 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 52 | #region Classes, Structs & Interfaces 53 | #endregion Classes, Structs & Interfaces 54 | 55 | /* ----------------------------------------------- Delegates */ 56 | #region Delegates 57 | #endregion Delegates 58 | } 59 | 60 | public static partial class Data 61 | { 62 | /* ----------------------------------------------- Functions */ 63 | #region Functions 64 | #endregion Functions 65 | 66 | /* ----------------------------------------------- Enums & Constants */ 67 | #region Enums & Constants 68 | #endregion Enums & Constants 69 | 70 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 71 | #region Classes, Structs & Interfaces 72 | [System.Serializable] 73 | public static partial class Palette 74 | { 75 | /* ----------------------------------------------- Variables & Properties */ 76 | #region Variables & Properties 77 | #endregion Variables & Properties 78 | 79 | /* ----------------------------------------------- Functions */ 80 | #region Functions 81 | #endregion Functions 82 | 83 | /* ----------------------------------------------- Enums & Constants */ 84 | #region Enums & Constants 85 | public const int CountColorMax = 256; 86 | #endregion Enums & Constants 87 | 88 | /* ----------------------------------------------- Delegates */ 89 | #region Delegates 90 | #endregion Delegates 91 | } 92 | 93 | public partial class ControlMaterialPalette 94 | { 95 | /* ----------------------------------------------- Variables & Properties */ 96 | #region Variables & Properties 97 | private MaterialPropertyBlock Property = null; 98 | private readonly static int IDMainTexture = UnityEngine.Shader.PropertyToID("_MainTex"); 99 | private readonly static int IDMainTextureST = UnityEngine.Shader.PropertyToID("_MainTex_ST"); 100 | private readonly static int IDColorTable = UnityEngine.Shader.PropertyToID("_ColorTable"); 101 | private readonly static int IDColor = UnityEngine.Shader.PropertyToID("_Color"); 102 | private readonly static int IDSetting = UnityEngine.Shader.PropertyToID("_Setting"); 103 | 104 | private Vector4 Setting; /* .x=Texture granularity-X, .y=Texture granularity-Y, .z=KindInterpolation, .w=Opacity */ 105 | #endregion Variables & Properties 106 | 107 | /* ----------------------------------------------- Functions */ 108 | #region Functions 109 | /* ******************************************************** */ 110 | //! Activate this class. 111 | /*! 112 | @param (none) 113 | 114 | @retval (none) 115 | 116 | */ 117 | public void BootUp() 118 | { 119 | if(null == Property) 120 | { 121 | Property = new MaterialPropertyBlock(); 122 | } 123 | #if false 124 | if(0 > IDMainTexture) 125 | { 126 | IDMainTexture = UnityEngine.Shader.PropertyToID("_MainTex"); 127 | } 128 | if(0 > IDMainTextureST) 129 | { 130 | IDMainTextureST = UnityEngine.Shader.PropertyToID("_MainTex_ST"); 131 | } 132 | if(0 > IDColorTable) 133 | { 134 | IDColorTable = UnityEngine.Shader.PropertyToID("_ColorTable"); 135 | } 136 | if(0 > IDColor) 137 | { 138 | IDColor = UnityEngine.Shader.PropertyToID("_Color"); 139 | } 140 | if(0 > IDSetting) 141 | { 142 | IDSetting = UnityEngine.Shader.PropertyToID("_Setting"); 143 | } 144 | #endif 145 | 146 | Setting = new Vector4(0.0f, 0.0f, 0.0f, 1.0f); 147 | } 148 | 149 | /* ******************************************************** */ 150 | //! Terminate this class 151 | /*! 152 | @param (none) 153 | 154 | @retval (none) 155 | */ 156 | public void ShutDown() 157 | { 158 | } 159 | 160 | /* ******************************************************** */ 161 | //! Update (for Renderer) 162 | /*! 163 | @param renderer 164 | Renderer to use for drawing. 165 | @param tableColor 166 | Palette(Color-LUT)
167 | Must be Vector4[256]. Elements are as .x=R,.y=G,.z=B,.w=Alpha. 168 | @param colorDiffuse 169 | Vertex color of primitive drawing 170 | @param interpolationTexture 171 | Kind of Texture-Filter
172 | KindInterpolation.NONE == Nearest-Neighbor interpolation
173 | KindInterpolation.LINEAR == (Bi)Linear interpolation 174 | @param texture 175 | Texture for drawing (be assigned to renderer.sharedMaterial.mainTexture)
176 | null == current renderer.sharedMaterial.mainTexture 177 | @param textureTilingOffset 178 | "Tiling" and "Offset" to be set for the material
179 | .x : Tiling.x (Scale.x) 180 | .y : Tiling.y (Scale.y) 181 | .z : Offset.x 182 | .w : Offset.y 183 | null == Texture's all range (Tiling=1,1 / Offset=0,0) 184 | 185 | @retval (none) 186 | 187 | Set Material's parameter and transfer constants to Shader. 188 | */ 189 | public void Update( Renderer renderer, 190 | Vector4[] tableColor, 191 | Color colorDiffuse, 192 | Library_IndexColorShader.KindInterpolation interpolationTexture, 193 | Texture texture, 194 | Vector4? textureTilingOffset 195 | ) 196 | { 197 | if(null == renderer) 198 | { 199 | return; 200 | } 201 | 202 | /* Set Palette */ 203 | if(0 <= IDColorTable) 204 | { 205 | Property.SetVectorArray(IDColorTable, tableColor); 206 | } 207 | 208 | /* Set Texture */ 209 | if(null == texture) 210 | { 211 | texture = renderer.sharedMaterial.mainTexture; 212 | } 213 | if(0 <= IDMainTexture) 214 | { 215 | Property.SetTexture(IDMainTexture, texture); 216 | } 217 | if(0 <= IDMainTextureST) 218 | { 219 | Vector4 tilingOffset = textureTilingOffset ?? TextureTilingOffsetDefault; 220 | Property.SetVector(IDMainTextureST, tilingOffset); 221 | } 222 | 223 | /* Set Mesh-Color */ 224 | if(0 <= IDColor) 225 | { 226 | Property.SetColor(IDColor, colorDiffuse); 227 | } 228 | 229 | /* Set Setting */ 230 | Setting.x = texture.width; 231 | Setting.y = texture.height; 232 | Setting.z = (float)interpolationTexture; 233 | Setting.w = 1.0f; 234 | if(0 <= IDSetting) 235 | { 236 | Property.SetVector(IDSetting, Setting); 237 | } 238 | 239 | /* Set current material's value */ 240 | renderer.SetPropertyBlock(Property); 241 | } 242 | 243 | /* ******************************************************** */ 244 | //! Update (for Material) 245 | /*! 246 | @param renderer 247 | Renderer to use for drawing. 248 | @param tableColor 249 | Palette(Color-LUT)
250 | Must be Vector4[256]. Elements are as .x=R,.y=G,.z=B,.w=Alpha. 251 | @param colorDiffuse 252 | Vertex color of primitive drawing 253 | @param interpolationTexture 254 | Kind of Texture-Filter
255 | KindInterpolation.NONE == Nearest-Neighbor interpolation
256 | KindInterpolation.LINEAR == (Bi)Linear interpolation 257 | @param texture 258 | Texture for drawing (be assigned to renderer.sharedMaterial.mainTexture)
259 | null == current renderer.sharedMaterial.mainTexture 260 | @param textureTilingOffset 261 | "Tiling" and "Offset" to be set for the material
262 | .x : Tiling.x (Scale.x) 263 | .y : Tiling.y (Scale.y) 264 | .z : Offset.x 265 | .w : Offset.y 266 | null == Texture's all range (Tiling=1,1 / Offset=0,0) 267 | 268 | @retval (none) 269 | 270 | Set Material's parameter and transfer constants to Shader. 271 | */ 272 | public static void Update( Material instanceMaterial, 273 | Vector4[] tableColor, 274 | Color colorDiffuse, 275 | Library_IndexColorShader.KindInterpolation interpolationTexture, 276 | Texture texture, 277 | Vector4? textureTilingOffset 278 | ) 279 | { 280 | if(null == instanceMaterial) 281 | { 282 | return; 283 | } 284 | 285 | /* Set Palette */ 286 | if(0 <= IDColorTable) 287 | { 288 | instanceMaterial.SetVectorArray(IDColorTable, tableColor); 289 | } 290 | 291 | /* Set Texture */ 292 | if(null == texture) 293 | { 294 | texture = instanceMaterial.mainTexture; 295 | } 296 | if(0 <= IDMainTexture) 297 | { 298 | instanceMaterial.SetTexture(IDMainTexture, texture); 299 | } 300 | if(0 <= IDMainTextureST) 301 | { 302 | Vector4 tilingOffset = textureTilingOffset ?? TextureTilingOffsetDefault; 303 | instanceMaterial.SetVector(IDMainTextureST, tilingOffset); 304 | } 305 | 306 | /* Set Mesh-Color */ 307 | if(0 <= IDColor) 308 | { 309 | instanceMaterial.SetColor(IDColor, colorDiffuse); 310 | } 311 | 312 | /* Set Setting */ 313 | if(0 <= IDSetting) 314 | { 315 | Vector4 setting = new Vector4(64.0f, 64.0f, (float)interpolationTexture, 1.0f); 316 | if(null != texture) 317 | { 318 | setting.x = texture.width; 319 | setting.y = texture.height; 320 | } 321 | instanceMaterial.SetVector(IDSetting, setting); 322 | } 323 | } 324 | #endregion Functions 325 | 326 | /* ----------------------------------------------- Enums & Constants */ 327 | #region Enums & Constants 328 | public readonly static Vector4 TextureTilingOffsetDefault = new Vector4(1.0f, 1.0f, 0.0f, 0.0f); 329 | 330 | /* MEMO: Old definition, but has been retained for backward compatibility. */ 331 | /* The new definition is "Library_IndexColorShader.KindInterpolation". */ 332 | public enum KindInterpolation 333 | { 334 | NONE = Library_IndexColorShader.KindInterpolation.NONE, 335 | LINEAR = Library_IndexColorShader.KindInterpolation.LINEAR, 336 | } 337 | #endregion Enums & Constants 338 | 339 | /* ----------------------------------------------- Delegates */ 340 | #region Delegates 341 | #endregion Delegates 342 | } 343 | #endregion Classes, Structs & Interfaces 344 | 345 | /* ----------------------------------------------- Delegates */ 346 | #region Delegates 347 | #endregion Delegates 348 | } 349 | 350 | public static partial class Palette 351 | { 352 | /* ----------------------------------------------- Variables & Properties */ 353 | #region Variables & Properties 354 | #endregion Variables & Properties 355 | 356 | /* ----------------------------------------------- Functions */ 357 | #region Functions 358 | public static Vector4[] ColorCopyDeep(Vector4[] paletteDestination, Vector4[] paletteSource) 359 | { 360 | Vector4[] destination = null; 361 | if(null == paletteDestination) 362 | { /* Auto (Create destination) */ 363 | destination = new Vector4[Data.Palette.CountColorMax]; 364 | if(null == destination) 365 | { 366 | return(null); 367 | } 368 | } else { /* Specified destination */ 369 | destination = paletteDestination; 370 | } 371 | 372 | /* Copy colors */ 373 | int countColor = paletteSource.Length; 374 | int countColorDestination = destination.Length; 375 | if(countColorDestination < countColor) 376 | { 377 | countColor = countColorDestination; 378 | } 379 | 380 | for(int i=0; i Data; 439 | 440 | public bool StatusIsBootedUp 441 | { 442 | get 443 | { 444 | return(null != Data); /* ? true : false*/ 445 | } 446 | } 447 | #endregion Variables & Properties 448 | 449 | /* ----------------------------------------------- Functions */ 450 | #region Functions 451 | public bool BootUp(int capacity) 452 | { 453 | if(0 >= capacity) 454 | { 455 | capacity = CapacityMaterialDefault; 456 | } 457 | 458 | Data = new List(capacity); 459 | Data.Clear(); 460 | 461 | return(true); 462 | } 463 | 464 | public void ShutDown(bool flagDestroyInstance) 465 | { 466 | DataPurge(flagDestroyInstance); 467 | 468 | Data = null; 469 | } 470 | 471 | public void DataPurge(bool flagDestroyInstance) 472 | { 473 | if(false == StatusIsBootedUp) 474 | { 475 | return; 476 | } 477 | 478 | int countData = Data.Count; 479 | for(int i=(countData-1); i>=0; i--) 480 | { 481 | DataRelease(i, flagDestroyInstance); 482 | } 483 | Data.Clear(); 484 | } 485 | 486 | public void DataAppend(long codeHash, UnityEngine.Material instanecMaterial) 487 | { 488 | InformationData informationData = new InformationData(codeHash, instanecMaterial); 489 | informationData.Count++; 490 | Data.Add(informationData); 491 | } 492 | 493 | public void DataRelease(int index, bool flagDestroyInstance=false) 494 | { 495 | if(true == flagDestroyInstance) 496 | { 497 | UnityEngine.Material material = Data[index].Instance; 498 | if(null != material) 499 | { 500 | Utility.Asset.ObjectDestroy(material); 501 | } 502 | } 503 | 504 | Data.RemoveAt(index); 505 | } 506 | 507 | public int IndexGet(long codeHash) 508 | { 509 | /* MEMO: Normally, Binary-Search is faster. */ 510 | /* But since delete invalid-cache at the same time, use Linear-Search now. */ 511 | int countData = Data.Count; 512 | for(int i=0; i indexCacheMaterial) 605 | { /* Not exist */ 606 | if(true == flagCreateNew) 607 | { 608 | /* Create new material */ 609 | instanceMaterial = new UnityEngine.Material(shader); 610 | instanceMaterial.mainTexture = texture; 611 | 612 | /* Append new material */ 613 | DataAppend(codeHash, instanceMaterial); 614 | } 615 | } 616 | else 617 | { /* Exist */ 618 | /* Increment reference-count. */ 619 | InformationData dataCache = Data[indexCacheMaterial]; 620 | dataCache.Count++; 621 | Data[indexCacheMaterial] = dataCache; 622 | 623 | instanceMaterial = dataCache.Instance; 624 | } 625 | 626 | return(instanceMaterial); 627 | } 628 | 629 | public void MaterialRelease(UnityEngine.Material instanceMaterial) 630 | { 631 | int indexCacheMaterial = IndexGet(instanceMaterial); 632 | if(0 > indexCacheMaterial) 633 | { /* Not exist */ 634 | return; 635 | } 636 | 637 | /* Decrement reference-count. */ 638 | InformationData dataCache = Data[indexCacheMaterial]; 639 | dataCache.Count--; 640 | if(0 < dataCache.Count) 641 | { /* Still referenced */ 642 | Data[indexCacheMaterial] = dataCache; 643 | } 644 | else 645 | { /* No referenced */ 646 | DataRelease(indexCacheMaterial, true); 647 | } 648 | } 649 | #endregion Functions 650 | 651 | /* ----------------------------------------------- Enums & Constants */ 652 | #region Enums & Constants 653 | private const int CapacityMaterialDefault = 100; 654 | 655 | public const string NameShaderPrefix = "Custom/IndexColorShader/"; 656 | public static UnityEngine.Shader ShaderDefaultSprite = UnityEngine.Shader.Find(NameShaderPrefix + "Palette256"); 657 | public static UnityEngine.Shader ShaderDefaultUIImage = UnityEngine.Shader.Find(NameShaderPrefix + "UIPalette256"); 658 | #endregion Enums & Constants 659 | 660 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 661 | #region Classes, Structs & Interfaces 662 | public struct InformationData 663 | { 664 | /* ----------------------------------------------- Variables & Properties */ 665 | #region Variables & Properties 666 | internal long CodeHash; 667 | internal int Count; 668 | internal Material Instance; 669 | #endregion Variables & Properties 670 | 671 | /* ----------------------------------------------- Functions */ 672 | #region Functions 673 | internal InformationData(long codeHash, UnityEngine.Material instance) 674 | { 675 | CodeHash = codeHash; 676 | Count = 0; 677 | Instance = instance; 678 | } 679 | 680 | internal static long CodeGet(int hashShader, int hashTexture, UnityEngine.Rendering.CompareFunction functionCompare, int idStencil) 681 | { 682 | long hashShaderLong = (long)hashShader & MaskCodeName; 683 | long hashCombined = hashShaderLong; 684 | hashCombined <<= 5; 685 | hashCombined |= (hashCombined >> 32); 686 | hashCombined += hashShaderLong; 687 | hashCombined ^= (long)hashTexture; 688 | hashCombined &= MaskCodeName; 689 | 690 | long code = (long)hashCombined & MaskCodeName; 691 | code |= ((long)idStencil & MaskCodeFunctionStencil) << CountShiftCodeFunctionStencil; 692 | code |= ((long)functionCompare & MaskCodeIDStencil) << CountShiftCodeIDStencil; 693 | 694 | return(code); 695 | } 696 | #endregion Functions 697 | 698 | /* ----------------------------------------------- Enums & Constants */ 699 | #region Enums & Constants 700 | internal const long MaskCodeName = 0x00000000ffffffffL; 701 | internal const long MaskCodeFunctionStencil = 0x00000000000000ffL; 702 | internal const long MaskCodeIDStencil = 0x000000000000000fL; 703 | 704 | // internal const int CountShiftCodeName = 0; 705 | internal const int CountShiftCodeFunctionStencil = 32; 706 | internal const int CountShiftCodeIDStencil = 40; 707 | #endregion Enums & Constants 708 | 709 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 710 | #region Classes, Structs & Interfaces 711 | #endregion Classes, Structs & Interfaces 712 | } 713 | #endregion Classes, Structs & Interfaces 714 | } 715 | #endregion Classes, Structs & Interfaces 716 | } 717 | 718 | public static partial class Utility 719 | { 720 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 721 | #region Classes, Structs & Interfaces 722 | public static partial class Asset 723 | { 724 | /* ----------------------------------------------- Functions */ 725 | #region Functions 726 | public static GameObject GameObjectCreate(string name, bool flagActive, GameObject gameObjectParent) 727 | { 728 | GameObject gameObject = new GameObject(name); 729 | if(null != gameObject) 730 | { 731 | gameObject.SetActive(flagActive); 732 | Transform transform = gameObject.transform; 733 | if(null != gameObjectParent) 734 | { 735 | transform.parent = gameObjectParent.transform; 736 | } 737 | transform.localPosition = Vector3.zero; 738 | transform.localEulerAngles = Vector3.zero; 739 | transform.localScale = Vector3.one; 740 | } 741 | return(gameObject); 742 | } 743 | 744 | public static void ObjectDestroy(UnityEngine.Object instanceObject) 745 | { 746 | if(null != instanceObject) 747 | { 748 | #if UNITY_EDITOR 749 | if(false == UnityEditor.EditorApplication.isPlaying) 750 | { 751 | UnityEngine.Object.DestroyImmediate(instanceObject); 752 | } 753 | else 754 | { 755 | UnityEngine.Object.Destroy(instanceObject); 756 | } 757 | #else 758 | UnityEngine.Object.Destroy(instanceObject); 759 | #endif 760 | } 761 | } 762 | #endregion Functions 763 | } 764 | #endregion Classes, Structs & Interfaces 765 | } 766 | /* ----------------------------------------------- Delegates */ 767 | #region Delegates 768 | #endregion Delegates 769 | } 770 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Library/Library_IndexColorShader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5961b1e9639e34458bb3324647154d0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Material.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c074d1875fc58754486f256e550903e0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Material/Default_Palette256.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: Default_Palette256 11 | m_Shader: {fileID: 4800000, guid: cd3b31afcd1a8d145a2bd16e7eaa4e34, type: 3} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0.5 65 | - _GlossyReflections: 1 66 | - _Metallic: 0 67 | - _Mode: 0 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 1 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 1, g: 1, b: 1, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 78 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Material/Default_Palette256.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 207c722ba7fbcba4ca8f1c313a9132d6 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Material/Default_UIPalette256.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: Default_UIPalette256 11 | m_Shader: {fileID: 4800000, guid: f4f5752fa206bd54db834a6adbb4ecb7, type: 3} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _AlphaTex: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _BumpMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailAlbedoMap: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailMask: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _DetailNormalMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _EmissionMap: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MainTex: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _MetallicGlossMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _OcclusionMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | - _ParallaxMap: 59 | m_Texture: {fileID: 0} 60 | m_Scale: {x: 1, y: 1} 61 | m_Offset: {x: 0, y: 0} 62 | m_Floats: 63 | - PixelSnap: 0 64 | - _BumpScale: 1 65 | - _Cutoff: 0.5 66 | - _DetailNormalMapScale: 1 67 | - _DstBlend: 0 68 | - _EnableExternalAlpha: 0 69 | - _GlossMapScale: 1 70 | - _Glossiness: 0.5 71 | - _GlossyReflections: 1 72 | - _Metallic: 0 73 | - _Mode: 0 74 | - _OcclusionStrength: 1 75 | - _Parallax: 0.02 76 | - _SmoothnessTextureChannel: 0 77 | - _SpecularHighlights: 1 78 | - _SrcBlend: 1 79 | - _UVSec: 0 80 | - _ZWrite: 1 81 | m_Colors: 82 | - _Color: {r: 1, g: 1, b: 1, a: 1} 83 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 84 | - _Flip: {r: 1, g: 1, b: 1, a: 1} 85 | - _RendererColor: {r: 1, g: 1, b: 1, a: 1} 86 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Material/Default_UIPalette256.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed514a6090bc5eb44a87989ec2b62c0a 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 2100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 130e3f4a7f60f6941a79a5e27feb9e9e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script/Script_IndexColorShader_Palette.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using UnityEngine; 12 | 13 | [System.Serializable] 14 | public class Script_IndexColorShader_Palette : ScriptableObject 15 | { 16 | /* ----------------------------------------------- Variables & Properties */ 17 | #region Variables & Properties 18 | public KindVersion Version; 19 | 20 | /* MEMO: Color.x=R, .y=G, .z=B, .w=Alpha */ 21 | public UnityEngine.Vector4[] Color; 22 | #endregion Variables & Properties 23 | 24 | /* ----------------------------------------------- ScriptableObject-Functions */ 25 | #region ScriptableObject-Functions 26 | #endregion ScriptableObject-Functions 27 | 28 | /* ----------------------------------------------- Functions */ 29 | #region Functions 30 | public void CleanUp() 31 | { 32 | Color = null; 33 | } 34 | 35 | public void BootUp() 36 | { 37 | if(null == Color) 38 | { 39 | Color = new Vector4[CountColorDefault]; 40 | } 41 | 42 | int countColor = Color.Length; 43 | for(int i=0; i= Version))); /* ? true : false */ 52 | } 53 | 54 | public int CountGetColor() 55 | { 56 | return((null == Color) ? -1 : Color.Length); 57 | } 58 | #endregion Functions 59 | 60 | /* ----------------------------------------------- Enums & Constants */ 61 | #region Enums & Constants 62 | public enum KindVersion 63 | { 64 | SUPPORT_EARLIEST = CODE_010000, 65 | SUPPORT_LATEST = CODE_010000, 66 | 67 | CODE_010000 = 0x00010000, 68 | } 69 | 70 | public const int CountColorDefault = 256; 71 | #endregion Enums & Constants 72 | 73 | /* ----------------------------------------------- Classes, Structs & Interfaces */ 74 | #region Classes, Structs & Interfaces 75 | #endregion Classes, Structs & Interfaces 76 | 77 | /* ----------------------------------------------- Delegates */ 78 | #region Delegates 79 | #endregion Delegates 80 | 81 | } -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script/Script_IndexColorShader_Palette.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a32587ae8831b4c46bb26c1a4bbd8c57 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script/Script_IndexColorShader_Sprite.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | // #define COMPILEOPTION_INHERIT_SPRITEPALETTE 10 | 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | using UnityEngine; 14 | 15 | [RequireComponent(typeof(SpriteRenderer))] 16 | [ExecuteInEditMode] 17 | #if COMPILEOPTION_INHERIT_SPRITEPALETTE 18 | public class Script_IndexColorShader_Sprite : Script_IndexColorShader_SpritePalette 19 | #else 20 | public class Script_IndexColorShader_Sprite : MonoBehaviour 21 | #endif 22 | { 23 | /* ----------------------------------------------- Variables & Properties */ 24 | #region Variables & Properties 25 | /* Settings */ 26 | #if COMPILEOPTION_INHERIT_SPRITEPALETTE 27 | #else 28 | public Script_IndexColorShader_Palette DataPalette; 29 | #endif 30 | public UnityEngine.Material MaterialMaster; 31 | public Library_IndexColorShader.KindInterpolation Interpolation; 32 | public UnityEngine.Texture Texture; 33 | public Rect RectDraw; 34 | public Vector2 RatePivot; 35 | public float PixelsPerUnit; 36 | 37 | /* WorkArea */ 38 | #if COMPILEOPTION_INHERIT_SPRITEPALETTE 39 | #else 40 | protected Library_IndexColorShader.Data.ControlMaterialPalette ControlMaterial = null; 41 | 42 | protected SpriteRenderer InstanceRendererSprite = null; 43 | #endif 44 | public SpriteRenderer SpriteRenderer 45 | { 46 | get 47 | { 48 | return(InstanceRendererSprite); 49 | } 50 | } 51 | protected Sprite InstanceSprite = null; 52 | protected Material InstanceMaterial = null; 53 | 54 | protected UnityEngine.Texture TexturePrevious = null; 55 | protected Rect RectDrawPrevious = new Rect(float.NaN, float.NaN, float.NaN, float.NaN); 56 | // protected Vector2 PivotPrevious = new Vector2(float.NaN, float.NaN); 57 | 58 | protected UnityEngine.Vector4[] InstanceDataColor = null; 59 | public UnityEngine.Vector4[] LUT 60 | { 61 | get 62 | { 63 | return(InstanceDataColor); 64 | } 65 | set 66 | { 67 | InstanceDataColor = value; 68 | } 69 | } 70 | #endregion Variables & Properties 71 | 72 | /* ----------------------------------------------- Functions (MonoBehaviour) */ 73 | #region Functions-MonoBehaviour 74 | // protected void Start() 75 | // { 76 | // } 77 | 78 | #if COMPILEOPTION_INHERIT_SPRITEPALETTE 79 | protected new void Update() 80 | #else 81 | protected void Update() 82 | #endif 83 | { 84 | /* ICS is Booted up ? */ 85 | // if(0 == (Status & FlagBitStatus.VALID)) 86 | { /* Not Valid */ 87 | bool flagBootedUpNow; 88 | if(false == BootUp(out flagBootedUpNow)) 89 | { /* Error */ 90 | return; 91 | } 92 | } 93 | 94 | /* Check Update */ 95 | if(TexturePrevious != Texture) 96 | { /* Change Texture */ 97 | if(false == TextureUpdate()) 98 | { 99 | return; 100 | } 101 | } 102 | // if((RectDrawPrevious != RectDraw) || (PivotPrevious != RatePivot)) 103 | if(RectDrawPrevious != RectDraw) 104 | { /* Change RectDraw */ 105 | if(false == VertexUpdateMesh()) 106 | { 107 | return; 108 | } 109 | } 110 | 111 | /* Update Shader-Constants */ 112 | ConstantsUpdateShader(ControlMaterial, Interpolation, null); 113 | } 114 | 115 | protected void OnDestroy() 116 | { 117 | if(null != InstanceMaterial) 118 | { 119 | Library_IndexColorShader.Control.CacheMaterialStatic managerMaterial = Library_IndexColorShader.Control.ManagerMaterial; 120 | if(null == managerMaterial) 121 | { 122 | Library_IndexColorShader.Utility.Asset.ObjectDestroy(InstanceMaterial); 123 | } 124 | else 125 | { 126 | managerMaterial.MaterialRelease(InstanceMaterial); 127 | } 128 | } 129 | } 130 | #endregion Functions-MonoBehaviour 131 | 132 | /* ----------------------------------------------- Functions */ 133 | #region Functions 134 | protected bool BootUp(out bool flagBootedUpNow) 135 | { 136 | flagBootedUpNow = false; 137 | 138 | if(false == Library_IndexColorShader.Control.ManagerBootUpMaterial(-1)) 139 | { 140 | return(false); 141 | } 142 | 143 | if(null == InstanceDataColor) 144 | { 145 | if(false == LUTSet(null)) 146 | { 147 | return(false); 148 | } 149 | } 150 | 151 | if(null == InstanceRendererSprite) 152 | { 153 | InstanceRendererSprite = GetComponent(); 154 | if(null == InstanceRendererSprite) 155 | { 156 | return(false); 157 | } 158 | flagBootedUpNow = true; 159 | } 160 | 161 | if(null == ControlMaterial) 162 | { 163 | ControlMaterial = new Library_IndexColorShader.Data.ControlMaterialPalette(); 164 | ControlMaterial.BootUp(); 165 | 166 | flagBootedUpNow = true; 167 | } 168 | 169 | if(null == InstanceSprite) 170 | { 171 | if(false == ParameterNormalizeSprite()) 172 | { 173 | return(false); 174 | } 175 | 176 | Texture2D texture = Texture as Texture2D; 177 | if(null == texture) 178 | { 179 | return(false); 180 | } 181 | 182 | #if false 183 | /* MEMO: When created to set "SpriteMeshType.FullRect", overhead is small, but the size cannot be changed. */ 184 | // InstanceSprite = UnityEngine.Sprite.Create(texture, RectDraw, RatePivot, PixelsPerUnit, 0, SpriteMeshType.FullRect); 185 | InstanceSprite = UnityEngine.Sprite.Create(texture, RectDraw, RatePivot); 186 | #else 187 | /* MEMO: Texture must be made at maximum size. */ 188 | /* If initial size is small, cannot enlarge size any further. */ 189 | Rect rectDraw = new Rect(0.0f, 0.0f, texture.width, texture.height); 190 | InstanceSprite = UnityEngine.Sprite.Create(texture, rectDraw, RatePivot); 191 | #endif 192 | } 193 | if(null == InstanceMaterial) 194 | { 195 | InstanceMaterial = Library_IndexColorShader.Control.ManagerMaterial.MaterialGet( MaterialMaster.mainTexture, 196 | MaterialMaster.shader, 197 | UnityEngine.Rendering.CompareFunction.Disabled, 198 | 0, 199 | true 200 | ); 201 | TextureUpdate(); 202 | 203 | InstanceRendererSprite.material = InstanceMaterial; 204 | } 205 | 206 | return(true); 207 | } 208 | protected bool ParameterNormalizeSprite() 209 | { 210 | /* Texture */ 211 | if(null == Texture) 212 | { 213 | return(false); 214 | } 215 | 216 | /* Pixels per Unit */ 217 | if(0.0f >= PixelsPerUnit) 218 | { 219 | PixelsPerUnit = 100.0f; 220 | } 221 | 222 | /* RectDraw */ 223 | float sizeTextureX = Texture.width; 224 | float sizeTextureY = Texture.height; 225 | if((0.0f > RectDraw.x) || (sizeTextureX <= RectDraw.x)) 226 | { 227 | RectDraw.x = 0.0f; 228 | } 229 | if((0.0f > RectDraw.y) || (sizeTextureY <= RectDraw.y)) 230 | { 231 | RectDraw.y = 0.0f; 232 | } 233 | if(0.0f > RectDraw.width) 234 | { 235 | RectDraw.width = sizeTextureX - RectDraw.x; 236 | } 237 | if(0.0f > RectDraw.height) 238 | { 239 | RectDraw.height = sizeTextureY - RectDraw.y; 240 | } 241 | if(sizeTextureX < (RectDraw.x + RectDraw.width)) 242 | { 243 | RectDraw.width = sizeTextureX - RectDraw.x; 244 | } 245 | if(sizeTextureY < (RectDraw.y + RectDraw.height)) 246 | { 247 | RectDraw.height = sizeTextureY - RectDraw.y; 248 | } 249 | 250 | /* Pivot */ 251 | RatePivot.x = Mathf.Clamp01(RatePivot.x); 252 | RatePivot.y = Mathf.Clamp01(RatePivot.y); 253 | 254 | return(true); 255 | } 256 | 257 | #if COMPILEOPTION_INHERIT_SPRITEPALETTE 258 | #else 259 | public void ConstantsUpdateShader( Library_IndexColorShader.Data.ControlMaterialPalette controlMaterialPalette, 260 | Library_IndexColorShader.KindInterpolation interpolation, 261 | Vector4? textureTillingOffset 262 | ) 263 | { 264 | if(null == controlMaterialPalette) 265 | { 266 | return; 267 | } 268 | 269 | Vector4[] dataColor = InstanceDataColor; 270 | if(null == dataColor) 271 | { 272 | if(false == LUTSet(null)) 273 | { 274 | return; 275 | } 276 | } 277 | 278 | /* MEMO: Check only on Unity-Editor, as be recompiled during running. */ 279 | if(null == dataColor) 280 | { 281 | return; 282 | } 283 | if(0 >= dataColor.Length) 284 | { 285 | return; 286 | } 287 | 288 | if(null == InstanceRendererSprite) 289 | { 290 | return; 291 | } 292 | InstanceRendererSprite.material = InstanceMaterial; 293 | 294 | /* Set Shader constants */ 295 | controlMaterialPalette.Update( InstanceRendererSprite, 296 | dataColor, 297 | InstanceRendererSprite.color, 298 | interpolation, 299 | null, 300 | textureTillingOffset 301 | ); 302 | } 303 | #endif 304 | 305 | protected bool TextureUpdate() 306 | { 307 | if(null == InstanceMaterial) 308 | { 309 | return(false); 310 | } 311 | 312 | InstanceMaterial.mainTexture = Texture; 313 | TexturePrevious = Texture; 314 | 315 | return(true); 316 | } 317 | protected bool VertexUpdateMesh() 318 | { 319 | if(false == ParameterNormalizeSprite()) 320 | { /* Error */ 321 | return(false); 322 | } 323 | 324 | RectDrawPrevious = RectDraw; 325 | // PivotPrevious = RatePivot; 326 | 327 | InstanceRendererSprite.sprite = null; /* Clear */ 328 | Vector2[] vertexSprite = InstanceSprite.vertices; 329 | Vector2 vertexLU = new Vector2(RectDraw.x, RectDraw.y); 330 | Vector2 vertexRD = new Vector2(RectDraw.width, RectDraw.height); 331 | vertexSprite[0] = vertexLU; 332 | vertexSprite[1] = vertexRD; 333 | vertexSprite[2].x = vertexRD.x; vertexSprite[2].y = vertexLU.y; 334 | vertexSprite[3].x = vertexLU.x; vertexSprite[3].y = vertexRD.y; 335 | InstanceSprite.OverrideGeometry(vertexSprite, InstanceSprite.triangles); 336 | 337 | InstanceRendererSprite.sprite = InstanceSprite; 338 | 339 | return(true); 340 | } 341 | 342 | /* ******************************************************** */ 343 | //! Set external-LUT(Palette) 344 | /*! 345 | @param tableColor 346 | external LUT
347 | null == Set originally-set palette 348 | @retval Return-Value 349 | true == Success
350 | false == Failure (Error) 351 | 352 | Set LUT externally. 353 | LUT must be an array of 256 Vector4(Color). (Vector4[256]) 354 | */ 355 | public bool LUTSet(UnityEngine.Vector4[] tableColor) 356 | { 357 | if(null == tableColor) 358 | { 359 | if(null == DataPalette) 360 | { 361 | return(false); 362 | } 363 | 364 | tableColor = DataPalette.Color; 365 | } 366 | 367 | InstanceDataColor = tableColor; 368 | 369 | return(true); 370 | } 371 | 372 | /* ******************************************************** */ 373 | //! Get LUT(Palette) 374 | /*! 375 | @param flagInUse 376 | true == Get currently in use
377 | false == Get originally-set 378 | @param flagCreateInstance 379 | true == Create new data instance (array)
380 | false == Get source-data itself 381 | Default: false 382 | @param flagCreateClean 383 | *) Valid only when "flagCreateInstance == true".
384 | true == Make LUT completely-transparent (all zero).
385 | false == Copy source data.
386 | Default: false 387 | @retval Return-Value 388 | LUT (Vector4[256])
389 | null == Failure (Error) 390 | 391 | Get LUT (Palette) data.
392 | When "flagCreateInstance == false" will directly modify the contents, note that modifying returned Vector4-array.
393 | To reflect the returned LUT, use function "LUTSet". 394 | */ 395 | public Vector4[] LUTGet(bool flagInUse, bool flagCreateInstance=false, bool flagCreateClean=false) 396 | { 397 | Vector4[] tableColorSource = null; 398 | if(false == flagInUse) 399 | { 400 | if(null == DataPalette) 401 | { 402 | return(null); 403 | } 404 | tableColorSource = DataPalette.Color; 405 | } 406 | else 407 | { 408 | if(null == InstanceDataColor) 409 | { 410 | return(null); 411 | } 412 | tableColorSource = InstanceDataColor; 413 | } 414 | if(null == tableColorSource) 415 | { 416 | return(null); 417 | } 418 | 419 | if(false == flagCreateInstance) 420 | { 421 | return(tableColorSource); 422 | } 423 | 424 | int countColor = tableColorSource.Length; 425 | Vector4[] tableColor = new Vector4[countColor]; 426 | if(false == flagCreateClean) 427 | { /* Copy LUT */ 428 | for(int i=0; i(); 61 | if(null == InstanceRendererSprite) 62 | { 63 | InstanceRenderer = GetComponent(); 64 | } 65 | 66 | ControlMaterial = new Library_IndexColorShader.Data.ControlMaterialPalette(); 67 | ControlMaterial.BootUp(); 68 | 69 | flagBootedUpNow = true; 70 | } 71 | 72 | return(ControlMaterial); 73 | } 74 | 75 | public void ConstantsUpdateShader( Library_IndexColorShader.Data.ControlMaterialPalette controlMaterialPalette, 76 | Library_IndexColorShader.KindInterpolation interpolation, 77 | Vector4[] tableColor, 78 | Vector4? textureTillingOffset 79 | ) 80 | { 81 | if(null == DataPalette) 82 | { 83 | return; 84 | } 85 | if(null == controlMaterialPalette) 86 | { 87 | return; 88 | } 89 | 90 | Vector4[] dataColor = tableColor; 91 | if(null == dataColor) 92 | { 93 | dataColor = DataPalette.Color; 94 | } 95 | 96 | #if UNITY_EDITOR 97 | /* MEMO: Check only on Unity-Editor, as be recompiled during running. */ 98 | if(null == dataColor) 99 | { 100 | return; 101 | } 102 | 103 | if((null == InstanceRenderer) && (null == InstanceRendererSprite)) 104 | { 105 | return; 106 | } 107 | #endif 108 | 109 | Renderer renderer = null; 110 | Texture texture = null; 111 | Color color; 112 | if(null == InstanceRendererSprite) 113 | { /* (Any)Renderer */ 114 | if(null == InstanceRenderer.sharedMaterial) 115 | { 116 | return; 117 | } 118 | 119 | renderer = InstanceRenderer; 120 | color = InstanceRenderer.sharedMaterial.color; 121 | texture = InstanceRenderer.sharedMaterial.mainTexture; 122 | } 123 | else 124 | { /* SpriteRenderer */ 125 | renderer = InstanceRendererSprite; 126 | color = InstanceRendererSprite.color; 127 | texture = InstanceRendererSprite.sharedMaterial.mainTexture; 128 | } 129 | 130 | controlMaterialPalette.Update( renderer, 131 | dataColor, 132 | color, 133 | interpolation, 134 | texture, 135 | textureTillingOffset 136 | ); 137 | } 138 | #endregion Functions 139 | 140 | /* ----------------------------------------------- Enums & Constants */ 141 | #region Enums & Constants 142 | public const int CountColorMax = 256; 143 | #endregion Enums & Constants 144 | 145 | /* ----------------------------------------------- Delegates */ 146 | #region Delegates 147 | #endregion Delegates 148 | } 149 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script/Script_IndexColorShader_SpritePalette.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35de0709cd7eacf4fb1c22ce6efd1f15 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Script/Script_IndexColorShader_UIImage.cs: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | // #define USE_MATRIXTRANSFORM_COORDINATE 10 | // #define USE_MATRIXTRANSFORM_TEXTURE 11 | 12 | using System.Collections; 13 | using System.Collections.Generic; 14 | using UnityEngine; 15 | 16 | [RequireComponent(typeof(RectTransform))] 17 | [RequireComponent(typeof(CanvasRenderer))] 18 | [ExecuteInEditMode] 19 | [System.Serializable] 20 | public partial class Script_IndexColorShader_UIImage : UnityEngine.UI.MaskableGraphic 21 | { 22 | /* ----------------------------------------------- Variables & Properties */ 23 | #region Variables & Properties 24 | /* Settings */ 25 | public override UnityEngine.Texture mainTexture 26 | { 27 | get 28 | { 29 | if(null == material) 30 | { 31 | return(null); 32 | } 33 | 34 | return(material.mainTexture); 35 | } 36 | } 37 | 38 | public Script_IndexColorShader_Palette DataPalette; 39 | public Library_IndexColorShader.KindInterpolation Interpolation; 40 | 41 | public bool FlagHideForce; 42 | public Rect uvRect; /* for UI.RawImage conpativility */ 43 | public Vector2 SizeImageForce; /* Vector2.zero: RectTransform's width,height / -Vector2.one: Texture size */ 44 | 45 | public UnityEngine.Rendering.CompareFunction StencilCompare; /* Disable: Auto */ 46 | public int StencilID; /* -1: Auto / Lower-8bits Valid */ 47 | 48 | /* WorkArea */ 49 | protected UnityEngine.CanvasRenderer InstanceRendererCanvas = null; 50 | public UnityEngine.CanvasRenderer CanvasRenderer 51 | { 52 | get 53 | { 54 | return(InstanceRendererCanvas); 55 | } 56 | } 57 | 58 | protected UnityEngine.Material InstanceMaterialInUse = null; 59 | 60 | protected bool MaskablePrevious = false; 61 | protected UnityEngine.Rendering.CompareFunction StencilComparePrevious = UnityEngine.Rendering.CompareFunction.Disabled; 62 | protected int StencilIDPrevious = -1; 63 | 64 | protected UnityEngine.Vector4[] InstanceDataColor = null; 65 | public UnityEngine.Vector4[] LUT 66 | { 67 | get 68 | { 69 | return(InstanceDataColor); 70 | } 71 | set 72 | { 73 | InstanceDataColor = value; 74 | } 75 | } 76 | #endregion Variables & Properties 77 | 78 | /* ----------------------------------------------- MonoBehaviour-Functions */ 79 | #region MonoBehaviour-Functions 80 | // void Awake() 81 | // { 82 | // } 83 | 84 | // void Start() 85 | // { 86 | // } 87 | 88 | void Update() 89 | { 90 | /* MEMO: To be called "OnPopulateMesh" each loop, keep constantly dirty. */ 91 | SetVerticesDirty(); 92 | } 93 | 94 | // void LateUpdate() 95 | // { 96 | // } 97 | 98 | protected override void OnDestroy() 99 | { 100 | if(null != InstanceMaterialInUse) 101 | { 102 | Library_IndexColorShader.Utility.Asset.ObjectDestroy(InstanceMaterialInUse); 103 | } 104 | } 105 | #endregion MonoBehaviour-Functions 106 | 107 | /* ----------------------------------------------- Override-Functions */ 108 | #region Override-Functions 109 | protected override void OnPopulateMesh(UnityEngine.UI.VertexHelper vertexHelper) 110 | { 111 | Texture texture = mainTexture; 112 | if(null == texture) 113 | { /* Material is missing */ 114 | return; 115 | } 116 | if(null == InstanceDataColor) 117 | { /* Palette is missing */ 118 | if(false == LUTSet(null)) 119 | { 120 | return; 121 | } 122 | } 123 | 124 | /* Renderer Initiallize */ 125 | if(null == InstanceRendererCanvas) 126 | { /* Not yet get */ 127 | InstanceRendererCanvas = gameObject.GetComponent(); 128 | if(null == InstanceRendererCanvas) 129 | { /* Failure (Not exist renderer) */ 130 | return; 131 | } 132 | } 133 | 134 | /* Calculate Transform-Matrix */ 135 | Matrix4x4 matrixTransform = Matrix4x4.identity; /* Matrix4x4.TRS(transform.localPosition, transform.localRotation, transform.localScale); */ 136 | 137 | /* Draw mesh */ 138 | vertexHelper.Clear(); 139 | if(false == FlagHideForce) 140 | { 141 | /* ICS is Booted up ? */ 142 | if(null == InstanceRendererCanvas) 143 | { 144 | InstanceRendererCanvas = GetComponent(); 145 | if(null == InstanceRendererCanvas) 146 | { 147 | return; 148 | } 149 | } 150 | 151 | /* Update Shader-Constants */ 152 | ConstantsUpdateShader( Interpolation, 153 | InstanceDataColor, 154 | new Vector4(uvRect.width, uvRect.height, uvRect.x, uvRect.y) 155 | ); 156 | 157 | int indexVertex = 0; 158 | indexVertex = MeshPopulate(vertexHelper, indexVertex); 159 | if(0 > indexVertex) 160 | { /* Error */ 161 | vertexHelper.Clear(); 162 | 163 | return; 164 | } 165 | } 166 | } 167 | 168 | protected int MeshPopulate(UnityEngine.UI.VertexHelper vertexHelper, int indexVertex) 169 | { 170 | Texture texture = mainTexture; 171 | if(null == texture) 172 | { 173 | return(-1); 174 | } 175 | 176 | /* Solve sprite-size */ 177 | Vector3 sizeTexture = SizeImageForce; 178 | if((0.0f > sizeTexture.x) || (0.0f > sizeTexture.y)) 179 | { /* Minus : (mainTexture.width, mainTexture.height) */ 180 | sizeTexture = new Vector2(texture.width, texture.height); 181 | 182 | /* MEMO: Write it back for convenience on UnityEditor. */ 183 | SizeImageForce = sizeTexture; 184 | } 185 | else 186 | { 187 | if((0.0f >= sizeTexture.x) || (0.0f >= sizeTexture.y)) 188 | { /* Zero : (RectTransform.width, RectTransform.height) */ 189 | sizeTexture = new Vector2(rectTransform.sizeDelta.x, rectTransform.sizeDelta.y); 190 | 191 | /* MEMO: Write both back to zero (to avoid failure). */ 192 | SizeImageForce = Vector2.zero; 193 | } 194 | } 195 | 196 | Vector3 sizeSprite = sizeTexture; 197 | Vector3 coordinateSprite = sizeSprite * -0.5f; /* -(sizeSprite / 2.0f) */ 198 | 199 | /* Create vertex-data */ 200 | UIVertex dataVertex = UIVertex.simpleVert; 201 | Vector3 coordinate = coordinateSprite; 202 | Vector3 uv = Vector3.zero; 203 | 204 | { /* LU */ 205 | // coordinate.x = coordinateSprite.x; 206 | // coordinate.y = coordinateSprite.y; 207 | dataVertex.position = coordinate; 208 | 209 | dataVertex.color = color; 210 | 211 | // uv.x = 0.0f; 212 | // uv.y = 0.0f; 213 | dataVertex.uv0 = uv; 214 | } 215 | vertexHelper.AddVert(dataVertex); 216 | 217 | { /* RU */ 218 | coordinate.x = coordinateSprite.x + sizeSprite.x; 219 | // coordinate.y = coordinateSprite.y; 220 | dataVertex.position = coordinate; 221 | 222 | // dataVertex.color = color; 223 | 224 | uv.x = 1.0f; 225 | // uv.y = 0.0f; 226 | dataVertex.uv0 = uv; 227 | } 228 | vertexHelper.AddVert(dataVertex); 229 | 230 | { /* RD */ 231 | // coordinate.x = coordinateSprite.x + sizeSprite.x; 232 | coordinate.y = coordinateSprite.y + sizeSprite.y; 233 | dataVertex.position = coordinate; 234 | 235 | // dataVertex.color = color; 236 | 237 | // uv.x = 1.0f; 238 | uv.y = 1.0f; 239 | dataVertex.uv0 = uv; 240 | } 241 | vertexHelper.AddVert(dataVertex); 242 | 243 | { /* LD */ 244 | coordinate.x = coordinateSprite.x; 245 | // coordinate.y = coordinateSprite.y + sizeSprite.y; 246 | dataVertex.position = coordinate; 247 | 248 | // dataVertex.color = color; 249 | 250 | uv.x = 0.0f; 251 | // uv.y = 1.0f; 252 | dataVertex.uv0 = uv; 253 | } 254 | vertexHelper.AddVert(dataVertex); 255 | 256 | /* Set vertex-indices (triangles) */ 257 | vertexHelper.AddTriangle(indexVertex + 0, indexVertex + 1, indexVertex + 2); 258 | vertexHelper.AddTriangle(indexVertex + 2, indexVertex + 3, indexVertex + 0); 259 | indexVertex += 4; 260 | 261 | return(indexVertex); 262 | } 263 | 264 | public void ConstantsUpdateShader( Library_IndexColorShader.KindInterpolation interpolation, 265 | Vector4[] tableColor, 266 | Vector4? textureTillingOffset 267 | ) 268 | { 269 | if(null == tableColor) 270 | { 271 | return; 272 | } 273 | if(0 >= tableColor.Length) 274 | { 275 | return; 276 | } 277 | 278 | if(null == InstanceMaterialInUse) 279 | { 280 | return; 281 | } 282 | 283 | if(null != InstanceRendererCanvas) 284 | { 285 | Library_IndexColorShader.Data.ControlMaterialPalette.Update( InstanceMaterialInUse, 286 | tableColor, 287 | color, 288 | interpolation, 289 | null, /* InstanceMaterialInUse.mainTexture, */ 290 | textureTillingOffset 291 | ); 292 | } 293 | } 294 | 295 | public override UnityEngine.Material GetModifiedMaterial(UnityEngine.Material materialBase) 296 | { 297 | /* MEMO: MaterialPropertyBlock is not available for UI. */ 298 | /* Therefore, force creation of a new material without using "MaterialManager". */ 299 | if(null == InstanceMaterialInUse) 300 | { 301 | if(null == material) 302 | { 303 | return(null); 304 | } 305 | 306 | InstanceMaterialInUse = new UnityEngine.Material(material); 307 | if(null == InstanceMaterialInUse) 308 | { 309 | return(null); 310 | } 311 | } 312 | 313 | /* Set Changing parameters */ 314 | bool flagModifyMaterial = false; 315 | if(MaskablePrevious != maskable) 316 | { /* State changed */ 317 | flagModifyMaterial = true; 318 | } 319 | else 320 | { 321 | if(true == maskable) 322 | { 323 | if( (StencilComparePrevious != StencilCompare) 324 | || (StencilIDPrevious != StencilID) 325 | ) 326 | { /* Stencil-parameter changed */ 327 | flagModifyMaterial = true; 328 | } 329 | } 330 | } 331 | if(false == flagModifyMaterial) 332 | { /* No changed */ 333 | return(InstanceMaterialInUse); 334 | } 335 | 336 | /* Determine parameters */ 337 | UnityEngine.Rendering.CompareFunction stencilCompare; 338 | int stencilID; 339 | 340 | MaskablePrevious = maskable; 341 | StencilComparePrevious = StencilCompare; 342 | StencilIDPrevious = StencilID; 343 | 344 | if(false == maskable) 345 | { /* UnMaskable */ 346 | stencilCompare = UnityEngine.Rendering.CompareFunction.Always; 347 | stencilID = 0; 348 | } 349 | else 350 | { /* Maskable */ 351 | stencilCompare = StencilComparePrevious; 352 | stencilID = StencilIDPrevious; 353 | 354 | if(UnityEngine.Rendering.CompareFunction.Disabled == stencilCompare) 355 | { /* Default */ 356 | stencilCompare = UnityEngine.Rendering.CompareFunction.Equal; 357 | } 358 | if(0 > stencilID) 359 | { /* Auto ID */ 360 | UnityEngine.Transform canvasRoot = UnityEngine.UI.MaskUtilities.FindRootSortOverrideCanvas(transform); 361 | stencilID = UnityEngine.UI.MaskUtilities.GetStencilDepth(transform, canvasRoot); 362 | } 363 | } 364 | 365 | return(InstanceMaterialInUse); 366 | } 367 | #endregion Override-Functions 368 | 369 | /* ----------------------------------------------- Functions */ 370 | #region Functions 371 | 372 | /* ******************************************************** */ 373 | //! Set external-LUT(Palette) 374 | /*! 375 | @param tableColor 376 | external LUT
377 | null == Set originally-set palette 378 | @retval Return-Value 379 | true == Success
380 | false == Failure (Error) 381 | 382 | Set LUT externally. 383 | LUT must be an array of 256 Vector4(Color). (Vector4[256]) 384 | */ 385 | public bool LUTSet(UnityEngine.Vector4[] tableColor) 386 | { 387 | if(null == tableColor) 388 | { 389 | if(null == DataPalette) 390 | { 391 | return(false); 392 | } 393 | 394 | tableColor = DataPalette.Color; 395 | } 396 | 397 | InstanceDataColor = tableColor; 398 | 399 | return(true); 400 | } 401 | 402 | /* ******************************************************** */ 403 | //! Get LUT(Palette) 404 | /*! 405 | @param flagInUse 406 | true == Get currently in use
407 | false == Get originally-set 408 | @param flagCreateInstance 409 | true == Create new data instance (array)
410 | false == Get source-data itself 411 | Default: false 412 | @param flagCreateClean 413 | *) Valid only when "flagCreateInstance == true".
414 | true == Make LUT completely-transparent (all zero).
415 | false == Copy source data.
416 | Default: false 417 | @retval Return-Value 418 | LUT (Vector4[256])
419 | null == Failure (Error) 420 | 421 | Get LUT (Palette) data.
422 | When "flagCreateInstance == false" will directly modify the contents, note that modifying returned Vector4-array.
423 | To reflect the returned LUT, use function "LUTSet". 424 | */ 425 | public Vector4[] LUTGet(bool flagInUse, bool flagCreateInstance=false, bool flagCreateClean=false) 426 | { 427 | Vector4[] tableColorSource = null; 428 | if(false == flagInUse) 429 | { 430 | if(null == DataPalette) 431 | { 432 | return(null); 433 | } 434 | tableColorSource = DataPalette.Color; 435 | } 436 | else 437 | { 438 | if(null == InstanceDataColor) 439 | { 440 | return(null); 441 | } 442 | tableColorSource = InstanceDataColor; 443 | } 444 | if(null == tableColorSource) 445 | { 446 | return(null); 447 | } 448 | 449 | if(false == flagCreateInstance) 450 | { 451 | return(tableColorSource); 452 | } 453 | 454 | int countColor = tableColorSource.Length; 455 | Vector4[] tableColor = new Vector4[countColor]; 456 | if(false == flagCreateClean) 457 | { /* Copy LUT */ 458 | for(int i=0; i= In.Property.z) 17 | { 18 | float indexColor = tex2D(_MainTex, coordTexel).a; /* LU */ 19 | indexColor *= INDEX_MAX_LUT; 20 | 21 | float4 pixel = ConstantColorTable(indexColor); 22 | pixel *= In.ColorMain; 23 | 24 | return(pixel); 25 | } 26 | 27 | /* Process UV */ 28 | float2 sizeTexture = float2(In.Property.x, In.Property.y); 29 | float2 rateTexelTexture = float2(1.0f, 1.0f) / sizeTexture; 30 | #if 1 31 | coordTexel *= sizeTexture; 32 | float2 rateInterpolation = frac(coordTexel); 33 | coordTexel = floor(coordTexel) * rateTexelTexture; 34 | #else 35 | float2 rateInterpolation = frac(coordTexel * sizeTexture); 36 | #endif 37 | 38 | /* Get Color-Index */ 39 | float4 indexColor; 40 | { 41 | float2 coordTexelRD = coordTexel; 42 | coordTexelRD.x += rateTexelTexture.x; 43 | coordTexelRD.y -= rateTexelTexture.y; 44 | 45 | indexColor.x = tex2D(_MainTex, coordTexel).a; /* LU */ 46 | indexColor.y = tex2D(_MainTex, float2(coordTexelRD.x, coordTexel.y)).a; /* RU */ 47 | indexColor.z = tex2D(_MainTex, float2(coordTexel.x, coordTexelRD.y)).a; /* LD */ 48 | indexColor.w = tex2D(_MainTex, coordTexelRD).a; /* RD */ 49 | } 50 | indexColor *= INDEX_MAX_LUT; 51 | indexColor = floor(indexColor); 52 | 53 | /* Convert to color */ 54 | #if 0 55 | float4 pixelU = lerp(ConstantColorTable(indexColor.x), ConstantColorTable(indexColor.y), rateInterpolation.x); 56 | float4 pixelD = lerp(ConstantColorTable(indexColor.z), ConstantColorTable(indexColor.w), rateInterpolation.x); 57 | float4 color = lerp(pixelU, pixelD, rateInterpolation.y); 58 | #else 59 | float4 pixelU = lerp(ConstantColorTable(indexColor.x), ConstantColorTable(indexColor.y), rateInterpolation.x); 60 | float4 pixelD = lerp(ConstantColorTable(indexColor.z), ConstantColorTable(indexColor.w), rateInterpolation.x); 61 | float4 color = lerp(pixelU, pixelD, 1.0f - rateInterpolation.y); 62 | #endif 63 | 64 | /* Considering Vertex-Color */ 65 | color *= In.ColorMain; 66 | 67 | return(color); 68 | } 69 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Pixel_Palette256.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e6f2ba3ae2813348b737c200e3ad8aa 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Pixel_UIPalette256.cginc: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | fixed4 PS_Main(InputPS In) : SV_Target 10 | { 11 | float2 coordTexel = In.Texture00UV; 12 | 13 | /* When "Nearest Neighbor" (No-Interpolation) */ 14 | if(1.0f >= In.Property.z) 15 | { 16 | float indexColor = tex2D(_MainTex, coordTexel).a; /* LU */ 17 | indexColor *= INDEX_MAX_LUT; 18 | 19 | float4 pixel = ConstantColorTable(indexColor); 20 | pixel *= In.ColorMain; 21 | 22 | return(pixel); 23 | } 24 | 25 | /* Process UV */ 26 | float2 sizeTexture = float2(In.Property.x, In.Property.y); 27 | float2 rateTexelTexture = float2(1.0f, 1.0f) / sizeTexture; 28 | #if 1 29 | coordTexel *= sizeTexture; 30 | float2 rateInterpolation = frac(coordTexel); 31 | coordTexel = floor(coordTexel) * rateTexelTexture; 32 | #else 33 | float2 rateInterpolation = frac(coordTexel * sizeTexture); 34 | #endif 35 | 36 | /* Get Color-Index */ 37 | float4 indexColor; 38 | { 39 | float2 coordTexelRD = coordTexel; 40 | coordTexelRD.x += rateTexelTexture.x; 41 | coordTexelRD.y -= rateTexelTexture.y; 42 | 43 | indexColor.x = tex2D(_MainTex, coordTexel).a; /* LU */ 44 | indexColor.y = tex2D(_MainTex, float2(coordTexelRD.x, coordTexel.y)).a; /* RU */ 45 | indexColor.z = tex2D(_MainTex, float2(coordTexel.x, coordTexelRD.y)).a; /* LD */ 46 | indexColor.w = tex2D(_MainTex, coordTexelRD).a; /* RD */ 47 | } 48 | indexColor *= INDEX_MAX_LUT; 49 | indexColor = floor(indexColor); 50 | 51 | /* Convert to color */ 52 | #if 0 53 | float4 pixelU = lerp(ConstantColorTable(indexColor.x), ConstantColorTable(indexColor.y), rateInterpolation.x); 54 | float4 pixelD = lerp(ConstantColorTable(indexColor.z), ConstantColorTable(indexColor.w), rateInterpolation.x); 55 | float4 color = lerp(pixelU, pixelD, rateInterpolation.y); 56 | #else 57 | float4 pixelU = lerp(ConstantColorTable(indexColor.x), ConstantColorTable(indexColor.y), rateInterpolation.x); 58 | float4 pixelD = lerp(ConstantColorTable(indexColor.z), ConstantColorTable(indexColor.w), rateInterpolation.x); 59 | float4 color = lerp(pixelU, pixelD, 1.0f - rateInterpolation.y); 60 | #endif 61 | 62 | /* Considering Vertex-Color */ 63 | color += ConstantTextureSampleAdd; 64 | color *= In.ColorMain; 65 | 66 | /* Masking & Clipping */ 67 | #ifdef UNITY_UI_CLIP_RECT 68 | half2 mask = saturate((ConstantClipRect.zw - ConstantClipRect.xy - abs(In.MaskUV.xy)) * In.MaskUV.zw); 69 | color.a *= mask.x * mask.y; 70 | #endif 71 | 72 | #ifdef UNITY_UI_ALPHACLIP 73 | clip(color.a - 0.001); 74 | #endif 75 | 76 | return(color); 77 | } 78 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Pixel_UIPalette256.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9cbf752df127a743b476e0e9ee79116 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Vertex_Palette256.cginc: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | InputPS VS_Main(InputVS In) 10 | { 11 | InputPS Out; 12 | 13 | UNITY_SETUP_INSTANCE_ID(In); 14 | 15 | /* Transform Vertex-Coordinate */ 16 | float4 coordinateVertes = UnityObjectToClipPos(In.Vertex); 17 | #if defined(PIXELSNAP_ON) 18 | coordinateVertes = UnityPixelSnap(coordinateVertes); 19 | #else 20 | #endif 21 | 22 | /* Texture's UV */ 23 | float2 coordTexture = In.Texture00UV; 24 | float2 coordTextureShift; 25 | float4 property = float4( ConstantSetting.x, /* Texture Width */ 26 | ConstantSetting.x, /* Texture Height */ 27 | 1.0f, /* Count Sampling */ 28 | ConstantSetting.w /* Opacity */ 29 | ); 30 | 31 | /* Transform UV */ 32 | coordTexture = coordTexture * _MainTex_ST.xy + _MainTex_ST.zw; /* TRANSFORM_TEX *//* Transform Texture */ 33 | 34 | if(1.0f > ConstantSetting.z) 35 | { /* Interpolation: None(Nearest Neighbor) */ 36 | property.z = 1.0f; 37 | } 38 | else 39 | { /* Interpolation: Bi-Linear */ 40 | property.z = 4.0f; 41 | } 42 | 43 | /* Vertex-Colors */ 44 | // float4 colorMain = _RendererColor * _Color; 45 | float4 colorMain = ConstantColor; 46 | 47 | /* Output */ 48 | Out.Position = coordinateVertes; 49 | Out.Texture00UV = coordTexture; 50 | Out.Property = property; 51 | UNITY_TRANSFER_INSTANCE_ID(In, Out); 52 | 53 | Out.ColorMain = colorMain; 54 | 55 | return(Out); 56 | } 57 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Vertex_Palette256.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 747e7af7d6b3e304e9b65250b3d97b0e 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Vertex_UIPalette256.cginc: -------------------------------------------------------------------------------- 1 | /** 2 | Index Color Shader for Unity 3 | 4 | Copyright(C) 1997-2021 Web Technology Corp. 5 | Copyright(C) CRI Middleware Co., Ltd. 6 | All rights reserved. 7 | */ 8 | 9 | InputPS VS_Main(InputVS In) 10 | { 11 | InputPS Out; 12 | 13 | UNITY_SETUP_INSTANCE_ID(In); 14 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(Out); 15 | 16 | /* Transform Coordinates */ 17 | float4 vertex = In.Vertex; 18 | float4 coordVertex = UnityObjectToClipPos(vertex); 19 | Out.PositionWorld = vertex; 20 | Out.Position = coordVertex; 21 | 22 | /* Calculate Clipping & Masking */ 23 | float2 sizePixel = coordVertex.w; 24 | sizePixel /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy)); 25 | 26 | float4 rectangleClamped = clamp(ConstantClipRect, -2e10, 2e10); 27 | float2 maskUV = (vertex.xy - rectangleClamped.xy) / (rectangleClamped.zw - rectangleClamped.xy); 28 | Out.MaskUV = float4(vertex.xy * 2.0 - rectangleClamped.xy - rectangleClamped.zw, 0.25 / (0.25 * float2(ConstantUIMaskSoftnessX, ConstantUIMaskSoftnessY) + abs(sizePixel.xy))); 29 | 30 | /* Transform Texture-UV */ 31 | Out.Texture00UV = TRANSFORM_TEX(In.Texcoord, _MainTex); 32 | 33 | /* Vertex Color */ 34 | Out.ColorMain = In.Color * ConstantColor; 35 | 36 | /* Properties */ 37 | float4 property = float4( ConstantSetting.x, /* Texture Width */ 38 | ConstantSetting.x, /* Texture Height */ 39 | 1.0f, /* Count Sampling */ 40 | ConstantSetting.w /* Opacity */ 41 | ); 42 | if(1.0f > ConstantSetting.z) 43 | { /* Interpolation: None(Nearest Neighbor) */ 44 | property.z = 1.0f; 45 | } 46 | else 47 | { /* Interpolation: Bi-Linear */ 48 | property.z = 4.0f; 49 | } 50 | Out.Property = property; 51 | 52 | return(Out); 53 | } 54 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/Base/Vertex_UIPalette256.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b2d43fef62f1df49a94ab347c4742b5 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/IndexColorShader_Palette256.shader: -------------------------------------------------------------------------------- 1 | // 2 | // Shader : Indexed 256 LUT 3 | // 4 | // Copyright(C) 1997-2021 Web Technology Corp. 5 | // Copyright(C) CRI Middleware Co., Ltd. 6 | // All rights reserved. 7 | // 8 | Shader "Custom/IndexColorShader/Palette256" 9 | { 10 | Properties 11 | { 12 | _MainTex("Sprite Texture", 2D) = "white" {} 13 | [PerRendererData] _Color("Tint", Color) = (1, 1, 1, 1) 14 | [Toggle(PIXELSNAP_ON)] PixelSnap("Pixel snap", Float) = 0 15 | [HideInInspector] _RendererColor("RendererColor", Color) = (1, 1, 1, 1) 16 | [HideInInspector] _Flip("Flip", Vector) = (1, 1, 1, 1) 17 | [PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {} 18 | [PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0 19 | } 20 | 21 | SubShader 22 | { 23 | Tags 24 | { 25 | "Queue" = "Transparent" 26 | "IgnoreProjector" = "True" 27 | "RenderType" = "Transparent" 28 | } 29 | 30 | Pass 31 | { 32 | Cull Off 33 | ZTest Always 34 | ZWRITE Off 35 | Blend SrcAlpha OneMinusSrcAlpha 36 | 37 | CGPROGRAM 38 | #pragma vertex VS_Main 39 | #pragma fragment PS_Main 40 | 41 | #pragma multi_compile _ PIXELSNAP_ON 42 | // #pragma multi_compile _ ETC1_EXTERNAL_ALPHA 43 | #pragma multi_compile_instancing 44 | #include "UnityCG.cginc" 45 | 46 | #include "Base/Data_IndexColorShader.cginc" 47 | #include "Base/Vertex_Palette256.cginc" 48 | #include "Base/Pixel_Palette256.cginc" 49 | ENDCG 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/IndexColorShader_Palette256.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cd3b31afcd1a8d145a2bd16e7eaa4e34 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/IndexColorShader_UIPalette256.shader: -------------------------------------------------------------------------------- 1 | // 2 | // Shader : Indexed 256 LUT 3 | // 4 | // Copyright(C) 1997-2021 Web Technology Corp. 5 | // Copyright(C) CRI Middleware Co., Ltd. 6 | // All rights reserved. 7 | // 8 | Shader "Custom/IndexColorShader/UIPalette256" 9 | { 10 | Properties 11 | { 12 | _MainTex("Sprite Texture", 2D) = "white" {} 13 | [PerRendererData] _Color("Tint", Color) = (1, 1, 1, 1) 14 | [Toggle(PIXELSNAP_ON)] PixelSnap("Pixel snap", Float) = 0 15 | [HideInInspector] _RendererColor("RendererColor", Color) = (1, 1, 1, 1) 16 | [HideInInspector] _Flip("Flip", Vector) = (1, 1, 1, 1) 17 | [PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {} 18 | [PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0 19 | } 20 | 21 | SubShader 22 | { 23 | Tags 24 | { 25 | "Queue" = "Transparent" 26 | "IgnoreProjector" = "True" 27 | "RenderType" = "Transparent" 28 | } 29 | 30 | Pass 31 | { 32 | Cull Off 33 | ZTest Always 34 | ZWRITE Off 35 | Blend SrcAlpha OneMinusSrcAlpha 36 | 37 | CGPROGRAM 38 | #pragma vertex VS_Main 39 | #pragma fragment PS_Main 40 | 41 | #pragma multi_compile _ PIXELSNAP_ON 42 | // #pragma multi_compile _ ETC1_EXTERNAL_ALPHA 43 | #pragma multi_compile_instancing 44 | #include "UnityCG.cginc" 45 | 46 | #include "Base/Data_IndexColorShaderUI.cginc" 47 | #include "Base/Vertex_UIPalette256.cginc" 48 | #include "Base/Pixel_UIPalette256.cginc" 49 | ENDCG 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Assets/IndexColorShader/Shader/IndexColorShader_UIPalette256.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4f5752fa206bd54db834a6adbb4ecb7 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | nonModifiableTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ICS_for_Unity.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/ICS_for_Unity.unitypackage -------------------------------------------------------------------------------- /ICS_for_Unity_Sample.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OPTPiX/IndexColorShaderForUnity/f97d8a1347c7adb665a663939bfcb3b7e99416b7/ICS_for_Unity_Sample.unitypackage -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Web Technology Corp. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IndexColorShaderForUnity 2 | 3 | ### 概要・ドキュメントは[Wiki](https://github.com/OPTPiX/IndexColorShaderForUnity/wiki)をご覧ください。 4 | --------------------------------------------------------------------------------