Author Topic: Prefab Question  (Read 4116 times)

darrkbeast

  • Guest
Prefab Question
« on: November 07, 2013, 03:56:20 PM »
So, Ive been making a simulation game, everything has been working just as i need it. The one issue I have is in my game I have worker prefabs that have stat windows attached to them. Those windows display, status, health and other info. All that works great, but if I spawn more workers and one runs by or is close to the other then I can see the window of the other one, even when I didnt click on the other one. Im guessing the camera, which is hooked on the prefab sees the other one. In any case, am I over looking something, or using Ngui in a way its not intended to.

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Prefab Question
« Reply #1 on: November 07, 2013, 05:08:12 PM »
I think a few screenshots of the issue happening and the hierarchy of the scene and prefab would help to understand this. From what you've described all I can think of is either a depth or layer issue.

darrkbeast

  • Guest
Re: Prefab Question
« Reply #2 on: November 07, 2013, 05:59:12 PM »
Ill work on getting some screen shots, I'm redoing them now so it will be a good time to get some. In the mean time, Ill try to explain more detailed. First off its a 2d game with the art style of prison architect or rimworld. So everything is flat. Basically I created a worker, which is a 2d sprite. To him I attached a NGUI UI complete with camera and all. On that worker I took stats from speed and others from variables I created and I update the NGUI labels. I then add a collider to the 2d sprite and turn it into a clickable sprite (not with any NGUI scripts), once clicked it would toggle the GUI attached to him. All that works great, no issues at all. Now I take completed worker and drag into prefab folder. Now hes a prefab that I can spawn by clicking a button. So I click the button, he spawns goes about working on task. The workers are programed to move about and do stuff. Now I click button again and spawn a 2nd worker from same prefab. 2nd worker is perfect does all that I programed him to. Now I got 2 workers moving about doing their thing. So I click on one worker, open his gui window and see his stats. As I look at them, I can see the other workers gui slide by, sometimes on top, other under, as he goes about his business. Now I have the gui anchor to the center of screen and that works fine. I just don't understand why the 2nd workers window is even visible, let alone showing while i view worker one. Ill work on getting some images tonight, might be a little longer as i'm updating the windows to add more stuff. To me it seems like, some how the prefab clones are sharing stuff once cloned and thus mimicking one another, except for the rest of the variables, they remain different.   

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Prefab Question
« Reply #3 on: November 08, 2013, 10:20:56 AM »
OK, that description helps a bit.

1. Why do you have a separate NGUI UI for every workers window ? Could you not have one NGUI UI (UIRoot and Camera) that is some kind of parent to your Workers ?

2. It sounds like all your windows are using the same depth; having the same depth results in the sometimes being on top, sometimes behind behaviour

3. It sounds like your camera's and windows are all using the same layer so every camera sees every window. Why it would be visible when closed I'm not sure, as I don't know how you open and close the windows.

However it seems like at least some of your problems would be solved or at least made easier to fix by managing depth (for every window opened increase the depth for example) and having only one NGUI UI hierarchy in your scene.

Once you post some screen shot I'll see if I see anything, but until then this might be something to think about.

darrkbeast

  • Guest
Re: Prefab Question
« Reply #4 on: November 08, 2013, 10:58:36 AM »
Ill get some images soon. The thing is all my windows use different depths, except the prefabs. Is there a way to have the prefabs change depth after spawn. I guess I could program a depth change on spawn. Oh and my regular UI uses buttons and tabs to open, and my workers menus are activated by clicking them, then closed by clicking a x. All of that works fine, and also they all have specific layers, main ui has its own, and the works ui has there own. Its only when I click on a worker that any issues appear and even then its only when the worker walks by the other one or is right by them. Now to your point I have not yet made a set UI location for the worker UI. As of now its just a child of the worker, but I was thinking about just having the worker UI, once activated, child itself either my main UI, or one I create specifically for the worker. Ill most likely try that this weekend, and share the results, and grab screen shots to. Thanks for helping.