Пример #1
0
        public static Rect RectHandle(Rect rect, Quaternion rotation, CapFunction capFunction)
        {
            var originalMatrix = SceneHandles.matrix;

            SceneHandles.matrix = originalMatrix * Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            var result = RectHandle(rect, capFunction);

            SceneHandles.matrix = originalMatrix;
            return(result);
        }
Пример #2
0
        public void BindToVariable(string key, string varName, CapFunction f = null, object capParms = null)
        {
            var isValidField = CheckIfFieldExists(varName);

            if (!isValidField)
            {
                Console.WriteLine("Failed to bind: " + varName);
                return;
            }
            if (key is null)
            {
                var field = Provider.Request <FieldLocatorService>().LocateLast();
                field?.BindToField(Owner.T, varName, f, capParms);
            }
            else
            {
                var field = Provider.Request <FieldLocatorService>().LocateName(key);
                field?.BindToField(Owner.T, varName, f, capParms);
            }
        }
Пример #3
0
 public static Vector2 Slider2D(int id, Vector2 position, CapFunction drawCapFunction)
 {
     return(Slider2D(id, position, drawCapFunction, Vector3.forward, Vector3.zero));
 }
Пример #4
0
 public static Vector3 Slider2DHandle(int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, CapFunction capFunction, Axes axes = Axes.None, bool selectLockingAxisOnClick = false, Vector3?snappingSteps = null)
 {
     return(Slider2D.Do(id, new Vector3[] { handlePos }, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, selectLockingAxisOnClick, false, snappingSteps)[0]);
 }
Пример #5
0
        public static Bounds BoundsHandle(Bounds bounds, Quaternion rotation, CapFunction sideCapFunction, CapFunction pointCapFunction, Vector3?snappingSteps = null)
        {
            var  hotControl   = GUIUtility.hotControl;
            bool isControlHot = false;

            for (int i = 0; i < s_BoundsControlIds.Length; i++)
            {
                s_BoundsControlIds[i] = GUIUtility.GetControlID(s_BoundsHash, FocusType.Keyboard);
                s_BoundsAxisHot[i]    = s_BoundsControlIds[i] == hotControl;
                isControlHot          = isControlHot || s_BoundsAxisHot[i];
            }

            s_BoundsSlideDirs[0] = rotation * Vector3.right;
            s_BoundsSlideDirs[1] = rotation * Vector3.up;
            s_BoundsSlideDirs[2] = rotation * Vector3.forward;

            var min    = bounds.min;
            var max    = bounds.max;
            var center = bounds.center;

            s_BoundsValues[0] = min.x;
            s_BoundsValues[1] = min.y;
            s_BoundsValues[2] = min.z;

            s_BoundsValues[3] = max.x;
            s_BoundsValues[4] = max.y;
            s_BoundsValues[5] = max.z;


            s_BoundsVertices[0] = rotation * new Vector3(s_BoundsValues[0], s_BoundsValues[1], s_BoundsValues[2]);
            s_BoundsVertices[1] = rotation * new Vector3(s_BoundsValues[3], s_BoundsValues[1], s_BoundsValues[2]);
            s_BoundsVertices[2] = rotation * new Vector3(s_BoundsValues[3], s_BoundsValues[4], s_BoundsValues[2]);
            s_BoundsVertices[3] = rotation * new Vector3(s_BoundsValues[0], s_BoundsValues[4], s_BoundsValues[2]);

            s_BoundsVertices[4] = rotation * new Vector3(s_BoundsValues[0], s_BoundsValues[1], s_BoundsValues[5]);
            s_BoundsVertices[5] = rotation * new Vector3(s_BoundsValues[3], s_BoundsValues[1], s_BoundsValues[5]);
            s_BoundsVertices[6] = rotation * new Vector3(s_BoundsValues[3], s_BoundsValues[4], s_BoundsValues[5]);
            s_BoundsVertices[7] = rotation * new Vector3(s_BoundsValues[0], s_BoundsValues[4], s_BoundsValues[5]);


            s_BoundsSidePoint[0] = rotation * new Vector3(s_BoundsValues[0], center.y, center.z);
            s_BoundsSidePoint[1] = rotation * new Vector3(center.x, s_BoundsValues[1], center.z);
            s_BoundsSidePoint[2] = rotation * new Vector3(center.x, center.y, s_BoundsValues[2]);
            s_BoundsSidePoint[3] = rotation * new Vector3(s_BoundsValues[3], center.y, center.z);
            s_BoundsSidePoint[4] = rotation * new Vector3(center.x, s_BoundsValues[4], center.z);
            s_BoundsSidePoint[5] = rotation * new Vector3(center.x, center.y, s_BoundsValues[5]);

            // TODO: add handles in the corners of each quad on the bounds, with an offset from the vertex, to drag from there


            using (new SceneHandles.DrawingScope())
            { var prevDisabled = SceneHandles.disabled;

              var isStatic = (!Tools.hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));


              for (int i = 0; i < s_BoundsAxisDisabled.Length; i++)
              {
                  s_BoundsAxisDisabled[i] = isStatic || prevDisabled || Snapping.AxisLocking[i % 3] || (isControlHot && !s_BoundsAxisHot[i]);
              }

              var camera               = Camera.current;
              var cameraLocalPos       = SceneHandles.inverseMatrix.MultiplyPoint(camera.transform.position);
              var cameraLocalForward   = SceneHandles.inverseMatrix.MultiplyVector(camera.transform.forward);
              var isCameraInsideBox    = bounds.Contains(cameraLocalPos);
              var isCameraOrthographic = camera.orthographic;


              var boundsColor    = SceneHandles.yAxisColor;
              var backfacedColor = new Color(boundsColor.r, boundsColor.g, boundsColor.b, boundsColor.a * SceneHandles.backfaceAlphaMultiplier);


              var prevGUIchanged = GUI.changed;

              bool haveChanged = false;

              var selectedAxes = Axes.None;

              // all sides of bounds
              int currentFocusControl = SceneHandleUtility.focusControl;
              for (int i = 0; i < s_BoundsValues.Length; i++)
              {
                  var id = s_BoundsControlIds[i];


                  GUI.changed = false;
                  var localPoint = s_BoundsSidePoint[i];
                  var handleSize = UnityEditor.HandleUtility.GetHandleSize(localPoint);
                  var pointSize  = handleSize * kPointScale;
                  var direction  = s_BoundsSlideDirs[i % 3];
                  var normal     = (i < 3) ? -direction : direction;
                  normal.x *= (bounds.size.x < 0) ? -1 : 1;
                  normal.y *= (bounds.size.y < 0) ? -1 : 1;
                  normal.z *= (bounds.size.z < 0) ? -1 : 1;

                  if (Event.current.type == EventType.Repaint)
                  {
                      s_BoundsBackfaced[i] = false;
                      if (!isCameraInsideBox)
                      {
                          var cosV = isCameraOrthographic ? Vector3.Dot(normal, -cameraLocalForward) :
                                     Vector3.Dot(normal, (cameraLocalPos - localPoint));
                          if (cosV < -0.0001f)
                          {
                              // TODO: do not set backfaced to true when side is infinitely thin
                              s_BoundsBackfaced[i] = !(isControlHot && !s_BoundsAxisHot[i % 3]);
                          }
                      }

                      var sideColor = (s_BoundsBackfaced[i] ? backfacedColor: boundsColor);
                      SceneHandles.color = SceneHandles.StateColor(sideColor, s_BoundsAxisDisabled[i], (currentFocusControl == id));

                      if (currentFocusControl == id)
                      {
                          var sceneView = SceneView.currentDrawingSceneView;
                          if (sceneView)
                          {
                              var rect = sceneView.position;
                              rect.min = Vector2.zero;
                              EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForDirection(localPoint, normal));
                          }
                          selectedAxes = s_BoundsAxes[i];
                      }

                      if (s_BoundsBackfaced[i])
                      {
                          pointSize *= backfaceSizeMultiplier;
                      }
                  }

                  var steps    = snappingSteps ?? Snapping.MoveSnappingSteps;
                  var newPoint = Slider1DHandle(id, (Axis)(i % 3), localPoint, normal, steps[i % 3], pointSize, sideCapFunction);
                  if (GUI.changed)
                  {
                      s_BoundsValues[i] += Vector3.Dot(direction, newPoint - localPoint);
                      haveChanged        = true;
                  }
              }

              // all edges of bounds
              for (int i = 0; i < s_BoundsEdgeIndices.GetLength(0); i++)
              {
                  var id = GUIUtility.GetControlID(s_BoundsHash, FocusType.Keyboard);

                  GUI.changed = false;
                  var index1 = s_BoundsEdgeIndices[i, 0];
                  var index2 = s_BoundsEdgeIndices[i, 1];
                  var point1 = s_BoundsVertices[index1];
                  var point2 = s_BoundsVertices[index2];

                  var midPoint = (point1 + point2) * 0.5f;

                  var offset1     = s_EdgeDirectionOffsets[i, 0];
                  var offset2     = s_EdgeDirectionOffsets[i, 1];
                  var offset3     = s_EdgeDirectionOffsets[i, 2];
                  var offset1_dir = offset1 % 3;
                  var offset2_dir = offset2 % 3;

                  if (Event.current.type == EventType.Repaint)
                  {
                      var highlight    = (currentFocusControl == id) || (currentFocusControl == s_BoundsControlIds[offset1]) || (currentFocusControl == s_BoundsControlIds[offset2]);
                      var edgeColor    = (s_BoundsBackfaced[offset1] && s_BoundsBackfaced[offset2]) ? backfacedColor : boundsColor;
                      var edgeDisabled = (s_BoundsAxisDisabled[offset1] && s_BoundsAxisDisabled[offset2]);
                      SceneHandles.color = SceneHandles.StateColor(edgeColor, edgeDisabled, highlight);

                      if (currentFocusControl == id)
                      {
                          selectedAxes = s_EdgeAxes[i];
                      }
                  }

                  // only use capFunction (render point) when in ortho mode & aligned with box or when side size is 0
                  bool isSideAlignedWithCamera = false;   // TODO: determine if aligned with camera direction & in ortho mode
                  bool showSidePoint           = !isSideAlignedWithCamera && ((point2 - point1).sqrMagnitude < kShowPointThreshold);

                  float   pointSize;
                  Vector3 offset;
                  if (showSidePoint)
                  {
                      pointSize = UnityEditor.HandleUtility.GetHandleSize(midPoint) * kPointScale;
                      offset    = Edge2DHandleOffset(id, point1, point2, midPoint, s_BoundsSlideDirs[offset3],
                                                     s_BoundsSlideDirs[offset1_dir],
                                                     s_BoundsSlideDirs[offset2_dir], pointSize, pointCapFunction, s_EdgeAxes[i], snappingSteps: snappingSteps);
                  }
                  else
                  {
                      offset = Edge2DHandleOffset(id, point1, point2, midPoint, s_BoundsSlideDirs[offset3],
                                                  s_BoundsSlideDirs[offset1_dir],
                                                  s_BoundsSlideDirs[offset2_dir], 0, null, s_EdgeAxes[i], snappingSteps: snappingSteps);
                  }

                  if (GUI.changed)
                  {
                      offset = Quaternion.Inverse(rotation) * offset;
                      if (Mathf.Abs(offset[offset1_dir]) > 0.000001f ||
                          Mathf.Abs(offset[offset2_dir]) > 0.000001f)
                      {
                          s_BoundsValues[offset1] += offset[offset1_dir];
                          s_BoundsValues[offset2] += offset[offset2_dir];
                          haveChanged              = true;
                      }
                      else
                      {
                          GUI.changed = false;
                      }
                  }
              }

              GUI.changed = prevGUIchanged || haveChanged;

              if (haveChanged)
              {
                  var size = bounds.size;

                  center.x = (s_BoundsValues[3] + s_BoundsValues[0]) * 0.5f;
                  size.x   = (s_BoundsValues[3] - s_BoundsValues[0]);

                  center.y = (s_BoundsValues[4] + s_BoundsValues[1]) * 0.5f;
                  size.y   = (s_BoundsValues[4] - s_BoundsValues[1]);

                  center.z = (s_BoundsValues[5] + s_BoundsValues[2]) * 0.5f;
                  size.z   = (s_BoundsValues[5] - s_BoundsValues[2]);

                  bounds.center = center;
                  bounds.size   = size;
              }

              // TODO: paint XZ intersection with grid plane + 'shadow'

              SceneHandles.disabled = prevDisabled; }

            return(bounds);
        }
Пример #6
0
 public static Vector3 Slider1DHandleOffset(int id, Axis axis, Vector3[] snapPoints, Vector3 handleDirection, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
 {
     return(Slider1D.Do(id, axis, snapPoints, snapPoints[0], handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - snapPoints[0]);
 }
Пример #7
0
        public static Vector3 Slider1DHandle(int id, Vector3 handleOrigin, Vector3 handleDirection, CapFunction capFunction, float snappingStep = 0, float handleSize = 0)
        {
            Axis axis = Grid.ActiveGrid.GetClosestAxis(Handles.matrix.MultiplyVector(handleDirection));

            return(UnitySceneExtensions.SceneHandles.Slider1DHandle(id, axis, handleOrigin, handleDirection, snappingStep, handleSize, capFunction));
        }
Пример #8
0
        public static Vector3 Slider1DHandle(Vector3 handleOrigin, Vector3 handleDirection, CapFunction capFunction, float snappingStep = 0, float handleSize = 0, Axis axis = Axis.Y)
        {
            var id = GUIUtility.GetControlID(s_Slider1DHash, FocusType.Passive);

            return(Slider1DHandle(id, axis, handleOrigin, handleDirection, capFunction, snappingStep, handleSize));
        }
Пример #9
0
        public static Vector3 Slider1DHandleOffset(int id, Vector3 handleOrigin, Vector3 handleDirection, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
        {
            Axis axis = Grid.ActiveGrid.GetClosestAxis(Handles.matrix.MultiplyVector(handleDirection));

            return(UnitySceneExtensions.SceneHandles.Slider1DHandle(id, axis, handleOrigin, handleDirection, snappingStep, handleSize, capFunction) - handleOrigin);
        }
Пример #10
0
 internal static bool Button(int controlID, Vector3 position, Quaternion direction, float size, float pickSize, CapFunction capFunction)
 {
     return UnityEditorInternal.Button.Do(controlID, position, direction, size, pickSize, capFunction);
 }
Пример #11
0
 public static bool Button(Vector3 position, Quaternion direction, float size, float pickSize, CapFunction capFunction)
 {
     return UnityEditorInternal.Button.Do(GUIUtility.GetControlID(s_ButtonHash, FocusType.Passive), position, direction, size, pickSize, capFunction);
 }
 public static Vector3 Slider1DHandle(int id, Axis axis, Vector3 handleOrigin, Vector3 handleDirection, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
 {
     pointArray[0] = handleOrigin;
     return(Slider1D.Do(id, axis, pointArray, handleOrigin, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0]);
 }
Пример #13
0
 public static Vector3 Slider2DHandleOffset(int id, Vector3 handlePos, Vector3 handleDir, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false, Vector3? snappingSteps = null)
 {
     var grid        = Grid.ActiveGrid;
     var normalAxis  = grid.GetClosestAxis(handleDir);
     var axes        = grid.GetTangentAxesForAxis(normalAxis, out Vector3 slideDir1, out Vector3 slideDir2);
     if (handleSize == 0)
         handleSize = UnityEditor.HandleUtility.GetHandleSize(handlePos) * 0.05f;
     return Slider2D.Do(id, new Vector3[] { handlePos }, handlePos, Vector3.zero, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, selectLockingAxisOnClick, false, snappingSteps)[0] - handlePos;
 }
Пример #14
0
 internal static bool Button(int controlID, Vector3 position, Quaternion direction, float size, float pickSize, CapFunction capFunction)
 {
     return(UnityEditorInternal.Button.Do(controlID, position, direction, size, pickSize, capFunction));
 }
Пример #15
0
        // Make a 3D Button.
        public static bool Button(Vector3 position, Quaternion direction, float size, float pickSize, CapFunction capFunction)
        {
            int id = GUIUtility.GetControlID(s_ButtonHash, FocusType.Passive);

            return(UnityEditorInternal.Button.Do(id, position, direction, size, pickSize, capFunction));
        }
Пример #16
0
 public static float ScaleValueHandle(int controlID, float value, Vector3 position, Quaternion rotation, float size, CapFunction capFunction, float snap)
 {
     return(UnityEditorInternal.SliderScale.DoCenter(controlID, value, position, rotation, size, capFunction, snap));
 }
        public static Vector3 Edge1DHandleOffset(Axis axis, Vector3 from, Vector3 to, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction)
        {
            var position = (from + to) * 0.5f;
            var id       = GUIUtility.GetControlID(s_Edge1DHash, FocusType.Keyboard);

            return(Edge1DHandleOffset(id, axis, from, to, position, direction, snappingStep, handleSize, capFunction));
        }
        public static Vector3 Edge2DHandleOffset(int id, Vector3 from, Vector3 to, Vector3 position, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, CapFunction capFunction, Axes axes = Axes.None, Vector3?snappingSteps = null)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (Tools.current == Tool.View ||
                    Tools.current == Tool.None ||
                    evt.alt)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 0.5f);
                break;
            }

            case EventType.Repaint:
            {
                var sceneView = SceneView.currentDrawingSceneView;
                if (sceneView &&
                    Tools.current != Tool.View &&
                    Tools.current != Tool.None &&
                    !evt.alt)
                {
                    if (UnityEditor.HandleUtility.nearestControl == id || EditorGUIUtility.hotControl == id)
                    {
                        var rect = sceneView.position;
                        rect.min = Vector2.zero;
                        EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForEdge(from, to));
                    }
                }
                if (EditorGUIUtility.keyboardControl == id)
                {
                    SceneHandles.DrawAAPolyLine(3.0f, from, to);
                }
                else
                {
                    SceneHandles.DrawAAPolyLine(2.5f, from, to);
                }
                break;
            }
            }


            var points = new Vector3[] { from, to };
            var result = Slider2D.Do(id, points, position, Vector3.zero, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, snappingSteps: snappingSteps);

            return(result[0] - from);
        }
Пример #19
0
        public static Vector3 Slider1DHandleAlignedOffset(int id, Vector3 from, Vector3 to, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
        {
            var snapPoints      = new[] { from, to };
            var handleDirection = (from - to).normalized;
            var grid            = Grid.ActiveGrid;
            var axis            = grid.GetClosestAxis(handleDirection);

            return(Slider1D.Do(id, axis, snapPoints, from, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - from);
        }
        public static Vector3 Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, Vector3 position, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction)
        {
            if (snappingStep == 0)
            {
                snappingStep = Snapping.MoveSnappingSteps[(int)axis];
            }
            if (handleSize == 0)
            {
                handleSize = UnityEditor.HandleUtility.GetHandleSize(position) * 0.05f;
            }

            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (SceneHandles.InCameraOrbitMode)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to));
                break;
            }

            case EventType.Repaint:
            {
                SetCursor(id, from, to);
                linePoints[0] = from;
                linePoints[1] = to;
                SceneHandles.DrawAAPolyLine(3.0f, linePoints);
                break;
            }
            }


            var points = new Vector3[] { from, to };
            var result = Slider1DHandle(id, axis, points, position, direction, snappingStep, handleSize, capFunction);

            return(result[0] - from);
        }
Пример #21
0
 public static Vector3 Slider1DHandle(int id, Axis axis, Vector3 handleOrigin, Vector3 handleDirection, CapFunction capFunction, float snappingStep = 0, float handleSize = 0)
 {
     return(UnitySceneExtensions.SceneHandles.Slider1DHandle(id, axis, handleOrigin, handleDirection, snappingStep, handleSize, capFunction));
 }
        public static Vector3[] Edge1DHandle(int id, Axis axis, Vector3[] points, Vector3 from, Vector3 to, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (SceneHandles.InCameraOrbitMode)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 2.0f);
                break;
            }

            case EventType.Repaint:
            {
                DrawLine(from, to);
                break;
            }
            }

            var position = (from + to) * 0.5f;
            var result   = Slider1D.Do(id, axis, points, position, direction, snappingStep, handleSize, capFunction, selectLockingAxisOnClick);

            return(result);
        }
Пример #23
0
 public static Vector3[] Slider1DHandle(int id, Axis axis, Vector3[] snapPoints, Vector3 handleOrigin, Vector3 handleDirection, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
 {
     return(Slider1D.Do(id, axis, snapPoints, handleOrigin, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick));
 }
        public static float Edge1DHandleOffset(Axis axis, Vector3 from, Vector3 to, float snappingStep, float handleSize, CapFunction capFunction)
        {
            var id = GUIUtility.GetControlID(s_Edge1DHash, FocusType.Keyboard);

            return(Edge1DHandleOffset(id, axis, from, to, snappingStep, handleSize, capFunction));
        }
Пример #25
0
        public static Vector3 Slider1DHandleOffset(int id, Vector3[] snapPoints, Vector3 handleDirection, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
        {
            Axis axis = Grid.ActiveGrid.GetClosestAxis(Handles.matrix.MultiplyVector(handleDirection));

            return(Slider1D.Do(id, axis, snapPoints, snapPoints[0], handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - snapPoints[0]);
        }
        public static float Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, float snappingStep, float handleSize, CapFunction capFunction)
        {
            var position  = (from + to) * 0.5f;
            var direction = (Vector3)Matrix4x4.identity.GetColumn((int)axis);

            return(Edge1DHandleOffset(id, axis, from, to, position, direction, snappingStep, handleSize, capFunction)[(int)axis]);
        }
Пример #27
0
        public static Vector3 Slider2DHandle(Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, CapFunction capFunction, Axes axes = Axes.None, bool selectLockingAxisOnClick = false, Vector3?snappingSteps = null)
        {
            var id = GUIUtility.GetControlID(s_Slider2DHash, FocusType.Keyboard);

            return(Slider2D.Do(id, new Vector3[] { handlePos }, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, selectLockingAxisOnClick, false, snappingSteps)[0]);
        }
        public static float Edge1DHandle(Axis axis, Vector3 from, Vector3 to, float snappingStep, float handleSize, CapFunction capFunction)
        {
            var id        = GUIUtility.GetControlID(s_Edge1DHash, FocusType.Keyboard);
            var position  = (from + to) * 0.5f;
            var direction = (Vector3)Matrix4x4.identity.GetColumn((int)axis);

            return(Edge1DHandleOffset(id, axis, from, to, position, direction, snappingStep, handleSize, capFunction)[(int)axis] + position[(int)axis]);
        }
 public Task <BigInteger> CapQueryAsync(CapFunction capFunction, BlockParameter blockParameter = null)
 {
     return(ContractHandler.QueryAsync <CapFunction, BigInteger>(capFunction, blockParameter));
 }
 public static float Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, CapFunction capFunction)
 {
     return(Edge1DHandleOffset(id, axis, from, to, 0, 0, capFunction));
 }
Пример #31
0
        public static Vector2 Slider2D(int id, Vector2 position, CapFunction drawCapFunction, Vector3 planeNormal, Vector3 planePosition)
        {
            EventType eventType = Event.current.GetTypeForControl(id);

            switch (eventType)
            {
            case EventType.MouseDown:
                if (Event.current.button == 0 && HandleUtility.nearestControl == id && !Event.current.alt)
                {
                    GUIUtility.keyboardControl = id;
                    GUIUtility.hotControl      = id;
                    s_CurrentMousePosition     = Event.current.mousePosition;
                    s_DragStartScreenPosition  = Event.current.mousePosition;
                    Vector2 b = HandleUtility.WorldToGUIPoint(position);
                    s_DragScreenOffset = s_CurrentMousePosition - b;
                    EditorGUIUtility.SetWantsMouseJumping(1);

                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (Event.current.button == 0 || Event.current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition = Event.current.mousePosition;
                    Vector2 center = position;
                    position = GUIToWorld(s_CurrentMousePosition - s_DragScreenOffset, planeNormal, planePosition);
                    if (!Mathf.Approximately((center - position).magnitude, 0f))
                    {
                        GUI.changed = true;
                    }
                    Event.current.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.hotControl == id && Event.current.keyCode == KeyCode.Escape)
                {
                    position = GUIToWorld(s_DragStartScreenPosition - s_DragScreenOffset);
                    GUIUtility.hotControl = 0;
                    GUI.changed           = true;
                    Event.current.Use();
                }
                break;
            }

            if (drawCapFunction != null)
            {
                drawCapFunction(id, position, Quaternion.identity, 1f, eventType);
            }

            return(position);
        }
        public static Vector3[] Edge1DHandle(Axis axis, Vector3[] points, Vector3 from, Vector3 to, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
        {
            var id = GUIUtility.GetControlID(s_Edge1DHash, FocusType.Keyboard);

            return(Edge1DHandle(id, axis, points, from, to, direction, snappingStep, handleSize, capFunction, selectLockingAxisOnClick));
        }