示例#1
0
文件: TKRect.cs 项目: kbhatt/TouchKit
	public TKRect copyWithExpansion( float xExpansion, float yExpansion )
	{
		xExpansion *= TouchKit.instance.runtimeScaleModifier.x;
		yExpansion *= TouchKit.instance.runtimeScaleModifier.y;

		var rect = new TKRect();
		rect.x = this.x - xExpansion;
		rect.y = this.y - yExpansion;
		rect.width = this.width + ( xExpansion * 2f );
		rect.height = this.height + ( yExpansion * 2f );

		return rect;
	}
	void createQuadButton( TKRect rect, Color color )
	{
		color.a = 0.2f;

		// find the center point in Unity units
		var center = Camera.main.ScreenToWorldPoint( rect.center );
		center.z = 0;

		// create the quad button
		var button = GameObject.CreatePrimitive( PrimitiveType.Quad );
		button.transform.position = center;
		button.GetComponent<Renderer>().material.shader = Shader.Find( "Sprites/Default" );
		button.GetComponent<Renderer>().material.color = color;

		// scale the quad button accordingly
		button.transform.localScale = new Vector3
		(
			TouchKit.instance.pixelsToUnityUnitsMultiplier.x * rect.width,
			TouchKit.instance.pixelsToUnityUnitsMultiplier.y * rect.height
		);
	}
    private void debugDrawRect( TKRect rect, Color color )
    {
        var bl = new Vector3( rect.xMin, rect.yMin, 0 );
        var br = new Vector3( rect.xMax, rect.yMin, 0 );
        var tl = new Vector3( rect.xMin, rect.yMax, 0 );
        var tr = new Vector3( rect.xMax, rect.yMax, 0 );

        bl = Camera.main.ScreenToWorldPoint( Camera.main.transform.InverseTransformPoint( bl ) );
        br = Camera.main.ScreenToWorldPoint( Camera.main.transform.InverseTransformPoint( br ) );
        tl = Camera.main.ScreenToWorldPoint( Camera.main.transform.InverseTransformPoint( tl ) );
        tr = Camera.main.ScreenToWorldPoint( Camera.main.transform.InverseTransformPoint( tr ) );

        // draw four sides
        Debug.DrawLine( bl, br, color );
        Debug.DrawLine( br, tr, color );
        Debug.DrawLine( tr, tl, color );
        Debug.DrawLine( tl, bl, color );

        // make an "x" at the midpoint
        Debug.DrawLine( tl, br, color );
        Debug.DrawLine( bl, tr, color );
    }
示例#4
0
    void createQuadButton(TKRect rect, Color color)
    {
        color.a = 0.2f;

        // find the center point in Unity units
        var center = Camera.main.ScreenToWorldPoint(rect.center);

        center.z = 0;

        // create the quad button
        var button = GameObject.CreatePrimitive(PrimitiveType.Quad);

        button.transform.position       = center;
        button.renderer.material.shader = Shader.Find("Sprites/Default");
        button.renderer.material.color  = color;

        // scale the quad button accordingly
        button.transform.localScale = new Vector3
                                      (
            TouchKit.instance.pixelsToUnityUnitsMultiplier.x * rect.width,
            TouchKit.instance.pixelsToUnityUnitsMultiplier.y * rect.height
                                      );
    }
 /// <summary>
 /// the constructor ensures we have a frame to work with for this recognizer
 /// </summary>
 public TKTouchPadRecognizer( TKRect frame )
 {
     boundaryFrame = frame;
 }
示例#6
0
    // private Vector2 _previousLocation;


    /// <summary>
    /// the constructor ensures we have a frame to work with for this recognizer
    /// </summary>
    public TKTouchPadRecognizer(TKRect frame)
    {
        boundaryFrame = frame;
    }
示例#7
0
	public TKButtonRecognizer( TKRect defaultFrame, TKRect highlightedFrame )
	{
		_defaultFrame = defaultFrame;
		_highlightedFrame = highlightedFrame;
		boundaryFrame = _defaultFrame;
	}
示例#8
0
	public TKButtonRecognizer( TKRect defaultFrame, float highlightedExpansion ) : this( defaultFrame, defaultFrame.copyWithExpansion( highlightedExpansion ) )
	{
    }
示例#9
0
	/* State Definitions
	 * Began: a touch started out on the button but has moved off. We still track it in case it comes back on the button
	 * RecognizedAndStillRecognizing: a touch is currently down on the button
	 * Recognized:
	 */

	#region Constructors

	/// <summary>
	/// the constructors ensure we have a frame to work with for button recognizers
	/// </summary>
	public TKButtonRecognizer( TKRect defaultFrame ): this( defaultFrame, 40f )
	{
    }
 public TKTouchPadRecognizer(TKRect frame)
 {
     base.boundaryFrame = new TKRect?(frame);
 }
示例#11
0
 public TKButtonRecognizer(TKRect defaultFrame, TKRect highlightedFrame)
 {
     _defaultFrame     = defaultFrame;
     _highlightedFrame = highlightedFrame;
     boundaryFrame     = _defaultFrame;
 }
示例#12
0
 public TKButtonRecognizer(TKRect defaultFrame, float highlightedExpansion) : this(defaultFrame, defaultFrame.copyWithExpansion(highlightedExpansion))
 {
 }
示例#13
0
    /* State Definitions
     * Began: a touch started out on the button but has moved off. We still track it in case it comes back on the button
     * RecognizedAndStillRecognizing: a touch is currently down on the button
     * Recognized:
     */

    #region Constructors

    /// <summary>
    /// the constructors ensure we have a frame to work with for button recognizers
    /// </summary>
    public TKButtonRecognizer(TKRect defaultFrame) : this(defaultFrame, 40f)
    {
    }
示例#14
0
	private void debugDrawRect( TKRect rect, Color color )
	{
		var bl = new Vector3( rect.xMin, rect.yMin, 0 );
		var br = new Vector3( rect.xMax, rect.yMin, 0 );
		var tl = new Vector3( rect.xMin, rect.yMax, 0 );
		var tr = new Vector3( rect.xMax, rect.yMax, 0 );

		bl = Camera.main.ScreenToWorldPoint( new Vector3( bl.x, bl.y, Camera.main.farClipPlane ) );
		br = Camera.main.ScreenToWorldPoint( new Vector3( br.x, br.y, Camera.main.farClipPlane ) );
		tl = Camera.main.ScreenToWorldPoint( new Vector3( tl.x, tl.y, Camera.main.farClipPlane ) );
		tr = Camera.main.ScreenToWorldPoint( new Vector3( tr.x, tr.y, Camera.main.farClipPlane ) );

		// draw four sides
		Debug.DrawLine( bl, br, color );
		Debug.DrawLine( br, tr, color );
		Debug.DrawLine( tr, tl, color );
		Debug.DrawLine( tl, bl, color );

		// make an "x" at the midpoint
        Debug.DrawLine( tl, br, color );
        Debug.DrawLine( bl, tr, color );
    }
 public TKAnyTouchRecognizer(TKRect frame)
 {
     base.alwaysSendTouchesMoved = true;
     base.boundaryFrame          = new TKRect?(frame);
 }
 /// <summary>
 /// the contstructor ensures we have a frame to work with
 /// </summary>
 public TKAnyTouchRecognizer(TKRect frame)
 {
     alwaysSendTouchesMoved = true;
     boundaryFrame          = frame;
 }
示例#17
0
 /// <summary>
 /// the contstructor ensures we have a frame to work with
 /// </summary>
 public TKAnyTouchRecognizer( TKRect frame )
 {
     alwaysSendTouchesMoved = true;
     boundaryFrame = frame;
 }
示例#18
0
 public TKButtonRecognizer(TKRect defaultFrame, TKRect highlightedFrame)
 {
     this._defaultFrame     = defaultFrame;
     this._highlightedFrame = highlightedFrame;
     base.boundaryFrame     = new TKRect?(this._defaultFrame);
 }