Skip to content

Commit

Permalink
feat: Assets/lilToon/[Material] Run migration (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilxyzw committed Dec 10, 2023
1 parent 36d1f48 commit c083f63
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions Assets/lilToon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Enabled to see property name with alt key
- Mode that treats IDMask as bitmap and Dissolve support
- `LILTOON_DISABLE_OPTIMIZATION` symbol that allows you to force disable optimization
- `Assets/lilToon/[Material] Run migration`

### Changed
- Temporary files are no longer generated under the Temp folder
Expand Down
1 change: 1 addition & 0 deletions Assets/lilToon/CHANGELOG_JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- altキーでプロパティ名を見られるようにした
- IDMaskをbitmapとして扱うモードとDissolve対応
- 最適化を強制的に無効化できる`LILTOON_DISABLE_OPTIMIZATION`シンボルを追加
- `Assets/lilToon/[Material] Run migration`を追加

### 変更
- Temp配下に一時ファイルを生成しなくなった
Expand Down
1 change: 1 addition & 0 deletions Assets/lilToon/Editor/lilInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,7 @@ private void DrawSettingsGUI()

EditorGUI.BeginChangeCheck();
ToggleGUI(GetLoc("sShaderSettingOptimizeInEditor"), ref shaderSetting.isDebugOptimize);
ToggleGUI("Migrate materials in startup", ref shaderSetting.isMigrateInStartUp);
edSet.isShowShaderSetting = lilEditorGUI.Foldout(GetLoc("sShaderSetting"), edSet.isShowShaderSetting);
lilEditorGUI.DrawHelpButton(GetLoc("sAnchorShaderSetting"));
if(edSet.isShowShaderSetting)
Expand Down
16 changes: 10 additions & 6 deletions Assets/lilToon/Editor/lilStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public static void lilStartupMethod()
if(lilToonInspector.edSet.currentVersionValue != lilConstants.currentVersionValue)
{
// Migrate Materials
MigrateMaterials();
lilToonSetting shaderSetting = null;
lilToonSetting.InitializeShaderSetting(ref shaderSetting);
if(shaderSetting.isMigrateInStartUp) EditorApplication.delayCall += MigrateMaterials;
lilToonInspector.edSet.currentVersionValue = lilConstants.currentVersionValue;

#if UNITY_2019_4_OR_NEWER
Expand Down Expand Up @@ -182,24 +184,26 @@ private static IEnumerator GetLatestVersionInfo()
}
}

private static void MigrateMaterials()
internal static void MigrateMaterials()
{
EditorApplication.delayCall -= MigrateMaterials;
var id = Shader.PropertyToID("_lilToonVersion");
foreach(var material in lilDirectoryManager.FindAssets<Material>("t:material"))
{
MigrateMaterial(material);
MigrateMaterial(material, id);
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}

private static void MigrateMaterial(Material material)
private static void MigrateMaterial(Material material, int id)
{
if(!lilMaterialUtils.CheckShaderIslilToon(material)) return;
int version = 0;
if(material.HasProperty("_lilToonVersion")) version = (int)material.GetFloat("_lilToonVersion");
if(material.HasProperty(id)) version = (int)material.GetFloat(id);
if(version >= lilConstants.currentVersionValue) return;
Debug.Log("[lilToon]Run migration: " + material.name);
material.SetFloat("_lilToonVersion", lilConstants.currentVersionValue);
material.SetFloat(id, lilConstants.currentVersionValue);

// 1.2.7 -> 1.2.8
if(version < 21)
Expand Down
21 changes: 16 additions & 5 deletions Assets/lilToon/Editor/lilToonEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class lilToonEditorUtils
private const string menuPathGameObject = "GameObject/lilToon/";
private const string menuPathRefreshShaders = menuPathAssets + "[Shader] Refresh shaders";
private const string menuPathRemoveUnusedProperties = menuPathAssets + "[Material] Remove unused properties";
private const string menuPathRunMigration = menuPathAssets + "[Material] Run migration";
private const string menuPathConvertNormal = menuPathAssets + "[Texture] Convert normal map (DirectX <-> OpenGL)";
private const string menuPathPixelArtReduction = menuPathAssets + "[Texture] Pixel art reduction";
private const string menuPathConvertGifToAtlas = menuPathAssets + "[Texture] Convert Gif to Atlas";
Expand All @@ -34,11 +35,12 @@ public static class lilToonEditorUtils
private const int menuPriorityGameObject = 21; // This must be 21 or less
private const int menuPriorityRefreshShaders = menuPriorityAssets + 0;
private const int menuPriorityRemoveUnusedProperties = menuPriorityAssets + 20;
private const int menuPriorityConvertNormal = menuPriorityAssets + 21;
private const int menuPriorityPixelArtReduction = menuPriorityAssets + 22;
private const int menuPriorityConvertGifToAtlas = menuPriorityAssets + 23;
private const int menuPriorityConvertLUTToPNG = menuPriorityAssets + 24;
private const int menuPrioritySetupFromFBX = menuPriorityAssets + 25;
private const int menuPriorityRunMigration = menuPriorityAssets + 21;
private const int menuPriorityConvertNormal = menuPriorityAssets + 22;
private const int menuPriorityPixelArtReduction = menuPriorityAssets + 23;
private const int menuPriorityConvertGifToAtlas = menuPriorityAssets + 24;
private const int menuPriorityConvertLUTToPNG = menuPriorityAssets + 25;
private const int menuPrioritySetupFromFBX = menuPriorityAssets + 26;
private const int menuPriorityFixLighting = menuPriorityGameObject;

private const string anchorName = "AutoAnchorObject";
Expand Down Expand Up @@ -87,6 +89,15 @@ private static bool CheckRemoveUnusedProperties()
return CheckExtension(".mat");
}

//------------------------------------------------------------------------------------------------------------------------------
// Assets/lilToon/Run migration
[MenuItem(menuPathRunMigration, false, menuPriorityRunMigration)]
private static void RunMigration()
{
lilStartup.MigrateMaterials();
EditorUtility.DisplayDialog("[lilToon] Run migration",GetLoc("sComplete"),GetLoc("sOK"));
}

//------------------------------------------------------------------------------------------------------------------------------
// Assets/lilToon/Convert normal map (DirectX <-> OpenGL)
[MenuItem(menuPathConvertNormal, false, menuPriorityConvertNormal)]
Expand Down
2 changes: 2 additions & 0 deletions Assets/lilToon/Editor/lilToonSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class lilToonSetting : ScriptableObject
public bool isLocked = false;
public bool isDebugOptimize = false;
public bool isOptimizeInTestBuild = false;
public bool isMigrateInStartUp = true;

public float defaultAsUnlit = 0.0f;
public float defaultVertexLightStrength = 0.0f;
Expand Down Expand Up @@ -169,6 +170,7 @@ internal static void LoadLockedSetting(ref lilToonSetting shaderSetting)
shaderSetting.LIL_OPTIMIZE_USE_LIGHTMAP = lockedSetting.LIL_OPTIMIZE_USE_LIGHTMAP;
shaderSetting.isDebugOptimize = lockedSetting.isDebugOptimize;
shaderSetting.isOptimizeInTestBuild = lockedSetting.isOptimizeInTestBuild;
shaderSetting.isMigrateInStartUp = lockedSetting.isMigrateInStartUp;
shaderSetting.mainLightModeName = lockedSetting.mainLightModeName;
shaderSetting.outlineLightModeName = lockedSetting.outlineLightModeName;
shaderSetting.preLightModeName = lockedSetting.preLightModeName;
Expand Down

0 comments on commit c083f63

Please sign in to comment.