Permalink
Browse files

Fix button in Web Player

This fixes the bug in the WebPlayer where it was erroring when using
the native Touch classes. Created a wrapper class to bypass the bug.
The bug was reported in issue 116.
  • Loading branch information...
hyakugei committed Feb 6, 2013
1 parent 4c351f2 commit 3dc80eb86133e03ab0bfdf09ed60a28fac1db010
Showing with 220 additions and 76 deletions.
  1. +3 −0 Assets/DemoSceneScripts/PanelManager.cs
  2. +1 −1 Assets/DemoSceneScripts/TextManager.cs
  3. BIN Assets/DemoScenes/ExtendedTextTest.unity
  4. +3 −3 Assets/Plugins/UIToolkit/BaseElements/ITouchable.cs
  5. +5 −5 Assets/Plugins/UIToolkit/BaseElements/UIAbstractTouchableContainer.cs
  6. +4 −4 Assets/Plugins/UIToolkit/BaseElements/UIControlTemplate.cs
  7. +4 −4 Assets/Plugins/UIToolkit/BaseElements/UITouchableSprite.cs
  8. +1 −1 Assets/Plugins/UIToolkit/Containers/UIScrollableHorizontalLayout.cs
  9. +1 −1 Assets/Plugins/UIToolkit/Containers/UIScrollableVerticalLayout.cs
  10. BIN Assets/Plugins/UIToolkit/Materials/UIToolkitMaterial.mat
  11. +35 −18 Assets/Plugins/UIToolkit/Structs/UITouchMaker.cs
  12. +104 −0 Assets/Plugins/UIToolkit/Structs/UITouchWrapper.cs
  13. +7 −0 Assets/Plugins/UIToolkit/Structs/UITouchWrapper.cs.meta
  14. +1 −1 Assets/Plugins/UIToolkit/UIElements/TouchInfo.cs
  15. +3 −3 Assets/Plugins/UIToolkit/UIElements/UIButton.cs
  16. +3 −3 Assets/Plugins/UIToolkit/UIElements/UIColorPicker.cs
  17. +4 −4 Assets/Plugins/UIToolkit/UIElements/UIContinuousButton.cs
  18. +3 −3 Assets/Plugins/UIToolkit/UIElements/UIGhostJoystick.cs
  19. +3 −3 Assets/Plugins/UIToolkit/UIElements/UIJoystick.cs
  20. +4 −4 Assets/Plugins/UIToolkit/UIElements/UIKnob.cs
  21. +4 −4 Assets/Plugins/UIToolkit/UIElements/UISlider.cs
  22. +1 −1 Assets/Plugins/UIToolkit/UIElements/UIStateButton.cs
  23. +4 −4 Assets/Plugins/UIToolkit/UIElements/UISwipeDetector.cs
  24. +2 −2 Assets/Plugins/UIToolkit/UIElements/UIToggleButton.cs
  25. +3 −3 Assets/Plugins/UIToolkit/UIElements/UIZoomButton.cs
  26. +17 −4 Assets/Plugins/UIToolkit/UIToolkit.cs
@@ -6,6 +6,9 @@ public class PanelManager : MonoBehaviour
{
void Start()
{
Debug.LogError("PanelManager.Start()");
// IMPORTANT: depth is 1 on top higher numbers on the bottom. This means the lower the number is the closer it gets to the camera.
var playButton = UIButton.create( "playUp.png", "playDown.png", 0, 0 );
@@ -68,7 +68,7 @@ void Start()
textWrap2 = wrapText.addTextInstance( "This should be hyphenated. Check baseline - tytyt", 0, 0, 0.5f, 1, Color.green, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom );
textWrap2.positionFromBottom( 0f );
StartCoroutine( modifyTextInstances() );
//StartCoroutine( modifyTextInstances() );
}
Binary file not shown.
@@ -17,12 +17,12 @@ public interface ITouchable
bool hitTest( Vector2 point );
void onTouchBegan( Touch touch, Vector2 touchPos );
void onTouchBegan( UITouchWrapper touch, Vector2 touchPos );
void onTouchMoved( Touch touch, Vector2 touchPos );
void onTouchMoved( UITouchWrapper touch, Vector2 touchPos );
void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame );
void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame );
}
@@ -25,7 +25,7 @@ public abstract class UIAbstractTouchableContainer : UIAbstractContainer, ITouch
// touch handling helpers
protected float _deltaTouch;
protected Touch _lastTouch;
protected UITouchWrapper _lastTouch;
protected Vector2 _lastTouchPosition;
protected ITouchable _activeTouchable;
@@ -392,8 +392,8 @@ public bool hitTest( Vector2 point )
}
// Touch handlers. Subclasses should override onTouchMoved
public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers. Subclasses should override onTouchMoved
public virtual void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
// sanity check in case we lost a touch (happens with Unity on occassion)
if( _activeTouchable != null )
@@ -412,13 +412,13 @@ public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
}
public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
}
public virtual void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public virtual void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
_isDragging = false;
@@ -66,20 +66,20 @@ public override bool highlighted
}
// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers
public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}
public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}
public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
highlighted = false;
}
@@ -213,20 +213,20 @@ public override void centerize()
#region ITouchable
// Touch handlers. Subclasses should override these to get their specific behaviour
public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers. Subclasses should override these to get their specific behaviour
public virtual void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}
public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
}
public virtual void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public virtual void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
highlighted = false;
}
@@ -62,7 +62,7 @@ protected override void clipChild( UISprite child )
#region ITouchable
public override void onTouchMoved( Touch touch, Vector2 touchPos )
public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
// increment deltaTouch so we can pass on the touch if necessary
_deltaTouch += touch.deltaPosition.x;
@@ -62,7 +62,7 @@ protected override void clipChild( UISprite child )
#region ITouchable
public override void onTouchMoved( Touch touch, Vector2 touchPos )
public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
// increment deltaTouch so we can pass on the touch if necessary
_deltaTouch += touch.deltaPosition.y;
Binary file not shown.
@@ -15,58 +15,75 @@ public enum UIMouseState
/// <summary>
/// this class now exists only to allow standalones/web players to create Touch objects
/// this class now exists only to allow standalones/web players to create UITouchWrapper objects
/// </summary>
public struct UITouchMaker
{
public static Touch createTouch( int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase )
public static UITouchWrapper createTouch( int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase )
{
var self = new Touch();
ValueType valueSelf = self;
var type = typeof( Touch );
var self = new UITouchWrapper();
//ValueType valueSelf = self;
//var type = typeof( UITouchWrapper );
/*
type.GetField( "m_FingerId", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, finderId );
type.GetField( "m_TapCount", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, tapCount );
type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, position );
type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, deltaPos );
type.GetField( "m_TimeDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, timeDelta );
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, phase );
return (Touch)valueSelf;
return (UITouchWrapper)valueSelf;
*/
self.fingerId = finderId;
self.tapCount = tapCount;
self.position = position;
self.deltaPosition = deltaPos;
self.deltaTime = timeDelta;
self.phase = phase;
return self;
}
public static Touch createTouchFromInput( UIMouseState mouseState, ref Vector2? lastMousePosition )
public static UITouchWrapper createTouchFromInput( UIMouseState mouseState, ref Vector2? lastMousePosition )
{
var self = new Touch();
ValueType valueSelf = self;
var type = typeof( Touch );
//var self = new UITouchWrapper();
//ValueType valueSelf = self;
//var type = typeof( UITouchWrapper );
var self = new UITouchWrapper();
var currentMousePosition = new Vector2( Input.mousePosition.x, Input.mousePosition.y );
if(lastMousePosition.HasValue)
// if we have a lastMousePosition use it to get a delta
if( lastMousePosition.HasValue )
type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition - lastMousePosition );
if( lastMousePosition.HasValue ) self.deltaPosition = currentMousePosition - (Vector2)lastMousePosition;
//type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition - lastMousePosition );
if( mouseState == UIMouseState.DownThisFrame ) // equivalent to touchBegan
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Began );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Began );
self.phase = TouchPhase.Began;
lastMousePosition = Input.mousePosition;
}
else if( mouseState == UIMouseState.UpThisFrame ) // equivalent to touchEnded
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Ended );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Ended );
self.phase = TouchPhase.Ended;
lastMousePosition = null;
}
else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Moved );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Moved );
self.phase = TouchPhase.Moved;
lastMousePosition = Input.mousePosition;
}
type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition );
//type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition );
self.position = currentMousePosition;
return (Touch)valueSelf;
return self;
//return (UITouchWrapper)valueSelf;
}
}
#endif
@@ -0,0 +1,104 @@
using System;
using UnityEngine;
public class UITouchWrapper
{
private int m_FingerId = 0;
private Vector2 m_Position = new Vector2();
private Vector2 m_PositionDelta = new Vector2();
private float m_TimeDelta = 0f;
private int m_TapCount = 0;
private TouchPhase m_Phase = TouchPhase.Stationary;
private bool m_Locked = false;
public UITouchWrapper()
{
}
public bool locked
{
get
{
return m_Locked;
}
set
{
if(value == true) m_Locked = true;
}
}
public int fingerId
{
get
{
return this.m_FingerId;
}
set
{
if(!locked) this.m_FingerId = value;
}
}
public Vector2 position
{
get
{
return this.m_Position;
}
set
{
if(!locked) this.m_Position = value;
}
}
public Vector2 deltaPosition
{
get
{
return this.m_PositionDelta;
}
set
{
if(!locked) this.m_PositionDelta = value;
}
}
public float deltaTime
{
get
{
return this.m_TimeDelta;
}
set
{
if(!locked) this.m_TimeDelta = value;
}
}
public int tapCount
{
get
{
return this.m_TapCount;
}
set
{
if(!locked) this.m_TapCount = value;
}
}
public TouchPhase phase
{
get
{
return this.m_Phase;
}
set
{
if(!locked) this.m_Phase = value;
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -43,7 +43,7 @@ public TouchInfo( SwipeDirection swipesToDetect )
}
public void resetWithTouch( Touch touch )
public void resetWithTouch( UITouchWrapper touch )
{
// Initialize the detectionState only with the swipe types we want to listen for
swipeDetectionState = swipesToDetect;
@@ -85,8 +85,8 @@ public override bool highlighted
}
// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers
public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
@@ -101,7 +101,7 @@ public override void onTouchBegan( Touch touch, Vector2 touchPos )
public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
// If someone has un-highlighted us through code we are deactivated
// and should not fire the event
@@ -53,8 +53,8 @@ public Color colorPicked
}
// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers
public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
@@ -67,7 +67,7 @@ public override void onTouchBegan( Touch touch, Vector2 touchPos )
}
public override void onTouchMoved( Touch touch, Vector2 touchPos )
public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
Color oldColor = colorPicked;
Vector2 textureCoord = getTouchTextureCoords(touchPos);
Oops, something went wrong.

0 comments on commit 3dc80eb

Please sign in to comment.