Skip to content

Commit

Permalink
Merge pull request #148 from Azukimochi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Azukimochi authored Apr 5, 2024
2 parents 6a9cdc7 + 0c6ba33 commit c9c31d6
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 16 deletions.
16 changes: 14 additions & 2 deletions Editor/LightLimitChangerPrefab.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using nadena.dev.modular_avatar.core;
using nadena.dev.ndmf.util;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -106,9 +107,20 @@ public static void SavePrefabSetting(LightLimitChangerParameters parameters)
}
}

public static void SavePrefabSettingAsGlobal(LightLimitChangerParameters parameters)
public static void SavePrefabSetting(SerializedObject serializedObject)
{
SavePrefabSetting(parameters);
Undo.SetCurrentGroupName("Save LLC Prefab Settings");
var idx = Undo.GetCurrentGroup();
foreach (var x in serializedObject.AllProperties())
{
PrefabUtility.ApplyPropertyOverride(x, AssetDatabase.GetAssetPath(Object), InteractionMode.UserAction);
}
Undo.CollapseUndoOperations(idx);
}

public static void SavePrefabSettingAsGlobal(SerializedObject serializedObject, LightLimitChangerParameters parameters)
{
SavePrefabSetting(serializedObject);
var json = JsonUtility.ToJson(parameters);
var key = GUID.Generate().ToString();
EditorPrefs.SetString(GlobalSettingsIDKey, key);
Expand Down
9 changes: 4 additions & 5 deletions Editor/LightLimitChangerSettingsEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor;
using nadena.dev.ndmf.util;
using UnityEditor;
using UnityEngine;

namespace io.github.azukimochi
Expand Down Expand Up @@ -103,16 +104,14 @@ public override void OnInspectorGUI()
ApplySettingToAvatar = GUILayout.Button(Localization.S("label.apply_settings_avatar"), EditorStyles.miniButton);
if (ApplySettingToAvatar)
{
LightLimitChangerPrefab.SavePrefabSetting(parameter);
PrefabUtility.RevertPrefabInstance(settings.gameObject, InteractionMode.AutomatedAction);
LightLimitChangerPrefab.SavePrefabSetting(serializedObject);
}
ApplySettingToProject = GUILayout.Button(Localization.S("label.apply_settings_project"), EditorStyles.miniButton);
if (ApplySettingToProject)
{
if (EditorUtility.DisplayDialog(Localization.S("Window.info.gloabl_settings.save"), Localization.S("Window.info.global_settings.save_message"), Localization.S("Window.info.choice.apply_save"), Localization.S("Window.info.cancel")))
{
LightLimitChangerPrefab.SavePrefabSettingAsGlobal(parameter);
PrefabUtility.RevertPrefabInstance(settings.gameObject, InteractionMode.AutomatedAction);
LightLimitChangerPrefab.SavePrefabSettingAsGlobal(serializedObject, parameter);
}
}

Expand Down
39 changes: 38 additions & 1 deletion Editor/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,32 @@ internal static class Localization
"OK"
}
},

///////////////////////////////////////////////////////
// Links
{
"link.document.changelog", new []
{
"Light Limit Changer OfficialSite | Changelog",
"Light Limit Changer OfficialSite | 更新履歴",
"Light Limit Changer OfficialSite | Changelog"
}
},
{
"link.document.recommend", new []
{
"Light Limit Changer OfficialSite | Recommend Settings",
"Light Limit Changer OfficialSite | おすすめ設定",
"Light Limit Changer OfficialSite | Recommend Settings"
}
},
{
"link.document.description", new []
{
"Light Limit Changer OfficialSite | Description",
"Light Limit Changer OfficialSite | 設定概要",
"Light Limit Changer OfficialSite | Description"
}
},

///////////////////////////////////////////////////////
// NDMF
Expand Down Expand Up @@ -260,7 +285,19 @@ internal static class Localization
@"檢測到 Poiyomi Shader 7.3 版本。
請使用最新版的 Poiyomi Shader。"
}
},
{
"NDMF.info.non_generated", new []
{
@"The menu was not generated because there was no animation target.
Please check your settings if this is not what you intended.",
@"アニメーションの生成対象が存在しなかったため、メニューを生成しませんでした。
これが意図したものでない場合には、設定を確認してください。",
@"The menu was not generated because there was no animation target.
Please check your settings if this is not what you intended."
}
}

};

public static string S(string text, int? language = null)
Expand Down
7 changes: 7 additions & 0 deletions Editor/NDMF/Passes.CollectTargetRenderersPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ protected override void Execute(BuildContext context, Session session, LightLimi

CollectMeshRenderers(context.AvatarRootObject, session.Parameters.TargetShaders, list);
CollectMeshRenderersInAnimation(context.AvatarRootObject, session.Parameters.TargetShaders, list);

if (list.Count == 0)
{
IError error = new ErrorMessage("NDMF.info.non_generated", ErrorSeverity.NonFatal);
ErrorReport.ReportError(error);
session.IsFailed = true;
}
}

private static void CollectMeshRenderers(GameObject avatarObject, in TargetShaders targetShaders, HashSet<Renderer> list)
Expand Down
15 changes: 14 additions & 1 deletion Editor/NDMF/Passes.FinalizePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ protected override void Execute(BuildContext context, Session session, LightLimi

internal static void Run(GameObject avatarObject, Session session, LightLimitChangerObjectCache cache)
{
var obj = session.Settings.gameObject;
var obj = session.Settings?.gameObject;
if (!session.IsValid())
{
if (obj == null)
return;

var mami = obj.GetComponent<ModularAvatarMenuInstaller>();
if (mami != null)
{
GameObject.DestroyImmediate(mami);
}
return;
}

var mergeAnimator_wd = obj.AddComponent<ModularAvatarMergeAnimator>();
var mergeAnimator = obj.AddComponent<ModularAvatarMergeAnimator>();
var maParameters = obj.GetOrAddComponent<ModularAvatarParameters>();
Expand Down
2 changes: 1 addition & 1 deletion Editor/NDMF/Passes.NormalizeMaterialsPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override void Execute(BuildContext context, Session session, LightLimi

//Report ColorTempCont or SaturationCnt information in NDMF error reporting

IError error = new ErrorMessage("NDMF.info.useColorTemporSaturation", ErrorSeverity.NonFatal);
IError error = new ErrorMessage("NDMF.info.useColorTemporSaturation", ErrorSeverity.Information);
ErrorReport.ReportError(error);

foreach (var material in cache.MappedObjects.Select(x => x as Material).Where(x => x != null).ToArray())
Expand Down
5 changes: 3 additions & 2 deletions Editor/NDMF/Passes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static LightLimitChangerObjectCache GetObjectCache(BuildContext context)
protected override void Execute(BuildContext context)
{
var session = GetSession(context);
if (!session.IsValid())
if (!session.IsValid() && typeof(TPass) != typeof(FinalizePass))
return;
_session = session;
var cache = _cache = GetObjectCache(context);
Expand All @@ -86,12 +86,13 @@ internal sealed class Session
public HashSet<Renderer> TargetRenderers;
public DirectBlendTree DirectBlendTree;
public List<ParameterConfig> AvatarParameters;
public bool IsFailed;

public HashSet<Object> Excludes;

private bool _initialized;

public bool IsValid() => Settings != null;
public bool IsValid() => Settings != null && !IsFailed;

public void InitializeSession(BuildContext context)
{
Expand Down
30 changes: 27 additions & 3 deletions Editor/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using nadena.dev.ndmf.util;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
Expand Down Expand Up @@ -76,6 +77,29 @@ public static bool IsNeedToEnterChildren(this SerializedPropertyType type)
}
}

public static void ResetPrefabInstance(GameObject prefab)
{
bool isPartOfPrefab = PrefabUtility.IsPartOfPrefabInstance(prefab);
if (isPartOfPrefab)
{
var parentPrefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(prefab.transform.parent);
var relativePath = prefab.AvatarRootPath();
var parent = PrefabUtility.LoadPrefabContents(parentPrefabPath);
try
{
PrefabUtility.RevertPrefabInstance(parent.transform.Find(relativePath).gameObject, InteractionMode.UserAction);
}
finally
{
PrefabUtility.UnloadPrefabContents(parent);
}
}
else
{
PrefabUtility.RevertPrefabInstance(prefab, InteractionMode.UserAction);
}
}

public static Color With(this Color color, float? r = null, float? g = null, float? b = null, float? a = null)
{
color.r = r ?? color.r;
Expand Down Expand Up @@ -215,7 +239,7 @@ public static void ShowVersionInfo()
{
if (foldout.IsOpen)
{
DrawWebButton("Light Limit Changer OfficialSite | 更新履歴 Changelog", "https://azukimochi.github.io/LLC-Docs/docs/changelog");
DrawWebButton(Localization.S("link.document.changelog"), "https://azukimochi.github.io/LLC-Docs/docs/changelog");
DrawWebButton("X|Twitter", "https://twitter.com/search?q=from%3Aazukimochi25%20%23LightLimitChanger&src=typed_query&f=live");
}
}
Expand All @@ -228,8 +252,8 @@ public static void ShowDocumentLink()
{
if (foldout.IsOpen)
{
DrawWebButton("Light Limit Changer OfficialSite | おすすめ設定 Recommend Setting", "https://azukimochi.github.io/LLC-Docs/docs/tutorial/howtouse-recommend");
DrawWebButton("Light Limit Changer OfficialSite | 設定概要 Description", "https://azukimochi.github.io/LLC-Docs/docs/discription/disc_param");
DrawWebButton(Localization.S("link.document.recommend"), "https://azukimochi.github.io/LLC-Docs/docs/tutorial/howtouse-recommend");
DrawWebButton(Localization.S("link.document.description"), "https://azukimochi.github.io/LLC-Docs/docs/discription/disc_param");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io.github.azukimochi.light-limit-changer",
"version": "1.11.1",
"version": "1.11.2",
"unity": "2019.4",
"displayName": "LightLimitChanger",
"description": "Light Limit ChangerはModular-Avatar前提のVRChatアバター向けの明るさ変更ジェネレーターです。―――――――――――――――――― Light Limit Changer is a brightness change generator for VRChat avatars based on Modular-Avatar. ―――――――――――――――――― by Azukimochi25",
Expand Down

0 comments on commit c9c31d6

Please sign in to comment.