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.


Topics - Fractalbase

Pages: [1]
1
I've had trouble getting my screen with a grid of instantiated buttons to work with the selected item (of UIKeyNavigation).  I've somehow gotten that to work, but am not sure now.

My screens have transitions where to move from current menu to a sub menu:
        subMenu.SetActive(true);
        currentMenu.SetActive(false);

This works well and traverses to the sub menu.

On the menus, there is a back button.  Clicking the back button has an effect like this:
        superMenu.SetActive(true);
        currentMenu.SetActive(false);

The difficulty is, while the first encountering of a menu with a grid of instantiated items has the startSelected set and works, whenever returning to that menu, nothing is selected.

Any ideas why?

thanks,
fb



2
Is it possible to center the game graphics rendered to a particular rectangle in the game window?  For example, in the interior of a sprite?  And then what would be the method to clip game artwork outside of that rectangle (or depending on how the graphics is rendered, I might assume that I have to calculate clipping myself)?  Is there a better way to zoom in and out of the graphics (for a 2D game) then adjusting the z position coordinate of the main camera?

thanks,
fb

3
Hi,

I'm attempting to draw UISprites with static and dynamic dimensions at dynamic positions on the screen base on the game screen resolution.  Unfortunately, the sprites don't seem to line up correctly with the Y access.  Any help?



using UnityEngine;
using System.Collections;



public class ManageGameScreen : MonoBehaviour
{

   // Use this for initialization
   void Start()
    {
        //int MaxPixelX = Screen.currentResolution.width;
        //int MaxPixelY = Screen.currentResolution.height;
        int MaxPixelX = 992;
        int MaxPixelY = 888;

        print("screen resolution: " + MaxPixelX + "x" + MaxPixelY);

        int HalfPixelX = (MaxPixelX / 2);
        int HalfPixelY = (MaxPixelY / 2);

        print("half screen resolution: " + HalfPixelX + "x" + HalfPixelY);

        UISprite[] screenElements = gameObject.GetComponentsInChildren<UISprite>();

        foreach (UISprite sprite in screenElements)
        {
            if (sprite.gameObject.name.Equals("Sprite - Text Input Field"))
            {
                print("textInputField");
                sprite.pivot = UISprite.Pivot.TopLeft;
                int xPos = -HalfPixelX;
                int yPos = -(HalfPixelY - 20);
                int xDim = MaxPixelX;
                int yDim = 20;
                print("xPos: " + xPos + "; yPos: " + yPos + "; xDim: " + xDim + "; yDim: " + yDim + ";");
                sprite.SetRect(xPos, yPos, xDim, yDim);
            }
            else if (sprite.gameObject.name.Equals("Sprite - Text Response Box"))
            {
                print("textResponseBox");
                sprite.pivot = UISprite.Pivot.TopLeft;
                int xPos = -HalfPixelX;
                int yPos = -(HalfPixelY - 140);
                int xDim = MaxPixelX;
                int yDim = 120;
                print("xPos: " + xPos + "; yPos: " + yPos + "; xDim: " + xDim + "; yDim: " + yDim + ";");
                sprite.SetRect(xPos, yPos, xDim, yDim);
            }
            else if (sprite.gameObject.name.Equals("Sprite - Minimap"))
            {
                print("minimap");
                sprite.pivot = UISprite.Pivot.TopLeft;
                int xPos = (HalfPixelX - 192);
                int yPos = HalfPixelY;
                int xDim = 192;
                int yDim = 192;
                print("xPos: " + xPos + "; yPos: " + yPos + "; xDim: " + xDim + "; yDim: " + yDim + ";");
                sprite.SetRect(xPos, yPos, xDim, yDim);
            }
            else if (sprite.gameObject.name.Equals("Sprite - Text Info Box"))
            {
                print("textInfoBox");
                sprite.pivot = UISprite.Pivot.TopLeft;
                int xPos = (HalfPixelX - 192);
                int yPos = (HalfPixelY - 192);
                int xDim = 192;
                int yDim = (MaxPixelY - (192 + 120 + 20));
                print("xPos: " + xPos + "; yPos: " + yPos + "; xDim: " + xDim + "; yDim: " + yDim + ";");
                sprite.SetRect(xPos, yPos, xDim, yDim);
            }

        }

    }
   

   // Update is called once per frame
   void Update()
    {
   }

}


4
NGUI 3 Support / screen dimensions
« on: June 16, 2014, 05:17:47 PM »
Is there a way to query for x&y screen dimensions, and to set those dimensions programmatically?

5
NGUI 3 Support / UITables: anchoring ui elements
« on: June 16, 2014, 05:16:17 PM »
I seem to have some trouble with anchoring ui elements to tables (including nested tables)... any recommendations?

6
Hi, I'm relatively new to NGUI, and I have some questions.  I don't think I'm asking for complete implementations, but helpful answers that point me in the right direction will be nice.

I'm making an RPG and I'm attempting to add the following items from NGUI:
1. text input bar (text field)
2. text dialog box (text box)
3. text dialog box #2 (text box)
4. minimap box

The minimap box I will code myself, but I'm not sure of the best way to integrate that code with NGUI.

My questions:
1. should I use the text field and text box prefabs and make modifications, or can/should I create those items from scratch?
2. I attempted to use the prefabs, and I'm having trouble 'anchoring' the items automatically using tables.  any ideas?
3. after I changes the atlas/sprite for the text items, the default text no longer appears on the items.  any ideas?
4. (general Unity question) is there a way to specify the screen dimensions and then query for the screen dimensions programmatically?
5. given the screen dimensions, is there a way to programmatically generate the mentioned items?
6. my 'game' view has its own camera, so there are two cameras (the main camera, and the ngui camera).  initially, the graphics overlapped.  the first workaround I tried was setting the x&y coordinates of UI Root to far away so that the camera items don't overlap.  is there a better way?
7. the text fields appear to have an anchor point of top-left and extend left and down, while ui sprites appear to have an anchor point of center, and extend to the sides left&right and up&down.  is there something else I can/should use besides a sprite for graphics(non-ngui) areas?
8. my current implementation of input for my game uses Unity's input system.  since I'm using NGUI, should I just replace that with NGUI's input system?
9. when I play the game in unity, the ngui ui elements shift upper left -- why would that happen?

Any information will be helpful.

thanks.

7
I'm attempting to create a text-input panel for my game, and I implemented one solution with UILabel.  I'm still learning NGUI, but the issue I'm running into is that backspace is only recognized one time after each press of return.  My code is included below.  Any help?

thanks,
fb

----

using System;
using System.Collections.Generic;
using UnityEngine;



public class DialogController : MonoBehaviour
{
    public int MaxLines;
    public int MaxLength;

    private List<String> textFrame;

    public DialogController()
    {
    }

    // Use this for initialization
    void Start()
    {
        if (textFrame == null)
        {
            textFrame = new List<string>();
            for (int index = 0; index < MaxLines; ++index)
            {
                textFrame.Add(String.Empty);
            }
        }
    }

    // Update is called once per frame
    private void Update()
    {
        String entered = Input.inputString;
        int last = (textFrame.Count - 1);

        textFrame[last] += entered;
        if (textFrame[last].Length > MaxLength)
        {
            textFrame[last] = textFrame[last].Substring(0, MaxLength);
        }

        if (Input.GetKeyDown(KeyCode.Return))
        {
            textFrame.RemoveAt(0);
            textFrame.Add(entered);
        }

        //TODO: only works for one backspace per line
        if (Input.GetKeyDown(KeyCode.Backspace))
        {
            int currentLength = textFrame[last].Length;
            textFrame[last] = textFrame[last].Substring(0, (currentLength - 1));
        }

        PopulateContents();
    }

    public void PopulateContents()
    {
        String content = String.Empty;
        foreach (String line in textFrame)
        {
            content += (line + '\n');
        }
        GetComponent<UILabel>().text = content;
    }

}


Pages: [1]