Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - hermesdavidms

Pages: [1]
1
Add-ons and Extensions / Virtual Joystick and D Pad for 2dtk 2.2
« on: October 11, 2013, 07:54:41 am »
hello

i made a simple virtual joystick that also acts as a directional pad for mobile games, it works with multi touch and is compatible with 2d toolkit 2.2

to use it, just add a sprite, then a ui item and a collider and after that add this script, it accepts a transform if you want a handle to be shown while using the joystick(the circle that follows your finger)  but its optional, make it a child for best results

it doesnt send events or messages, so you will have to poll the info that a couple of functions give you which can be isTouching() or GetPosition() for a normalised(-1.0 to 1.0) joystick input or GetRight() GetUp() and so on to get DPad like input which is just true or false, you can change the deadzone for different results

here is the code

Code: [Select]

using UnityEngine;
using System.Collections;

public class VPad : tk2dUIBaseItemControl
{
public Transform handle;
public bool invertX = false;
public bool invertY = false;


private Vector2 position = Vector2.zero;
private float deadZone = 0.25f;
private bool isTouching = false;
private bool isRight = false;
private bool isLeft = false;
private bool isDown = false;
private bool isUp = false;


void OnEnable()
    {
        if (uiItem)
        {
            uiItem.OnDown += ButtonDown;
        uiItem.OnRelease += ButtonRelease;
        }
    }

void OnDisable()
    {
        if (uiItem)
        {
            uiItem.OnDown -= ButtonDown;
            uiItem.OnRelease -= ButtonRelease;
        }
    }

public void ButtonDown()
    {
isTouching = true;
    }

    public void ButtonRelease()
    {
Reset();
    }

public Vector2 GetPosition()
{
return position;
}

public bool GetRight()
{
return isRight;
}

public bool GetLeft()
{
return isLeft;
}

public bool GetDown()
{
return isDown;
}

public bool GetUp()
{
return isUp;
}

public bool IsTouching()
{
return isTouching;
}

private void Reset()
{
isTouching = false;
if(handle)
{
handle.localPosition = transform.InverseTransformPoint(renderer.bounds.center) + Vector3.back;
}
position = Vector2.zero;
isUp = false;
isDown = false;
isRight = false;
isLeft = false;
}

public void Update()
{
if(isTouching)
{

if (tk2dUIManager.Instance != null)
            {
Camera viewingCamera = tk2dUIManager.Instance.GetUICameraForControl( gameObject );
Vector3 localPos = transform.InverseTransformPoint(viewingCamera.ScreenToWorldPoint((Vector3)uiItem.Touch.position));
localPos.z = -1;

Vector3 padBoundsMin =  transform.InverseTransformPoint(renderer.bounds.min);
Vector3 padBoundsMax =  transform.InverseTransformPoint(renderer.bounds.max);

localPos.x = Mathf.Clamp(localPos.x,padBoundsMin.x,padBoundsMax.x);
localPos.y = Mathf.Clamp(localPos.y,padBoundsMin.y,padBoundsMax.y);

position.x = localPos.x / (renderer.bounds.size.x / 2);
position.y = localPos.y / (renderer.bounds.size.y / 2);
position.x = Mathf.Clamp(position.x , -1.0f,1.0f);
position.y = Mathf.Clamp(position.y , -1.0f,1.0f);

if(handle)
{
handle.localPosition = localPos;
}

if(invertX)
{
position.x = -position.x;
}

if(invertY)
{
position.y = -position.y;
}

if(position.x > deadZone)
{
isRight = true;
}
else
{
isRight = false;
}

if(position.x < -deadZone)
{
isLeft = true;
}
else
{
isLeft = false;
}

if(position.y > deadZone)
{
isUp = true;
}
else
{
isUp = false;
}

if(position.y < -deadZone)
{
isDown = true;
}
else
{
isDown = false;
}

            }
else
{
Reset();
}
}
else
{
Reset();
}
}
}


Cheers

2
Support / Re: What next?
« on: June 02, 2012, 04:30:36 pm »
I must quote this feature meaning multiplatform also as multi iOS devices (retina, standard, iPad, iPad retina)

that would be very cool..

i also would like to see sprite clipping, a clipping area where everything behind gets clipped , that would be very useful

3
Support / Re: Can't change texture compression settings?
« on: March 09, 2012, 10:33:58 pm »
hello there, SimpleUI author here.. first im sorry, leaving that AssetProcessor.cs script in the Editor folder inside the SimpleUI was a mistake, that file was meant to be for my own use only, and i surely left it by mistake when i submitted the package to the Asset Store

so to fix the problem, just delete that file, and everythings ok

i will submit a corrected version to the asset store as soon as possible

Pages: [1]