Esempio n. 1
0
    private Vector2 guiCenter;                                  // Center of joystick

    void Start()
    {
        // Cache this component at startup instead of looking up every frame
        gui = GetComponent <GUITexture>();
        gui.AutoResize();

        // Store the default rect for the gui, so we can snap back to it
        defaultRect = gui.pixelInset;

        defaultRect.x += transform.position.x * Screen.width;    // + gui.pixelInset.x; // -  Screen.width * 0.5;
        defaultRect.y += transform.position.y * Screen.height;   // - Screen.height * 0.5;

        transform.position = new Vector3(0.0f, 0.0f, transform.position.z);

        if (touchPad)
        {
            // If a texture has been assigned, then use the rect ferom the gui as our touchZone
            if (gui.texture)
            {
                touchZone = defaultRect;
            }
        }
        else
        {
            // This is an offset for touch input to match with the top left
            // corner of the GUI
            guiTouchOffset.x = defaultRect.width * 0.5f;
            guiTouchOffset.y = defaultRect.height * 0.5f;

            // Cache the center of the GUI, since it doesn't change
            guiCenter.x = defaultRect.x + guiTouchOffset.x;
            guiCenter.y = defaultRect.y + guiTouchOffset.y;

            // Let's build the GUI boundary, so we can clamp joystick movement
            guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
            guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
            guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
            guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
        }
    }
Esempio n. 2
0
	private Vector2 guiCenter;							// Center of joystick
	
	void Start()
	{
		// Cache this component at startup instead of looking up every frame	
		gui = GetComponent<GUITexture>();
		gui.AutoResize();
		
		// Store the default rect for the gui, so we can snap back to it
		defaultRect = gui.pixelInset;	
	    
	    defaultRect.x += transform.position.x * Screen.width;// + gui.pixelInset.x; // -  Screen.width * 0.5;
	    defaultRect.y += transform.position.y * Screen.height;// - Screen.height * 0.5;
	    
	    transform.position = new Vector3( 0.0f, 0.0f, transform.position.z);

		if ( touchPad )
		{
			// If a texture has been assigned, then use the rect ferom the gui as our touchZone
			if ( gui.texture )
				touchZone = defaultRect;
		}
		else
		{				
			// This is an offset for touch input to match with the top left
			// corner of the GUI
			guiTouchOffset.x = defaultRect.width * 0.5f;
			guiTouchOffset.y = defaultRect.height * 0.5f;
			
			// Cache the center of the GUI, since it doesn't change
			guiCenter.x = defaultRect.x + guiTouchOffset.x;
			guiCenter.y = defaultRect.y + guiTouchOffset.y;
			
			// Let's build the GUI boundary, so we can clamp joystick movement
			guiBoundary.min.x = defaultRect.x - guiTouchOffset.x;
			guiBoundary.max.x = defaultRect.x + guiTouchOffset.x;
			guiBoundary.min.y = defaultRect.y - guiTouchOffset.y;
			guiBoundary.max.y = defaultRect.y + guiTouchOffset.y;
		}
	}
Esempio n. 3
0
	public void Awake()
	{
		_gui = GetComponent<GUITexture>();	
		
		_gui.AutoResize();
	}
Esempio n. 4
0
    public void Awake()
    {
        _gui = GetComponent <GUITexture>();

        _gui.AutoResize();
    }
Esempio n. 5
0
    void Awake()
    {
        GUITexture gui = GetComponent <GUITexture>();

        gui.AutoResize();
    }