Ejemplo n.º 1
0
 private void initialize()
 {
     guiElem         = GetComponent <GUICustomElement>();
     _screenBounds.x = -1f;  // initialize the screen bounds cache
     setupButtons();         // locate the buttons
     EffectPrioritizerHelper.registerAsEndEffect(this as IEffectListener);
 }
Ejemplo n.º 2
0
    private Vector2 levelExtent = Vector2.zero; // level length according the game objects that define the level extent

    void Awake()
    {
        // initializes as inifnite to avoid NaN in division operation
        levelExtent.x = float.PositiveInfinity;
        levelExtent.y = float.PositiveInfinity;

        guiElem = GetComponent <GUICustomElement>();
    }
Ejemplo n.º 3
0
    private Vector2 offsetInPixels;     // used to store temporal calculation of offset member as a percentage or pixel-wise of the screen

    void Awake()
    {
        // if using with a GUITexture then no GUICustomElement musn't be found
        guiElem = GetComponent <GUICustomElement>();

        // register this class with ScreenLayoutManager for screen resize event
        GUIScreenLayoutManager.Instance.register(this as IGUIScreenLayout);
    }
    public static Rect getPositionInScreen(GUICustomElement guiElem)
    {
        Vector3 guiPos       = guiElem.transform.localPosition;   // GUI custom element uses localPosition for correctly on screen location
        Vector2 sizeInGUI    = guiElem.getSizeInGUI();
        Vector2 sizeInPixels = guiElem.getSizeInPixels();
        Vector2 pixelMin     = GUIToScreen(guiPos.x - sizeInGUI.x / 2f, guiPos.y - sizeInGUI.y / 2f);

        return(new Rect(pixelMin.x, pixelMin.y, sizeInPixels.x, sizeInPixels.y));
    }
Ejemplo n.º 5
0
    void Awake()
    {
        if (dontDestroy)
        {
            // keep this game object alive between scenes
            DontDestroyOnLoad(this.gameObject);
        }

        TransitionGUIFxManager.Instance.register(this, false);

        // calculate scaling if current GUI texture dimension is diferent than 64x64 because
        // the array of arrows were defined in a 64x64 basis
        float scaleW = 1f;
        float scaleH = 1f;

        // support Unity's gui elements
        if (guiTexture != null)
        {
            scaleW = guiTexture.pixelInset.width / 64f;
            scaleH = guiTexture.pixelInset.height / 64f;
        }
        // assuming it has a GUICustomElement
        else
        {
            GUICustomElement guiElem     = GetComponent <GUICustomElement>();
            Vector2          guiElemSize = guiElem.getSizeInPixels();
            scaleW = guiElemSize.x / 64f;
            scaleH = guiElemSize.y / 64f;
        }

        // apply the scale
        for (int i = 0; i < arrowRects.Length; ++i)
        {
            Rect r = arrowRects[i];
            arrowRects[i].Set(r.x * scaleW, r.y * scaleH, r.width * scaleW, r.height * scaleH);
        }
    }
Ejemplo n.º 6
0
    private void initialize()
    {
        // calculate scaling if current GUI texture dimension is diferent than 64x64 because
        // the array of arrows were defined in a 64x64 basis
        float scaleW = 1f;
        float scaleH = 1f;

        guiElem = GetComponent <GUICustomElement>();
        Vector2 guiElemSize = guiElem.getSizeInPixels();

        scaleW = guiElemSize.x / 64f;
        scaleH = guiElemSize.y / 64f;

        // apply the scale
        for (int i = 0; i < arrowRects.Length; ++i)
        {
            Rect r = arrowRects[i];
            arrowRects[i].Set(r.x * scaleW, r.y * scaleH, r.width * scaleW, r.height * scaleH);
        }

        _screenBounds.x = -1f;         // initialize the screen bounds cache

        EffectPrioritizerHelper.registerAsEndEffect(this as IEffectListener);
    }
    /// <summary>
    /// Locates the transform element in the screen according the layout value.
    /// It depends on the way the transform originally was z-located and xy-scaled to act as a GUI element.
    /// </summary>
    /// <param name='tr'>
    /// Transform
    /// </param>
    /// <param name='guiElem'>
    /// Is the GUI element containing the info about size in pixels or as a proportion
    /// </param>
    /// <param name='offsetInPixels'>
    /// Offset measured in pixels.
    /// </param>
    /// <param name='layout'>
    /// Layout. Base screen positions
    /// </param>
    public static void adjustPos(Transform tr, GUICustomElement guiElem, Vector2 offsetInPixels, EnumScreenLayout layout)
    {
        Vector3 p = tr.localPosition;

        // assume the GUI element has its size as pixels
        Vector2 size = guiElem.virtualSize.x != 0 ? guiElem.virtualSize : guiElem.size;

        // convert to pixels if GUI element's size is set as a proportion
        if (!guiElem.sizeAsPixels)
        {
            size.x *= Screen.width;
            size.y *= Screen.height;
        }

        switch (layout)
        {
        case EnumScreenLayout.NONE: {
            Vector2 temp = screenToGUI(offsetInPixels.x, offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.TOP_LEFT: {
            Vector2 temp = screenToGUI(offsetInPixels.x + size.x / 2f, Screen.height - size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.TOP: {
            Vector2 temp = screenToGUI(Screen.width / 2 + offsetInPixels.x, Screen.height - size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.TOP_RIGHT: {
            Vector2 temp = screenToGUI(Screen.width + offsetInPixels.x - size.x / 2f, Screen.height - size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.CENTER_LEFT: {
            Vector2 temp = screenToGUI(offsetInPixels.x + size.x / 2f, Screen.height / 2 + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.CENTER: {
            p.x = Screen.width / 2 - size.x / 2 + offsetInPixels.x;
            p.y = Screen.height / 2 - size.y / 2 + offsetInPixels.y;
            Vector2 temp = screenToGUI(Screen.width / 2 + offsetInPixels.x, Screen.height / 2 + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.CENTER_RIGHT: {
            Vector2 temp = screenToGUI(Screen.width + offsetInPixels.x - size.x / 2f, Screen.height / 2 + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.BOTTOM_LEFT: {
            Vector2 temp = screenToGUI(offsetInPixels.x + size.x / 2f, size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.BOTTOM: {
            Vector2 temp = screenToGUI(Screen.width / 2 + offsetInPixels.x, size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        case EnumScreenLayout.BOTTOM_RIGHT: {
            Vector2 temp = screenToGUI(Screen.width + offsetInPixels.x - size.x / 2f, size.y / 2f + offsetInPixels.y);
            p.x = temp.x;
            p.y = temp.y;
            break;
        }

        default: break;
        }
#if UNITY_EDITOR
        if (float.IsNegativeInfinity(p.x) || float.IsInfinity(p.x) || float.IsNaN(p.x))
        {
            p.x = 0f;
        }
        if (float.IsNegativeInfinity(p.y) || float.IsInfinity(p.y) || float.IsNaN(p.y))
        {
            p.y = 0f;
        }
#endif
        tr.localPosition = p;
    }
Ejemplo n.º 8
0
    private Rect _screenBounds;     // cache for the screen bounds the GUI element covers

    protected override void ownAwake()
    {
        _screenBounds.x = -1f;         // initialize the screen bounds cache
        guiElem         = GetComponent <GUICustomElement>();
        EffectPrioritizerHelper.registerAsEndEffect(this as IEffectListener);
    }