9using System.Collections;
10using System.Collections.Generic;
19 private Texture _handTex;
20 private Rect _handTexRect;
25 _handTex = EditorResources.Load<Texture2D>(
"HandTex");
30 private void drawAttachmentPointsEditor(SerializedProperty property) {
34 EditorGUILayout.Space();
35 EditorGUILayout.LabelField(
"Attachment Transforms", EditorStyles.boldLabel);
38 var isTargetPrefab = Utils.IsObjectPartOfPrefabAsset(
target.gameObject);
41 EditorGUILayout.HelpBox(
"Drag the prefab into the scene to make changes to attachment points.", MessageType.Info,
true);
44 _handTexRect = EditorGUILayout.BeginVertical(GUILayout.MinWidth(EditorGUIUtility.currentViewWidth),
45 GUILayout.MinHeight(EditorGUIUtility.currentViewWidth * (_handTex.height / (
float)_handTex.width)),
46 GUILayout.MaxWidth(_handTex.width),
47 GUILayout.MaxHeight(_handTex.height));
49 Rect imageContainerRect = _handTexRect; imageContainerRect.width = EditorGUIUtility.currentViewWidth - 30F;
50 EditorGUI.DrawRect(imageContainerRect,
new Color(0.2F, 0.2F, 0.2F));
51 imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2;
52 EditorGUI.DrawRect(imageContainerRect,
new Color(0.6F, 0.6F, 0.6F));
53 imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2;
54 EditorGUI.DrawRect(imageContainerRect,
new Color(0.2F, 0.2F, 0.2F));
56 _handTexRect =
new Rect(_handTexRect.x + (imageContainerRect.center.x - _handTexRect.center.x),
60 EditorGUI.DrawTextureTransparent(_handTexRect, _handTex);
61 EditorGUILayout.Space();
66 EditorGUI.BeginDisabledGroup(isTargetPrefab);
68 makeAttachmentPointsToggle(
"Palm",
new Vector2( 0.100F, 0.160F));
69 makeAttachmentPointsToggle(
"Wrist",
new Vector2( 0.080F, 0.430F));
71 makeAttachmentPointsToggle(
"ThumbProximalJoint",
new Vector2(-0.190F, 0.260F));
72 makeAttachmentPointsToggle(
"ThumbDistalJoint",
new Vector2(-0.310F, 0.170F));
73 makeAttachmentPointsToggle(
"ThumbTip",
new Vector2(-0.390F, 0.110F));
75 makeAttachmentPointsToggle(
"IndexKnuckle",
new Vector2(-0.040F, -0.040F));
76 makeAttachmentPointsToggle(
"IndexMiddleJoint",
new Vector2(-0.060F, -0.170F));
77 makeAttachmentPointsToggle(
"IndexDistalJoint",
new Vector2(-0.075F, -0.280F));
78 makeAttachmentPointsToggle(
"IndexTip",
new Vector2(-0.080F, -0.380F));
80 makeAttachmentPointsToggle(
"MiddleKnuckle",
new Vector2( 0.080F, -0.050F));
81 makeAttachmentPointsToggle(
"MiddleMiddleJoint",
new Vector2( 0.080F, -0.190F));
82 makeAttachmentPointsToggle(
"MiddleDistalJoint",
new Vector2( 0.080F, -0.310F));
83 makeAttachmentPointsToggle(
"MiddleTip",
new Vector2( 0.090F, -0.420F));
85 makeAttachmentPointsToggle(
"RingKnuckle",
new Vector2( 0.195F, -0.020F));
86 makeAttachmentPointsToggle(
"RingMiddleJoint",
new Vector2( 0.220F, -0.150F));
87 makeAttachmentPointsToggle(
"RingDistalJoint",
new Vector2( 0.230F, -0.270F));
88 makeAttachmentPointsToggle(
"RingTip",
new Vector2( 0.245F, -0.380F));
90 makeAttachmentPointsToggle(
"PinkyKnuckle",
new Vector2( 0.295F, 0.040F));
91 makeAttachmentPointsToggle(
"PinkyMiddleJoint",
new Vector2( 0.340F, -0.050F));
92 makeAttachmentPointsToggle(
"PinkyDistalJoint",
new Vector2( 0.380F, -0.130F));
93 makeAttachmentPointsToggle(
"PinkyTip",
new Vector2( 0.410F, -0.210F));
95 EditorGUI.EndDisabledGroup();
97 EditorGUILayout.EndVertical();
100 private void makeAttachmentPointsToggle(
string attachmentFlagName, Vector2 offCenterPosImgSpace) {
105 if (EditorGUI.Toggle(makeToggleRect(_handTexRect.center
106 +
new Vector2(offCenterPosImgSpace.x * _handTexRect.width,
107 offCenterPosImgSpace.y * _handTexRect.height)),
108 (attachmentPoints & flag) == flag)) {
110 target.attachmentPoints = attachmentPoints | flag;
113 if (!wouldFlagDeletionDestroyData(
target, flag)
114 || EditorUtility.DisplayDialog(
"Delete " + flag +
" Attachment Point?",
115 "Deleting the " + flag +
" attachment point will destroy "
116 +
"its GameObject and any of its non-Attachment-Point children, "
117 +
"and will remove any components attached to it.",
118 "Delete " + flag +
" Attachment Point",
"Cancel")) {
120 target.attachmentPoints = attachmentPoints & (~flag);
125 private const float TOGGLE_SIZE = 15.0F;
126 private Rect makeToggleRect(Vector2 centerPos) {
127 return new Rect(centerPos.x - TOGGLE_SIZE / 2F, centerPos.y - TOGGLE_SIZE / 2F, TOGGLE_SIZE, TOGGLE_SIZE);
131 if (
target.attachmentHands ==
null)
return false;
133 foreach (var attachmentHand
in target.attachmentHands) {
134 var point = attachmentHand.GetBehaviourForPoint(flag);
136 if (point ==
null)
return false;
140 foreach (var child
in point.transform.GetChildren()) {
141 if (child.GetComponent<AttachmentPointBehaviour>() ==
null)
return true;
146 foreach (var component
in point.gameObject.GetComponents<
Component>()) {
147 if (component is Transform)
continue;
148 if (component is AttachmentPointBehaviour)
continue;
UnityEngine.Component Component
Add an GameObject with this script to your scene if you would like to have a Transform hierarchy that...
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.
AttachmentPointFlags
Flags for attachment points on the hand.