Пример #1
0
        void OnSceneGUI()
        {
            Handles.color = targetColor;

            Inspector.SphereCap(0, script.transform.position, Quaternion.identity, size);

            DrawChildrenRecursive(script.transform);

            if (script.pivot != null)
            {
                Handles.color = pivotColor;
                GUI.color     = pivotColor;

                Inspector.SphereCap(0, script.pivot.position, Quaternion.identity, size);

                if (script.rotationMode == InteractionTarget.RotationMode.TwoDOF)
                {
                    Vector3 twistAxisWorld = script.pivot.rotation * script.twistAxis.normalized * size * 40;
                    Handles.DrawLine(script.pivot.position, script.pivot.position + twistAxisWorld);
                    Inspector.SphereCap(0, script.pivot.position + twistAxisWorld, Quaternion.identity, size);

                    Inspector.CircleCap(0, script.pivot.position, Quaternion.LookRotation(twistAxisWorld), size * 20);
                    Handles.Label(script.pivot.position + twistAxisWorld, twistAxisLabel);
                }
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }
Пример #2
0
    void OnSceneGUI()
    {
        // Set defaultLocalRotation so that the initial local rotation will be the zero point for the rotation limit
        if (!Application.isPlaying)
        {
            script.defaultLocalRotation = script.transform.localRotation;
        }
        if (script.axis == Vector3.zero)
        {
            return;
        }

        // Quick Editing Tools
        Handles.BeginGUI();
        GUILayout.BeginArea(new Rect(10, Screen.height - 100, 200, 50), "Rotation Limit Hinge", "Window");

        // Rotating display
        if (GUILayout.Button("Rotate display 90 degrees"))
        {
            if (!Application.isPlaying)
            {
                Undo.RecordObject(script, "Rotate Display");
            }
            script.zeroAxisDisplayOffset += 90;
            if (script.zeroAxisDisplayOffset >= 360)
            {
                script.zeroAxisDisplayOffset = 0;
            }
        }

        GUILayout.EndArea();
        Handles.EndGUI();

        // Normalize the main axes
        Vector3 axis  = Direction(script.axis.normalized);
        Vector3 cross = Direction(Quaternion.AngleAxis(script.zeroAxisDisplayOffset, script.axis) * script.crossAxis.normalized);

        // Axis vector
        DrawArrow(script.transform.position, axis, colorDefault, "Axis", 0.02f);

        if (script.useLimits)
        {
            // Zero rotation vector
            DrawArrow(script.transform.position, cross * 0.5f, colorDefault, " 0", 0.02f);

            // Arcs for the rotation limit
            Handles.color = colorDefaultTransparent;
            Handles.DrawSolidArc(script.transform.position, axis, cross, script.min, 0.5f);
            Handles.DrawSolidArc(script.transform.position, axis, cross, script.max, 0.5f);
        }

        Handles.color = colorDefault;
        GUI.color     = colorDefault;

        Inspector.CircleCap(0, script.transform.position, Quaternion.LookRotation(axis, cross), 0.5f);

        if (!script.useLimits)
        {
            return;
        }

        // Handles for adjusting rotation limits in the scene
        Quaternion minRotation = Quaternion.AngleAxis(script.min, axis);

        Handles.DrawLine(script.transform.position, script.transform.position + minRotation * cross);

        Quaternion maxRotation = Quaternion.AngleAxis(script.max, axis);

        Handles.DrawLine(script.transform.position, script.transform.position + maxRotation * cross);

        // Undoable scene handles
        float min = script.min;

        min = DrawLimitHandle(min, script.transform.position + minRotation * cross, Quaternion.identity, 0.5f, "Min", -10);
        if (min != script.min)
        {
            if (!Application.isPlaying)
            {
                Undo.RecordObject(script, "Min Limit");
            }
            script.min = min;
        }

        float max = script.max;

        max = DrawLimitHandle(max, script.transform.position + maxRotation * cross, Quaternion.identity, 0.5f, "Max", 10);
        if (max != script.max)
        {
            if (!Application.isPlaying)
            {
                Undo.RecordObject(script, "Max Limit");
            }
            script.max = max;
        }

        Handles.color = Color.white;
        GUI.color     = Color.white;
    }
Пример #3
0
        private void DrawCameraPosition(InteractionTrigger.Range range, int index)
        {
            if (range.cameraPosition.lookAtTarget == null)
            {
                return;
            }

            Vector3 labelPosition = range.cameraPosition.lookAtTarget.transform.position - Vector3.up * index * 0.05f;

            if (range.cameraPosition.direction == Vector3.zero)
            {
                Handles.Label(labelPosition, "Camera Position direction is Vector3.zero for Range" + index.ToString() + ": " + range.name);
                return;
            }
            if (range.cameraPosition.maxAngle <= 0f)
            {
                Handles.Label(labelPosition, "Camera Position max angle is zero for Range" + index.ToString() + ": " + range.name);
                return;
            }
            range.cameraPosition.maxDistance = Mathf.Max(range.cameraPosition.maxDistance, 0f);
            if (range.cameraPosition.maxDistance <= 0f)
            {
                Handles.Label(labelPosition, "Camera Position Max Distance is zero for Range" + index.ToString() + ": " + range.name);
                return;
            }

            Quaternion targetRotation = range.cameraPosition.GetRotation();
            Vector3    position       = range.cameraPosition.lookAtTarget.transform.position;

            Vector3 direction = targetRotation * range.cameraPosition.direction;

            direction = direction.normalized * range.cameraPosition.maxDistance;

            Handles.DrawLine(position, position + direction);
            Inspector.DotCap(0, position + direction, Quaternion.identity, 0.005f);

            Handles.Label(position + direction * 1.1f, "Camera Position for Range " + index.ToString() + ": " + range.name);

            if (range.cameraPosition.maxAngle >= 180f)
            {
                return;
            }

            float r = Mathf.Sin(range.cameraPosition.maxAngle * Mathf.Deg2Rad) * range.cameraPosition.maxDistance;
            float d = Mathf.Cos(range.cameraPosition.maxAngle * Mathf.Deg2Rad) * range.cameraPosition.maxDistance;

            Quaternion rotation = targetRotation * Quaternion.LookRotation(range.cameraPosition.direction);

            Inspector.CircleCap(0, position + direction.normalized * d, rotation, r);

            if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null)
            {
                //Vector3 c = Vector3.Cross(direction, SceneView.lastActiveSceneView.camera.transform.forward);
                Vector3 c = Vector3.Cross(direction, (range.cameraPosition.lookAtTarget.transform.position - SceneView.lastActiveSceneView.camera.transform.position).normalized);
                c = Vector3.Cross(direction, c);
                Quaternion dirRotation = Quaternion.AngleAxis(range.cameraPosition.maxAngle, c);
                Vector3    dir3        = dirRotation * direction;
                Handles.DrawLine(position, position + dir3);

                Vector3 dir4 = Quaternion.Inverse(dirRotation) * direction;
                Handles.DrawLine(position, position + dir4);

                Handles.DrawWireArc(position, -c, dir3, range.cameraPosition.maxAngle * 2, range.cameraPosition.maxDistance);
            }
        }