static IRigEffectorOverlay FetchOrCreateEffectorOverlay() { Transform[] transforms = Selection.GetTransforms(SelectionMode.ExcludePrefab | SelectionMode.Editable); var inspectedEffectors = new List <ScriptableObject>(); for (int i = 0; i < s_ActiveEffectors.Count; ++i) { var effector = s_ActiveEffectors[i]; if (effector != null && effector.transform != null) { if (Selection.Contains(effector.transform) || Selection.Contains(effector.transform.gameObject)) { inspectedEffectors.Add(s_ActiveEffectors[i]); } } } if (inspectedEffectors.Count > 0) { var overlay = new RigEffectorOverlay(); overlay.Initialize(new SerializedObject(inspectedEffectors.ToArray())); s_ActiveOverlay = overlay; } else { RigEffectorWizard wizard = null; foreach (var transform in transforms) { RigBuilder rigBuilder = EditorHelper.GetClosestComponent <RigBuilder>(transform); Rig rig = EditorHelper.GetClosestComponent <Rig>(transform, (rigBuilder != null) ? rigBuilder.transform : null); IRigEffectorHolder holder = (rig != null) ? (IRigEffectorHolder)rig : (IRigEffectorHolder)rigBuilder; if (holder == null) { continue; } if (wizard == null) { wizard = new RigEffectorWizard(); } wizard.Add(holder, transform); } if (wizard != null) { s_ActiveOverlay = wizard; } else { s_ActiveOverlay = null; } } s_ActiveSelection = transforms; return(s_ActiveOverlay); }
private static void DoBoneRender(Transform transform, Transform childTransform, BoneShape shape, Color color, float size) { Vector3 start = transform.position; Vector3 end = childTransform != null ? childTransform.position : start; GameObject boneGO = transform.gameObject; float length = (end - start).magnitude; bool tipBone = (length < k_Epsilon); int id = GUIUtility.GetControlID(s_ButtonHash, FocusType.Passive); Event evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: { HandleUtility.AddControl(id, tipBone ? HandleUtility.DistanceToCircle(start, k_BoneTipSize * size * 0.5f) : HandleUtility.DistanceToLine(start, end)); break; } case EventType.MouseMove: if (id == HandleUtility.nearestControl) { HandleUtility.Repaint(); } break; case EventType.MouseDown: { if (HandleUtility.nearestControl == id && evt.button == 0) { #if UNITY_2019_3_OR_NEWER if (!SceneVisibilityManager.instance.IsPickingDisabled(boneGO, false)) #endif { GUIUtility.hotControl = id; // Grab mouse focus EditorHelper.HandleClickSelection(boneGO, evt); evt.Use(); } } break; } case EventType.MouseDrag: { if (!evt.alt && GUIUtility.hotControl == id) { #if UNITY_2019_3_OR_NEWER if (!SceneVisibilityManager.instance.IsPickingDisabled(boneGO, false)) #endif { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new UnityEngine.Object[] { transform }; DragAndDrop.StartDrag(ObjectNames.GetDragAndDropTitle(transform)); GUIUtility.hotControl = 0; evt.Use(); } } break; } case EventType.MouseUp: { if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2)) { GUIUtility.hotControl = 0; evt.Use(); } break; } case EventType.Repaint: { Color highlight = color; bool hoveringBone = GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id; #if UNITY_2019_3_OR_NEWER hoveringBone = hoveringBone && !SceneVisibilityManager.instance.IsPickingDisabled(transform.gameObject, false); #endif if (hoveringBone) { highlight = Handles.preselectionColor; } else if (Selection.Contains(boneGO) || Selection.activeObject == boneGO) { highlight = Handles.selectedColor; } if (tipBone) { Handles.color = highlight; Handles.SphereHandleCap(0, start, Quaternion.identity, k_BoneTipSize * size, EventType.Repaint); } else if (shape == BoneShape.Line) { Handles.color = highlight; Handles.DrawLine(start, end); } else { if (shape == BoneShape.Pyramid) { pyramidMeshRenderer.AddInstance(ComputeBoneMatrix(start, end, length, size), color, highlight); } else // if (shape == BoneShape.Box) { boxMeshRenderer.AddInstance(ComputeBoneMatrix(start, end, length, size), color, highlight); } } } break; } }