diff --git a/.csc.rsp.nullsafe b/.csc.rsp.nullsafe
new file mode 100644
index 000000000..9a26da866
--- /dev/null
+++ b/.csc.rsp.nullsafe
@@ -0,0 +1,5 @@
+#"Shared csc.rsp file with null safe. origin is at .csc.rsp.nullsafe and symlinked to each assemblies of AAO"
+-langversion:10
+#"PUBLISH DELETE MARKER // lines below are only for development to reduce unexpected compile errors"
+-warnaserror:nullable
+-nullable:enable
diff --git a/.csc.rsp.nullunsafe b/.csc.rsp.nullunsafe
new file mode 100644
index 000000000..e55888f86
--- /dev/null
+++ b/.csc.rsp.nullunsafe
@@ -0,0 +1,4 @@
+#"Shared csc.rsp file with null unsafe. origin is at .csc.rsp.nullunsafe and symlinked to each assemblies of AAO"
+-langversion:10
+#"PUBLISH DELETE MARKER // lines below are only for development to reduce unexpected compile errors"
+-warnaserror:nullable
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 8d413c00d..da21fbbc1 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -169,6 +169,11 @@ jobs:
sed -i'.bak' -e "s|${STABLE_URL}|${STABLE_URL}#${VERSION}|" package.json
fi
rm package.json.bak
+
+ - name: update csc.rsp
+ run: |
+ sed -n '/PUBLISH DELETE MARKER/q;p' -i .csc.rsp.nullunsafe
+ sed -n '/PUBLISH DELETE MARKER/q;p' -i .csc.rsp.nullsafe
# region vpm release
- name: Build VPM release
diff --git a/API-Editor/ComponentInformation.cs b/API-Editor/ComponentInformation.cs
index f57805108..65230dd04 100644
--- a/API-Editor/ComponentInformation.cs
+++ b/API-Editor/ComponentInformation.cs
@@ -1,3 +1,5 @@
+#nullable enable
+
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
@@ -30,7 +32,7 @@ public sealed class ComponentInformationAttribute : APIInternal.ComponentInforma
[PublicAPI]
public ComponentInformationAttribute(Type targetType)
{
- TargetType = targetType;
+ TargetType = targetType ?? throw new ArgumentNullException(nameof(targetType));
}
internal override Type GetTargetType() => TargetType;
@@ -167,7 +169,7 @@ internal ComponentDependencyCollector()
/// The dependency
/// The object to configure the dependency
[PublicAPI]
- public abstract ComponentDependencyInfo AddDependency(Component dependant, Component dependency);
+ public abstract ComponentDependencyInfo AddDependency(Component? dependant, Component? dependency);
///
/// Adds as dependencies of current component.
@@ -178,7 +180,7 @@ internal ComponentDependencyCollector()
/// The dependency
/// The object to configure the dependency
[PublicAPI]
- public abstract ComponentDependencyInfo AddDependency(Component dependency);
+ public abstract ComponentDependencyInfo AddDependency(Component? dependency);
///
/// Adds relative path from to as dependencies of current component.
@@ -223,7 +225,7 @@ internal ComponentDependencyCollector()
/// The GameObject the relative path starts from
/// If the is not child of .
[PublicAPI]
- public abstract PathDependencyInfo AddPathDependency([NotNull] Transform dependency, [NotNull] Transform root);
+ public abstract PathDependencyInfo AddPathDependency(Transform dependency, Transform root);
// TODO: rename to better name and make public
// NOTE for external users: this is API Proposal to compute value of animatable bool property
@@ -309,13 +311,11 @@ internal ComponentMutationsCollector()
/// The component current component will modifies
/// The list of properties current component will modifies
[PublicAPI]
- public abstract void ModifyProperties([NotNull] Component component,
- [NotNull] [ItemNotNull] IEnumerable properties);
+ public abstract void ModifyProperties(Component component, IEnumerable properties);
///
[PublicAPI]
- public void ModifyProperties([NotNull] Component component,
- [NotNull] [ItemNotNull] params string[] properties) =>
+ public void ModifyProperties(Component component, params string[] properties) =>
ModifyProperties(component, (IEnumerable)properties);
}
@@ -370,7 +370,7 @@ internal MappedComponentInfo()
/// to animation property, for example, blendShape related SkinnedMeshRenderer.
///
[PublicAPI]
- public abstract T MappedComponent { get; }
+ public abstract T? MappedComponent { get; }
///
/// Maps animation property name to component and MappedPropertyInfo.
diff --git a/API-Editor/Internal/InternalParts.cs b/API-Editor/Internal/InternalParts.cs
index 9b063a963..54686a3e5 100644
--- a/API-Editor/Internal/InternalParts.cs
+++ b/API-Editor/Internal/InternalParts.cs
@@ -1,6 +1,7 @@
+#nullable enable
+
using System;
using Anatawa12.AvatarOptimizer.API;
-using JetBrains.Annotations;
using UnityEngine;
namespace Anatawa12.AvatarOptimizer.APIInternal
@@ -8,7 +9,7 @@ namespace Anatawa12.AvatarOptimizer.APIInternal
public abstract class ComponentInformationAttributeBase : Attribute
{
internal ComponentInformationAttributeBase() { }
- [CanBeNull] internal abstract Type GetTargetType();
+ internal abstract Type? GetTargetType();
}
///
@@ -33,4 +34,4 @@ internal ComponentInformation()
internal class AllowInheritAttribute : Attribute
{
}
-}
\ No newline at end of file
+}
diff --git a/Editor/.MergePhysBoneEditorModificationUtils.ts b/Editor/.MergePhysBoneEditorModificationUtils.ts
index dbae92fa7..8174d252f 100644
--- a/Editor/.MergePhysBoneEditorModificationUtils.ts
+++ b/Editor/.MergePhysBoneEditorModificationUtils.ts
@@ -43,7 +43,8 @@ const config: Config = {
} satisfies Config;
console.log("// ")
-console.log("// generated by .MergePhysBoneEditorModificationUtils.ts")
+console.log("#nullable enable")
+console.log("")
console.log("#if AAO_VRCSDK3_AVATARS")
console.log("")
console.log("using System.Collections.Generic;")
@@ -59,14 +60,14 @@ for (let [type, info] of Object.entries(config)) {
console.log(` {`)
for (let [value] of info.values) {
console.log(` public readonly SerializedProperty Override${value};`)
- console.log(` public SerializedProperty Source${value} { get; private set; }`)
+ console.log(` public SerializedProperty? Source${value} { get; private set; }`)
console.log(` public readonly string PhysBone${value}Name;`)
}
console.log(``)
console.log(` public ${type}(`)
- console.log(` [NotNull] SerializedProperty rootProperty`)
+ console.log(` SerializedProperty rootProperty`)
for (let [value] of info.values) {
- console.log(` , [NotNull] string physBone${value}Name`)
+ console.log(` , string physBone${value}Name`)
}
console.log(` ) : base(rootProperty)`)
console.log(` {`)
@@ -83,7 +84,7 @@ for (let [type, info] of Object.entries(config)) {
}
console.log(` }`)
for (let [value] of info.values) {
- console.log(` public SerializedProperty Get${value}Property(bool @override) => @override ? Override${value} : Source${value};`)
+ console.log(` public SerializedProperty Get${value}Property(bool @override) => @override ? Override${value} : Source${value}!;`)
}
console.log(` }`)
}
diff --git a/Editor/APIInternal/ComponentInfoRegistry.cs b/Editor/APIInternal/ComponentInfoRegistry.cs
index 951d31f0a..0c8ffd86b 100644
--- a/Editor/APIInternal/ComponentInfoRegistry.cs
+++ b/Editor/APIInternal/ComponentInfoRegistry.cs
@@ -8,8 +8,7 @@ namespace Anatawa12.AvatarOptimizer.APIInternal
{
internal static class ComponentInfoRegistry
{
- private static readonly Dictionary InformationByType =
- new Dictionary();
+ private static readonly Dictionary InformationByType = new();
[InitializeOnLoadMethod]
static void FindAllInfoImplements()
@@ -107,7 +106,7 @@ internal static bool TryGetInformation(Type type, out ComponentInformation infor
return false;
}
- private static HashSet _meaninglessTypes;
+ private static HashSet? _meaninglessTypes;
public static void InvalidateCache() => _meaninglessTypes = null;
@@ -128,7 +127,7 @@ private static bool IsMeaninglessType(Type type)
class MeaninglessComponentInformation : ComponentInformation
{
- public static MeaninglessComponentInformation Instance { get; } = new MeaninglessComponentInformation();
+ public static MeaninglessComponentInformation Instance { get; } = new();
private MeaninglessComponentInformation()
{
diff --git a/Editor/APIInternal/ComponentInformationWithGUIDAttribute.cs b/Editor/APIInternal/ComponentInformationWithGUIDAttribute.cs
index b9bfcc8fe..ca3a084c7 100644
--- a/Editor/APIInternal/ComponentInformationWithGUIDAttribute.cs
+++ b/Editor/APIInternal/ComponentInformationWithGUIDAttribute.cs
@@ -19,12 +19,12 @@ public ComponentInformationWithGUIDAttribute(string guid, int fileID)
FileID = fileID;
}
- internal override Type GetTargetType()
+ internal override Type? GetTargetType()
{
if (!GlobalObjectId.TryParse($"GlobalObjectId_V1-{1}-{Guid}-{(uint)FileID}-{0}", out var id)) return null;
var script = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) as MonoScript;
- if (!script) return null;
+ if (script == null) return null;
return script.GetClass();
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/APIInternal/ComponentInfos.DynamicBone.cs b/Editor/APIInternal/ComponentInfos.DynamicBone.cs
index 7e28e80ea..450228e42 100644
--- a/Editor/APIInternal/ComponentInfos.DynamicBone.cs
+++ b/Editor/APIInternal/ComponentInfos.DynamicBone.cs
@@ -58,4 +58,4 @@ protected override void CollectDependency(Component component, ComponentDependen
{
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/APIInternal/ComponentInfos.VRCSDK.cs b/Editor/APIInternal/ComponentInfos.VRCSDK.cs
index 704591bf8..4ade32523 100644
--- a/Editor/APIInternal/ComponentInfos.VRCSDK.cs
+++ b/Editor/APIInternal/ComponentInfos.VRCSDK.cs
@@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.API;
-using JetBrains.Annotations;
using nadena.dev.ndmf.runtime;
using UnityEngine;
using VRC.SDK3;
@@ -14,10 +13,8 @@
using VRC.SDK3.Dynamics.PhysBone.Components;
using VRC.SDKBase;
-#if AAO_VRCSDK3_AVATARS_CONSTRAINTS
using VRC.Dynamics.ManagedTypes;
using VRC.SDK3.Dynamics.Constraint.Components;
-#endif
namespace Anatawa12.AvatarOptimizer.APIInternal.VRCSDK
{
@@ -162,7 +159,6 @@ protected override void ApplySpecialMapping(T component, MappingSource mappingSo
}
}
- [NotNull]
private static string ParseBlendShapeProperty(string prop) =>
prop.StartsWith("blendShape.", StringComparison.Ordinal)
? prop.Substring("blendShape.".Length)
@@ -472,7 +468,6 @@ protected override void CollectDependency(VRCImpostorSettings component, Compone
}
}
-#if AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS
// this component has no documentation so this implementation is based on assumption
[ComponentInformation(typeof(VRCImpostorEnvironment))]
internal class VRCImpostorEnvironmentInformation : ComponentInformation
@@ -483,9 +478,7 @@ protected override void CollectDependency(VRCImpostorEnvironment component, Comp
collector.MarkEntrypoint();
}
}
-#endif
-#if AAO_VRCSDK3_AVATARS_HEAD_CHOP
[ComponentInformation(typeof(VRCHeadChop))]
internal class VRCHeadChopInformation : ComponentInformation
{
@@ -501,9 +494,7 @@ protected override void CollectDependency(VRCHeadChop component, ComponentDepend
collector.MarkBehaviour();
}
}
-#endif
-#if AAO_VRCSDK3_AVATARS_CONSTRAINTS
[ComponentInformation(typeof(VRCConstraintBase))]
[ComponentInformation(typeof(VRCParentConstraintBase))]
[ComponentInformation(typeof(VRCParentConstraint))]
@@ -548,7 +539,5 @@ protected override void CollectDependency(VRCWorldUpConstraintBase component, Co
collector.AddDependency(component.WorldUpTransform);
}
}
-
-#endif
}
#endif
diff --git a/Editor/APIInternal/ComponentInfos.VRM0.cs b/Editor/APIInternal/ComponentInfos.VRM0.cs
index ffa182461..6aa955d08 100644
--- a/Editor/APIInternal/ComponentInfos.VRM0.cs
+++ b/Editor/APIInternal/ComponentInfos.VRM0.cs
@@ -151,4 +151,4 @@ protected override void ApplySpecialMapping(VRMFirstPerson component, MappingSou
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Editor/APIInternal/ComponentInfos.VRM1.cs b/Editor/APIInternal/ComponentInfos.VRM1.cs
index 5d1533df5..c0dfb22a6 100644
--- a/Editor/APIInternal/ComponentInfos.VRM1.cs
+++ b/Editor/APIInternal/ComponentInfos.VRM1.cs
@@ -76,14 +76,14 @@ protected override void CollectMutations(Vrm10Instance component, ComponentMutat
}
}
- Transform GetBoneTransformForVrm10(Vrm10Instance component, HumanBodyBones bones)
+ Transform? GetBoneTransformForVrm10(Vrm10Instance component, HumanBodyBones bones)
{
- if (component.GetComponent() is Humanoid avatarHumanoid)
+ if (component.GetComponent() is { } avatarHumanoid)
{
return avatarHumanoid.GetBoneTransform(bones);
}
- if (component.GetComponent() is Animator avatarAnimator)
+ if (component.GetComponent() is { } avatarAnimator)
{
return avatarAnimator.GetBoneTransform(bones);
}
@@ -180,4 +180,4 @@ protected override void CollectDependency(Humanoid component, ComponentDependenc
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Editor/APIInternal/ComponentInfos.cs b/Editor/APIInternal/ComponentInfos.cs
index fb4283ab8..f0e0b9dc1 100644
--- a/Editor/APIInternal/ComponentInfos.cs
+++ b/Editor/APIInternal/ComponentInfos.cs
@@ -178,11 +178,7 @@ protected override void CollectDependency(ParticleSystem component, ComponentDep
switch (component.collision.type) // not animated
{
case ParticleSystemCollisionType.Planes:
-#if UNITY_2020_2_OR_NEWER
for (var i = 0; i < component.collision.planeCount; i++)
-#else
- for (var i = 0; i < component.collision.maxPlaneCount; i++)
-#endif
collector.AddDependency(component.collision.GetPlane(i));
break;
case ParticleSystemCollisionType.World:
@@ -193,11 +189,7 @@ protected override void CollectDependency(ParticleSystem component, ComponentDep
if (collector.GetAnimatedFlag(component, "TriggerModule.enabled", component.trigger.enabled) != false)
{
-#if UNITY_2020_2_OR_NEWER
for (var i = 0; i < component.trigger.colliderCount; i++)
-#else
- for (var i = 0; i < component.trigger.maxColliderCount; i++)
-#endif
{
var collider = component.trigger.GetCollider(i);
if (!collider) continue;
diff --git a/Editor/AnimatorParserV2/AnimationParser.cs b/Editor/AnimatorParserV2/AnimationParser.cs
index c895381bd..cbaf2ec8e 100644
--- a/Editor/AnimatorParserV2/AnimationParser.cs
+++ b/Editor/AnimatorParserV2/AnimationParser.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
using nadena.dev.ndmf;
using UnityEditor;
using UnityEditor.Animations;
@@ -12,15 +11,15 @@ namespace Anatawa12.AvatarOptimizer.AnimatorParsersV2
{
class AnimationParser
{
- internal ImmutableNodeContainer ParseMotion([NotNull] GameObject root, [CanBeNull] Motion motion,
- [NotNull] IReadOnlyDictionary mapping)
+ internal ImmutableNodeContainer ParseMotion(GameObject root, Motion? motion,
+ IReadOnlyDictionary mapping)
{
using (ErrorReport.WithContextObject(motion))
return ParseMotionInner(root, motion, mapping);
}
- private ImmutableNodeContainer ParseMotionInner([NotNull] GameObject root, [CanBeNull] Motion motion,
- [NotNull] IReadOnlyDictionary mapping)
+ private ImmutableNodeContainer ParseMotionInner(GameObject root, Motion? motion,
+ IReadOnlyDictionary mapping)
{
switch (motion)
{
@@ -74,7 +73,7 @@ public BlendTreeMergeProperty(BlendTreeType blendType)
_blendType = blendType;
}
- public ImmutableNodeContainer CreateContainer() => new ImmutableNodeContainer();
+ public ImmutableNodeContainer CreateContainer() => new();
public ImmutableNodeContainer GetContainer(ImmutableNodeContainer source) => source;
public BlendTreeElement GetIntermediate(ImmutableNodeContainer source,
@@ -90,10 +89,9 @@ public ImmutablePropModNode
internal abstract class PropModNode : IErrorContext, IPropModNode
+ where T : notnull
{
///
/// Returns true if this node is always applied. For inactive nodes, this returns false.
///
public abstract bool AppliedAlways { get; }
+
public abstract ValueInfo Value { get; }
public abstract IEnumerable ContextReferences { get; }
}
@@ -41,27 +43,27 @@ internal abstract class PropModNode : IErrorContext, IPropModNode
///
// by design, this struct doesn't handle blending between two states.
internal readonly struct ValueInfo
+ where T : notnull
{
public bool IsConstant => _possibleValues != null && _possibleValues.Length == 1;
- [CanBeNull] private readonly T[] _possibleValues;
+ private readonly T[]? _possibleValues;
public T ConstantValue
{
get
{
if (!IsConstant) throw new InvalidOperationException("Not Constant");
- Debug.Assert(_possibleValues != null, nameof(_possibleValues) + " != null");
- return _possibleValues[0];
+ return _possibleValues![0]; // non constant => there is value
}
}
- [CanBeNull] public T[] PossibleValues => _possibleValues;
+ public T[]? PossibleValues => _possibleValues;
public static ValueInfo Variable => default;
public ValueInfo(T value) => _possibleValues = new[] { value };
- public ValueInfo([NotNull] T[] possibleValues)
+ public ValueInfo(T[] possibleValues)
{
if (possibleValues == null) throw new ArgumentNullException(nameof(possibleValues));
if (possibleValues.Length == 0)
@@ -71,7 +73,7 @@ public ValueInfo([NotNull] T[] possibleValues)
_possibleValues = possibleValues;
}
- public bool TryGetConstantValue(out T o)
+ public bool TryGetConstantValue([NotNullWhen(true)] out T? o)
{
if (IsConstant)
{
@@ -92,9 +94,7 @@ public bool Equals(ValueInfo other)
public override bool Equals(object obj) => obj is ValueInfo other && Equals(other);
- public override int GetHashCode() => _possibleValues == null
- ? 0
- : _possibleValues.Aggregate(0, (current, value) => current ^ value.GetHashCode());
+ public override int GetHashCode() => _possibleValues == null ? 0 : _possibleValues.GetSetHashCode();
public override string ToString() =>
_possibleValues == null
@@ -104,7 +104,7 @@ public override string ToString() =>
internal static class NodeImplUtils
{
- public static bool SetEquals(T[] a, T[] b)
+ public static bool SetEquals(T[]? a, T[]? b)
{
if (a == null && b == null) return true;
if (a == null || b == null) return false;
@@ -112,7 +112,7 @@ public static bool SetEquals(T[] a, T[] b)
return new HashSet(a).SetEquals(b);
}
- public static ValueInfo ConstantInfoForSideBySide(IEnumerable> nodes)
+ public static ValueInfo ConstantInfoForSideBySide(IEnumerable> nodes) where T : notnull
{
using (var enumerator = nodes.GetEnumerator())
{
@@ -136,6 +136,7 @@ public static ValueInfo ConstantInfoForSideBySide(IEnumerable(IEnumerable layersReversed)
+ where T : notnull
where TLayer : ILayer
{
return layersReversed.Any(x =>
@@ -144,6 +145,7 @@ public static bool AlwaysAppliedForOverriding(IEnumerable lay
}
public static ValueInfo ConstantInfoForOverriding(IEnumerable layersReversed)
+ where T : notnull
where TLayer : ILayer
{
var allPossibleValues = new HashSet();
@@ -183,7 +185,7 @@ public static bool IsAlwaysOverride(this TLayer layer)
}
public static IEnumerable WhileApplied(this IEnumerable layer)
- where TLayer : ILayer
+ where TLayer : ILayer
{
foreach (var layerInfo in layer)
{
@@ -201,6 +203,7 @@ interface ILayer
}
internal interface ILayer : ILayer
+ where T : notnull
{
new AnimatorWeightState Weight { get; }
new AnimatorLayerBlendingMode BlendingMode { get; }
@@ -208,6 +211,7 @@ internal interface ILayer : ILayer
}
internal sealed class RootPropModNode : PropModNode, IErrorContext
+ where T : notnull
{
internal readonly struct ComponentInfo
{
@@ -230,7 +234,10 @@ public ComponentInfo(ComponentPropModNodeBase node, bool alwaysApplied)
public IEnumerable Children => _children;
public override bool AppliedAlways => _children.All(x => x.AppliedAlways);
- public override IEnumerable ContextReferences => _children.SelectMany(x => x.ContextReferences);
+
+ public override IEnumerable ContextReferences =>
+ _children.SelectMany(x => x.ContextReferences);
+
public override ValueInfo Value => NodeImplUtils.ConstantInfoForSideBySide(_children.Select(x => x.Node));
public bool IsEmpty => _children.Count == 0;
@@ -243,8 +250,8 @@ public void Add(ComponentPropModNodeBase node, bool alwaysApplied)
_children.Add(new ComponentInfo(node, alwaysApplied));
DestroyTracker.Track(node.Component, OnDestroy);
}
-
- public void Add([NotNull] RootPropModNode toAdd)
+
+ public void Add(RootPropModNode toAdd)
{
if (toAdd == null) throw new ArgumentNullException(nameof(toAdd));
foreach (var child in toAdd._children)
@@ -263,20 +270,20 @@ public void Invalidate()
_children.Clear();
}
- [CanBeNull] public RootPropModNode Normalize() => IsEmpty ? null : this;
+ public RootPropModNode? Normalize() => IsEmpty ? null : this;
}
internal abstract class ImmutablePropModNode : PropModNode
+ where T : notnull
{
}
internal class FloatAnimationCurveNode : ImmutablePropModNode
{
- [NotNull] public AnimationCurve Curve { get; }
- [NotNull] public AnimationClip Clip { get; }
+ public AnimationCurve Curve { get; }
+ public AnimationClip Clip { get; }
- [CanBeNull]
- public static FloatAnimationCurveNode Create([NotNull] AnimationClip clip, EditorCurveBinding binding)
+ public static FloatAnimationCurveNode? Create(AnimationClip clip, EditorCurveBinding binding)
{
var curve = AnimationUtility.GetEditorCurve(clip, binding);
if (curve == null) return null;
@@ -284,7 +291,7 @@ public static FloatAnimationCurveNode Create([NotNull] AnimationClip clip, Edito
return new FloatAnimationCurveNode(clip, curve);
}
- private FloatAnimationCurveNode([NotNull] AnimationClip clip, [NotNull] AnimationCurve curve)
+ private FloatAnimationCurveNode(AnimationClip clip, AnimationCurve curve)
{
if (!clip) throw new ArgumentNullException(nameof(clip));
if (curve == null) throw new ArgumentNullException(nameof(curve));
@@ -298,7 +305,7 @@ private FloatAnimationCurveNode([NotNull] AnimationClip clip, [NotNull] Animatio
public override bool AppliedAlways => true;
public override ValueInfo Value => _constantInfo.Value;
- public override IEnumerable ContextReferences => new []{ ObjectRegistry.GetReference(Clip) };
+ public override IEnumerable ContextReferences => new[] { ObjectRegistry.GetReference(Clip) };
private static ValueInfo ParseProperty(AnimationCurve curve)
{
@@ -328,8 +335,7 @@ internal class ObjectAnimationCurveNode : ImmutablePropModNode
public ObjectReferenceKeyframe[] Frames { get; set; }
public AnimationClip Clip { get; }
- [CanBeNull]
- public static ObjectAnimationCurveNode Create([NotNull] AnimationClip clip, EditorCurveBinding binding)
+ public static ObjectAnimationCurveNode? Create(AnimationClip clip, EditorCurveBinding binding)
{
var curve = AnimationUtility.GetObjectReferenceCurve(clip, binding);
if (curve == null) return null;
@@ -350,18 +356,19 @@ private ObjectAnimationCurveNode(AnimationClip clip, ObjectReferenceKeyframe[] f
public override bool AppliedAlways => true;
public override ValueInfo Value => _constantInfo.Value;
- public override IEnumerable ContextReferences => new []{ ObjectRegistry.GetReference(Clip) };
+ public override IEnumerable ContextReferences => new[] { ObjectRegistry.GetReference(Clip) };
private static ValueInfo ParseProperty(ObjectReferenceKeyframe[] frames) =>
new ValueInfo(frames.Select(x => x.value).Distinct().ToArray());
}
internal struct BlendTreeElement
+ where T : notnull
{
public int Index;
public ImmutablePropModNode Node;
- public BlendTreeElement(int index, [NotNull] ImmutablePropModNode node)
+ public BlendTreeElement(int index, ImmutablePropModNode node)
{
Index = index;
Node = node ?? throw new ArgumentNullException(nameof(node));
@@ -369,12 +376,14 @@ public BlendTreeElement(int index, [NotNull] ImmutablePropModNode node)
}
internal class BlendTreeNode : ImmutablePropModNode
+ where T : notnull
{
private readonly List> _children;
private readonly BlendTreeType _blendTreeType;
private readonly bool _partial;
- public BlendTreeNode([NotNull] List> children, BlendTreeType blendTreeType, bool partial)
+ public BlendTreeNode(List> children,
+ BlendTreeType blendTreeType, bool partial)
{
// expected to pass list or array
// ReSharper disable once PossibleMultipleEnumeration
@@ -389,6 +398,7 @@ public BlendTreeNode([NotNull] List> children, BlendTreeType
private bool WeightSumIsOne => _blendTreeType != BlendTreeType.Direct;
public IReadOnlyList> Children => _children;
public override bool AppliedAlways => WeightSumIsOne && !_partial && _children.All(x => x.Node.AppliedAlways);
+
public override ValueInfo Value => !WeightSumIsOne
? ValueInfo.Variable
: NodeImplUtils.ConstantInfoForSideBySide(_children.Select(x => x.Node));
@@ -398,8 +408,9 @@ public BlendTreeNode([NotNull] List> children, BlendTreeType
}
abstract class ComponentPropModNodeBase : PropModNode
+ where T : notnull
{
- protected ComponentPropModNodeBase([NotNull] Component component)
+ protected ComponentPropModNodeBase(Component component)
{
if (!component) throw new ArgumentNullException(nameof(component));
Component = component;
@@ -407,13 +418,15 @@ protected ComponentPropModNodeBase([NotNull] Component component)
public Component Component { get; }
- public override IEnumerable ContextReferences => new [] { ObjectRegistry.GetReference(Component) };
+ public override IEnumerable ContextReferences =>
+ new[] { ObjectRegistry.GetReference(Component) };
}
abstract class ComponentPropModNode : ComponentPropModNodeBase
+ where T : notnull
where TComponent : Component
{
- protected ComponentPropModNode([NotNull] TComponent component) : base(component)
+ protected ComponentPropModNode(TComponent component) : base(component)
{
if (!component) throw new ArgumentNullException(nameof(component));
Component = component;
@@ -421,12 +434,14 @@ protected ComponentPropModNode([NotNull] TComponent component) : base(component)
public new TComponent Component { get; }
- public override IEnumerable ContextReferences => new [] { ObjectRegistry.GetReference(Component) };
+ public override IEnumerable ContextReferences =>
+ new[] { ObjectRegistry.GetReference(Component) };
}
class VariableComponentPropModNode : ComponentPropModNode
+ where T : notnull
{
- public VariableComponentPropModNode([NotNull] Component component) : base(component)
+ public VariableComponentPropModNode(Component component) : base(component)
{
}
@@ -435,10 +450,11 @@ public VariableComponentPropModNode([NotNull] Component component) : base(compon
}
class AnimationComponentPropModNode : ComponentPropModNode
+ where T : notnull
{
public ImmutablePropModNode Animation { get; }
- public AnimationComponentPropModNode([NotNull] Animation component, ImmutablePropModNode animation) : base(component)
+ public AnimationComponentPropModNode(Animation component, ImmutablePropModNode animation) : base(component)
{
Animation = animation;
_constantInfo = new Lazy>(() => animation.Value, isThreadSafe: false);
diff --git a/Editor/AnimatorParserV2/Utilities.cs b/Editor/AnimatorParserV2/Utilities.cs
index 349a46b51..19c3f1f55 100644
--- a/Editor/AnimatorParserV2/Utilities.cs
+++ b/Editor/AnimatorParserV2/Utilities.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using JetBrains.Annotations;
+using System.Diagnostics.CodeAnalysis;
using UnityEditor.Animations;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -23,7 +23,13 @@ public static TResultContainer Merge<
TSourceObjectNode,
TMerger
- >([NotNull] [ItemNotNull] IEnumerable sources, TMerger merger)
+ >(IEnumerable sources, TMerger merger)
+ where TSource : notnull
+ where TIntermediateFloat : notnull
+ where TIntermediateObject : notnull
+ where TSourceFloatNode : notnull
+ where TSourceObjectNode : notnull
+
where TResultContainer : NodeContainerBase
where TResultFloatNode : PropModNode
where TResultObjectNode : PropModNode
@@ -93,25 +99,29 @@ interface IMergeProperty1 <
where TResultFloatNode : PropModNode
where TResultObjectNode : PropModNode
where TSourceContainer : INodeContainer
+
+ where TSource : notnull
+ where TIntermediateFloat : notnull
+ where TIntermediateObject : notnull
+ where TSourceFloatNode : notnull
+ where TSourceObjectNode : notnull
{
- [NotNull] TResultContainer CreateContainer();
+ TResultContainer CreateContainer();
- [CanBeNull] TSourceContainer GetContainer([NotNull] TSource source);
+ TSourceContainer? GetContainer(TSource source);
- [NotNull] TIntermediateFloat GetIntermediate([NotNull] TSource source, [NotNull] TSourceFloatNode node, int index);
- [NotNull] TIntermediateObject GetIntermediate([NotNull] TSource source, [NotNull] TSourceObjectNode node, int index);
+ TIntermediateFloat GetIntermediate(TSource source, TSourceFloatNode node, int index);
+ TIntermediateObject GetIntermediate(TSource source, TSourceObjectNode node, int index);
- [CanBeNull] TResultFloatNode MergeNode([NotNull] [ItemNotNull] List nodes, int sourceCount);
- [CanBeNull] TResultObjectNode MergeNode([NotNull] [ItemNotNull] List nodes, int sourceCount);
+ TResultFloatNode? MergeNode(List nodes, int sourceCount);
+ TResultObjectNode? MergeNode(List nodes, int sourceCount);
}
static partial class NodesMerger
{
- [CanBeNull]
- [ContractAnnotation("controller: null => null")]
- [ContractAnnotation("controller: notnull => notnull")]
- public static ComponentNodeContainer AnimatorComponentFromController([NotNull] Animator animator,
- [CanBeNull] AnimatorControllerNodeContainer controller)
+ [return:NotNullIfNotNull("controller")]
+ public static ComponentNodeContainer? AnimatorComponentFromController(Animator animator,
+ AnimatorControllerNodeContainer? controller)
{
if (controller == null) return null;
@@ -132,9 +142,8 @@ public static ComponentNodeContainer AnimatorComponentFromController([NotNull] A
return animatorNodeContainer;
}
- [NotNull]
- public static ComponentNodeContainer AnimationComponentFromAnimationClip([NotNull] Animation animation,
- [NotNull] ImmutableNodeContainer animationClip)
+ public static ComponentNodeContainer AnimationComponentFromAnimationClip(Animation animation,
+ ImmutableNodeContainer animationClip)
{
if (animationClip == null) throw new ArgumentNullException(nameof(animationClip));
var animatorNodeContainer = new ComponentNodeContainer();
@@ -153,12 +162,12 @@ public static ComponentNodeContainer AnimationComponentFromAnimationClip([NotNul
}
public static ComponentNodeContainer ComponentFromPlayableLayers(Animator animator,
- IEnumerable<(AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer)>
+ IEnumerable<(AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?)>
playableLayers) =>
Merge<
ComponentNodeContainer, ComponentPropModNodeBase, ComponentPropModNodeBase,
PlayableLayerNodeInfo, PlayableLayerNodeInfo,
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer),
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?),
AnimatorControllerNodeContainer, AnimatorControllerPropModNode,
AnimatorControllerPropModNode,
PlayableLayerMerger
@@ -167,7 +176,7 @@ public static ComponentNodeContainer ComponentFromPlayableLayers(Animator animat
readonly struct PlayableLayerMerger : IMergeProperty1<
ComponentNodeContainer, ComponentPropModNodeBase, ComponentPropModNodeBase,
PlayableLayerNodeInfo, PlayableLayerNodeInfo,
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer),
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?),
AnimatorControllerNodeContainer, AnimatorControllerPropModNode, AnimatorControllerPropModNode
>
{
@@ -177,17 +186,17 @@ public static ComponentNodeContainer ComponentFromPlayableLayers(Animator animat
public ComponentNodeContainer CreateContainer() => new ComponentNodeContainer();
- public AnimatorControllerNodeContainer GetContainer(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer) source) =>
+ public AnimatorControllerNodeContainer? GetContainer(
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?) source) =>
source.Item3;
public PlayableLayerNodeInfo GetIntermediate(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer) source,
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?) source,
AnimatorControllerPropModNode node, int index) =>
new PlayableLayerNodeInfo(source.Item1, source.Item2, node, index);
public PlayableLayerNodeInfo GetIntermediate(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer) source,
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorControllerNodeContainer?) source,
AnimatorControllerPropModNode node, int index) =>
new PlayableLayerNodeInfo(source.Item1, source.Item2, node, index);
@@ -199,11 +208,11 @@ public ComponentPropModNodeBase MergeNode(List layers) =>
+ IEnumerable<(AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?)> layers) =>
Merge<
AnimatorControllerNodeContainer, AnimatorControllerPropModNode, AnimatorControllerPropModNode,
AnimatorLayerNodeInfo, AnimatorLayerNodeInfo,
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer),
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?),
AnimatorLayerNodeContainer, AnimatorLayerPropModNode, AnimatorLayerPropModNode,
AnimatorLayerMerger
>(layers, default);
@@ -212,31 +221,31 @@ private struct AnimatorLayerMerger : IMergeProperty1<
AnimatorControllerNodeContainer, AnimatorControllerPropModNode, AnimatorControllerPropModNode
,
AnimatorLayerNodeInfo, AnimatorLayerNodeInfo,
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer),
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?),
AnimatorLayerNodeContainer, AnimatorLayerPropModNode, AnimatorLayerPropModNode
>
{
public AnimatorControllerNodeContainer CreateContainer() => new AnimatorControllerNodeContainer();
- public AnimatorLayerNodeContainer GetContainer(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer) source) =>
+ public AnimatorLayerNodeContainer? GetContainer(
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?) source) =>
source.Item3;
public AnimatorLayerNodeInfo GetIntermediate(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer) source,
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?) source,
AnimatorLayerPropModNode node, int index) =>
new AnimatorLayerNodeInfo(source.Item1, source.Item2, node, index);
public AnimatorLayerNodeInfo GetIntermediate(
- (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer) source,
+ (AnimatorWeightState, AnimatorLayerBlendingMode, AnimatorLayerNodeContainer?) source,
AnimatorLayerPropModNode node, int index) =>
new AnimatorLayerNodeInfo(source.Item1, source.Item2, node, index);
- public AnimatorControllerPropModNode MergeNode(List> nodes,
+ public AnimatorControllerPropModNode? MergeNode(List> nodes,
int sourceCount) =>
AnimatorControllerPropModNode.Create(nodes);
- public AnimatorControllerPropModNode MergeNode(List> nodes,
+ public AnimatorControllerPropModNode? MergeNode(List> nodes,
int sourceCount) =>
AnimatorControllerPropModNode.Create(nodes);
}
diff --git a/Editor/AssetDescription.cs b/Editor/AssetDescription.cs
index c740bfd47..645d1e4de 100644
--- a/Editor/AssetDescription.cs
+++ b/Editor/AssetDescription.cs
@@ -14,7 +14,10 @@ internal class AssetDescription : ScriptableObject
{
[SerializeField]
[TextArea]
+ // only for serialization so ignore warning
+#pragma warning disable CS0414
private string comment = "";
+#pragma warning restore CS0414
[SerializeField]
private ClassReference[] meaninglessComponents = Array.Empty();
@@ -36,7 +39,7 @@ public static IEnumerable GetMeaninglessComponents()
.SelectMany(description => description.meaninglessComponents)
.Select(component => GetMonoScriptFromGuid(component.guid, component.fileID) as MonoScript)
.Where(monoScript => monoScript != null)
- .Select(monoScript => monoScript.GetClass());
+ .Select(monoScript => monoScript!.GetClass());
}
private static Object GetMonoScriptFromGuid(string guid, ulong fileid)
@@ -49,8 +52,8 @@ private static Object GetMonoScriptFromGuid(string guid, ulong fileid)
[CustomEditor(typeof(AssetDescription))]
internal class AssetDescriptionEditor : Editor
{
- private SerializedProperty _comment;
- private SerializedProperty _meaninglessComponents;
+ private SerializedProperty _comment = null!; // Initialized by OnEnable
+ private SerializedProperty _meaninglessComponents = null!; // Initialized by OnEnable
private void OnEnable()
{
diff --git a/Editor/CheckForUpdate.cs b/Editor/CheckForUpdate.cs
index e321b79b5..d44efb5db 100644
--- a/Editor/CheckForUpdate.cs
+++ b/Editor/CheckForUpdate.cs
@@ -4,7 +4,6 @@
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
@@ -24,7 +23,7 @@ public static bool OutOfDate
private set => SessionState.SetBool("com.anatawa12.avatar-optimizer.out-of-date", value);
}
- public static string LatestVersionName
+ public static string? LatestVersionName
{
get => SessionState.GetString("com.anatawa12.avatar-optimizer.latest", "");
private set => SessionState.SetString("com.anatawa12.avatar-optimizer.latest", value);
@@ -61,8 +60,7 @@ static async void DoCheckForUpdate()
}
}
- [CanBeNull]
- static string GetCurrentVersion()
+ static string? GetCurrentVersion()
{
try
{
@@ -80,8 +78,7 @@ static string GetCurrentVersion()
}
}
- [ItemCanBeNull]
- static async Task GetLatestVersion(bool beta, string version)
+ static async Task GetLatestVersion(bool beta, string version)
{
var latestVersionUrl =
beta
@@ -112,7 +109,7 @@ static async Task GetLatestVersion(bool beta, string version)
// out of date or invalid cached version
- string fetchedLatestVersion = null;
+ string? fetchedLatestVersion = null;
try
{
using (var client = new HttpClient())
@@ -158,7 +155,7 @@ static async Task GetLatestVersion(bool beta, string version)
[Serializable]
class PackageJson
{
- public string version;
+ public string? version;
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/ContextExtensions.cs b/Editor/ContextExtensions.cs
index 1fff440fc..9d81d5a9e 100644
--- a/Editor/ContextExtensions.cs
+++ b/Editor/ContextExtensions.cs
@@ -1,8 +1,5 @@
using System;
using Anatawa12.AvatarOptimizer.AnimatorParsersV2;
-using Anatawa12.AvatarOptimizer.Processors;
-using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes;
-using JetBrains.Annotations;
using nadena.dev.ndmf;
using UnityEngine;
@@ -10,53 +7,53 @@ namespace Anatawa12.AvatarOptimizer
{
internal static class ContextExtensions
{
- public static T[] GetComponents([NotNull] this BuildContext context) where T : Component
+ public static T[] GetComponents(this BuildContext context) where T : Component
{
if (context == null) throw new ArgumentNullException(nameof(context));
return context.AvatarRootObject.GetComponentsInChildren(true);
}
- public static ObjectMappingBuilder GetMappingBuilder([NotNull] this BuildContext context)
+ public static ObjectMappingBuilder GetMappingBuilder(this BuildContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
- return context.Extension().MappingBuilder;
+ return context.Extension().MappingBuilder!; // activated so not null
}
- public static void RecordMergeComponent([NotNull] this BuildContext context, T from, T mergeTo)
+ public static void RecordMergeComponent(this BuildContext context, T from, T mergeTo)
where T : Component =>
GetMappingBuilder(context).RecordMergeComponent(from, mergeTo);
- public static void RecordMoveProperties([NotNull] this BuildContext context, Component from,
+ public static void RecordMoveProperties(this BuildContext context, Component from,
params (string old, string @new)[] props) =>
GetMappingBuilder(context).RecordMoveProperties(from, props);
- public static void RecordMoveProperty([NotNull] this BuildContext context, Component from, string oldProp,
+ public static void RecordMoveProperty(this BuildContext context, Component from, string oldProp,
string newProp) =>
GetMappingBuilder(context).RecordMoveProperty(from, oldProp, newProp);
- public static void RecordRemoveProperty([NotNull] this BuildContext context, Component from, string oldProp) =>
+ public static void RecordRemoveProperty(this BuildContext context, Component from, string oldProp) =>
GetMappingBuilder(context).RecordRemoveProperty(from, oldProp);
- public static AnimationComponentInfo GetAnimationComponent([NotNull] this BuildContext context,
+ public static AnimationComponentInfo GetAnimationComponent(this BuildContext context,
ComponentOrGameObject component) =>
GetMappingBuilder(context).GetAnimationComponent(component);
- public static bool? GetConstantValue([NotNull] this BuildContext context, ComponentOrGameObject obj,
+ public static bool? GetConstantValue(this BuildContext context, ComponentOrGameObject obj,
string property, bool currentValue) =>
!context.GetAnimationComponent(obj).TryGetFloat(property, out var node)
? currentValue
: node.AsConstantValue(currentValue);
- public static bool? AsConstantValue([CanBeNull] this PropModNode node, bool currentValue)
+ public static bool? AsConstantValue(this PropModNode? node, bool currentValue)
{
if (node == null) return currentValue;
- if (node.Value.PossibleValues is float[] values)
+ if (node.Value.PossibleValues is { } values)
{
bool? constValue = null;
foreach (var value in values)
{
var current = value != 0;
- if (!(constValue is bool b)) constValue = current;
+ if (constValue is not { } b) constValue = current;
else if (b != current) return null;
}
if (node.AppliedAlways || constValue == currentValue)
@@ -66,4 +63,4 @@ public static AnimationComponentInfo GetAnimationComponent([NotNul
return null;
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/EditModePreview/BlendShapePreviewContext.cs b/Editor/EditModePreview/BlendShapePreviewContext.cs
index e3060be37..694c6c2f7 100644
--- a/Editor/EditModePreview/BlendShapePreviewContext.cs
+++ b/Editor/EditModePreview/BlendShapePreviewContext.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
using System;
using System.Collections.Generic;
using System.Linq;
@@ -202,4 +204,4 @@ bool ZeroForWeightZero()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/EditModePreview/MeshPreviewController.cs b/Editor/EditModePreview/MeshPreviewController.cs
index 57ccdf36b..3dc5f653a 100644
--- a/Editor/EditModePreview/MeshPreviewController.cs
+++ b/Editor/EditModePreview/MeshPreviewController.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
using System;
using System.Linq;
using System.Reflection;
@@ -5,9 +7,6 @@
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
-#if !UNITY_2020_1_OR_NEWER
-using AnimationModeDriver = UnityEngine.Object;
-#endif
namespace Anatawa12.AvatarOptimizer.EditModePreview
{
@@ -242,39 +241,6 @@ public void StopPreview()
_previewController = null;
}
-#if !UNITY_2020_1_OR_NEWER
- private static AnimationModeDriver CreateDriver() =>
- ScriptableObject.CreateInstance(
- typeof(UnityEditor.AnimationMode).Assembly.GetType("UnityEditor.AnimationModeDriver"));
-#else
private static AnimationModeDriver CreateDriver() => ScriptableObject.CreateInstance();
-#endif
-
-#if !UNITY_2020_1_OR_NEWER
- public static class AnimationMode
- {
- public static void BeginSampling() => UnityEditor.AnimationMode.BeginSampling();
- public static void EndSampling() => UnityEditor.AnimationMode.EndSampling();
- public static bool InAnimationMode() => UnityEditor.AnimationMode.InAnimationMode();
- public static bool InAnimationMode(AnimationModeDriver o) => StartAnimationMode("InAnimationMode", o);
- public static void StartAnimationMode(AnimationModeDriver o) => StartAnimationMode("StartAnimationMode", o);
- public static void StopAnimationMode(AnimationModeDriver o) => StartAnimationMode("StopAnimationMode", o);
-
- public static void AddPropertyModification(EditorCurveBinding binding, PropertyModification modification,
- bool keepPrefabOverride) =>
- UnityEditor.AnimationMode.AddPropertyModification(binding, modification, keepPrefabOverride);
-
- private static R StartAnimationMode(string name, AnimationModeDriver o)
- {
- var method = typeof(UnityEditor.AnimationMode).GetMethod(name,
- BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
- null,
- new[] { typeof(AnimationModeDriver) },
- null);
- System.Diagnostics.Debug.Assert(method != null, nameof(method) + " != null");
- return (R)method.Invoke(null, new object[] { o });
- }
- }
-#endif
}
}
diff --git a/Editor/EditModePreview/RemoveMeshByBlendShapePreviewContext.cs b/Editor/EditModePreview/RemoveMeshByBlendShapePreviewContext.cs
index d429ce0af..ceb62c479 100644
--- a/Editor/EditModePreview/RemoveMeshByBlendShapePreviewContext.cs
+++ b/Editor/EditModePreview/RemoveMeshByBlendShapePreviewContext.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
using System;
using System.Collections.Generic;
using Unity.Collections;
@@ -51,4 +53,4 @@ public void Dispose()
_blendShapeMovements.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/EditModePreview/RemoveMeshPreviewController.cs b/Editor/EditModePreview/RemoveMeshPreviewController.cs
index 354fffdc1..a94858249 100644
--- a/Editor/EditModePreview/RemoveMeshPreviewController.cs
+++ b/Editor/EditModePreview/RemoveMeshPreviewController.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
diff --git a/Editor/EditModePreview/RemoveMeshWithBoxPreviewContext.cs b/Editor/EditModePreview/RemoveMeshWithBoxPreviewContext.cs
index b68bd2749..120afe852 100644
--- a/Editor/EditModePreview/RemoveMeshWithBoxPreviewContext.cs
+++ b/Editor/EditModePreview/RemoveMeshWithBoxPreviewContext.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
using System;
using JetBrains.Annotations;
using Unity.Burst;
@@ -155,4 +157,4 @@ public void Dispose()
_boneIndexStart.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/EditSkinnedMeshComponentUtil.cs b/Editor/EditSkinnedMeshComponentUtil.cs
index ed2682a9b..100c35770 100644
--- a/Editor/EditSkinnedMeshComponentUtil.cs
+++ b/Editor/EditSkinnedMeshComponentUtil.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
@@ -33,18 +32,17 @@ private static SkinnedMeshEditorSorter CreateSharedSorterWithScene()
public static (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent before) =>
EditorShared.GetBlendShapes(renderer, before);
- public static Material[] GetMaterials(SkinnedMeshRenderer renderer) => EditorShared.GetMaterials(renderer);
+ public static Material?[] GetMaterials(SkinnedMeshRenderer renderer) => EditorShared.GetMaterials(renderer);
// Rider's problem, to call GetMaterials(renderer, fast: false)
// ReSharper disable once MethodOverloadWithOptionalParameter
- public static Material[] GetMaterials(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent before = null,
+ public static Material?[] GetMaterials(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent? before = null,
bool fast = true) => EditorShared.GetMaterials(renderer, before, fast);
- [CanBeNull] private static SkinnedMeshEditorSorter _editorShared;
+ private static SkinnedMeshEditorSorter? _editorShared;
- [NotNull]
private static SkinnedMeshEditorSorter EditorShared =>
- _editorShared ?? (_editorShared = CreateSharedSorterWithScene());
+ _editorShared ??= CreateSharedSorterWithScene();
}
internal class SkinnedMeshEditorSorter
@@ -66,19 +64,18 @@ public bool IsModifiedByEditComponent(SkinnedMeshRenderer renderer) =>
public (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer renderer) => GetBlendShapes(renderer, null);
- public (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent before) =>
+ public (string name, float weight)[] GetBlendShapes(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent? before) =>
GetProcessors(renderer)?.GetBlendShapes(before) ?? SourceMeshInfoComputer.BlendShapes(renderer);
- public Material[] GetMaterials(SkinnedMeshRenderer renderer) => GetMaterials(renderer, null);
+ public Material?[] GetMaterials(SkinnedMeshRenderer renderer) => GetMaterials(renderer, null);
// Rider's problem, to call GetMaterials(renderer, fast: false)
// ReSharper disable once MethodOverloadWithOptionalParameter
- public Material[] GetMaterials(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent before = null,
+ public Material?[] GetMaterials(SkinnedMeshRenderer renderer, EditSkinnedMeshComponent? before = null,
bool fast = true) =>
GetProcessors(renderer)?.GetMaterials(before, fast) ?? SourceMeshInfoComputer.Materials(renderer);
- [CanBeNull]
- private SkinnedMeshProcessors GetProcessors(SkinnedMeshRenderer target)
+ private SkinnedMeshProcessors? GetProcessors(SkinnedMeshRenderer target)
{
ProcessorsByRenderer.TryGetValue(target, out var processors);
return processors;
@@ -87,7 +84,7 @@ private SkinnedMeshProcessors GetProcessors(SkinnedMeshRenderer target)
public IEnumerable GetSortedProcessors(
IEnumerable targets)
{
- var processors = new LinkedList(targets.Select(GetProcessors).Where(x => x != null));
+ var processors = new LinkedList(targets.Select(GetProcessors).Where(x => x != null)!);
var proceed = new HashSet();
foreach (var renderer in processors
@@ -114,8 +111,8 @@ internal class SkinnedMeshProcessors
{
internal readonly SkinnedMeshRenderer Target;
private readonly HashSet _processors = new HashSet();
- private List _sorted = new List();
- private IMeshInfoComputer[] _computers;
+ private List? _sorted = new List();
+ private IMeshInfoComputer[]? _computers;
public SkinnedMeshProcessors(SkinnedMeshRenderer target)
{
@@ -157,13 +154,13 @@ private IMeshInfoComputer[] GetComputers()
return _computers;
}
- private IMeshInfoComputer GetComputer(EditSkinnedMeshComponent before = null) => !before
+ private IMeshInfoComputer GetComputer(EditSkinnedMeshComponent? before = null) => !before
? GetComputers().Last()
- : GetComputers()[_sorted.FindIndex(x => x.Component == before)];
+ : GetComputers()[_sorted!.FindIndex(x => x.Component == before)];
- public (string, float)[] GetBlendShapes(EditSkinnedMeshComponent before = null) => GetComputer(before).BlendShapes();
+ public (string, float)[] GetBlendShapes(EditSkinnedMeshComponent? before = null) => GetComputer(before).BlendShapes();
- public Material[] GetMaterials(EditSkinnedMeshComponent before = null, bool fast = true) =>
+ public Material?[] GetMaterials(EditSkinnedMeshComponent? before = null, bool fast = true) =>
GetComputer(before).Materials(fast);
private class RecursiveDetector : IMeshInfoComputer
@@ -176,7 +173,7 @@ public RecursiveDetector(IMeshInfoComputer origin)
}
[ThreadStatic]
- private static HashSet _currentThreadDetectors;
+ private static HashSet? _currentThreadDetectors;
private T CheckRecursive(Func compute)
{
@@ -195,7 +192,7 @@ private T CheckRecursive(Func compute)
}
public (string, float)[] BlendShapes() => CheckRecursive(() => _origin.BlendShapes());
- public Material[] Materials(bool fast = true) => CheckRecursive(() => _origin.Materials(fast));
+ public Material?[] Materials(bool fast = true) => CheckRecursive(() => _origin.Materials(fast));
}
}
diff --git a/Editor/Inspector/AvatarGlobalComponentEditorBase.cs b/Editor/Inspector/AvatarGlobalComponentEditorBase.cs
index 459c934ce..6cac14492 100644
--- a/Editor/Inspector/AvatarGlobalComponentEditorBase.cs
+++ b/Editor/Inspector/AvatarGlobalComponentEditorBase.cs
@@ -1,13 +1,8 @@
using UnityEditor;
using UnityEngine;
-#if AAO_VRCSDK3_AVATARS
-using VRC.SDK3.Avatars.Components;
-#endif
-
namespace Anatawa12.AvatarOptimizer
{
- [InitializeOnLoad]
abstract class AvatarGlobalComponentEditorBase : AvatarTagComponentEditorBase
{
protected override void OnInspectorGUIInner()
diff --git a/Editor/Inspector/AvatarTagComponentEditorBase.cs b/Editor/Inspector/AvatarTagComponentEditorBase.cs
index 9afa73a34..42ce52f82 100644
--- a/Editor/Inspector/AvatarTagComponentEditorBase.cs
+++ b/Editor/Inspector/AvatarTagComponentEditorBase.cs
@@ -1,4 +1,3 @@
-using JetBrains.Annotations;
using UnityEditor;
namespace Anatawa12.AvatarOptimizer
@@ -16,9 +15,8 @@ public sealed override void OnInspectorGUI()
OnInspectorGUIInner();
}
- private string _descriptionKey;
- [CanBeNull]
- protected virtual string Description
+ private string? _descriptionKey;
+ protected virtual string? Description
{
get
{
diff --git a/Editor/Inspector/ClearEndpointPositionEditor.cs b/Editor/Inspector/ClearEndpointPositionEditor.cs
index 139d1a7c6..e69232dd3 100644
--- a/Editor/Inspector/ClearEndpointPositionEditor.cs
+++ b/Editor/Inspector/ClearEndpointPositionEditor.cs
@@ -34,4 +34,4 @@ protected override void OnInspectorGUIInner()
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/Editor/Inspector/FreezeBlendShapeEditor.cs b/Editor/Inspector/FreezeBlendShapeEditor.cs
index 01465a8b4..a03a53241 100644
--- a/Editor/Inspector/FreezeBlendShapeEditor.cs
+++ b/Editor/Inspector/FreezeBlendShapeEditor.cs
@@ -6,7 +6,7 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(FreezeBlendShape))]
class FreezeBlendShapeEditor : AvatarTagComponentEditorBase
{
- private PrefabSafeSet.EditorUtil _shapeKeysSet;
+ private PrefabSafeSet.EditorUtil _shapeKeysSet = null!; // initialized in OnEnable
private void OnEnable()
{
diff --git a/Editor/Inspector/MakeChildrenEditor.cs b/Editor/Inspector/MakeChildrenEditor.cs
index 51683d304..fc7f42d43 100644
--- a/Editor/Inspector/MakeChildrenEditor.cs
+++ b/Editor/Inspector/MakeChildrenEditor.cs
@@ -6,8 +6,8 @@ namespace Anatawa12.AvatarOptimizer
[CanEditMultipleObjects]
internal class MakeChildrenEditor : AvatarTagComponentEditorBase
{
- private SerializedProperty _executeEarly;
- private SerializedProperty _children;
+ private SerializedProperty _executeEarly = null!; // initialized in OnEnable
+ private SerializedProperty _children = null!; // initialized in OnEnable
private void OnEnable()
{
diff --git a/Editor/Inspector/MergePhysBoneEditor.cs b/Editor/Inspector/MergePhysBoneEditor.cs
index 02d503231..cf63bd513 100644
--- a/Editor/Inspector/MergePhysBoneEditor.cs
+++ b/Editor/Inspector/MergePhysBoneEditor.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using VRC.Dynamics;
@@ -13,9 +12,9 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(MergePhysBone))]
internal class MergePhysBoneEditor : AvatarTagComponentEditorBase
{
- private MergePhysBoneEditorRenderer _renderer;
- private SerializedProperty _makeParent;
- private SerializedProperty _componentsSetProp;
+ private MergePhysBoneEditorRenderer _renderer = null!; // initialized in OnEnable
+ private SerializedProperty _makeParent = null!; // initialized in OnEnable
+ private SerializedProperty _componentsSetProp = null!; // initialized in OnEnable
private void OnEnable()
{
@@ -170,7 +169,7 @@ protected override void PbVersionProp(string label,
{
// Copy mode
EditorGUI.BeginDisabledGroup(true);
- var differ = renderer(prop.SourceValue);
+ var differ = renderer(prop.SourceValue!);
EditorGUI.EndDisabledGroup();
EditorGUI.BeginProperty(overrideRect, null, prop.IsOverrideProperty);
@@ -359,10 +358,10 @@ void DrawCurve(string curveLabel, SerializedProperty curveProp)
private static readonly string[] CopyOverride = { "C:Copy", "O:Override" };
- private void PbPropImpl([NotNull] string label,
- [NotNull] OverridePropBase prop,
+ private void PbPropImpl(string label,
+ OverridePropBase prop,
bool forceOverride,
- [NotNull] Func renderer)
+ Func renderer)
{
var labelContent = new GUIContent(label);
@@ -420,7 +419,7 @@ protected override void CollidersProp(string label, CollidersConfigProp prop)
{
case MergePhysBone.CollidersConfig.CollidersOverride.Copy:
{
- var colliders = prop.PhysBoneValue;
+ var colliders = prop.PhysBoneValue!;
var height = EditorGUI.GetPropertyHeight(colliders, null, true);
@@ -496,7 +495,7 @@ private void EndpointPositionProp(string label, EndpointPositionConfigProp prop)
break;
case MergePhysBone.EndPointPositionConfig.Override.Copy:
{
- var valueProperty = prop.PhysBoneValue;
+ var valueProperty = prop.PhysBoneValue!;
var height = EditorGUI.GetPropertyHeight(valueProperty, null, true);
@@ -607,7 +606,7 @@ protected override void TransformSection()
if (EndpointPosition.OverrideProperty.enumValueIndex ==
(int)MergePhysBone.EndPointPositionConfig.Override.Copy)
{
- if (EndpointPosition.PhysBoneValue.hasMultipleDifferentValues)
+ if (EndpointPosition.PhysBoneValue!.hasMultipleDifferentValues)
_differProps.Add("Endpoint Position");
}
@@ -649,10 +648,10 @@ protected override void Pb3DCurveProp(string label,
{
if (forceOverride || prop.IsOverride) return;
- if (prop.SourceValue.hasMultipleDifferentValues
- || prop.SourceCurveX.hasMultipleDifferentValues
- || prop.SourceCurveY.hasMultipleDifferentValues
- || prop.SourceCurveZ.hasMultipleDifferentValues)
+ if (prop.SourceValue!.hasMultipleDifferentValues
+ || prop.SourceCurveX!.hasMultipleDifferentValues
+ || prop.SourceCurveY!.hasMultipleDifferentValues
+ || prop.SourceCurveZ!.hasMultipleDifferentValues)
_differProps.Add(label);
_usingCopyCurve |= prop.GetCurveXProperty(false).animationCurveValue.length > 0;
@@ -664,10 +663,10 @@ protected override void PbPermissionProp(string label, PermissionConfigProp prop
{
if (forceOverride || prop.IsOverride) return;
- if (prop.SourceValue.enumValueIndex == 2)
+ if (prop.SourceValue!.enumValueIndex == 2)
{
if (prop.SourceValue.hasMultipleDifferentValues
- || prop.SourceFilter.hasMultipleDifferentValues)
+ || prop.SourceFilter!.hasMultipleDifferentValues)
_differProps.Add(label);
}
else
@@ -682,7 +681,7 @@ protected override void CollidersProp(string label, CollidersConfigProp prop)
// 0: copy
if (prop.OverrideProperty.enumValueIndex == 0)
{
- if (prop.PhysBoneValue.hasMultipleDifferentValues)
+ if (prop.PhysBoneValue!.hasMultipleDifferentValues)
_differProps.Add(label);
}
}
diff --git a/Editor/Inspector/MergeSkinnedMeshEditor.cs b/Editor/Inspector/MergeSkinnedMeshEditor.cs
index d317a3cfe..f9077b72f 100644
--- a/Editor/Inspector/MergeSkinnedMeshEditor.cs
+++ b/Editor/Inspector/MergeSkinnedMeshEditor.cs
@@ -23,11 +23,11 @@ private static class Style
};
}
- SerializedProperty _renderersSetProp;
- SerializedProperty _staticRenderersSetProp;
- SerializedProperty _removeEmptyRendererObjectProp;
- SerializedProperty _skipEnablementMismatchedRenderers;
- PrefabSafeSet.EditorUtil _doNotMergeMaterials;
+ SerializedProperty _renderersSetProp = null!; // initialized in OnEnable
+ SerializedProperty _staticRenderersSetProp = null!; // initialized in OnEnable
+ SerializedProperty _removeEmptyRendererObjectProp = null!; // initialized in OnEnable
+ SerializedProperty _skipEnablementMismatchedRenderers = null!; // initialized in OnEnable
+ PrefabSafeSet.EditorUtil _doNotMergeMaterials = null!; // initialized in OnEnable
private void OnEnable()
{
@@ -40,7 +40,7 @@ private void OnEnable()
_doNotMergeMaterials = PrefabSafeSet.EditorUtil.Create(
serializedObject.FindProperty("doNotMergeMaterials"),
nestCount,
- x => x.objectReferenceValue as Material,
+ x => (Material)x.objectReferenceValue,
(x, v) => x.objectReferenceValue = v);
}
@@ -68,7 +68,7 @@ protected override void OnInspectorGUIInner()
public void MergeMaterials(MergeSkinnedMesh merge)
{
- var materials = new HashSet();
+ var materials = new HashSet();
var renderersSetAsList = merge.renderersSet.GetAsList();
var staticRenderersSetAsList = merge.staticRenderersSet.GetAsList();
var ofRenderers = renderersSetAsList.Select(EditSkinnedMeshComponentUtil.GetMaterials);
@@ -77,6 +77,7 @@ public void MergeMaterials(MergeSkinnedMesh merge)
.SelectMany((x, renderer) => x.Select((mat, material) => (mat, renderer, material)))
.GroupBy(x => x.mat))
{
+ if (group.Key == null) continue;
materials.Add(group.Key);
if (group.Count() == 1)
{
diff --git a/Editor/Inspector/MergeToonLitMaterialEditor.cs b/Editor/Inspector/MergeToonLitMaterialEditor.cs
index a9adfdbe7..f0442568d 100644
--- a/Editor/Inspector/MergeToonLitMaterialEditor.cs
+++ b/Editor/Inspector/MergeToonLitMaterialEditor.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes;
using UnityEditor;
@@ -11,20 +12,19 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(MergeToonLitMaterial))]
internal class MergeToonLitMaterialEditor : AvatarTagComponentEditorBase
{
- private Material[] _upstreamMaterials;
- private (Material mat, int index)[] _materials;
+ private Material?[] _upstreamMaterials = null!; // initialized in OnEnable
+ private (Material mat, int index)[] _materials = null!; // initialized in OnEnable
- private (Material mat, int index)[] _candidateMaterials;
- private string[] _candidateNames;
+ private (Material mat, int index)[] _candidateMaterials = null!; // initialized in OnEnable
+ private string[] _candidateNames = null!; // initialized in OnEnable
- private Texture[] _generatedPreviews;
+ private Texture[]? _generatedPreviews;
private readonly Func _createNewSource;
private readonly Func _createNewMergeInfo;
public MergeToonLitMaterialEditor()
{
- // ReSharper disable once PossibleNullReferenceException
_createNewSource = () => new MergeToonLitMaterial.MergeSource
{ materialIndex = _candidateMaterials[0].index };
_createNewMergeInfo = () => new MergeToonLitMaterial.MergeInfo
@@ -32,15 +32,15 @@ public MergeToonLitMaterialEditor()
}
private static void DrawList(
- ref T[] array,
+ [AllowNull] ref T[] array,
string addButton,
Action drawer,
- Func newElement,
+ Func? newElement,
bool noEmpty = false,
- Action postButtons = null,
- Action onMoved = null,
- Action onRemoved = null,
- Action onAdded = null
+ Action? postButtons = null,
+ Action? onMoved = null,
+ Action? onRemoved = null,
+ Action? onAdded = null
)
{
if (array == null) array = Array.Empty();
@@ -85,10 +85,10 @@ private static void DrawList(
using (new EditorGUI.DisabledScope(newElement == null))
if (GUILayout.Button(addButton))
{
- Debug.Assert(newElement != null, nameof(newElement) + " != null");
+ if (newElement == null) throw new InvalidOperationException();
T element;
ArrayUtility.Add(ref array, element = newElement());
- onAdded(element);
+ onAdded?.Invoke(element);
}
}
@@ -101,7 +101,7 @@ protected override void OnInspectorGUIInner()
DrawList(ref component.merges, AAOL10N.Tr("MergeToonLitMaterial:button:Add Merged Material"), (componentMerge, i) =>
{
- DrawList(ref componentMerge.source, AAOL10N.Tr("MergeToonLitMaterial:button:Add Source"), (mergeSource, _2) =>
+ DrawList(ref componentMerge.source, AAOL10N.Tr("MergeToonLitMaterial:button:Add Source"), (mergeSource, _) =>
{
var found = _materials.FirstOrDefault(x => x.index == mergeSource.materialIndex);
_candidateNames[0] = found.mat != null ? found.mat.name : "(invalid)";
@@ -166,8 +166,8 @@ private void OnEnable()
.GetMaterials(component.GetComponent(), component);
_materials = _upstreamMaterials
.Select((mat, index) => (mat, index))
- .Where(x => x.mat.shader == Assets.ToonLitShader)
- .ToArray();
+ .Where(x => x.mat?.shader == Assets.ToonLitShader)
+ .ToArray()!;
OnChanged(dirty: false);
}
}
diff --git a/Editor/Inspector/RemoveMeshByBlendShapeEditor.cs b/Editor/Inspector/RemoveMeshByBlendShapeEditor.cs
index 25c1e74e8..efd0e48a5 100644
--- a/Editor/Inspector/RemoveMeshByBlendShapeEditor.cs
+++ b/Editor/Inspector/RemoveMeshByBlendShapeEditor.cs
@@ -7,9 +7,9 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(RemoveMeshByBlendShape))]
internal class RemoveMeshByBlendShapeEditor : AvatarTagComponentEditorBase
{
- private PrefabSafeSet.EditorUtil _shapeKeysSet;
- private SerializedProperty _toleranceProp;
- private SkinnedMeshRenderer _renderer;
+ private PrefabSafeSet.EditorUtil _shapeKeysSet = null!; // initialized in OnEnable
+ private SerializedProperty _toleranceProp = null!; // initialized in OnEnable
+ private SkinnedMeshRenderer? _renderer;
public bool automaticallySetWeightWhenToggle;
private void OnEnable()
@@ -31,7 +31,7 @@ protected override void OnInspectorGUIInner()
EditModePreview.MeshPreviewController.ShowPreviewControl(component);
- if (!_renderer)
+ if (_renderer == null)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ToggleLeft(
@@ -86,7 +86,7 @@ protected override void OnInspectorGUIInner()
if (existence != element.Contains)
{
element.SetExistence(existence);
- if (automaticallySetWeightWhenToggle)
+ if (automaticallySetWeightWhenToggle && _renderer != null)
{
var shapeIndex = _renderer.sharedMesh.GetBlendShapeIndex(shapeKeyName);
if (shapeIndex != -1)
diff --git a/Editor/Inspector/RemoveMeshByMaskEditor.cs b/Editor/Inspector/RemoveMeshByMaskEditor.cs
index b05fb9018..e2a4c8b7c 100644
--- a/Editor/Inspector/RemoveMeshByMaskEditor.cs
+++ b/Editor/Inspector/RemoveMeshByMaskEditor.cs
@@ -1,5 +1,3 @@
-using System.Linq;
-using JetBrains.Annotations;
using Unity.Collections;
using UnityEditor;
using UnityEngine;
@@ -9,8 +7,8 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(RemoveMeshByMask))]
internal class RemoveMeshByMaskEditor : AvatarTagComponentEditorBase
{
- private SerializedProperty _materials;
- private SkinnedMeshRenderer _renderer;
+ private SerializedProperty _materials = null!; // Initialized in OnEnable
+ private SkinnedMeshRenderer _renderer = null!; // Initialized in OnEnable
public bool automaticallySetWeightWhenToggle;
private void OnEnable()
@@ -107,7 +105,7 @@ protected override void OnInspectorGUIInner()
serializedObject.ApplyModifiedProperties();
}
- [CanBeNull] TextureImporter GetTextureImporter(Texture2D texture)
+ TextureImporter? GetTextureImporter(Texture2D texture)
{
var path = AssetDatabase.GetAssetPath(texture);
if (string.IsNullOrEmpty(path))
diff --git a/Editor/Inspector/RemoveMeshInBoxEditor.cs b/Editor/Inspector/RemoveMeshInBoxEditor.cs
index 5d432b6b0..d0ee15725 100644
--- a/Editor/Inspector/RemoveMeshInBoxEditor.cs
+++ b/Editor/Inspector/RemoveMeshInBoxEditor.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
@@ -10,8 +9,8 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(RemoveMeshInBox))]
internal class RemoveMeshInBoxEditor : AvatarTagComponentEditorBase
{
- private SerializedProperty _boxes;
- private string _editingBoxPropPath;
+ private SerializedProperty _boxes = null!; // Initialized in OnEnable
+ private string? _editingBoxPropPath;
private readonly Dictionary _eulerAngles =
new Dictionary();
@@ -36,11 +35,11 @@ protected override void OnInspectorGUIInner()
[CustomPropertyDrawer(typeof(RemoveMeshInBox.BoundingBox))]
class BoundingBoxEditor : PropertyDrawer
{
- [CanBeNull] private static RemoveMeshInBoxEditor _upstreamEditor;
+ private static RemoveMeshInBoxEditor? _upstreamEditor;
public readonly struct EditorScope : IDisposable
{
- private readonly RemoveMeshInBoxEditor _oldEditor;
+ private readonly RemoveMeshInBoxEditor? _oldEditor;
public EditorScope(RemoveMeshInBoxEditor editor)
{
@@ -84,7 +83,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
using (new GUILayout.HorizontalScope())
{
- if (_upstreamEditor)
+ if (_upstreamEditor != null)
{
var editingCurrent = _upstreamEditor._editingBoxPropPath == property.propertyPath;
if (GUI.Button(position, editingCurrent ? "Finish Editing Box" : "Edit This Box"))
@@ -107,7 +106,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
EditorGUI.PropertyField(position, sizeProp);
position.y += EditorGUIUtility.standardVerticalSpacing + vector3Height;
- if (!_upstreamEditor ||
+ if (_upstreamEditor == null ||
!_upstreamEditor._eulerAngles.TryGetValue(property.propertyPath, out var eulerCache) ||
eulerCache.value != rotationProp.quaternionValue)
{
@@ -127,7 +126,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
eulerCache = (quot, euler);
}
- if (_upstreamEditor)
+ if (_upstreamEditor != null)
_upstreamEditor._eulerAngles[property.propertyPath] = eulerCache;
EditorGUI.EndProperty();
diff --git a/Editor/Inspector/TraceAndOptimizeEditor.cs b/Editor/Inspector/TraceAndOptimizeEditor.cs
index 441d33873..e3adbafa8 100644
--- a/Editor/Inspector/TraceAndOptimizeEditor.cs
+++ b/Editor/Inspector/TraceAndOptimizeEditor.cs
@@ -6,18 +6,16 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(TraceAndOptimize))]
internal class TraceAndOptimizeEditor : AvatarGlobalComponentEditorBase
{
- private SerializedProperty _freezeBlendShape;
- private SerializedProperty _removeUnusedObjects;
- private SerializedProperty _preserveEndBone;
- private SerializedProperty _removeZeroSizedPolygons;
- private SerializedProperty _optimizePhysBone;
- private SerializedProperty _optimizeAnimator;
- private SerializedProperty _mergeSkinnedMesh;
- private SerializedProperty _allowShuffleMaterialSlots;
- private SerializedProperty _animatorOptimizerEnabled;
- private SerializedProperty _animatorOptimizerEnd;
- private SerializedProperty _mmdWorldCompatibility;
- private SerializedProperty _advancedSettings;
+ private SerializedProperty _freezeBlendShape = null!; // Initialized in OnEnable
+ private SerializedProperty _removeUnusedObjects = null!; // Initialized in OnEnable
+ private SerializedProperty _preserveEndBone = null!; // Initialized in OnEnable
+ private SerializedProperty _removeZeroSizedPolygons = null!; // Initialized in OnEnable
+ private SerializedProperty _optimizePhysBone = null!; // Initialized in OnEnable
+ private SerializedProperty _optimizeAnimator = null!; // Initialized in OnEnable
+ private SerializedProperty _mergeSkinnedMesh = null!; // Initialized in OnEnable
+ private SerializedProperty _allowShuffleMaterialSlots = null!; // Initialized in OnEnable
+ private SerializedProperty _mmdWorldCompatibility = null!; // Initialized in OnEnable
+ private SerializedProperty _advancedSettings = null!; // Initialized in OnEnable
private GUIContent _advancedSettingsLabel = new GUIContent();
private GUIContent _debugOptionsLabel = new GUIContent();
@@ -61,10 +59,6 @@ protected override void OnInspectorGUIInner()
EditorGUI.indentLevel--;
}
-#if !UNITY_2021_3_OR_NEWER
- if (_optimizeAnimator.boolValue)
- EditorGUILayout.HelpBox(AAOL10N.Tr("TraceAndOptimize:OptimizeAnimator:Unity2019"), MessageType.Info);
-#endif
_advancedSettingsLabel.text = AAOL10N.Tr("TraceAndOptimize:prop:advancedOptimization");
AdvancedOpened = EditorGUILayout.Foldout(AdvancedOpened, _advancedSettingsLabel);
if (AdvancedOpened)
diff --git a/Editor/Inspector/UnusedBonesByReferencesToolEditor.cs b/Editor/Inspector/UnusedBonesByReferencesToolEditor.cs
index 4020df5b2..8dfcf6552 100644
--- a/Editor/Inspector/UnusedBonesByReferencesToolEditor.cs
+++ b/Editor/Inspector/UnusedBonesByReferencesToolEditor.cs
@@ -9,8 +9,8 @@ namespace Anatawa12.AvatarOptimizer
[CustomEditor(typeof(UnusedBonesByReferencesTool))]
class UnusedBonesByReferencesToolEditor : AvatarGlobalComponentEditorBase
{
- private SerializedProperty _preserveEndBone;
- private SerializedProperty _detectExtraChild;
+ private SerializedProperty _preserveEndBone = null!; // Initialized in OnEnable
+ private SerializedProperty _detectExtraChild = null!; // Initialized in OnEnable
private void OnEnable()
{
@@ -61,4 +61,4 @@ protected override void OnInspectorGUIInner()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Editor/MaskTextureEditor/Inspector.cs b/Editor/MaskTextureEditor/Inspector.cs
index c362718d2..5f52783b2 100644
--- a/Editor/MaskTextureEditor/Inspector.cs
+++ b/Editor/MaskTextureEditor/Inspector.cs
@@ -77,7 +77,7 @@ public static void DrawFields(
EditorGUILayout.PropertyField(mode);
}
- private static Texture2D CreateTexture(Vector2Int size, Color color)
+ private static Texture2D? CreateTexture(Vector2Int size, Color color)
{
var path = EditorUtility.SaveFilePanelInProject(
AAOL10N.Tr("MaskTextureEditor:create"),
@@ -100,7 +100,7 @@ private static Texture2D CreateTexture(Vector2Int size, Color color)
AssetDatabase.ImportAsset(path);
- var importer = AssetImporter.GetAtPath(path) as TextureImporter;
+ var importer = (TextureImporter)AssetImporter.GetAtPath(path);
importer.isReadable = true;
importer.SaveAndReimport();
diff --git a/Editor/MaskTextureEditor/TexturePainter.cs b/Editor/MaskTextureEditor/TexturePainter.cs
index 2fc5dc536..c98fe0872 100644
--- a/Editor/MaskTextureEditor/TexturePainter.cs
+++ b/Editor/MaskTextureEditor/TexturePainter.cs
@@ -17,19 +17,19 @@ internal class TexturePainter : ScriptableObject
private Color _brushColor = Color.black;
[SerializeField]
- private RenderTexture _target = null;
+ private RenderTexture _target = null!; // Initialized by Init and Load
[SerializeField]
- private RenderTexture _buffer = null;
+ private RenderTexture _buffer = null!; // Initialized by Init and Load
[SerializeField]
- private Material _fillMaterial = null;
+ private Material _fillMaterial = null!; // Initialized by Init and Load
[SerializeField]
- private Material _paintMaterial = null;
+ private Material _paintMaterial = null!; // Initialized by Init and Load
[SerializeField]
- private Material _inverseMaterial = null;
+ private Material _inverseMaterial = null!; // Initialized by Init and Load
public float BrushSize { get => _brushSize; set => _brushSize = value; }
public Color BrushColor { get => _brushColor; set => _brushColor = value; }
@@ -114,11 +114,7 @@ public void Save(Texture2D texture)
{
RenderTexture.active = _target;
-#if UNITY_2021_2_OR_NEWER
texture.Reinitialize(_target.width, _target.height);
-#else
- texture.Resize(_target.width, _target.height);
-#endif
texture.ReadPixels(new Rect(Vector2.zero, TextureSize), 0, 0);
texture.Apply();
@@ -159,27 +155,27 @@ private void OnDestroy()
if (_target != null)
{
DestroyImmediate(_target);
- _target = null;
+ _target = null!; // resetting
}
if (_buffer != null)
{
DestroyImmediate(_buffer);
- _buffer = null;
+ _buffer = null!; // resetting
}
if (_fillMaterial != null)
{
DestroyImmediate(_fillMaterial);
- _fillMaterial = null;
+ _fillMaterial = null!; // resetting
}
if (_paintMaterial != null)
{
DestroyImmediate(_paintMaterial);
- _paintMaterial = null;
+ _paintMaterial = null!; // resetting
}
if (_inverseMaterial != null)
{
DestroyImmediate(_inverseMaterial);
- _inverseMaterial = null;
+ _inverseMaterial = null!; // resetting
}
}
}
diff --git a/Editor/MaskTextureEditor/TextureUndoStack.cs b/Editor/MaskTextureEditor/TextureUndoStack.cs
index a0fee039a..cbd91066b 100644
--- a/Editor/MaskTextureEditor/TextureUndoStack.cs
+++ b/Editor/MaskTextureEditor/TextureUndoStack.cs
@@ -20,13 +20,13 @@ private void Awake()
}
[SerializeField]
- private RenderTexture _target = null;
+ private RenderTexture _target = null!; // initialized by Init
[SerializeField]
- private List _stack = null;
+ private List _stack = null!; // initialized by Init
[SerializeField]
- private Counter _counter = null;
+ private Counter _counter = null!; // initialized by Init
public bool CanUndo => _counter.Count > 1;
public bool CanRedo => _counter.Count < _stack.Count;
@@ -131,12 +131,12 @@ private void OnDestroy()
DestroyImmediate(texture);
}
}
- _stack = null;
+ _stack = null!; // resetting
}
if (_counter != null)
{
DestroyImmediate(_counter);
- _counter = null;
+ _counter = null!; // resetting
}
}
}
diff --git a/Editor/MaskTextureEditor/UvMapDrawer.cs b/Editor/MaskTextureEditor/UvMapDrawer.cs
index f40c42afc..b3f550ba6 100644
--- a/Editor/MaskTextureEditor/UvMapDrawer.cs
+++ b/Editor/MaskTextureEditor/UvMapDrawer.cs
@@ -8,17 +8,17 @@ namespace Anatawa12.AvatarOptimizer.MaskTextureEditor
internal class UvMapDrawer : ScriptableObject
{
[SerializeField]
- private SkinnedMeshRenderer _renderer = null;
+ private SkinnedMeshRenderer _renderer = null!; // Initialized by Init
[SerializeField]
private int _subMesh = 0;
- private Mesh _mesh = null;
+ private Mesh? _mesh = null;
private int _meshDirtyCount = 0;
- private Vector2[] _points = null;
- private Vector3[] _buffer = null;
- private int[] _lineIndices = null;
- private int[] _removedLineIndices = null;
+ private Vector2[]? _points = null;
+ private Vector3[]? _buffer = null;
+ private int[]? _lineIndices = null;
+ private int[]? _removedLineIndices = null;
private void Awake()
{
@@ -45,6 +45,8 @@ public void Draw(Rect rect)
_meshDirtyCount = EditorUtility.GetDirtyCount(_mesh);
CollectPointsAndLineIndices();
+ _ = _buffer![0]; // initialized by CollectPointsAndLineIndices
+ _ = _points![0]; // initialized by CollectPointsAndLineIndices
}
// Draw the main texture if present
@@ -90,8 +92,8 @@ private void CollectPointsAndLineIndices()
}
else
{
- var lines = CollectLines(_mesh, _subMesh);
- _points = _mesh.uv;
+ var lines = CollectLines(_mesh!, _subMesh);
+ _points = _mesh!.uv;
_buffer = new Vector3[_points.Length];
_lineIndices = FlattenLineIndices(lines);
_removedLineIndices = new int[0];
diff --git a/Editor/MaskTextureEditor/Window.cs b/Editor/MaskTextureEditor/Window.cs
index a23260f85..fce301fef 100644
--- a/Editor/MaskTextureEditor/Window.cs
+++ b/Editor/MaskTextureEditor/Window.cs
@@ -37,13 +37,13 @@ private static class Events
private const float BrushSizeFactor = 0.1f;
[SerializeField]
- private SkinnedMeshRenderer _renderer = null;
+ private SkinnedMeshRenderer _renderer = null!; // Initialized by Open
[SerializeField]
private int _subMesh = 0;
[SerializeField]
- private Texture2D _texture = null;
+ private Texture2D? _texture = null;
[SerializeField]
private Vector2 _viewPosition = Vector2.zero;
@@ -58,23 +58,18 @@ private static class Events
private bool _requestResetView = true;
[SerializeField]
- private UvMapDrawer _uvMapDrawer = null;
+ private UvMapDrawer _uvMapDrawer = null!; // Initialized by Open
[SerializeField]
- private TexturePainter _texturePainter = null;
+ private TexturePainter _texturePainter = null!; // Initialized by Open
[SerializeField]
- private TextureUndoStack _textureUndoStack = null;
+ private TextureUndoStack _textureUndoStack = null!; // Initialized by Open
[SerializeField]
private int _previewTextureInstanceIdWhenSaved = 0;
-#if !UNITY_2020_2_OR_NEWER
- private bool hasUnsavedChanges = false;
- private string saveChangesMessage = string.Empty;
-#endif
-
- public static Window Instance
+ public static Window? Instance
{
get
{
@@ -148,7 +143,6 @@ public void SafeClose()
}
case 2:
{
- DiscardChanges();
Close();
break;
}
@@ -429,14 +423,9 @@ private void HandleEvents(Rect rect)
_viewPosition = Vector2.Max(_viewPosition, Vector2.zero);
}
-#if UNITY_2020_2_OR_NEWER
public override void SaveChanges()
{
base.SaveChanges();
-#else
- private void SaveChanges()
- {
-#endif
var path = AssetDatabase.GetAssetPath(_texture);
var texture = new Texture2D(0, 0);
@@ -448,7 +437,7 @@ private void SaveChanges()
AssetDatabase.ImportAsset(path);
- var importer = AssetImporter.GetAtPath(path) as TextureImporter;
+ var importer = (TextureImporter)AssetImporter.GetAtPath(path);
importer.isReadable = true;
importer.SaveAndReimport();
@@ -469,32 +458,22 @@ private void SaveChanges()
}
}
-#if UNITY_2020_2_OR_NEWER
- public override void DiscardChanges()
- {
- base.DiscardChanges();
-#else
- private void DiscardChanges()
- {
-#endif
- }
-
private void OnDestroy()
{
if (_uvMapDrawer != null)
{
DestroyImmediate(_uvMapDrawer);
- _uvMapDrawer = null;
+ _uvMapDrawer = null!; // reset
}
if (_texturePainter != null)
{
DestroyImmediate(_texturePainter);
- _texturePainter = null;
+ _texturePainter = null!; // reset
}
if (_textureUndoStack != null)
{
DestroyImmediate(_textureUndoStack);
- _textureUndoStack = null;
+ _textureUndoStack = null!; // reset
}
}
}
diff --git a/Editor/MergePhysBoneEditorModificationUtils.cs b/Editor/MergePhysBoneEditorModificationUtils.cs
index 2a712f636..c2feee93c 100644
--- a/Editor/MergePhysBoneEditorModificationUtils.cs
+++ b/Editor/MergePhysBoneEditorModificationUtils.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
using UnityEditor;
using VRC.Dynamics;
using Object = UnityEngine.Object;
@@ -14,56 +13,56 @@ internal abstract partial class MergePhysBoneEditorModificationUtils
{
// ReSharper disable MemberCanBePrivate.Global
private readonly SerializedObject _serializedObject;
- private SerializedObject _sourcePhysBone;
+ private SerializedObject? _sourcePhysBone;
protected readonly SerializedProperty MakeParent;
private readonly List _props = new List();
- [NotNull] protected readonly ValueConfigProp Version;
+ protected readonly ValueConfigProp Version;
#region == Transform ==
// rootTransform
// ignoreTransforms
- [NotNull] protected readonly EndpointPositionConfigProp EndpointPosition;
+ protected readonly EndpointPositionConfigProp EndpointPosition;
// multiChildType
#endregion
#region == Forces ==
- [NotNull] protected readonly ValueConfigProp IntegrationType;
- [NotNull] protected readonly CurveConfigProp Pull;
+ protected readonly ValueConfigProp IntegrationType;
+ protected readonly CurveConfigProp Pull;
// spring a.k.a. Momentum
- [NotNull] protected readonly CurveConfigProp Spring;
- [NotNull] protected readonly CurveConfigProp Stiffness;
- [NotNull] protected readonly CurveConfigProp Gravity;
- [NotNull] protected readonly CurveConfigProp GravityFalloff;
- [NotNull] protected readonly ValueConfigProp ImmobileType;
- [NotNull] protected readonly CurveConfigProp Immobile;
+ protected readonly CurveConfigProp Spring;
+ protected readonly CurveConfigProp Stiffness;
+ protected readonly CurveConfigProp Gravity;
+ protected readonly CurveConfigProp GravityFalloff;
+ protected readonly ValueConfigProp ImmobileType;
+ protected readonly CurveConfigProp Immobile;
#endregion
#region == Limits ==
- [NotNull] protected readonly ValueConfigProp LimitType;
- [NotNull] protected readonly CurveConfigProp MaxAngleX;
- [NotNull] protected readonly CurveConfigProp MaxAngleZ;
- [NotNull] protected readonly CurveVector3ConfigProp LimitRotation;
+ protected readonly ValueConfigProp LimitType;
+ protected readonly CurveConfigProp MaxAngleX;
+ protected readonly CurveConfigProp MaxAngleZ;
+ protected readonly CurveVector3ConfigProp LimitRotation;
#endregion
#region == Collision ==
- [NotNull] protected readonly CurveConfigProp Radius;
- [NotNull] protected readonly PermissionConfigProp AllowCollision;
- [NotNull] protected readonly CollidersConfigProp Colliders;
+ protected readonly CurveConfigProp Radius;
+ protected readonly PermissionConfigProp AllowCollision;
+ protected readonly CollidersConfigProp Colliders;
#endregion
#region == Stretch & Squish ==
- [NotNull] protected readonly CurveConfigProp StretchMotion;
- [NotNull] protected readonly CurveConfigProp MaxStretch;
- [NotNull] protected readonly CurveConfigProp MaxSquish;
+ protected readonly CurveConfigProp StretchMotion;
+ protected readonly CurveConfigProp MaxStretch;
+ protected readonly CurveConfigProp MaxSquish;
#endregion
#region == Grab & Pose ==
- [NotNull] protected readonly PermissionConfigProp AllowGrabbing;
- [NotNull] protected readonly PermissionConfigProp AllowPosing;
- [NotNull] protected readonly ValueConfigProp GrabMovement;
- [NotNull] protected readonly ValueConfigProp SnapToHand;
+ protected readonly PermissionConfigProp AllowGrabbing;
+ protected readonly PermissionConfigProp AllowPosing;
+ protected readonly ValueConfigProp GrabMovement;
+ protected readonly ValueConfigProp SnapToHand;
#endregion
#region == Options ==
- [NotNull] protected readonly NoOverrideValueConfigProp Parameter;
- [NotNull] protected readonly NoOverrideValueConfigProp IsAnimated;
- [NotNull] protected readonly ValueConfigProp ResetWhenDisabled;
+ protected readonly NoOverrideValueConfigProp Parameter;
+ protected readonly NoOverrideValueConfigProp IsAnimated;
+ protected readonly ValueConfigProp ResetWhenDisabled;
#endregion
protected readonly PrefabSafeSet.EditorUtil ComponentsSetEditorUtil;
@@ -268,9 +267,9 @@ public void DoProcess()
}
}
- protected SerializedProperty GetSourceProperty(string name) => _sourcePhysBone.FindProperty(name);
+ protected SerializedProperty GetSourceProperty(string name) => _sourcePhysBone!.FindProperty(name);
- protected IEnumerable SourcePhysBones => _sourcePhysBone.targetObjects.Cast();
+ protected IEnumerable SourcePhysBones => _sourcePhysBone!.targetObjects.Cast();
protected abstract void BeginPbConfig();
@@ -293,29 +292,28 @@ private bool NextSection(string name, string docTag)
protected abstract void UnsupportedPbVersion();
- protected abstract void PbVersionProp([NotNull] string label, [NotNull] ValueConfigProp prop, bool forceOverride = false);
+ protected abstract void PbVersionProp(string label, ValueConfigProp prop, bool forceOverride = false);
- protected abstract void PbProp([NotNull] string label, [NotNull] ValueConfigProp prop, bool forceOverride = false);
+ protected abstract void PbProp(string label, ValueConfigProp prop, bool forceOverride = false);
- protected abstract void PbCurveProp([NotNull] string label, [NotNull] CurveConfigProp prop, bool forceOverride = false);
+ protected abstract void PbCurveProp(string label, CurveConfigProp prop, bool forceOverride = false);
- protected abstract void PbPermissionProp([NotNull] string label, [NotNull] PermissionConfigProp prop, bool forceOverride = false);
+ protected abstract void PbPermissionProp(string label, PermissionConfigProp prop, bool forceOverride = false);
- protected abstract void Pb3DCurveProp([NotNull] string label,
- [NotNull] string pbXCurveLabel,
- [NotNull] string pbYCurveLabel,
- [NotNull] string pbZCurveLabel,
- [NotNull] CurveVector3ConfigProp prop,
+ protected abstract void Pb3DCurveProp(string label,
+ string pbXCurveLabel,
+ string pbYCurveLabel,
+ string pbZCurveLabel,
+ CurveVector3ConfigProp prop,
bool forceOverride = false);
- protected abstract void CollidersProp([NotNull] string label,
- [NotNull] CollidersConfigProp prop);
+ protected abstract void CollidersProp(string label, CollidersConfigProp prop);
protected abstract class PropBase
{
public readonly SerializedProperty RootProperty;
- public PropBase([NotNull] SerializedProperty rootProperty)
+ public PropBase(SerializedProperty rootProperty)
{
RootProperty = rootProperty ?? throw new ArgumentNullException(nameof(rootProperty));
}
@@ -329,7 +327,7 @@ protected abstract class OverridePropBase: PropBase
public bool IsOverride => IsOverrideProperty.boolValue;
- public OverridePropBase([NotNull] SerializedProperty rootProperty) : base(rootProperty)
+ public OverridePropBase(SerializedProperty rootProperty) : base(rootProperty)
{
IsOverrideProperty = rootProperty.FindPropertyRelative("override");
}
@@ -340,12 +338,12 @@ protected class CollidersConfigProp : PropBase
{
public readonly SerializedProperty OverrideProperty;
public readonly SerializedProperty ValueProperty;
- public SerializedProperty PhysBoneValue { get; private set; }
+ public SerializedProperty? PhysBoneValue { get; private set; }
public readonly string PhysBoneValueName;
public CollidersConfigProp(
- [NotNull] SerializedProperty rootProperty,
- [NotNull] string physBoneValueName) : base(rootProperty)
+ SerializedProperty rootProperty,
+ string physBoneValueName) : base(rootProperty)
{
OverrideProperty = rootProperty.FindPropertyRelative("override");
ValueProperty = rootProperty.FindPropertyRelative("value");
@@ -363,12 +361,12 @@ protected class EndpointPositionConfigProp : PropBase
{
public readonly SerializedProperty OverrideProperty;
public readonly SerializedProperty ValueProperty;
- public SerializedProperty PhysBoneValue { get; private set; }
+ public SerializedProperty? PhysBoneValue { get; private set; }
public readonly string PhysBoneValueName;
public EndpointPositionConfigProp(
- [NotNull] SerializedProperty rootProperty,
- [NotNull] string physBoneValueName) : base(rootProperty)
+ SerializedProperty rootProperty,
+ string physBoneValueName) : base(rootProperty)
{
OverrideProperty = rootProperty.FindPropertyRelative("override");
ValueProperty = rootProperty.FindPropertyRelative("value");
diff --git a/Editor/MergePhysBoneEditorModificationUtils.generated.cs b/Editor/MergePhysBoneEditorModificationUtils.generated.cs
index d70ef3421..082318e2c 100644
--- a/Editor/MergePhysBoneEditorModificationUtils.generated.cs
+++ b/Editor/MergePhysBoneEditorModificationUtils.generated.cs
@@ -1,5 +1,6 @@
//
-// generated by .MergePhysBoneEditorModificationUtils.ts
+#nullable enable
+
#if AAO_VRCSDK3_AVATARS
using System.Collections.Generic;
@@ -13,16 +14,16 @@ partial class MergePhysBoneEditorModificationUtils
protected partial class CurveConfigProp : OverridePropBase
{
public readonly SerializedProperty OverrideValue;
- public SerializedProperty SourceValue { get; private set; }
+ public SerializedProperty? SourceValue { get; private set; }
public readonly string PhysBoneValueName;
public readonly SerializedProperty OverrideCurve;
- public SerializedProperty SourceCurve { get; private set; }
+ public SerializedProperty? SourceCurve { get; private set; }
public readonly string PhysBoneCurveName;
public CurveConfigProp(
- [NotNull] SerializedProperty rootProperty
- , [NotNull] string physBoneValueName
- , [NotNull] string physBoneCurveName
+ SerializedProperty rootProperty
+ , string physBoneValueName
+ , string physBoneCurveName
) : base(rootProperty)
{
OverrideValue = rootProperty.FindPropertyRelative("value");
@@ -36,30 +37,30 @@ internal override void UpdateSource(SerializedObject sourcePb)
SourceValue = sourcePb.FindProperty(PhysBoneValueName);
SourceCurve = sourcePb.FindProperty(PhysBoneCurveName);
}
- public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue;
- public SerializedProperty GetCurveProperty(bool @override) => @override ? OverrideCurve : SourceCurve;
+ public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue!;
+ public SerializedProperty GetCurveProperty(bool @override) => @override ? OverrideCurve : SourceCurve!;
}
protected partial class CurveVector3ConfigProp : OverridePropBase
{
public readonly SerializedProperty OverrideValue;
- public SerializedProperty SourceValue { get; private set; }
+ public SerializedProperty? SourceValue { get; private set; }
public readonly string PhysBoneValueName;
public readonly SerializedProperty OverrideCurveX;
- public SerializedProperty SourceCurveX { get; private set; }
+ public SerializedProperty? SourceCurveX { get; private set; }
public readonly string PhysBoneCurveXName;
public readonly SerializedProperty OverrideCurveY;
- public SerializedProperty SourceCurveY { get; private set; }
+ public SerializedProperty? SourceCurveY { get; private set; }
public readonly string PhysBoneCurveYName;
public readonly SerializedProperty OverrideCurveZ;
- public SerializedProperty SourceCurveZ { get; private set; }
+ public SerializedProperty? SourceCurveZ { get; private set; }
public readonly string PhysBoneCurveZName;
public CurveVector3ConfigProp(
- [NotNull] SerializedProperty rootProperty
- , [NotNull] string physBoneValueName
- , [NotNull] string physBoneCurveXName
- , [NotNull] string physBoneCurveYName
- , [NotNull] string physBoneCurveZName
+ SerializedProperty rootProperty
+ , string physBoneValueName
+ , string physBoneCurveXName
+ , string physBoneCurveYName
+ , string physBoneCurveZName
) : base(rootProperty)
{
OverrideValue = rootProperty.FindPropertyRelative("value");
@@ -79,24 +80,24 @@ internal override void UpdateSource(SerializedObject sourcePb)
SourceCurveY = sourcePb.FindProperty(PhysBoneCurveYName);
SourceCurveZ = sourcePb.FindProperty(PhysBoneCurveZName);
}
- public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue;
- public SerializedProperty GetCurveXProperty(bool @override) => @override ? OverrideCurveX : SourceCurveX;
- public SerializedProperty GetCurveYProperty(bool @override) => @override ? OverrideCurveY : SourceCurveY;
- public SerializedProperty GetCurveZProperty(bool @override) => @override ? OverrideCurveZ : SourceCurveZ;
+ public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue!;
+ public SerializedProperty GetCurveXProperty(bool @override) => @override ? OverrideCurveX : SourceCurveX!;
+ public SerializedProperty GetCurveYProperty(bool @override) => @override ? OverrideCurveY : SourceCurveY!;
+ public SerializedProperty GetCurveZProperty(bool @override) => @override ? OverrideCurveZ : SourceCurveZ!;
}
protected partial class PermissionConfigProp : OverridePropBase
{
public readonly SerializedProperty OverrideValue;
- public SerializedProperty SourceValue { get; private set; }
+ public SerializedProperty? SourceValue { get; private set; }
public readonly string PhysBoneValueName;
public readonly SerializedProperty OverrideFilter;
- public SerializedProperty SourceFilter { get; private set; }
+ public SerializedProperty? SourceFilter { get; private set; }
public readonly string PhysBoneFilterName;
public PermissionConfigProp(
- [NotNull] SerializedProperty rootProperty
- , [NotNull] string physBoneValueName
- , [NotNull] string physBoneFilterName
+ SerializedProperty rootProperty
+ , string physBoneValueName
+ , string physBoneFilterName
) : base(rootProperty)
{
OverrideValue = rootProperty.FindPropertyRelative("value");
@@ -110,18 +111,18 @@ internal override void UpdateSource(SerializedObject sourcePb)
SourceValue = sourcePb.FindProperty(PhysBoneValueName);
SourceFilter = sourcePb.FindProperty(PhysBoneFilterName);
}
- public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue;
- public SerializedProperty GetFilterProperty(bool @override) => @override ? OverrideFilter : SourceFilter;
+ public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue!;
+ public SerializedProperty GetFilterProperty(bool @override) => @override ? OverrideFilter : SourceFilter!;
}
protected partial class ValueConfigProp : OverridePropBase
{
public readonly SerializedProperty OverrideValue;
- public SerializedProperty SourceValue { get; private set; }
+ public SerializedProperty? SourceValue { get; private set; }
public readonly string PhysBoneValueName;
public ValueConfigProp(
- [NotNull] SerializedProperty rootProperty
- , [NotNull] string physBoneValueName
+ SerializedProperty rootProperty
+ , string physBoneValueName
) : base(rootProperty)
{
OverrideValue = rootProperty.FindPropertyRelative("value");
@@ -132,17 +133,17 @@ internal override void UpdateSource(SerializedObject sourcePb)
{
SourceValue = sourcePb.FindProperty(PhysBoneValueName);
}
- public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue;
+ public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue!;
}
protected partial class NoOverrideValueConfigProp : PropBase
{
public readonly SerializedProperty OverrideValue;
- public SerializedProperty SourceValue { get; private set; }
+ public SerializedProperty? SourceValue { get; private set; }
public readonly string PhysBoneValueName;
public NoOverrideValueConfigProp(
- [NotNull] SerializedProperty rootProperty
- , [NotNull] string physBoneValueName
+ SerializedProperty rootProperty
+ , string physBoneValueName
) : base(rootProperty)
{
OverrideValue = rootProperty.FindPropertyRelative("value");
@@ -153,7 +154,7 @@ internal override void UpdateSource(SerializedObject sourcePb)
{
SourceValue = sourcePb.FindProperty(PhysBoneValueName);
}
- public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue;
+ public SerializedProperty GetValueProperty(bool @override) => @override ? OverrideValue : SourceValue!;
}
}
}
diff --git a/Editor/MergeSkinnedMeshWindow.cs b/Editor/MergeSkinnedMeshWindow.cs
index 1ba3b2c2e..84f605407 100644
--- a/Editor/MergeSkinnedMeshWindow.cs
+++ b/Editor/MergeSkinnedMeshWindow.cs
@@ -5,7 +5,7 @@ namespace Anatawa12.AvatarOptimizer
{
internal class MergeSkinnedMeshWindow : EditorWindow
{
- private Mesh _mesh;
+ private Mesh? _mesh;
private void OnGUI()
{
@@ -51,7 +51,7 @@ private void OnGUI()
}
}
- private void SelectableLabelField(string label, T value)
+ private void SelectableLabelField(string label, T value) where T : notnull
{
var fullRect = EditorGUILayout.GetControlRect(true);
var elementRect = EditorGUI.PrefixLabel(fullRect, new GUIContent(label));
diff --git a/Editor/ObjectMapping/AnimationObjectMapper.cs b/Editor/ObjectMapping/AnimationObjectMapper.cs
index ed5184d6a..73d88fdd2 100644
--- a/Editor/ObjectMapping/AnimationObjectMapper.cs
+++ b/Editor/ObjectMapping/AnimationObjectMapper.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
@@ -12,8 +11,7 @@ internal class AnimationObjectMapper
readonly BeforeGameObjectTree _beforeGameObjectTree;
readonly ObjectMapping _objectMapping;
- private readonly Dictionary _pathsCache =
- new Dictionary();
+ private readonly Dictionary _pathsCache = new();
public AnimationObjectMapper(GameObject rootGameObject, BeforeGameObjectTree beforeGameObjectTree,
ObjectMapping objectMapping)
@@ -24,8 +22,7 @@ public AnimationObjectMapper(GameObject rootGameObject, BeforeGameObjectTree bef
}
// null means nothing to map
- [CanBeNull]
- private MappedGameObjectInfo GetGameObjectInfo(string path)
+ private MappedGameObjectInfo? GetGameObjectInfo(string path)
{
if (_pathsCache.TryGetValue(path, out var info)) return info;
@@ -38,7 +35,7 @@ private MappedGameObjectInfo GetGameObjectInfo(string path)
else
{
var foundGameObject = EditorUtility.InstanceIDToObject(tree.InstanceId) as GameObject;
- var newPath = foundGameObject
+ var newPath = foundGameObject != null
? Utils.RelativePath(_rootGameObject.transform, foundGameObject.transform)
: null;
@@ -56,17 +53,16 @@ class MappedGameObjectInfo
readonly BeforeGameObjectTree _tree;
// null means removed gameObject
- [CanBeNull] public readonly string NewPath;
+ public readonly string? NewPath;
- public MappedGameObjectInfo(ObjectMapping objectMapping, string newPath,
- BeforeGameObjectTree tree)
+ public MappedGameObjectInfo(ObjectMapping objectMapping, string? newPath, BeforeGameObjectTree tree)
{
_objectMapping = objectMapping;
NewPath = newPath;
_tree = tree;
}
- public (int instanceId, ComponentInfo) GetComponentByType(Type type)
+ public (int instanceId, ComponentInfo?) GetComponentByType(Type type)
{
if (!_tree.ComponentInstanceIdByType.TryGetValue(type, out var instanceId))
return (instanceId, null); // Nothing to map
@@ -74,8 +70,7 @@ public MappedGameObjectInfo(ObjectMapping objectMapping, string newPath,
}
}
- [CanBeNull]
- public string MapPath(string srcPath, Type type)
+ public string? MapPath(string srcPath, Type type)
{
var gameObjectInfo = GetGameObjectInfo(srcPath);
if (gameObjectInfo == null)
@@ -105,8 +100,7 @@ public string MapPath(string srcPath, Type type)
}
}
- [CanBeNull]
- public (string path, Type type, string propertyName)[] MapBinding(string path, Type type, string propertyName)
+ public (string path, Type type, string propertyName)[]? MapBinding(string path, Type type, string propertyName)
{
var gameObjectInfo = GetGameObjectInfo(path);
if (gameObjectInfo == null)
@@ -159,13 +153,18 @@ public string MapPath(string srcPath, Type type)
}
else
{
- var component = new ComponentOrGameObject(EditorUtility.InstanceIDToObject(componentInfo.MergedInto));
- if (!component) return Array.Empty<(string path, Type type, string propertyName)>(); // this means removed.
+ var component =
+ new ComponentOrGameObject(EditorUtility.InstanceIDToObject(componentInfo.MergedInto));
+ if (!component)
+ return Array.Empty<(string path, Type type, string propertyName)>(); // this means removed.
var newPath = Utils.RelativePath(_rootGameObject.transform, component.transform);
- if (newPath == null) return Array.Empty<(string path, Type type, string propertyName)>(); // this means moved to out of the animator scope
+ if (newPath == null)
+ return Array
+ .Empty<(string path, Type type, string propertyName
+ )>(); // this means moved to out of the animator scope
if (path == newPath) return null;
- return new []{ (newPath, type, propertyName) };
+ return new[] { (newPath, type, propertyName) };
}
}
else
@@ -173,7 +172,8 @@ public string MapPath(string srcPath, Type type)
// The component is not merged & no prop mapping so process GameObject mapping
var component = EditorUtility.InstanceIDToObject(instanceId);
- if (!component) return Array.Empty<(string path, Type type, string propertyName)>(); // this means removed
+ if (!component)
+ return Array.Empty<(string path, Type type, string propertyName)>(); // this means removed
if (gameObjectInfo.NewPath == null) return Array.Empty<(string path, Type type, string propertyName)>();
if (path == gameObjectInfo.NewPath) return null;
diff --git a/Editor/ObjectMapping/ObjectMapping.cs b/Editor/ObjectMapping/ObjectMapping.cs
index 259da4d45..9327087ea 100644
--- a/Editor/ObjectMapping/ObjectMapping.cs
+++ b/Editor/ObjectMapping/ObjectMapping.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -21,7 +20,7 @@ public ObjectMapping(
_componentMapping = componentMapping;
}
- public bool MapComponentInstance(int instanceId, out Component component)
+ public bool MapComponentInstance(int instanceId, out Component? component)
{
if (instanceId == 0)
{
@@ -47,18 +46,17 @@ public bool MapComponentInstance(int instanceId, out Component component)
return false;
}
- internal BeforeGameObjectTree GetBeforeGameObjectTree(GameObject rootGameObject) =>
+ internal BeforeGameObjectTree? GetBeforeGameObjectTree(GameObject rootGameObject) =>
_beforeTree.TryGetValue(rootGameObject.GetInstanceID(), out var tree) ? tree : null;
// null means nothing to map
- [CanBeNull]
- public ComponentInfo GetComponentMapping(int instanceId) =>
+ public ComponentInfo? GetComponentMapping(int instanceId) =>
_componentMapping.TryGetValue(instanceId, out var info) ? info : null;
- [CanBeNull]
public AnimationObjectMapper CreateAnimationMapper(GameObject rootGameObject)
{
- if (!_beforeTree.TryGetValue(rootGameObject.GetInstanceID(), out var beforeTree)) return null;
+ if (!_beforeTree.TryGetValue(rootGameObject.GetInstanceID(), out var beforeTree))
+ throw new InvalidOperationException($"rootGameObject {rootGameObject} is not in the mapping");
return new AnimationObjectMapper(rootGameObject, beforeTree, this);
}
}
@@ -66,10 +64,10 @@ class BeforeGameObjectTree
{
public readonly int InstanceId;
public readonly int ParentInstanceId;
- [NotNull] public readonly string Name;
- [NotNull] public readonly IReadOnlyDictionary ComponentInstanceIdByType;
- [NotNull] public readonly int[] ComponentInstanceIds;
- [NotNull] public readonly BeforeGameObjectTree[] Children;
+ public readonly string Name;
+ public readonly IReadOnlyDictionary ComponentInstanceIdByType;
+ public readonly int[] ComponentInstanceIds;
+ public readonly BeforeGameObjectTree[] Children;
public bool HasSlashInNameInDirectChildren { get; private set; }
public bool HasSlashInNameInChildren { get; private set; }
@@ -114,8 +112,7 @@ public void InitializeRecursive()
HasSlashInNameInChildren = Children.Any(x => x.HasSlashInNameInChildren || x.Name.Contains('/'));
}
- [CanBeNull]
- public BeforeGameObjectTree ResolvePath(string relative) =>
+ public BeforeGameObjectTree? ResolvePath(string relative) =>
relative == "" ? this : ResolvePathAll(relative).FirstOrDefault();
private IEnumerable ResolvePathAll(string relative)
@@ -167,8 +164,8 @@ public ComponentInfo(int instanceId, int mergedInto, Type type,
{
public static readonly PropertyDescriptor Removed = default;
public readonly int InstanceId;
- [NotNull] public readonly Type Type;
- [NotNull] public readonly string Name;
+ public readonly Type Type;
+ public readonly string Name;
public PropertyDescriptor(int instanceId, Type type, string name)
{
@@ -177,20 +174,10 @@ public PropertyDescriptor(int instanceId, Type type, string name)
Name = name;
}
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = InstanceId;
- hashCode = (hashCode * 397) ^ Type.GetHashCode();
- hashCode = (hashCode * 397) ^ Name.GetHashCode();
- return hashCode;
- }
- }
-
+ public override int GetHashCode() => HashCode.Combine(InstanceId, Type, Name);
public bool Equals(PropertyDescriptor other) =>
InstanceId == other.InstanceId && Type == other.Type && Name == other.Name;
- public override bool Equals(object obj) => obj is PropertyDescriptor other && Equals(other);
+ public override bool Equals(object? obj) => obj is PropertyDescriptor other && Equals(other);
public static bool operator ==(PropertyDescriptor left, PropertyDescriptor right) => left.Equals(right);
public static bool operator !=(PropertyDescriptor left, PropertyDescriptor right) => !left.Equals(right);
}
@@ -244,7 +231,7 @@ static class Props
{
private const string Enabled = "m_Enabled";
// enabled for behaviour-like components
- public static string EnabledFor(Object obj) => obj == null ? Enabled : EnabledFor(obj.GetType());
+ public static string EnabledFor(Object? obj) => obj == null ? Enabled : EnabledFor(obj.GetType());
public static string EnabledFor(Type type) =>
type == typeof(Animator) ? VProp.AnimatorEnabledAsBehavior : Enabled;
diff --git a/Editor/ObjectMapping/ObjectMappingBuilder.cs b/Editor/ObjectMapping/ObjectMappingBuilder.cs
index 5d30c7eca..58262ad2b 100644
--- a/Editor/ObjectMapping/ObjectMappingBuilder.cs
+++ b/Editor/ObjectMapping/ObjectMappingBuilder.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
@@ -21,10 +20,10 @@ internal class ObjectMappingBuilder
private readonly IReadOnlyDictionary _beforeGameObjectInfos;
// key: instanceId
- private readonly Dictionary _originalComponentInfos = new Dictionary();
- private readonly Dictionary _componentInfos = new Dictionary();
+ private readonly Dictionary _originalComponentInfos = new();
+ private readonly Dictionary _componentInfos = new();
- public ObjectMappingBuilder([NotNull] GameObject rootObject)
+ public ObjectMappingBuilder(GameObject rootObject)
{
if (!rootObject) throw new ArgumentNullException(nameof(rootObject));
var transforms = rootObject.GetComponentsInChildren(true);
@@ -103,16 +102,16 @@ public ObjectMapping BuildObjectMapping()
class AnimationPropertyInfo
{
- [CanBeNull] public readonly BuildingComponentInfo Component;
- [CanBeNull] public readonly string Name;
- [CanBeNull] public AnimationPropertyInfo MergedTo { get; private set; }
+ public readonly BuildingComponentInfo? Component;
+ public readonly string? Name;
+ public AnimationPropertyInfo? MergedTo { get; private set; }
private MappedPropertyInfo? _mappedPropertyInfo;
public TPropInfo PropertyInfo;
- [CanBeNull] public List CopiedTo { get; private set; }
+ public List? CopiedTo { get; private set; }
- public AnimationPropertyInfo([NotNull] BuildingComponentInfo component, [NotNull] string name)
+ public AnimationPropertyInfo(BuildingComponentInfo component, string name)
{
Component = component ?? throw new ArgumentNullException(nameof(component));
Name = name ?? throw new ArgumentNullException(nameof(name));
@@ -122,7 +121,9 @@ private AnimationPropertyInfo()
{
}
- public static readonly AnimationPropertyInfo RemovedMarker = new AnimationPropertyInfo();
+ // TODO: split type for removed marker?
+ // If we do that, we can remove nullabile from Component and Name
+ public static readonly AnimationPropertyInfo RemovedMarker = new();
public void MergeTo(AnimationPropertyInfo property)
{
@@ -140,7 +141,7 @@ public void CopyTo(AnimationPropertyInfo property)
public MappedPropertyInfo GetMappedInfo()
{
- if (_mappedPropertyInfo is MappedPropertyInfo property) return property;
+ if (_mappedPropertyInfo is { } property) return property;
property = ComputeMappedInfo();
_mappedPropertyInfo = property;
return property;
@@ -149,8 +150,8 @@ public MappedPropertyInfo GetMappedInfo()
private MappedPropertyInfo ComputeMappedInfo()
{
if (this == RemovedMarker) return MappedPropertyInfo.Removed;
-
- System.Diagnostics.Debug.Assert(Component != null, nameof(Component) + " != null");
+
+ if (Component == null) throw new InvalidOperationException("Component is null");
if (MergedTo != null)
{
@@ -170,9 +171,9 @@ private MappedPropertyInfo ComputeMappedInfo()
{
// this is edge
if (CopiedTo == null || CopiedTo.Count == 0)
- return new MappedPropertyInfo(Component.InstanceId, Component.Type, Name);
+ return new MappedPropertyInfo(Component.InstanceId, Component.Type, Name!);
- var descriptor = new PropertyDescriptor(Component.InstanceId, Component.Type, Name);
+ var descriptor = new PropertyDescriptor(Component.InstanceId, Component.Type, Name!);
var copied = new List { descriptor };
foreach (var copiedTo in CopiedTo)
@@ -189,13 +190,11 @@ class BuildingComponentInfo : AnimationComponentInfo
internal readonly Type Type;
// id in this -> id in merged
- private BuildingComponentInfo _mergedInto;
+ private BuildingComponentInfo? _mergedInto;
- private readonly Dictionary _beforePropertyIds =
- new Dictionary();
+ private readonly Dictionary _beforePropertyIds = new();
- private readonly Dictionary _afterPropertyIds =
- new Dictionary();
+ private readonly Dictionary _afterPropertyIds = new();
public BuildingComponentInfo(ComponentOrGameObject component)
{
@@ -205,7 +204,6 @@ public BuildingComponentInfo(ComponentOrGameObject component)
internal bool IsMerged => _mergedInto != null;
- [NotNull]
private AnimationPropertyInfo GetProperty(string name, bool remove = false)
{
if (_afterPropertyIds.TryGetValue(name, out var prop))
@@ -223,13 +221,13 @@ private AnimationPropertyInfo GetProperty(string name, bool remove = false)
}
}
- public void MergedTo([NotNull] BuildingComponentInfo mergeTo)
+ public void MergedTo(BuildingComponentInfo mergeTo)
{
if (Type == typeof(Transform)) throw new Exception("Merging Transform is not supported!");
if (_mergedInto != null) throw new InvalidOperationException("Already merged");
_mergedInto = mergeTo ?? throw new ArgumentNullException(nameof(mergeTo));
foreach (var property in _afterPropertyIds.Values)
- property.MergeTo(mergeTo.GetProperty(property.Name));
+ property.MergeTo(mergeTo.GetProperty(property.Name!));
_afterPropertyIds.Clear();
}
diff --git a/Editor/ObjectMapping/ObjectMappingContext.cs b/Editor/ObjectMapping/ObjectMappingContext.cs
index edd0f67e3..1f0fefffe 100644
--- a/Editor/ObjectMapping/ObjectMappingContext.cs
+++ b/Editor/ObjectMapping/ObjectMappingContext.cs
@@ -1,8 +1,6 @@
-using System;
using System.Linq;
using Anatawa12.AvatarOptimizer.API;
using Anatawa12.AvatarOptimizer.APIInternal;
-using JetBrains.Annotations;
using nadena.dev.ndmf;
using UnityEditor;
using UnityEditor.Animations;
@@ -13,7 +11,7 @@ namespace Anatawa12.AvatarOptimizer
{
internal class ObjectMappingContext : IExtensionContext
{
- public ObjectMappingBuilder MappingBuilder { get; private set; }
+ public ObjectMappingBuilder