diff --git a/AVA/UNIVRM0/Editor/Processors/AVA_Avatar.cs b/AVA/UNIVRM0/Editor/Processors/AVA_Avatar.cs index 33d497b..bd3391b 100644 --- a/AVA/UNIVRM0/Editor/Processors/AVA_Avatar.cs +++ b/AVA/UNIVRM0/Editor/Processors/AVA_Avatar.cs @@ -2,6 +2,7 @@ #if NNA_AVA_UNIVRM0_FOUND using System.Linq; +using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; using nna.processors; using UnityEditor; @@ -57,15 +58,6 @@ public static VRMMeta InitAvatarDescriptor(NNAContext Context) } Context.AddObjectToAsset(vrmMeta.name, vrmMeta); - // set viewport - if(Context.Root.transform.GetComponentsInChildren().FirstOrDefault(t => t.name == "$ViewportFirstPerson") is var viewportNode && viewportNode != null) - { - var vrmFirstPerson = Context.Root.AddComponent(); - vrmFirstPerson.FirstPersonBone = viewportNode.parent; - vrmFirstPerson.FirstPersonOffset = viewportNode.transform.position; - Context.AddTrash(viewportNode); - } - var vrmBlendshapeProxy = Context.Root.AddComponent(); var vrmBlendShapeAvatar = ScriptableObject.CreateInstance(); vrmBlendShapeAvatar.name = "VRM_BlendshapeAvatar"; @@ -97,6 +89,31 @@ public static Animator GetOrInitAnimator(NNAContext Context) } } + + public class AVA_ViewportFirstPerson_VRC_Processor : INameProcessor + { + public const string MatchViewport = @"(?i)\$ViewportFirstPerson$"; + + public const string _Type = "ava.viewport.first_person"; + public string Type => _Type; + public uint Order => AVA_Avatar_UNIVRM0Processor._Order + 1; + + public int CanProcessName(NNAContext Context, string NameDefinition) + { + var match = Regex.Match(NameDefinition, MatchViewport); + return match.Success ? match.Index : -1; + } + + public void Process(NNAContext Context, Transform Node, string NameDefinition) + { + var vrmFirstPerson = Context.Root.AddComponent(); + vrmFirstPerson.FirstPersonBone = Node.parent; + vrmFirstPerson.FirstPersonOffset = Node.localPosition; + Context.AddTrash(Node); + } + } + + [InitializeOnLoad] public class Register_AVA_Avatar_UniVRM0 { diff --git a/AVA/VRChat/Editor/Processors/AVA_Avatar.cs b/AVA/VRChat/Editor/Processors/AVA_Avatar.cs index dbf3c33..8a320c9 100644 --- a/AVA/VRChat/Editor/Processors/AVA_Avatar.cs +++ b/AVA/VRChat/Editor/Processors/AVA_Avatar.cs @@ -7,10 +7,11 @@ using System.Linq; using UnityEditor; using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; namespace nna.ava.vrchat { - public class AVA_Avatar_VRCProcessor : IGlobalProcessor + public class AVA_Avatar_VRC_Processor : IGlobalProcessor { public const string _Type = "ava.avatar"; public string Type => _Type; @@ -37,14 +38,6 @@ public static class AVAVRCUtils public static VRCAvatarDescriptor InitAvatarDescriptor(NNAContext Context) { var avatar = Context.Root.AddComponent(); - - // set viewport - if(Context.Root.transform.GetComponentsInChildren().FirstOrDefault(t => t.name == "$ViewportFirstPerson") is var viewportNode && viewportNode != null) - { - avatar.ViewPosition = viewportNode.transform.position - Context.Root.transform.position; - Context.AddTrash(viewportNode); - } - return avatar; } @@ -62,12 +55,38 @@ public static Animator GetOrInitAnimator(NNAContext Context) } } + public class AVA_ViewportFirstPerson_VRC_Processor : INameProcessor + { + public const string MatchViewport = @"(?i)\$ViewportFirstPerson$"; + + public const string _Type = "ava.viewport.first_person"; + public string Type => _Type; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; + + public int CanProcessName(NNAContext Context, string NameDefinition) + { + var match = Regex.Match(NameDefinition, MatchViewport); + return match.Success ? match.Index : -1; + } + + public void Process(NNAContext Context, Transform Node, string NameDefinition) + { + var avatar = Context.Root.GetComponent(); + if(!avatar) throw new NNAException("No Avatar Component created!", _Type); + + avatar.ViewPosition = Node.position - Context.Root.transform.position; + Context.AddTrash(Node); + } + } + + [InitializeOnLoad] public class Register_AVA_Avatar_VRC { static Register_AVA_Avatar_VRC() { - NNARegistry.RegisterGlobalProcessor(new AVA_Avatar_VRCProcessor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT, true); + NNARegistry.RegisterGlobalProcessor(new AVA_Avatar_VRC_Processor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT, true); + NNARegistry.RegisterNameProcessor(new AVA_ViewportFirstPerson_VRC_Processor(), DetectorVRC.NNA_VRC_AVATAR_CONTEXT); } } } diff --git a/AVA/VRChat/Editor/Processors/AVA_EyeTrackingBoneLimits.cs b/AVA/VRChat/Editor/Processors/AVA_EyeTrackingBoneLimits.cs index 9f047b2..d8b42ca 100644 --- a/AVA/VRChat/Editor/Processors/AVA_EyeTrackingBoneLimits.cs +++ b/AVA/VRChat/Editor/Processors/AVA_EyeTrackingBoneLimits.cs @@ -50,7 +50,7 @@ public class AVA_EyeTrackingBoneLimits_VRC_Processor : IGlobalProcessor { public const string _Type = EyeTrackingBoneLimits._Type; public string Type => _Type; - public uint Order => AVA_Avatar_VRCProcessor._Order + 1; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; public void Process(NNAContext Context) { diff --git a/AVA/VRChat/Editor/Processors/AVA_EyelidTrackingBlendshape.cs b/AVA/VRChat/Editor/Processors/AVA_EyelidTrackingBlendshape.cs index 7adadcf..80b9330 100644 --- a/AVA/VRChat/Editor/Processors/AVA_EyelidTrackingBlendshape.cs +++ b/AVA/VRChat/Editor/Processors/AVA_EyelidTrackingBlendshape.cs @@ -13,7 +13,7 @@ public class AVA_EyelidTrackingBlendshape_VRCProcessor : IGlobalProcessor { public const string _Type = "ava.eyelidtracking_blendshape"; public string Type => _Type; - public uint Order => AVA_Avatar_VRCProcessor._Order + 1; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; public void Process(NNAContext Context) { diff --git a/AVA/VRChat/Editor/Processors/AVA_VisemesBlendshape.cs b/AVA/VRChat/Editor/Processors/AVA_VisemesBlendshape.cs index dd6ff13..a1b2584 100644 --- a/AVA/VRChat/Editor/Processors/AVA_VisemesBlendshape.cs +++ b/AVA/VRChat/Editor/Processors/AVA_VisemesBlendshape.cs @@ -14,7 +14,7 @@ public class AVA_VisemesBlendshape_VRCProcessor : IGlobalProcessor { public const string _Type = "ava.voice_visemes_blendshape"; public string Type => _Type; - public uint Order => AVA_Avatar_VRCProcessor._Order + 1; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; public int Priority => 0; public void Process(NNAContext Context) diff --git a/AVA/VRChat/Editor/Processors/VRC_AvatarColliders.cs b/AVA/VRChat/Editor/Processors/VRC_AvatarColliders.cs index a974947..dd43505 100644 --- a/AVA/VRChat/Editor/Processors/VRC_AvatarColliders.cs +++ b/AVA/VRChat/Editor/Processors/VRC_AvatarColliders.cs @@ -17,7 +17,7 @@ public class VRC_AvatarColliders_VRCJsonProcessor : IJsonProcessor { public const string _Type = "vrc.avatar_colliders"; public string Type => _Type; - public uint Order => AVA_Avatar_VRCProcessor._Order + 1; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; public int Priority => int.MaxValue; public void Process(NNAContext Context, Transform Node, JObject Json) diff --git a/AVA/VRChat/Editor/Processors/VRC_ControllerMapping.cs b/AVA/VRChat/Editor/Processors/VRC_ControllerMapping.cs index 24119e5..16087c8 100644 --- a/AVA/VRChat/Editor/Processors/VRC_ControllerMapping.cs +++ b/AVA/VRChat/Editor/Processors/VRC_ControllerMapping.cs @@ -18,7 +18,7 @@ public class VRC_ControllerMapping_VRCJsonProcessor : IJsonProcessor { public const string _Type = "vrc.controller_mapping"; public string Type => _Type; - public uint Order => AVA_Avatar_VRCProcessor._Order + 1; + public uint Order => AVA_Avatar_VRC_Processor._Order + 1; public int Priority => int.MaxValue; public void Process(NNAContext Context, Transform Node, JObject Json)