Skip to content

Commit

Permalink
Merge branch 'master' into write-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Oct 30, 2023
2 parents bc78806 + 8b2c105 commit 8f708ff
Show file tree
Hide file tree
Showing 32 changed files with 813 additions and 685 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Small performance improve `#641`

### Changed
- All logs passed to ErrorReport is now shown on the console log `#643`

### Deprecated

### Removed
- Preventing removing `IEditorOnly` in callback order -1024 `#658`
- This is no longer needed sincd 1.5.0 but I forgot to remove so I removed in 1.6

### Fixed
- Prefab blinks when we see editor of PrefabSafeSet of prefab asset `#645`
- Fixes in 1.5.9 `#654`

### Security

## [1.5.9] - 2023-10-29
## [1.5.9-rc.1] - 2023-10-28
### Fixed
- Animation clip length can be changed [`#647`](https://github.com/anatawa12/AvatarOptimizer/pull/647)

## [1.6.0-beta.1] - 2023-10-25
### Added
- Public API for registering component information [`#623`](https://github.com/anatawa12/AvatarOptimizer/pull/623)
Expand Down Expand Up @@ -949,7 +960,9 @@ This release is mistake.
- Clear Endpoint Position

[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.6.0-beta.1...HEAD
[1.6.0-beta.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.8...v1.6.0-beta.1
[1.6.0-beta.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.9...v1.6.0-beta.1
[1.5.9]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.9-rc.1...v1.5.9
[1.5.9-rc.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.8...v1.5.9-rc.1
[1.5.8]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.8-rc.1...v1.5.8
[1.5.8-rc.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.7...v1.5.8-rc.1
[1.5.7]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.7-beta.1...v1.5.7
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@ The format is based on [Keep a Changelog].
- Public API for registering component information `#632`
- Disabling PhysBone animation based on mesh renderer enabled animation `#640`
- If you toggles your clothes with simple toggle, PhysBones on the your avatar will also be toggled automatically!
- Small performance improve `#641`

### Changed
- All logs passed to ErrorReport is now shown on the console log `#643`

### Deprecated

### Removed
- Legacy GC `#633`
- Preventing removing `IEditorOnly` in callback order -1024 `#658`
- This is no longer needed sincd 1.5.0 but I forgot to remove so I removed in 1.6

### Fixed
- Improve support of newer Unity versions `#608`
- Improve support of projects without VRCSDK `#609` `#625` `#627`
- Prefab blinks when we see editor of PrefabSafeSet of prefab asset `#645`

### Security

## [1.5.9] - 2023-10-29
### Fixed
- Animation clip length can be changed [`#647`](https://github.com/anatawa12/AvatarOptimizer/pull/647)

## [1.5.8] - 2023-10-20
### Fixed
- warning about VRCTestMarker when Build & Test [`#628`](https://github.com/anatawa12/AvatarOptimizer/pull/628)
Expand Down Expand Up @@ -626,7 +635,8 @@ The format is based on [Keep a Changelog].
- Merge Bone
- Clear Endpoint Position

[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.8...HEAD
[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.9...HEAD
[1.5.9]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.8...v1.5.9
[1.5.8]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.7...v1.5.8
[1.5.7]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.6...v1.5.7
[1.5.6]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.5...v1.5.6
Expand Down
29 changes: 24 additions & 5 deletions Editor/APIInternal/ComponentInfoRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Anatawa12.AvatarOptimizer.APIInternal.Externals;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -64,11 +65,29 @@ private static void LoadType(Type type, ComponentInformationAttributeBase attrib

if (!informationType.IsAssignableFrom(type))
throw new Exception("Unsupported type : Not Extends from ComponentInformation<Target>");
if (InformationByType.ContainsKey(targetType))
throw new Exception($"Target Type duplicated: {targetType}");

var instance = (ComponentInformation)System.Activator.CreateInstance(type);
InformationByType.Add(targetType, instance);
if (InformationByType.TryGetValue(targetType, out var existing))
{
if (existing is IExternalMarker)
{
// if existing is fallback, use new one
var instance = (ComponentInformation)System.Activator.CreateInstance(type);
InformationByType[targetType] = instance;
}
else if (typeof(IExternalMarker).IsAssignableFrom(targetType))
{
// if adding is fallback, use existing one
}
else
{
// otherwise, in other words, If both are not fallback, throw exception
throw new Exception($"Target Type duplicated: {targetType}");
}
}
else
{
var instance = (ComponentInformation)System.Activator.CreateInstance(type);
InformationByType.Add(targetType, instance);
}
}

internal static bool TryGetInformation(Type type, out ComponentInformation information) =>
Expand Down
102 changes: 102 additions & 0 deletions Editor/APIInternal/ComponentInfos.Externals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Collections.Generic;
using Anatawa12.AvatarOptimizer.API;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer.APIInternal.Externals
{
/// <summary>
/// Marker interface for fallback ComponentInformation(s) for external library.
///
/// Thanks to this interface, upstream author can register those component types without causing duplication error
/// and override information by Avatar Optimizer.
/// </summary>
internal interface IExternalMarker
{
}

#region Dynamic Bones

[ComponentInformationWithGUID("f9ac8d30c6a0d9642a11e5be4c440740", 11500000)]
internal class DynamicBoneInformation : ComponentInformation<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
collector.MarkBehaviour();

foreach (var transform in GetAffectedTransforms(component))
{
collector.AddDependency(transform, component)
.EvenIfDependantDisabled()
.OnlyIfTargetCanBeEnable();
collector.AddDependency(transform);
}

foreach (var collider in (IReadOnlyList<MonoBehaviour>)((dynamic)component).m_Colliders)
{
// DynamicBone ignores enabled/disabled of Collider Component AFAIK
collector.AddDependency(collider);
}
}

protected override void CollectMutations(Component component, ComponentMutationsCollector collector)
{
foreach (var transform in GetAffectedTransforms(component))
collector.TransformRotation(transform);
}

private static IEnumerable<Transform> GetAffectedTransforms(dynamic dynamicBone)
{
var ignores = new HashSet<Transform>(dynamicBone.m_Exclusions);
var queue = new Queue<Transform>();
Transform root = dynamicBone.m_Root;
queue.Enqueue(root ? root : (Transform)dynamicBone.transform);

while (queue.Count != 0)
{
var transform = queue.Dequeue();
yield return transform;

foreach (var child in transform.DirectChildrenEnumerable())
if (!ignores.Contains(child))
queue.Enqueue(child);
}
}
}

[ComponentInformationWithGUID("baedd976e12657241bf7ff2d1c685342", 11500000)]
internal class DynamicBoneColliderInformation : ComponentInformation<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
}
}

#endregion

#region Satania's KiseteneEx Components

[ComponentInformationWithGUID("e78466b6bcd24e5409dca557eb81d45b", 11500000)] // KiseteneComponent
[ComponentInformationWithGUID("7f9c3fe1cfb9d1843a9dc7da26352ce2", 11500000)] // FlyAvatarSetupTool
[ComponentInformationWithGUID("95f6e1368d803614f8a351322ab09bac", 11500000)] // BlendShapeOverrider
internal class SataniaKiseteneExComponents : ComponentInformation<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
}
}

#endregion


#region VRCQuestTools

[ComponentInformationWithGUID("f055e14e1beba894ea68aedffde8ada6", 11500000)] // VertexColorRemover
internal class VRCQuestToolsComponents : ComponentInformation<Component>, IExternalMarker
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
}
}

#endregion
}
3 changes: 3 additions & 0 deletions Editor/APIInternal/ComponentInfos.Externals.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f708ff

Please sign in to comment.