Beispiel #1
0
        Rect ResizeRect(Rect rect, UnityEditor.Handles.DrawCapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap)
#endif
        {
            Vector2 halfSize = new Vector2(rect.size.x * 0.5f, rect.size.y * 0.5f);

            Vector3[] rectangleCorners =
            {
                VectorHVD(rect.position.x - halfSize.x, rect.position.y - halfSize.y, 0),       // Bottom Left
                VectorHVD(rect.position.x + halfSize.x, rect.position.y - halfSize.y, 0),       // Bottom Right
                VectorHVD(rect.position.x + halfSize.x, rect.position.y + halfSize.y, 0),       // Top Right
                VectorHVD(rect.position.x - halfSize.x, rect.position.y + halfSize.y, 0)        // Top Left
            };

            Handles.color = fillCol;
            Handles.DrawSolidRectangleWithOutline(rectangleCorners, new Color(fillCol.r, fillCol.g, fillCol.b, 0.25f), capCol);

            Vector3[] handlePoints =
            {
                VectorHVD(rect.position.x - halfSize.x, rect.position.y, 0),              // Left
                VectorHVD(rect.position.x + halfSize.x, rect.position.y, 0),              // Right
                VectorHVD(rect.position.x,              rect.position.y + halfSize.y, 0), // Top
                VectorHVD(rect.position.x,              rect.position.y - halfSize.y, 0)  // Bottom
            };

            Handles.color = capCol;

            var newSize     = rect.size;
            var newPosition = rect.position;

            var leftHandle   = Utils.AlignToGrid(Vector3H(Handles.Slider(handlePoints[0], -VectorHVD(1, 0, 0), capSize, capFunc, snap)) - Vector3H(handlePoints[0]), snap);
            var rightHandle  = Utils.AlignToGrid(Vector3H(Handles.Slider(handlePoints[1], VectorHVD(1, 0, 0), capSize, capFunc, snap)) - Vector3H(handlePoints[1]), snap);
            var topHandle    = Utils.AlignToGrid(Vector3V(Handles.Slider(handlePoints[2], VectorHVD(0, 1, 0), capSize, capFunc, snap)) - Vector3V(handlePoints[2]), snap);
            var bottomHandle = Utils.AlignToGrid(Vector3V(Handles.Slider(handlePoints[3], -VectorHVD(0, 1, 0), capSize, capFunc, snap)) - Vector3V(handlePoints[3]), snap);

            newSize = new Vector2(
                Mathf.Max(0f, newSize.x - leftHandle + rightHandle),
                Mathf.Max(0f, newSize.y + topHandle - bottomHandle));

            newPosition = new Vector2(
                newPosition.x + leftHandle * .5f + rightHandle * .5f,
                newPosition.y + topHandle * .5f + bottomHandle * .5f);

            return(new Rect(newPosition.x, newPosition.y, newSize.x, newSize.y));
        }
Beispiel #2
0
    private void OnSceneGUI()
    {
        RenderAttenuationSpheres();

        if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Simple_Mode)
        {
            return;
        }

        var someHashCode = GetHashCode();

        UnityEditor.Handles.matrix = m_AkAmbient.transform.localToWorldMatrix;

        for (var i = 0; i < m_AkAmbient.multiPositionArray.Count; i++)
        {
            var pos = m_AkAmbient.multiPositionArray[i];

            UnityEditor.Handles.Label(pos, "Point_" + i);

            var handleSize = UnityEditor.HandleUtility.GetHandleSize(pos);

            // Get the needed data before the handle
            var controlIDBeforeHandle   = UnityEngine.GUIUtility.GetControlID(someHashCode, UnityEngine.FocusType.Passive);
            var isEventUsedBeforeHandle = UnityEngine.Event.current.type == UnityEngine.EventType.Used;

            UnityEditor.Handles.color = UnityEngine.Color.green;
#if UNITY_5_6_OR_NEWER
            UnityEditor.Handles.CapFunction capFunc = UnityEditor.Handles.SphereHandleCap;
#else
            UnityEditor.Handles.DrawCapFunction capFunc = UnityEditor.Handles.SphereCap;
#endif
            UnityEditor.Handles.ScaleValueHandle(0, pos, UnityEngine.Quaternion.identity, handleSize, capFunc, 0);

            if (curPointIndex == i)
            {
                pos = UnityEditor.Handles.PositionHandle(pos, UnityEngine.Quaternion.identity);
            }

            // Get the needed data after the handle
            var controlIDAfterHandle = UnityEngine.GUIUtility.GetControlID(someHashCode, UnityEngine.FocusType.Passive);
            var isEventUsedByHandle  = !isEventUsedBeforeHandle && UnityEngine.Event.current.type == UnityEngine.EventType.Used;

            if (controlIDBeforeHandle < UnityEngine.GUIUtility.hotControl &&
                UnityEngine.GUIUtility.hotControl < controlIDAfterHandle || isEventUsedByHandle)
            {
                curPointIndex = i;
            }

            m_AkAmbient.multiPositionArray[i] = pos;
        }

        if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Large_Mode)
        {
            UnityEditor.Handles.BeginGUI();

            var size = new UnityEngine.Rect(0, 0, 200, 70);
            UnityEngine.GUI.Window(0,
                                   new UnityEngine.Rect(UnityEngine.Screen.width - size.width - 10, UnityEngine.Screen.height - size.height - 50,
                                                        size.width, size.height), DoMyWindow, "AkAmbient Tool Bar");

            UnityEditor.Handles.EndGUI();
        }
    }