Skip to content

Commit

Permalink
Merge branch 'master' into fix-deprecation-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Sep 28, 2023
2 parents c9859d8 + b75443c commit 6ba1769
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 47 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ The format is based on [Keep a Changelog].

### Security

## [1.5.0-rc.9] - 2023-09-28
### Fixed
- Editor of EditSkinnedMesh components may not work well if the object is inactive [`#518`](https://github.com/anatawa12/AvatarOptimizer/pull/518)

## [1.5.0-rc.8] - 2023-09-25
### Added
- Warning Dialog for Legacy Modular Avatar [`#509`](https://github.com/anatawa12/AvatarOptimizer/pull/509)
Expand Down Expand Up @@ -812,7 +816,8 @@ This release is mistake.
- Merge Bone
- Clear Endpoint Position

[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.8...HEAD
[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.9...HEAD
[1.5.0-rc.9]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.8...v1.5.0-rc.9
[1.5.0-rc.8]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.7...v1.5.0-rc.8
[1.5.0-rc.7]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.6...v1.5.0-rc.7
[1.5.0-rc.6]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.0-rc.5...v1.5.0-rc.6
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog].
- MergeBone may make some bone inactive to active if bone being merged is inactive `#454`
- Avoid problematic material slot in MergeSkinnedMesh [`#508`](https://github.com/anatawa12/AvatarOptimizer/pull/508)
- This avoids [Unity's bug in 2019][unity-bug-material]. In Unity 2022, this is no longer needed.
- Editor of EditSkinnedMesh components may not work well if the object is inactive `#518`

[unity-bug]: https://issuetracker.unity3d.com/issues/crash-on-gettargetassemblybyscriptpath-when-a-po-file-in-the-packages-directory-is-not-under-an-assembly-definition
[unity-bug-material]: https://issuetracker.unity3d.com/issues/material-is-applied-to-two-slots-when-applying-material-to-a-single-slot-while-recording-animation
Expand Down
52 changes: 14 additions & 38 deletions Editor/EditSkinnedMeshComponentUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Anatawa12.AvatarOptimizer
{
Expand All @@ -14,34 +13,20 @@ internal static class EditSkinnedMeshComponentUtil
{
static EditSkinnedMeshComponentUtil()
{
RuntimeUtil.OnAwakeEditSkinnedMesh += OnAwake;
RuntimeUtil.OnDestroyEditSkinnedMesh += OnDestroy;

AssemblyReloadEvents.afterAssemblyReload += AfterAssemblyReload;
}

private static void AfterAssemblyReload()
{
foreach (var component in Enumerable.Range(0, SceneManager.sceneCount)
.Select(SceneManager.GetSceneAt)
.SelectMany(x => x.GetRootGameObjects())
.SelectMany(x => x.GetComponentsInChildren<EditSkinnedMeshComponent>(true)))
OnAwake(component);
}

// might be called by Processor to make sure the component is registered
internal static void OnAwake(EditSkinnedMeshComponent component)
{
EditorShared.AddComponent(component);
EditorApplication.hierarchyChanged += ResetSharedSorter;
}

private static void OnDestroy(EditSkinnedMeshComponent component)
private static SkinnedMeshEditorSorter CreateSharedSorterWithScene()
{
EditorShared.RemoveComponent(component);
var sorter = new SkinnedMeshEditorSorter();
foreach (var component in Resources.FindObjectsOfTypeAll<EditSkinnedMeshComponent>()
.Where(x => !EditorUtility.IsPersistent(x))
.Where(x => x.gameObject.scene.IsValid()))
sorter.AddComponent(component);
return sorter;
}

public static bool IsModifiedByEditComponent(SkinnedMeshRenderer renderer) =>
EditorShared.IsModifiedByEditComponent(renderer);
private static void ResetSharedSorter() => _editorShared = null;

public static (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer renderer) => EditorShared.GetBlendShapes(renderer);

Expand All @@ -55,7 +40,11 @@ public static (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer r
public static Material[] GetMaterials(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent before = null,
bool fast = true) => EditorShared.GetMaterials(renderer, before, fast);

private static readonly SkinnedMeshEditorSorter EditorShared = new SkinnedMeshEditorSorter();
[CanBeNull] private static SkinnedMeshEditorSorter _editorShared;

[NotNull]
private static SkinnedMeshEditorSorter EditorShared =>
_editorShared ?? (_editorShared = CreateSharedSorterWithScene());
}

internal class SkinnedMeshEditorSorter
Expand All @@ -69,12 +58,6 @@ public void AddComponent(EditSkinnedMeshComponent component)
processors.AddProcessor(processor);
}

public void RemoveComponent(EditSkinnedMeshComponent component)
{
var target = component.GetComponent<SkinnedMeshRenderer>();
GetProcessors(target)?.RemoveProcessorOf(component);
}

public bool IsModifiedByEditComponent(SkinnedMeshRenderer renderer) =>
ProcessorsByRenderer.ContainsKey(renderer);

Expand Down Expand Up @@ -151,13 +134,6 @@ public void AddProcessor(IEditSkinnedMeshProcessor processor)
PurgeCache();
}

public void RemoveProcessorOf(EditSkinnedMeshComponent component)
{
var removed = _processors.RemoveWhere(x => x.Component == component);
if (removed == 0) return;
PurgeCache(removing: true);
}

internal List<IEditSkinnedMeshProcessor> GetSorted()
{
if (_sorted != null) return _sorted;
Expand Down
4 changes: 0 additions & 4 deletions Runtime/EditSkinnedMeshComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
namespace Anatawa12.AvatarOptimizer
{
[RequireComponent(typeof(SkinnedMeshRenderer))]
[ExecuteAlways]
internal abstract class EditSkinnedMeshComponent : AvatarTagComponent
{
private void Awake() => RuntimeUtil.OnAwakeEditSkinnedMesh?.Invoke(this);

private void OnDestroy() => RuntimeUtil.OnDestroyEditSkinnedMesh?.Invoke(this);
}
}
3 changes: 0 additions & 3 deletions Runtime/RuntimeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ public static string RelativePath(GameObject root, GameObject child)
#else
public static bool isPlaying => true;
#endif

public static Action<EditSkinnedMeshComponent> OnAwakeEditSkinnedMesh;
public static Action<EditSkinnedMeshComponent> OnDestroyEditSkinnedMesh;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.anatawa12.avatar-optimizer",
"version": "1.5.0-rc.8",
"version": "1.5.0-rc.9",
"unity": "2019.4",
"description": "Set of Anatawa12's Small Avatar Optimization Utilities",
"displayName": "Anatawa12's AvatarOptimizer",
Expand Down

0 comments on commit 6ba1769

Please sign in to comment.