avatar label helper
This commit is contained in:
parent
40fff9bba3
commit
6031db6620
7 changed files with 171 additions and 0 deletions
8
AviLabels.meta
Normal file
8
AviLabels.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eae4e10ae346ec24984d58b3b87d55e3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
94
AviLabels/AviLabelParent.cs
Normal file
94
AviLabels/AviLabelParent.cs
Normal file
|
|
@ -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<Transform> childrenToDestroy = new List<Transform>();
|
||||||
|
foreach (Transform child in transform)
|
||||||
|
{
|
||||||
|
childrenToDestroy.Add(child);
|
||||||
|
}
|
||||||
|
foreach (Transform child in childrenToDestroy)
|
||||||
|
{
|
||||||
|
DestroyImmediate(child.gameObject);
|
||||||
|
}
|
||||||
|
var avatarDescriptors = GameObject.FindObjectsOfType<VRCAvatarDescriptor>();
|
||||||
|
foreach (var avatarDescriptor in avatarDescriptors)
|
||||||
|
{
|
||||||
|
LabelConfig labelConfig = LabelConfig.GetDefault();
|
||||||
|
if (avatarDescriptor.GetComponent<LabelConfig>() != null)
|
||||||
|
{
|
||||||
|
labelConfig = avatarDescriptor.GetComponent<LabelConfig>();
|
||||||
|
}
|
||||||
|
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<VRCParentConstraint>();
|
||||||
|
parentConstraint.AffectsPositionY = false;
|
||||||
|
parentConstraint.AffectsRotationY = false;
|
||||||
|
parentConstraint.Sources.Add(new VRCConstraintSource {
|
||||||
|
SourceTransform = avatarDescriptor.transform,
|
||||||
|
Weight = 1
|
||||||
|
});
|
||||||
|
parentConstraint.ActivateConstraint();
|
||||||
|
parentConstraint.ZeroConstraint();
|
||||||
|
|
||||||
|
|
||||||
|
var textMeshPro = child.AddComponent<TextMeshPro>();
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
11
AviLabels/AviLabelParent.cs.meta
Normal file
11
AviLabels/AviLabelParent.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7bb30b2bdab228a479fae7db4ab367c2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
AviLabels/AviLabels.asmdef
Normal file
18
AviLabels/AviLabels.asmdef
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
7
AviLabels/AviLabels.asmdef.meta
Normal file
7
AviLabels/AviLabels.asmdef.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0758760262efba643b9c9c20179b4985
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
22
AviLabels/LabelConfig.cs
Normal file
22
AviLabels/LabelConfig.cs
Normal file
|
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
AviLabels/LabelConfig.cs.meta
Normal file
11
AviLabels/LabelConfig.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9bb9a03d585aaee48b5a80cf79cbb00f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue