public static void blinkButton(object sender, UIArgs uxArgs) { if (uxArgs.uiEvent.targetButton != null) { uxArgs.uiEvent.targetButton.DefaultBlink(); } }
// Translate a 3D camera by a vector3. static void TranslateCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject cameraObject; cameraObject = interFace.uiCam3D.cameraObject; Constraint constraint = interFace.uiCam3D.constraint; Vector3 delta = uxArgs.delta; Vector3 cameraPositionOut = cameraObject.transform.position; cameraPositionOut += delta; // Constraint is applied to camera object. if (constraint != null && constraint.hardClamp) { cameraPositionOut.x = Mathf.Clamp(cameraPositionOut.x, constraint.hardClampMin.x, constraint.hardClampMax.x); cameraPositionOut.y = Mathf.Clamp(cameraPositionOut.y, constraint.hardClampMin.y, constraint.hardClampMax.y); cameraPositionOut.z = Mathf.Clamp(cameraPositionOut.z, constraint.hardClampMin.z, constraint.hardClampMax.z); } // Translation is applied to camera object. cameraObject.transform.position = cameraPositionOut; }
/*!\brief Rotate a camera around its interest using pitch and yaw. */ static public void OrbitCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject cameraObject = interFace.uiCam3D.cameraObject; GameObject cameraInterest = interFace.uiCam3D.cameraInterest; Constraint orbitConstraint = interFace.uiCam3D.constraint; if (cameraInterest != null && cameraObject != null) { float degreesPerPixel = 360f / Screen.height; Quaternion orientation = cameraInterest.transform.rotation; Vector3 euler = orientation.eulerAngles; euler.y += uxArgs.delta.x * degreesPerPixel; euler.x -= uxArgs.delta.y * degreesPerPixel; euler.z = 0; //Constraint orbitConstraint = interFace.uiCam3D.constraint; if (orbitConstraint != null && orbitConstraint.pitchClamp) { // transform to plus minus range, clamp, transform back float pitch = euler.x <= 180f ? euler.x : euler.x - 360f; pitch = Mathf.Clamp(pitch, orbitConstraint.pitchClampMin, orbitConstraint.pitchClampMax); euler.x = pitch >= 0f ? pitch : pitch + 360f; } orientation = Quaternion.Euler(euler); cameraInterest.transform.rotation = orientation; } }
public static void tapButton2D(object sender, UIArgs uxArgs) { if (uxArgs.uiEvent.targetButton != null) { uxArgs.uiEvent.callback = uxArgs.uiEvent.targetButton.callback; uxArgs.uiEvent.targetButton.Tap(); //Verbose("Tap button 2d, callback: "+uxArgs.uiEvent.targetButton.callback); } }
public static void doubleTapButton2D(object sender, UIArgs uxArgs) { if (uxArgs.uiEvent.targetButton != null) { uxArgs.uiEvent.callback = uxArgs.uiEvent.targetButton.callbackDoubleTap; uxArgs.uiEvent.targetButton.Tap(); Verbose("Double tap button 2d, callback: " + uxArgs.uiEvent.targetButton.callbackDoubleTap); } }
// ------------------------------------------------------------------------------------------------------------------ // OLD CODE, from Fabric /* * * * void TerrainClamp{ * * // this clamps the camera to a lowest point (from fabric). based on geometry. however, it's not generic right now -> refactor. * * // Vector3 newCameraPosition = state.cameraInterest.transform.position + orientation * new Vector3 (0, 0, -distanceToInterest); * * Vector3 newCameraPosition = ci.transform.position + orientation * new Vector3(0, 0, -distanceToInterest); * * * float hh = 0; * // float hh = cc.getActiveLandscape ().getHeight (cp.x, cp.z) + minimumHeight; * * if (newCameraPosition.y < hh) * { * // float pitch = Mathf.Asin ((hh - TPObject.transform.position.y) / distanceToInterest) * Mathf.Rad2Deg; * float pitch = Mathf.Asin((hh - 0) / distanceToInterest) * Mathf.Rad2Deg; * * //Debug.Log ("orbitcam under hull, locking pitch to: " + pitch); * euler.x = pitch; * } * * } * * void HullClamp{ * // control for camera hitting the hull. camera will be pushed up and when possible it'll smoothly lower back along the hull towards its original y. * * // !!!!!!!!!!!!!!!!!!!!! * // float hullHeight = cc.getActiveLandscape ().getHeight (cameraPositionOut.x, cameraPositionOut.z) + minimumHeight; * * * if (false) * { * * float lockValueY = 0; * bool lockY = false; * float hullHeight = 0; * * * * * bool yUnlocked = false; * bool yIsTooLow = false; * bool hullHigherThanLockvalue = false; * float modifY = 0f; * * if (cameraPositionOut.y > lockValueY) * yUnlocked = true; * * if (cameraPositionOut.y <= hullHeight) * yIsTooLow = true; * * if (lockValueY <= hullHeight) * hullHigherThanLockvalue = true; * * if (yIsTooLow) * { * // find out how much y needs to go up and create a correction vector along the vertical axis to do it. (thus controlling x and z as well) * modifY = hullHeight - cameraPositionOut.y; * float factor = modifY / vertical.y; * Vector3 yCorrection = factor * vertical; * cameraPositionOut += yCorrection; * * if (!yUnlocked) * { * // store unmodified y value. effectively this stores the lock value only the first time the cam gets bumped up * lockValueY = cameraPositionIn.y; * } * } * * if (!yIsTooLow && yUnlocked && hullHigherThanLockvalue && lockY) * { * * // smooth towards hull y * float cameraVel = 0f; * cameraPositionOut.y = Mathf.SmoothDamp(cameraPositionIn.y, hullHeight, ref cameraVel, 0.25f); * } * * if (!yIsTooLow && yUnlocked && !hullHigherThanLockvalue && lockY) * { * // smooth towards unmodified y value * float cameraVel = 0f; * cameraPositionOut.y = Mathf.SmoothDamp(cameraPositionIn.y, lockValueY, ref cameraVel, 0.25f); * if (Mathf.Abs(cameraPositionOut.y - lockValueY) < 0.1f) * { * // snap value * cameraPositionOut.y = lockValueY; * yUnlocked = false;// this is redundant * } * } * * // Log.Message ( "ytoolow " + yIsTooLow.ToString () + " y modded " + yUnlocked.ToString ()); * // Log.Message ( "y: " + cameraPositionOut.y + " unmod y: " + state.lockValueY); * * } * * } */ // ------------------------------------------------------------------------------------------------------------------ public static void clearSelectedObjects(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; foreach (GameObject go in interFace.selectedObjects) { go.GetComponent <MeshRenderer>().material = interFace.defaultMat; } interFace.selectedObjects.Clear(); }
// -------------------------------------------- 2D ---------------------------------------------------------------------- /*!\brief Drag a 2d interactive object (ie button). */ public static void Drag2D(object sender, UIArgs uxArgs) { if (uxArgs.uiEvent.targetButton == null) { return; } GameObject dragTarget = uxArgs.uiEvent.targetButton.GetDragTarget(uxArgs.uiEvent.direction); Constraint constraint = uxArgs.uiEvent.targetButton.GetConstraint(uxArgs.uiEvent.direction); if (dragTarget == null || constraint == null) { return; // don't drag if no target or constraint availabe. } Translate2D(dragTarget, uxArgs.delta, constraint, uxArgs.uiEvent); }
public static void select3dObject(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; Log("3d target: " + uxArgs.uiEvent.target3D.transform.name); if (interFace.selectedObjects.IndexOf(uxArgs.uiEvent.target3D) != -1) { // object was selected, deselect // uxArgs.uiEvent.target3D.GetComponent<MeshRenderer>().material = interFace.defaultMat; interFace.selectedObjects.Remove(uxArgs.uiEvent.target3D); } else { // object was not selected, select // uxArgs.uiEvent.target3D.GetComponent<MeshRenderer>().material = interFace.editMat; interFace.selectedObjects.Add(uxArgs.uiEvent.target3D); } }
static public void rotateCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; if (interFace.uiCam3D.control == CAMERACONTROL.ORBIT) { OrbitCamera(sender, uxArgs); } if (interFace.uiCam3D.control == CAMERACONTROL.TURN) { turnCamera(sender, uxArgs); } if (interFace.uiCam3D.control == CAMERACONTROL.GYRO) { gyroCamera(sender, uxArgs); } }
// -------------------------------------------- 3D ---------------------------------------------------------------------- /*!\brief Dolly a 3d camera in and out by argument dd */ public static void LongitudinalCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject cameraObject, cameraInterest; cameraObject = interFace.uiCam3D.cameraObject; cameraInterest = interFace.uiCam3D.cameraInterest; float delta = uxArgs.delta.z; if (cameraInterest != null && cameraObject != null) { float unitsPerPixel = 10f / Screen.height; Quaternion cameraOrientation = cameraObject.transform.rotation; Vector3 forward = cameraOrientation * Vector3.forward; //uxArgs.delta = unitsPerPixel * delta * forward; TranslateCamera(interFace.uiCam3D, unitsPerPixel * delta * forward); } }
// -------------------------------------------- 2D ---------------------------------------------------------------------- /*!\brief Drag a 2d interactive object (ie button). */ public static void Drag2D(object sender, UIArgs uxArgs) { // Log("Dragging"); if (uxArgs.uiEvent.targetButton == null) { return; } GameObject dragTarget = uxArgs.uiEvent.targetButton.GetDragTarget(uxArgs.uiEvent.direction); Constraint constraint = uxArgs.uiEvent.targetButton.GetConstraint(uxArgs.uiEvent.direction); if (dragTarget == null || constraint == null) { // if no target or constraint don't drag, and also stop inertia and springing which may be set uxArgs.uiEvent.isInert = false; uxArgs.uiEvent.isSpringing = false; //Log("no target or constraint, so setting inert and springing to false"); return; // don't drag if no target or constraint availabe. } Translate2D(dragTarget, uxArgs.delta, constraint, uxArgs.uiEvent); }
// static readonly Quaternion landscapeRight = Quaternion.Euler(0, 0, 90); // static readonly Quaternion landscapeLeft = Quaternion.Euler(0, 0, -90); // static readonly Quaternion upsideDown = Quaternion.Euler(0, 0, 180); static public void gyroCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject co, ci; co = interFace.uiCam3D.cameraObject; ci = interFace.uiCam3D.cameraInterest; Vector3 startPosition = co.transform.position; Quaternion gyro = GyroToUnity(Input.gyro.attitude); // Debug.Log ("gyro " + gyro.ToString()); // ci.transform.rotation = gyro * Quaternion.Euler (0, 0, -90); // landscape left ci.transform.rotation = baseIdentity * gyro; // Quaternion landscapeLeft = Quaternion.Euler(0, 0, -90); // Debug.Log ("gyroToUnity " + ci.transform.rotation.ToString()); // ci.transform.rotation = Input.gyro.attitude; Vector3 endPosition = co.transform.position; ci.transform.position -= (endPosition - startPosition); // Vector3 forward = ci.transform.rotation * Vector3.forward; // Vector3 up = ci.transform.rotation * Vector3.up; // Vector3 right = ci.transform.rotation * Vector3.right; // // Debug.Log ("f " + forward.ToString () + "u " + forward.ToString () + "r " + forward.ToString ()); }
/*!\brief Pan a 3d camera laterally by arguments dx,dy */ public static void LateralCamera(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject cameraObject = interFace.uiCam3D.cameraObject; GameObject cameraInterest = interFace.uiCam3D.cameraInterest; Constraint constraint = interFace.uiCam3D.constraint; Vector3 delta = -1f * uxArgs.delta; //Debug.Log(delta.ToString()); Vector3 cameraPositionIn = cameraObject.transform.position; Vector3 cameraPositionOut = cameraPositionIn; Quaternion cameraOrientation = cameraInterest.transform.rotation; Vector3 horizontal = cameraOrientation * Vector3.right; Vector3 vertical = cameraOrientation * Vector3.up; float unitsPerPixel = 10f / Screen.height; // feels random cameraPositionOut += (delta.x * unitsPerPixel * 1f) * horizontal; cameraPositionOut += (delta.y * unitsPerPixel * 1f) * vertical; // Constraint is applied to camera object. if (constraint != null && constraint.hardClamp) { cameraPositionOut.x = Mathf.Clamp(cameraPositionOut.x, constraint.hardClampMin.x, constraint.hardClampMax.x); cameraPositionOut.y = Mathf.Clamp(cameraPositionOut.y, constraint.hardClampMin.y, constraint.hardClampMax.y); cameraPositionOut.z = Mathf.Clamp(cameraPositionOut.z, constraint.hardClampMin.z, constraint.hardClampMax.z); } // Translation is applied to interest object. cameraInterest.transform.position += (cameraPositionOut - cameraPositionIn); }
static public void turnCamera(object sender, UIArgs uxArgs) { // Create direct references for ease of use. InterFace interFace = uxArgs.uiEvent.plane.interFace; GameObject co, ci; co = interFace.uiCam3D.cameraObject; ci = interFace.uiCam3D.cameraInterest; if (ci != null && co != null) { Vector3 startPosition = co.transform.position; // we need a gameobject to be the interest, and a gameobject that holds the camera. float degreesPerPixel = 360f / Screen.height; // float distanceToInterest = -1f * co.transform.localPosition.z; // delta.x -> YAW. rotate around (world) y axis. Quaternion orientation = co.transform.rotation; Quaternion yawRotation = Quaternion.AngleAxis(uxArgs.delta.x * degreesPerPixel, Vector3.up); orientation = yawRotation * orientation; // delta.y -> PITCH. rotate around (relative) x axis Vector3 cameraDirection = co.transform.rotation * Vector3.forward; Vector3 pitchAxis = Vector3.Cross(cameraDirection, Vector3.up); Quaternion pitchRotation = Quaternion.AngleAxis(uxArgs.delta.y * degreesPerPixel, pitchAxis); orientation = pitchRotation * orientation; // neutralise roll, clamp pitch, leave yaw unchanged Vector3 euler = orientation.eulerAngles; euler.z = 0; if (euler.x > 70 && euler.x <= 180) { euler.x = 70; } if (euler.x < 290 && euler.x > 180) { euler.x = 290; } if (false) { } orientation = Quaternion.Euler(euler); ci.transform.rotation = orientation; Vector3 endPosition = co.transform.position; ci.transform.position -= (endPosition - startPosition); // co.transform.position = startPosition; } }
public void doubletap_3d(object sender, UIArgs args) { mapping.doubletap_3d(sender, args); }
public static void stopControls(object sender, UIArgs uxArgs) { InterFace interFace = uxArgs.uiEvent.plane.interFace; setTargetBrightness(interFace.getButtonNames(), 0.75f, interFace); }
// ------------------------------------------------------------------------------------------------------------------------------------------ void processUiEvent(Event ui) { if (ui.plane == null || ui.plane.interFace == null) { return; } ui.callback = ""; UIArgs args = new UIArgs(); args.delta = Vector3.zero; args.uiEvent = ui; InterFace interFace = ui.plane.interFace; switch (ui.action) { case ACTION.TAP: ui.action = ACTION.SINGLEDRAG; if (ui.target2D != null) { interFace.tap_2d(this, args); } else if (ui.target3D != null) { interFace.tap_3d(this, args); } else { interFace.tap_none(this, args); } break; case ACTION.SINGLEDRAG: // If this is an orthodrag button, we need to set and lock the initial direction. // We also get the appropriate targets and constraints for that direction and load them into the uievent. if (ui.targetButton != null && ui.targetButton.orthoDragging && ui.direction == DIRECTION.FREE) { if (Mathf.Abs(ui.scaledDx) > Mathf.Abs(ui.scaledDy)) { ui.direction = DIRECTION.HORIZONTAL; Verbose("Locking to drag horizontally"); } if (Mathf.Abs(ui.scaledDx) < Mathf.Abs(ui.scaledDy)) { ui.direction = DIRECTION.VERTICAL; Verbose("Locking to drag vertically"); } } // Verbose("singledrag"); args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0); if (ui.target2D != null) { interFace.single_2d(this, args); } else if (ui.target3D != null) { interFace.single_3d(this, args); } else { interFace.single_none(this, args); } // interFace.AddMapping // ui.isInert = false; // ui.isSpringing = false; break; case ACTION.DOUBLEDRAG: args.delta = new Vector3(ui.scaledDx, ui.scaledDy, ui.scaledDd); if (ui.target2D != null) { interFace.double_2d(this, args); } else if (ui.target3D != null) { interFace.double_3d(this, args); } else { interFace.double_none(this, args); } break; default: interFace.none(this, args); break; } ui.Inertia(); }
public void single_none(object sender, UIArgs args) { mapping.single_none(sender, args); }
public static void tapNone(object sender, UIArgs uxArgs) { uxArgs.uiEvent.callback = uxArgs.uiEvent.plane.interFace.tapNoneCallback; }
public void double_none(object sender, UIArgs args) { mapping.double_none(sender, args); }
public void tap_none(object sender, UIArgs args) { mapping.tap_none(sender, args); }
// public static void panCamera (UxInterface state, Vector2 delta) // { // panCamera (state, delta, emptyConstraint, false); // // } public static void none(object sender, UIArgs uxArgs) { }
// ------------------------------------------------------------------------------------------------------------------------------------------ void processUiEvent(Event ui) { if (ui.plane == null || ui.plane.interFace == null) { return; } ui.callback = ""; UIArgs args = new UIArgs(); args.delta = Vector3.zero; args.uiEvent = ui; InterFace interFace = ui.plane.interFace; switch (ui.action) { case ACTION.TAP: if (ui.targetJustTapped) { Verbose("Double tap."); if (ui.target2D != null) { interFace.doubletap_2d(this, args); } else if (ui.target3D != null) { interFace.doubletap_3d(this, args); } else { interFace.doubletap_none(this, args); } ui.action = ACTION.SINGLEDRAG; } else { if (ui.tapTimeOut < float.Epsilon) { // Log("Setting tap time out"); ui.tapTimeOut = Time.time + 0.1f; } else if (Time.time > ui.tapTimeOut) { Verbose("tap timed out, single tap."); ui.tapTimeOut = 0; if (ui.target2D != null) { interFace.tap_2d(this, args); } else if (ui.target3D != null) { interFace.tap_3d(this, args); } else { interFace.tap_none(this, args); } ui.action = ACTION.SINGLEDRAG; } } // also perform single drag (which'll allow things like springs to work while waiting for timeout) args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0); if (ui.target2D != null) { interFace.single_2d(this, args); } else if (ui.target3D != null) { interFace.single_3d(this, args); } else { interFace.single_none(this, args); } break; case ACTION.SINGLEDRAG: // If this is an orthodrag button, we need to set and lock the initial direction. // We also get the appropriate targets and constraints for that direction and load them into the uievent. if (ui.targetButton != null && ui.targetButton.orthoDragging && ui.direction == DIRECTION.FREE) { if (Mathf.Abs(ui.scaledDx) > Mathf.Abs(ui.scaledDy)) { ui.direction = DIRECTION.HORIZONTAL; Verbose("Locking to drag horizontally"); } if (Mathf.Abs(ui.scaledDx) < Mathf.Abs(ui.scaledDy)) { ui.direction = DIRECTION.VERTICAL; Verbose("Locking to drag vertically"); } } //Verbose("singledrag"); args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0); if (ui.target2D != null) { interFace.single_2d(this, args); } else if (ui.target3D != null) { interFace.single_3d(this, args); } else { interFace.single_none(this, args); } // interFace.AddMapping // ui.isInert = false; // ui.isSpringing = false; break; case ACTION.DOUBLEDRAG: args.delta = new Vector3(ui.scaledDx, ui.scaledDy, ui.scaledDd); if (ui.target2D != null) { interFace.double_2d(this, args); } else if (ui.target3D != null) { interFace.double_3d(this, args); } else { interFace.double_none(this, args); } break; default: interFace.none(this, args); break; } ui.Inertia(); }
// -------------------------------------------- DEBUG ---------------------------------------------------------------------- public static void someAction(object sender, UIArgs uxArgs) { Log("Debug action called."); }