diff --git a/AviLabels.meta b/AviLabels.meta new file mode 100644 index 0000000..37a0514 --- /dev/null +++ b/AviLabels.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eae4e10ae346ec24984d58b3b87d55e3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AviLabels/AviLabelParent.cs b/AviLabels/AviLabelParent.cs new file mode 100644 index 0000000..f087a96 --- /dev/null +++ b/AviLabels/AviLabelParent.cs @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using UnityEngine; +using VRC.SDK3.Avatars.Components; +using VRC.SDK3.Dynamics.Constraint.Components; +using TMPro; +using VRC.Dynamics; + + +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace gay.lilyy.AviLabels +{ + + [AddComponentMenu("LillithRosePup/Avatar Label/Driver")] + public class AviLabelParent : MonoBehaviour, VRC.SDKBase.IEditorOnly + { + public Color defaultColor = Color.white; + public TMP_FontAsset defaultFont = null; + public void UpdateLabels() + { + List childrenToDestroy = new List(); + foreach (Transform child in transform) + { + childrenToDestroy.Add(child); + } + foreach (Transform child in childrenToDestroy) + { + DestroyImmediate(child.gameObject); + } + var avatarDescriptors = GameObject.FindObjectsOfType(); + foreach (var avatarDescriptor in avatarDescriptors) + { + LabelConfig labelConfig = LabelConfig.GetDefault(); + if (avatarDescriptor.GetComponent() != null) + { + labelConfig = avatarDescriptor.GetComponent(); + } + if (labelConfig.font == null) + { + labelConfig.font = defaultFont; + } + if (labelConfig.color == Color.white) + { + labelConfig.color = defaultColor; + } + var child = new GameObject(avatarDescriptor.name); + child.transform.SetParent(transform); + child.transform.localPosition = Vector3.zero; + child.transform.localRotation = Quaternion.identity; + child.transform.localScale = Vector3.one; + + + var parentConstraint = child.AddComponent(); + parentConstraint.AffectsPositionY = false; + parentConstraint.AffectsRotationY = false; + parentConstraint.Sources.Add(new VRCConstraintSource { + SourceTransform = avatarDescriptor.transform, + Weight = 1 + }); + parentConstraint.ActivateConstraint(); + parentConstraint.ZeroConstraint(); + + + var textMeshPro = child.AddComponent(); + if (labelConfig.font != null) + { + textMeshPro.font = labelConfig.font; + } + textMeshPro.color = labelConfig.color; + textMeshPro.text = !string.IsNullOrEmpty(labelConfig.overrideName) ? labelConfig.overrideName : avatarDescriptor.name; + textMeshPro.alignment = TextAlignmentOptions.Center; + textMeshPro.fontSize = 1; + } + } + } + + #if UNITY_EDITOR + [CustomEditor(typeof(AviLabelParent))] + public class AviLabelParentInspector : Editor + { + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + if (GUILayout.Button("Update Labels")) + { + ((AviLabelParent)target).UpdateLabels(); + } + } + } + #endif +} + diff --git a/AviLabels/AviLabelParent.cs.meta b/AviLabels/AviLabelParent.cs.meta new file mode 100644 index 0000000..044edfa --- /dev/null +++ b/AviLabels/AviLabelParent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bb30b2bdab228a479fae7db4ab367c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AviLabels/AviLabels.asmdef b/AviLabels/AviLabels.asmdef new file mode 100644 index 0000000..7464589 --- /dev/null +++ b/AviLabels/AviLabels.asmdef @@ -0,0 +1,18 @@ +{ + "name": "AviLabels", + "rootNamespace": "", + "references": [ + "GUID:3456780c4fb2d324ab9c633d6f1b0ddb", + "GUID:5718fb738711cd34ea54e9553040911d", + "GUID:6055be8ebefd69e48b49212b09b47b2f" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/AviLabels/AviLabels.asmdef.meta b/AviLabels/AviLabels.asmdef.meta new file mode 100644 index 0000000..fe84f58 --- /dev/null +++ b/AviLabels/AviLabels.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0758760262efba643b9c9c20179b4985 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AviLabels/LabelConfig.cs b/AviLabels/LabelConfig.cs new file mode 100644 index 0000000..2402e82 --- /dev/null +++ b/AviLabels/LabelConfig.cs @@ -0,0 +1,22 @@ +using TMPro; +using UnityEngine; + +namespace gay.lilyy.AviLabels +{ + [AddComponentMenu("LillithRosePup/Avatar Label/Config")] + public class LabelConfig : MonoBehaviour, VRC.SDKBase.IEditorOnly + { + public string overrideName; + public Color color; + public TMP_FontAsset font; + + internal static LabelConfig GetDefault() + { + return new LabelConfig { + overrideName = "", + color = Color.white, + font = null + }; + } + } +} \ No newline at end of file diff --git a/AviLabels/LabelConfig.cs.meta b/AviLabels/LabelConfig.cs.meta new file mode 100644 index 0000000..2684dfe --- /dev/null +++ b/AviLabels/LabelConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9bb9a03d585aaee48b5a80cf79cbb00f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: