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 - Fractalbase

Pages: 1 [2]
16
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()
    {
   }

}


17
NGUI 3 Documentation / Re: UICamera
« on: June 16, 2014, 09:16:41 PM »
I have an issue where I have a gameobject programmatically render my graphics, and those are viewed by the main camera created with the scene.  now with ngui in the picture, it seems that both main camera and ui camera are drawing my game graphics.  I tried one work around where I made the position of uiroot to be 3000,3000,0.  Is there a better way?

18
NGUI 3 Documentation / Re: UITable
« on: June 16, 2014, 09:12:08 PM »
Does usage of UITable require Panels?  I'm attempting to use nested tables with 2 text boxes, a text field, and a sprite, and the ngui items don't seem to work with the uitable (no 'locking' of ui items to table columns).

19
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?

20
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?

21
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.

22
I haven't looked into NGUI's input yet.  I've somewhat written my input code already using Unity input -- will have to investigate.

23
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 [2]