Skip to content

Commit

Permalink
Merge pull request #104 from lyuma/beta-support
Browse files Browse the repository at this point in the history
Add beta support
  • Loading branch information
lyuma authored Apr 28, 2023
2 parents dc6316f + 24c099c commit d27082d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Editor/LyumaAv3EditorSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using UnityEditor.Animations;
using UnityEditor.Compilation;
using UnityEngine;
using static Lyuma.Av3Emulator.Runtime.LyumaAv3Emulator;
using VRC.SDK3.Avatars.Components;
using VRC.SDKBase.Editor.BuildPipeline;

Expand Down Expand Up @@ -285,8 +286,8 @@ public static void EnableAv3Testing() {
}
Selection.SetActiveObjectWithContext(go, go);
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
go.GetOrAddComponent<LyumaAv3Emulator>();
go.GetOrAddComponent<LyumaAv3Osc>();
GetOrAddComponent<LyumaAv3Emulator>(go);
GetOrAddComponent<LyumaAv3Osc>(go);
EditorGUIUtility.PingObject(go);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Editor/OldVersionFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using static Lyuma.Av3Emulator.Runtime.LyumaAv3Emulator;
using Directory = UnityEngine.Windows.Directory;
using Object = System.Object;

Expand Down Expand Up @@ -72,8 +73,8 @@ private static void ReplaceEmulator()
if (go != null)
{
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
go.GetOrAddComponent<LyumaAv3Emulator>();
go.GetOrAddComponent<LyumaAv3Osc>();
GetOrAddComponent<LyumaAv3Emulator>(go);
GetOrAddComponent<LyumaAv3Osc>(go);
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions Runtime/Scripts/LyumaAv3Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void Awake()
{
Camera.onPreCull += PreCull;
Camera.onPostRender += PostRender;
Animator animator = gameObject.GetOrAddComponent<Animator>();
Animator animator = GetOrAddComponent<Animator>(gameObject);
animator.enabled = false;
animator.runtimeAnimatorController = EmptyController;
emulatorInstance = this;
Expand Down Expand Up @@ -175,9 +175,9 @@ private void ScanForAvatars() {
avadesc.gameObject.SetActive(true);
}

var oml = avadesc.gameObject.GetOrAddComponent<UnityEngine.AI.OffMeshLink>();
var oml = GetOrAddComponent<UnityEngine.AI.OffMeshLink>(avadesc.gameObject);
oml.startTransform = this.transform;
var runtime = avadesc.gameObject.GetOrAddComponent<LyumaAv3Runtime>();
var runtime = GetOrAddComponent<LyumaAv3Runtime>(avadesc.gameObject);
if (RunPreprocessAvatarHook && !alreadyHadComponent) {
forceActiveRuntimes.AddLast(runtime);
}
Expand Down Expand Up @@ -289,5 +289,14 @@ private void Update() {
}
}
}

public static T GetOrAddComponent<T>(GameObject go) where T : Component
{
T component = go.GetComponent<T>();
if (component == null)
component = go.AddComponent<T>();
return component;
}

}
}
28 changes: 25 additions & 3 deletions Runtime/Scripts/LyumaAv3Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using static Lyuma.Av3Emulator.Runtime.LyumaAv3Emulator;
using VRC.Dynamics;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
using VRC.SDK3.Dynamics.Contact.Components;
Expand Down Expand Up @@ -250,6 +252,26 @@ public void assignPhysBoneParameters(VRCPhysBone[] behaviours) {
accessInst.paramName = parameter + VRCPhysBone.PARAM_STRETCH;
mb.param_Stretch = accessInst;
accessInst.floatVal = mb.param_StretchValue;

FieldInfo posedParam = typeof(VRCPhysBoneBase).GetField("PARAM_ISPOSED", BindingFlags.Public | BindingFlags.Static);
if (posedParam != null)
{
accessInst = new Av3EmuParameterAccess();
accessInst.runtime = this;
accessInst.paramName = parameter + posedParam.GetValue(null);
typeof(VRCPhysBoneBase).GetField("param_IsPosed").SetValue(mb, accessInst);
accessInst.boolVal = (bool)typeof(VRCPhysBoneBase).GetField("param_IsPosedValue").GetValue(mb);
}

FieldInfo squishParam = typeof(VRCPhysBoneBase).GetField("PARAM_SQUISH", BindingFlags.Public | BindingFlags.Static);
if (squishParam != null)
{
accessInst = new Av3EmuParameterAccess();
accessInst.runtime = this;
accessInst.paramName = parameter + squishParam.GetValue(null);
typeof(VRCPhysBoneBase).GetField("param_Squish").SetValue(mb, accessInst);
accessInst.floatVal = (float)typeof(VRCPhysBoneBase).GetField("param_SquishValue").GetValue(mb);
}
// Debug.Log("Assigned strech access " + physBoneState.param_Stretch.GetValue(mb) + " to param " + parameter + ": was " + old_value);
}
}
Expand Down Expand Up @@ -915,7 +937,7 @@ void Awake()
ViewAnimatorOnlyNoParams = this.emulator.DefaultAnimatorToDebug;
}

animator = this.gameObject.GetOrAddComponent<Animator>();
animator = GetOrAddComponent<Animator>(this.gameObject);
if (animatorAvatar != null && animator.avatar == null) {
animator.avatar = animatorAvatar;
} else {
Expand Down Expand Up @@ -1070,7 +1092,7 @@ private void InitializeAnimator()
PrevAnimatorToDebug = (char)(int)DebugDuplicateAnimator;
ViewAnimatorOnlyNoParams = DebugDuplicateAnimator;

animator = this.gameObject.GetOrAddComponent<Animator>();
animator = GetOrAddComponent<Animator>(this.gameObject);
animator.avatar = animatorAvatar;
animator.applyRootMotion = false;
animator.updateMode = AnimatorUpdateMode.Normal;
Expand Down Expand Up @@ -1891,7 +1913,7 @@ void NormalUpdate()
OSCController = null;
}
if (OSCController == null && EnableAvatarOSC) {
osc = emulator.gameObject.GetOrAddComponent<LyumaAv3Osc>();
osc = GetOrAddComponent<LyumaAv3Osc>(emulator.gameObject);
osc.openSocket = true;
osc.avatarDescriptor = avadesc;
osc.enabled = true;
Expand Down

0 comments on commit d27082d

Please sign in to comment.