private void OnDrawGizmos() { if (SpringManager.showColliders && !SpringBone.SelectionContainsSpringBones()) { DrawGizmos((manager != null) ? manager.colliderColor : Color.gray); } }
public ChainInfo(SpringBone rootBone) { springBones = rootBone.GetComponentsInChildren <SpringBone>(true); transforms = rootBone.GetComponentsInChildren <Transform>(true); var bonePosition = rootBone.transform.position; baseVector = new Vector2(bonePosition.x, bonePosition.z).normalized; sideVector = new Vector2(-baseVector.y, baseVector.x); }
private static void SelectSpringManager(SpringBone bone) { var manager = bone.gameObject.GetComponentInParent <SpringManager>(); if (manager != null) { Selection.objects = new Object[] { manager.gameObject }; } }
private void ShowActionButtons(SpringBone bone) { InitializeActionButtons(); var buttonCount = actionButtons.Length; var buttonHeight = GUILayout.Height(ButtonHeight); for (int buttonIndex = 0; buttonIndex < buttonCount; buttonIndex++) { actionButtons[buttonIndex].Show(bone, buttonHeight); } }
private void OnDrawGizmos() { if (!enabled) { return; } DrawPickBox(); if (SpringManager.showColliders && !SpringBone.SelectionContainsSpringBones()) { DrawGizmos((manager != null) ? manager.colliderColor : Color.gray); } }
private static void SelectPivotNode(SpringBone bone) { var pivotObjects = new List <GameObject>(); foreach (var gameObject in Selection.gameObjects) { var springBone = gameObject.GetComponent <SpringBone>(); if (springBone != null && springBone.pivotNode != null) { pivotObjects.Add(springBone.pivotNode.gameObject); } } Selection.objects = pivotObjects.ToArray(); }
// Copies dynamics properties to the target. // Excludes child, boneAxis, target nodes, and private members. public void CopyDynamicsPropertiesTo(SpringBone target) { target.stiffnessForce = stiffnessForce; target.dragForce = dragForce; target.springForce = springForce; target.angularStiffness = angularStiffness; yAngleLimits.CopyTo(target.yAngleLimits); zAngleLimits.CopyTo(target.zAngleLimits); target.radius = radius; target.sphereColliders = (SpringSphereCollider[])sphereColliders.Clone(); target.capsuleColliders = (SpringCapsuleCollider[])capsuleColliders.Clone(); target.panelColliders = (SpringPanelCollider[])capsuleColliders.Clone(); }
private void OnDrawGizmos() { if (!enabled) { return; } if (manager == null) { manager = GetComponentInParent <SpringManager>(); } if (SpringManager.showColliders && !SpringBone.SelectionContainsSpringBones()) { DrawGizmos((manager != null) ? manager.colliderColor : Color.gray); } }
private static bool TryToGetPivotSideDirection ( SpringBone springBone, Vector3 lookDirection, out Vector3 sideDirection ) { sideDirection = Vector3.up; var meshNormal = FindClosestMeshNormalToPoint(springBone.transform.root, springBone.transform.position); var upDirection = Vector3.Cross(meshNormal, lookDirection).normalized; var possibleSideDirection = Vector3.Cross(lookDirection, upDirection).normalized; var isSideDirectionValid = IsPivotSideDirectionValid(lookDirection, possibleSideDirection); if (isSideDirectionValid) { sideDirection = possibleSideDirection; } return(isSideDirectionValid); }
// 基点ノードを作成 public static GameObject CreateSpringPivotNode(SpringBone springBone) { var pivotObject = new GameObject(springBone.name + "_Pivot"); pivotObject.transform.parent = springBone.transform.parent; pivotObject.transform.rotation = GetPivotRotation(springBone); pivotObject.transform.position = springBone.transform.position; pivotObject.AddComponent <SpringBonePivot>(); var oldPivotNode = springBone.pivotNode; if (oldPivotNode != null) { var skinBones = GameObjectUtil.GetAllBones(springBone.transform.root.gameObject); if (IsPivotProbablySafeToDestroy(oldPivotNode, skinBones)) { Object.DestroyImmediate(oldPivotNode.gameObject); } } springBone.pivotNode = pivotObject.transform; springBone.yAngleLimits.active = true; if (springBone.yAngleLimits.min > -0.5f && springBone.yAngleLimits.max < 0.5f) { springBone.yAngleLimits.min = -20f; springBone.yAngleLimits.max = 20f; } springBone.zAngleLimits.active = true; if (springBone.zAngleLimits.min > -0.5f && springBone.zAngleLimits.max < 0.5f) { springBone.zAngleLimits.min = 0f; springBone.zAngleLimits.max = 20f; } return(pivotObject); }
private static Quaternion GetPivotRotation(SpringBone springBone) { var lookDirection = springBone.ComputeChildPosition() - springBone.transform.position; lookDirection.Normalize(); Vector3 sideDirection; if (!TryToGetPivotSideDirection(springBone, lookDirection, out sideDirection)) { sideDirection = springBone.transform.position; sideDirection.y = 0f; sideDirection.Normalize(); if (!IsPivotSideDirectionValid(lookDirection, sideDirection)) { sideDirection = Vector3.up; if (!IsPivotSideDirectionValid(lookDirection, sideDirection)) { sideDirection = Vector3.forward; } } } var flattenedPosition = springBone.transform.position; flattenedPosition.y = 0f; if (Vector3.Dot(sideDirection, flattenedPosition) < 0f) { sideDirection = -sideDirection; } var upDirection = Vector3.Cross(lookDirection, sideDirection).normalized; var lookRotation = Quaternion.LookRotation(lookDirection, upDirection); var axisShift = Quaternion.Euler(180f, 90f, 0f); return(lookRotation * axisShift); }
private static SpringBoneBaseSerializer SpringBoneToBaseSerializer(SpringBone sourceBone) { return(new SpringBoneBaseSerializer { boneName = sourceBone.name, radius = sourceBone.radius, stiffness = sourceBone.stiffnessForce, drag = sourceBone.dragForce, springForce = sourceBone.springForce, windInfluence = sourceBone.windInfluence, pivotName = (sourceBone.pivotNode != null) ? sourceBone.pivotNode.name : "", yAngleLimits = AngleLimitsToSerializer(sourceBone.yAngleLimits), zAngleLimits = AngleLimitsToSerializer(sourceBone.zAngleLimits), angularStiffness = sourceBone.angularStiffness, lengthLimits = sourceBone.lengthLimitTargets .Where(item => item != null) .Select(item => new LengthLimitSerializer { objectName = item.name, ratio = 1.01f }) .ToArray() }); }