private void RotateRandomSlice() { var position = Random.rotationUniform * Vector3.right * Random.Range(-randomPointVariance, randomPointVariance); var axis = Random.Range(0, sliceFinders.Count - 1); var slice = sliceFinders[axis](position); var command = new RotateSliceCommand(slice, Random.value > 0.5f); MessengerHub.Publish(new EnqueueCommandMessage(this, command, transient: true)); }
public bool AcceptDragInput(DragEndMessage drag, out RotateSliceCommand command) { command = null; if (drag.Length < MinimumDragDistance) { return(false); } var camera = IoC.Resolve <UnityEngine.Camera>(); // TODO: Remove use of IoC in methods var ray = camera.ScreenPointToRay(drag.StartPosition); if (!Physics.Raycast(ray, out var hit)) { return(false); } var piece = pieces.First(p => p.Is(hit.transform.gameObject)); var face = InverseTransformPoint(hit.point); var direction = InverseTransformDirection(camera.transform.TransformDirection(drag.Direction)).ToIntegerAxis(); var axis = Vector3.Cross(face, direction).ToIntegerAxis(); // logger.Info("Direction: {0}, Axis: {1}", direction, axis); if (axis.y != 0) { var sign = Math.Sign(direction.x); if (sign == 0) { sign = Math.Sign(direction.z); } // We flip the comparison on this one because of the positive direction on Z in unity. command = new RotateSliceCommand(FindYAxisSlice(piece.Position), sign > 0); } else if (axis.x != 0) { var sign = Math.Sign(direction.y); if (sign == 0) { sign = Math.Sign(direction.z); } command = new RotateSliceCommand(FindXAxisSlice(piece.Position), sign < 0); } else if (axis.z != 0) { var sign = Math.Sign(direction.x); if (sign == 0) { sign = Math.Sign(direction.y); } command = new RotateSliceCommand(FindZAxisSlice(piece.Position), sign < 0); } return(command != null); }