本文整理汇总了C#中MouseOrTouch类的典型用法代码示例。如果您正苦于以下问题:C# MouseOrTouch类的具体用法?C# MouseOrTouch怎么用?C# MouseOrTouch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MouseOrTouch类属于命名空间,在下文中一共展示了MouseOrTouch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTouch
/// <summary>
/// Get or create a touch event.
/// </summary>
static public MouseOrTouch GetTouch (int id)
{
MouseOrTouch touch = null;
if (!mTouches.TryGetValue(id, out touch))
{
touch = new MouseOrTouch();
touch.touchBegan = true;
mTouches.Add(id, touch);
}
return touch;
}
示例2: Raycast
/// <summary>
/// Raycast into the screen underneath the touch and update its 'current' value.
/// </summary>
static public void Raycast (MouseOrTouch touch)
{
if (!Raycast(touch.pos)) mRayHitObject = fallThrough;
if (mRayHitObject == null) mRayHitObject = mGenericHandler;
touch.last = touch.current;
touch.current = mRayHitObject;
mLastPos = touch.pos;
}
示例3: GetTouch
/// <summary>
/// Get or create a touch event. If you are trying to iterate through a list of active touches, use activeTouches instead.
/// </summary>
static public MouseOrTouch GetTouch (int id, bool createIfMissing = false)
{
if (id < 0) return GetMouse(-id - 1);
for (int i = 0, imax = mTouchIDs.Count; i < imax; ++i)
if (mTouchIDs[i] == id) return activeTouches[i];
if (createIfMissing)
{
MouseOrTouch touch = new MouseOrTouch();
touch.pressTime = RealTime.time;
touch.touchBegan = true;
activeTouches.Add(touch);
mTouchIDs.Add(id);
return touch;
}
return null;
}
示例4: ProcessTouch
/// <summary>
/// Process the events of the specified touch.
/// </summary>
void ProcessTouch(MouseOrTouch touch, bool pressed, bool unpressed)
{
// If we're using the mouse for input, we should send out a hover(false) message first
if (touch.pressed == null && touch.hover != touch.current && touch.hover != null)
{
if (mTooltip != null) ShowTooltip(false);
Highlight(touch.hover, false);
}
// Send the drag notification, intentionally before the pressed object gets changed
if (touch.pressed != null && touch.delta.magnitude != 0f)
{
if (mTooltip != null) ShowTooltip(false);
touch.totalDelta += touch.delta;
touch.pressed.SendMessage("OnDrag", touch.delta, SendMessageOptions.DontRequireReceiver);
float threshold = (touch == mMouse) ? 5f : 30f;
if (touch.totalDelta.magnitude > threshold) touch.considerForClick = false;
}
// Send out the press message
if (pressed)
{
if (mTooltip != null) ShowTooltip(false);
touch.pressed = touch.current;
touch.considerForClick = true;
touch.totalDelta = Vector2.zero;
if (touch.pressed != null) touch.pressed.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
// Clear the selection
if (touch.pressed != mSel)
{
if (mTooltip != null) ShowTooltip(false);
selectedObject = null;
}
}
// Send out the unpress message
if (unpressed)
{
if (mTooltip != null) ShowTooltip(false);
if (touch.pressed != null)
{
touch.pressed.SendMessage("OnPress", false, SendMessageOptions.DontRequireReceiver);
// Send a hover message to the object, but don't add it to the list of hovered items as it's already present
if (touch.pressed == touch.hover) touch.pressed.SendMessage("OnHover", true, SendMessageOptions.DontRequireReceiver);
// If the button/touch was released on the same object, consider it a click and select it
if (touch.pressed == touch.current)
{
if (touch.pressed != mSel)
{
mSel = touch.pressed;
touch.pressed.SendMessage("OnSelect", true, SendMessageOptions.DontRequireReceiver);
}
else
{
mSel = touch.pressed;
}
if (touch.considerForClick) touch.pressed.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
}
else // The button/touch was released on a different object
{
// Send a drop notification (for drag & drop)
if (touch.current != null) touch.current.SendMessage("OnDrop", touch.pressed, SendMessageOptions.DontRequireReceiver);
// If we're using mouse-based input, send a hover notification
Highlight(touch.pressed, false);
}
}
touch.pressed = null;
}
// Send out a hover(true) message last
if (useMouse && touch.pressed == null && touch.hover != touch.current)
{
mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
touch.hover = touch.current;
Highlight(touch.hover, true);
}
}
示例5: GetTouch
/// <summary>
/// Get or create a touch event.
/// </summary>
MouseOrTouch GetTouch(int id)
{
if (!allowMultiTouch) id = 1;
MouseOrTouch touch;
if (!mTouches.TryGetValue(id, out touch))
{
touch = new MouseOrTouch();
mTouches.Add(id, touch);
}
return touch;
}
示例6: OnMouseClick
protected virtual void OnMouseClick(MouseOrTouch touch, bool isPressed) {
if (isPressed || touch.dragStarted || UICamera.isOverUI) { return; }
if (touch.fingerId != 0 || city.HoveredCityObject == null) { return; }
if (!IsInteractable(city.HoveredCityObject)) { return; }
// When the player clicks the lion, add some money
if (city.HoveredCityObject is CityLion) {
(city.HoveredCityObject as CityLion).Cheat();
return;
}
stateManager.SetStateWithData<EditCityObjectState>(city.HoveredCityObject);
}
示例7: GetTouch
/// <summary>
/// Get or create a touch event.
/// </summary>
static public MouseOrTouch GetTouch (int id)
{
MouseOrTouch touch = null;
if (id < 0) return GetMouse(-id - 1);
if (!mTouches.TryGetValue(id, out touch))
{
touch = new MouseOrTouch();
touch.pressTime = RealTime.time;
touch.touchBegan = true;
mTouches.Add(id, touch);
}
return touch;
}
示例8: OnApplicationPause
/// <summary>
/// Clear all active press states when the application gets paused.
/// </summary>
void OnApplicationPause ()
{
MouseOrTouch prev = currentTouch;
if (useTouch)
{
BetterList<int> ids = new BetterList<int>();
foreach (KeyValuePair<int, MouseOrTouch> pair in mTouches)
{
if (pair.Value != null && pair.Value.pressed)
{
currentTouch = pair.Value;
currentTouchID = pair.Key;
currentScheme = ControlScheme.Touch;
currentTouch.clickNotification = ClickNotification.None;
ProcessTouch(false, true);
ids.Add(currentTouchID);
}
}
for (int i = 0; i < ids.size; ++i)
RemoveTouch(ids[i]);
}
if (useMouse)
{
for (int i = 0; i < 3; ++i)
{
if (mMouse[i].pressed)
{
currentTouch = mMouse[i];
currentTouchID = -1 - i;
currentKey = KeyCode.Mouse0 + i;
currentScheme = ControlScheme.Mouse;
currentTouch.clickNotification = ClickNotification.None;
ProcessTouch(false, true);
}
}
}
if (useController)
{
if (controller.pressed)
{
currentTouch = controller;
currentTouchID = -100;
currentScheme = ControlScheme.Controller;
currentTouch.last = currentTouch.current;
currentTouch.current = mCurrentSelection;
currentTouch.clickNotification = ClickNotification.None;
ProcessTouch(false, true);
currentTouch.last = null;
}
}
currentTouch = prev;
}
示例9: GetTouch
/// <summary>
/// Get or create a touch event.
/// </summary>
MouseOrTouch GetTouch(int id)
{
MouseOrTouch touch;
if (!mTouches.TryGetValue(id, out touch))
{
touch = new MouseOrTouch();
mTouches.Add(id, touch);
}
return touch;
}
示例10: ProcessOthers
/// <summary>
/// Process keyboard and joystick events.
/// </summary>
void ProcessOthers()
{
currentTouchID = -100;
currentTouch = mJoystick;
// Enter key and joystick button 1 keys are treated the same -- as a "click"
bool returnKeyDown = (useKeyboard && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)));
bool buttonKeyDown = (useController && Input.GetKeyDown(KeyCode.JoystickButton0));
bool returnKeyUp = (useKeyboard && (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.Space)));
bool buttonKeyUp = (useController && Input.GetKeyUp(KeyCode.JoystickButton0));
bool down = returnKeyDown || buttonKeyDown;
bool up = returnKeyUp || buttonKeyUp;
if (down || up)
{
currentTouch.hover = mSel;
currentTouch.current = mSel;
ProcessTouch(down, up);
}
int vertical = 0;
int horizontal = 0;
if (useKeyboard)
{
vertical += GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
horizontal += GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
}
if (useController)
{
vertical += GetDirection("Vertical");
horizontal += GetDirection("Horizontal");
}
// Send out key notifications
if (vertical != 0) mSel.SendMessage("OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow, SendMessageOptions.DontRequireReceiver);
if (horizontal != 0) mSel.SendMessage("OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow, SendMessageOptions.DontRequireReceiver);
if (useKeyboard && Input.GetKeyDown(KeyCode.Tab)) mSel.SendMessage("OnKey", KeyCode.Tab, SendMessageOptions.DontRequireReceiver);
if (useController && Input.GetKeyUp(KeyCode.JoystickButton1)) mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);
currentTouch = null;
}
示例11: ProcessMouse
/// <summary>
/// Update mouse input.
/// </summary>
public void ProcessMouse ()
{
// Is any button currently pressed?
bool isPressed = false;
bool justPressed = false;
for (int i = 0; i < 3; ++i)
{
if (Input.GetMouseButtonDown(i))
{
currentKey = KeyCode.Mouse0 + i;
justPressed = true;
isPressed = true;
}
else if (Input.GetMouseButton(i))
{
currentKey = KeyCode.Mouse0 + i;
isPressed = true;
}
}
// We're currently using touches -- do nothing
if (currentScheme == ControlScheme.Touch) return;
currentTouch = mMouse[0];
// Update the position and delta
Vector2 pos = Input.mousePosition;
if (currentTouch.ignoreDelta == 0)
{
currentTouch.delta = pos - currentTouch.pos;
}
else
{
--currentTouch.ignoreDelta;
currentTouch.delta.x = 0f;
currentTouch.delta.y = 0f;
}
float sqrMag = currentTouch.delta.sqrMagnitude;
currentTouch.pos = pos;
mLastPos = pos;
bool posChanged = false;
if (currentScheme != ControlScheme.Mouse)
{
if (sqrMag < 0.001f) return; // Nothing changed and we are not using the mouse -- exit
currentKey = KeyCode.Mouse0;
posChanged = true;
}
else if (sqrMag > 0.001f) posChanged = true;
// Propagate the updates to the other mouse buttons
for (int i = 1; i < 3; ++i)
{
mMouse[i].pos = currentTouch.pos;
mMouse[i].delta = currentTouch.delta;
}
// No need to perform raycasts every frame
if (isPressed || posChanged || mNextRaycast < RealTime.time)
{
mNextRaycast = RealTime.time + 0.02f;
Raycast(currentTouch);
for (int i = 0; i < 3; ++i) mMouse[i].current = currentTouch.current;
}
bool highlightChanged = (currentTouch.last != currentTouch.current);
bool wasPressed = (currentTouch.pressed != null);
if (!wasPressed)
hoveredObject = currentTouch.current;
currentTouchID = -1;
if (highlightChanged) currentKey = KeyCode.Mouse0;
if (!isPressed && posChanged && (!stickyTooltip || highlightChanged))
{
if (mTooltipTime != 0f)
{
// Delay the tooltip
mTooltipTime = Time.unscaledTime + tooltipDelay;
}
else if (mTooltip != null)
{
// Hide the tooltip
ShowTooltip(null);
}
}
// Generic mouse move notifications
if (posChanged && onMouseMove != null)
{
onMouseMove(currentTouch.delta);
//.........这里部分代码省略.........
示例12: ProcessFakeTouches
/// <summary>
/// Process fake touch events where the mouse acts as a touch device.
/// Useful for testing mobile functionality in the editor.
/// </summary>
void ProcessFakeTouches ()
{
bool pressed = Input.GetMouseButtonDown(0);
bool unpressed = Input.GetMouseButtonUp(0);
bool held = Input.GetMouseButton(0);
if (pressed || unpressed || held)
{
currentTouchID = 1;
currentTouch = mMouse[0];
currentTouch.touchBegan = pressed;
if (pressed)
{
currentTouch.pressTime = RealTime.time;
activeTouches.Add(currentTouch);
}
Vector2 pos = Input.mousePosition;
currentTouch.delta = pos - currentTouch.pos;
currentTouch.pos = pos;
// Raycast into the screen
Raycast(currentTouch);
// We don't want to update the last camera while there is a touch happening
if (pressed) currentTouch.pressedCam = currentCamera;
else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
// Process the events from this touch
currentKey = KeyCode.None;
ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed) activeTouches.Remove(currentTouch);
currentTouch.last = null;
currentTouch = null;
}
}
示例13: ProcessOthers
/// <summary>
/// Process keyboard and joystick events.
/// </summary>
public void ProcessOthers ()
{
currentTouchID = -100;
currentTouch = controller;
bool submitKeyDown = false;
bool submitKeyUp = false;
if (submitKey0 != KeyCode.None && Input.GetKeyDown(submitKey0))
{
currentKey = submitKey0;
submitKeyDown = true;
}
if (submitKey1 != KeyCode.None && Input.GetKeyDown(submitKey1))
{
currentKey = submitKey1;
submitKeyDown = true;
}
if (submitKey0 != KeyCode.None && Input.GetKeyUp(submitKey0))
{
currentKey = submitKey0;
submitKeyUp = true;
}
if (submitKey1 != KeyCode.None && Input.GetKeyUp(submitKey1))
{
currentKey = submitKey1;
submitKeyUp = true;
}
if (submitKeyDown || submitKeyUp)
{
currentScheme = ControlScheme.Controller;
currentTouch.last = currentTouch.current;
currentTouch.current = mCurrentSelection;
ProcessTouch(submitKeyDown, submitKeyUp);
currentTouch.last = null;
}
int vertical = 0;
int horizontal = 0;
if (useKeyboard)
{
if (inputHasFocus)
{
vertical += GetDirection(KeyCode.UpArrow, KeyCode.DownArrow);
horizontal += GetDirection(KeyCode.RightArrow, KeyCode.LeftArrow);
}
else
{
vertical += GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
horizontal += GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
}
}
if (useController)
{
if (!string.IsNullOrEmpty(verticalAxisName)) vertical += GetDirection(verticalAxisName);
if (!string.IsNullOrEmpty(horizontalAxisName)) horizontal += GetDirection(horizontalAxisName);
}
// Send out key notifications
if (vertical != 0)
{
currentScheme = ControlScheme.Controller;
Notify(mCurrentSelection, "OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow);
}
if (horizontal != 0)
{
currentScheme = ControlScheme.Controller;
Notify(mCurrentSelection, "OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow);
}
if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
{
currentKey = KeyCode.Tab;
currentScheme = ControlScheme.Controller;
Notify(mCurrentSelection, "OnKey", KeyCode.Tab);
}
// Send out the cancel key notification
if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
{
currentKey = cancelKey0;
currentScheme = ControlScheme.Controller;
Notify(mCurrentSelection, "OnKey", KeyCode.Escape);
}
if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
{
currentKey = cancelKey1;
currentScheme = ControlScheme.Controller;
//.........这里部分代码省略.........
示例14: ProcessTouches
/// <summary>
/// Update touch-based events.
/// </summary>
public void ProcessTouches ()
{
for (int i = 0; i < Input.touchCount; ++i)
{
Touch input = Input.GetTouch(i);
currentTouchID = allowMultiTouch ? input.fingerId : 1;
currentTouch = GetTouch(currentTouchID);
bool pressed = (input.phase == TouchPhase.Began) || currentTouch.touchBegan;
bool unpressed = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);
currentTouch.touchBegan = false;
if (pressed)
{
currentTouch.delta = Vector2.zero;
}
else
{
// Although input.deltaPosition can be used, calculating it manually is safer (just in case)
currentTouch.delta = input.position - currentTouch.pos;
}
currentTouch.pos = input.position;
if (!Raycast(currentTouch.pos, out lastHit)) hoveredObject = fallThrough;
if (hoveredObject == null) hoveredObject = genericEventHandler;
currentTouch.current = hoveredObject;
lastTouchPosition = currentTouch.pos;
// We don't want to update the last camera while there is a touch happening
if (pressed) currentTouch.pressedCam = currentCamera;
else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
// Double-tap support
if (input.tapCount > 1) currentTouch.clickTime = Time.realtimeSinceStartup;
// Process the events from this touch
ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed) RemoveTouch(currentTouchID);
currentTouch = null;
// Don't consider other touches
if (!allowMultiTouch) break;
}
}
示例15: ProcessTouches
/// <summary>
/// Update touch-based events.
/// </summary>
public void ProcessTouches ()
{
currentScheme = ControlScheme.Touch;
int count = (GetInputTouchCount == null) ? Input.touchCount : GetInputTouchCount();
for (int i = 0; i < count; ++i)
{
int fingerId;
TouchPhase phase;
Vector2 position;
int tapCount;
if (GetInputTouch == null)
{
UnityEngine.Touch touch = Input.GetTouch(i);
phase = touch.phase;
fingerId = touch.fingerId;
position = touch.position;
tapCount = touch.tapCount;
}
else
{
Touch touch = GetInputTouch(i);
phase = touch.phase;
fingerId = touch.fingerId;
position = touch.position;
tapCount = touch.tapCount;
}
currentTouchID = allowMultiTouch ? fingerId : 1;
currentTouch = GetTouch(currentTouchID);
bool pressed = (phase == TouchPhase.Began) || currentTouch.touchBegan;
bool unpressed = (phase == TouchPhase.Canceled) || (phase == TouchPhase.Ended);
currentTouch.touchBegan = false;
// Although input.deltaPosition can be used, calculating it manually is safer (just in case)
currentTouch.delta = pressed ? Vector2.zero : position - currentTouch.pos;
currentTouch.pos = position;
// Raycast into the screen
if (!Raycast(currentTouch.pos)) hoveredObject = fallThrough;
if (hoveredObject == null) hoveredObject = mGenericHandler;
currentTouch.last = currentTouch.current;
currentTouch.current = hoveredObject;
lastTouchPosition = currentTouch.pos;
// We don't want to update the last camera while there is a touch happening
if (pressed) currentTouch.pressedCam = currentCamera;
else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
// Double-tap support
if (tapCount > 1) currentTouch.clickTime = RealTime.time;
// Process the events from this touch
ProcessTouch(pressed, unpressed);
// If the touch has ended, remove it from the list
if (unpressed) RemoveTouch(currentTouchID);
currentTouch.last = null;
currentTouch = null;
// Don't consider other touches
if (!allowMultiTouch) break;
}
if (count == 0)
{
// Skip the first frame after using touch events
if (mUsingTouchEvents)
{
mUsingTouchEvents = false;
return;
}
if (useMouse) ProcessMouse();
#if UNITY_EDITOR
else ProcessFakeTouches();
#endif
}
else mUsingTouchEvents = true;
}