void OnSceneGUI() { // Bone Handles if (LipSyncEditorExtensions.currentToggle >= 0 && LipSyncEditorExtensions.currentTarget == myTarget) { BoneShape bone = null; Shape shape = null; switch (LipSyncEditorExtensions.currentToggle) { case 0: shape = myTarget.blinkingShape; break; case 1: shape = myTarget.lookingUpShape; break; case 2: shape = myTarget.lookingDownShape; break; case 3: shape = myTarget.lookingLeftShape; break; case 4: shape = myTarget.lookingRightShape; break; } if (LipSyncEditorExtensions.selectedBone < shape.bones.Count && shape.bones.Count > 0) { bone = shape.bones[LipSyncEditorExtensions.selectedBone]; } else { return; } if (bone.bone == null) { return; } if (Tools.current == Tool.Move) { Undo.RecordObject(bone.bone, "Move"); Vector3 change = Handles.PositionHandle(bone.bone.position, bone.bone.rotation); if (change != bone.bone.position) { bone.bone.position = change; bone.endPosition = bone.bone.localPosition; } } else if (Tools.current == Tool.Rotate) { Undo.RecordObject(bone.bone, "Rotate"); Quaternion change = Handles.RotationHandle(bone.bone.rotation, bone.bone.position); if (change != bone.bone.rotation) { bone.bone.rotation = change; bone.endRotation = bone.bone.localEulerAngles; } } else if (Tools.current == Tool.Scale) { Undo.RecordObject(bone.bone, "Scale"); Vector3 change = Handles.ScaleHandle(bone.bone.localScale, bone.bone.position, bone.bone.rotation, HandleUtility.GetHandleSize(bone.bone.position)); if (change != bone.bone.localScale) { bone.bone.localScale = change; } } } }
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 (evt.alt) { break; } if (HandleUtility.nearestControl == id && evt.button == 0) { if (!SceneVisibilityManager.instance.IsPickingDisabled(boneGO, false)) { GUIUtility.hotControl = id; // Grab mouse focus EditorHelper.HandleClickSelection(boneGO, evt); evt.Use(); } } break; } case EventType.MouseDrag: { if (!evt.alt && GUIUtility.hotControl == id) { if (!SceneVisibilityManager.instance.IsPickingDisabled(boneGO, false)) { 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; hoveringBone = hoveringBone && !SceneVisibilityManager.instance.IsPickingDisabled(transform.gameObject, false); 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; } }
void OnSceneGUI() { if (markerTab == 0 && LipSyncEditorExtensions.currentToggle >= 0) { Handles.BeginGUI(); GUI.Box(new Rect(Screen.width - 256, Screen.height - 246, 256, 256), guides[LipSyncEditorExtensions.currentToggle], GUIStyle.none); Handles.EndGUI(); } // Bone Handles if (lsTarget.useBones && LipSyncEditorExtensions.currentToggle >= 0 && LipSyncEditorExtensions.currentTarget == lsTarget) { BoneShape bone = null; if (markerTab == 0) { if (LipSyncEditorExtensions.selectedBone < lsTarget.phonemes[LipSyncEditorExtensions.currentToggle].bones.Count && lsTarget.phonemes[LipSyncEditorExtensions.currentToggle].bones.Count > 0) { bone = lsTarget.phonemes[LipSyncEditorExtensions.currentToggle].bones[LipSyncEditorExtensions.selectedBone]; } else { return; } } if (bone.bone == null) { return; } if (Tools.current == Tool.Move) { Undo.RecordObject(bone.bone, "Move"); Vector3 change = Handles.PositionHandle(bone.bone.position, bone.bone.rotation); if (change != bone.bone.position) { bone.bone.position = change; bone.endPosition = bone.bone.localPosition; } } else if (Tools.current == Tool.Rotate) { Undo.RecordObject(bone.bone, "Rotate"); Quaternion change = Handles.RotationHandle(bone.bone.rotation, bone.bone.position); if (change != bone.bone.rotation) { bone.bone.rotation = change; bone.endRotation = bone.bone.localEulerAngles; } } else if (Tools.current == Tool.Scale) { Undo.RecordObject(bone.bone, "Scale"); Vector3 change = Handles.ScaleHandle(bone.bone.localScale, bone.bone.position, bone.bone.rotation, HandleUtility.GetHandleSize(bone.bone.position)); if (change != bone.bone.localScale) { bone.bone.localScale = change; } } } }
void LoadPreset(object data) { string file = (string)data; if (file.EndsWith(".asset", true, null)) { LipSyncPreset preset = AssetDatabase.LoadAssetAtPath <LipSyncPreset>("Assets" + file.Substring((Application.dataPath).Length)); if (preset != null) { List <PhonemeShape> newPhonemes = new List <PhonemeShape>(); // Phonemes for (int shape = 0; shape < preset.phonemeShapes.Length; shape++) { newPhonemes.Add(new PhonemeShape(preset.phonemeShapes[shape].phoneme)); for (int blendable = 0; blendable < preset.phonemeShapes[shape].blendables.Length; blendable++) { int finalBlendable = preset.FindBlendable(preset.phonemeShapes[shape].blendables[blendable], lsTarget.blendSystem); if (finalBlendable >= 0) { newPhonemes[shape].blendShapes.Add(finalBlendable); newPhonemes[shape].weights.Add(preset.phonemeShapes[shape].blendables[blendable].weight); } } for (int bone = 0; bone < preset.phonemeShapes[shape].bones.Length; bone++) { BoneShape newBone = new BoneShape(); newBone.bone = preset.FindBone(preset.phonemeShapes[shape].bones[bone], lsTarget.transform); newBone.SetNeutral(); newBone.endPosition = preset.phonemeShapes[shape].bones[bone].localPosition; newBone.endRotation = preset.phonemeShapes[shape].bones[bone].localRotation; newBone.lockPosition = preset.phonemeShapes[shape].bones[bone].lockPosition; newBone.lockRotation = preset.phonemeShapes[shape].bones[bone].lockRotation; newPhonemes[shape].bones.Add(newBone); } } lsTarget.phonemes = newPhonemes; for (int bShape = 0; bShape < lsTarget.blendSystem.blendableCount; bShape++) { lsTarget.blendSystem.SetBlendableValue(bShape, 0); } if (markerTab == 0) { if (LipSyncEditorExtensions.currentToggle >= 0) { int b = 0; foreach (int shape in lsTarget.phonemes[LipSyncEditorExtensions.currentToggle].blendShapes) { lsTarget.blendSystem.SetBlendableValue(shape, lsTarget.phonemes[LipSyncEditorExtensions.currentToggle].weights[b]); b++; } } } } } }
public BoneShapeInfo(BoneShape boneShape) { bone = boneShape.bone; m_storedPosition = boneShape.neutralPosition; m_storedRotation = Quaternion.Euler(boneShape.neutralRotation); }