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

Pages: [1]
1
Hi!
I am having the problem that, as soon as I am switching a Scene my NGUI Ui does not work anymore. The Resource Bars and Buttons that show from the beginning are working perfectly. But the Panels are not working anymore. i got the following error message:

MissingReferenceException: The object of type 'UIGamePanel' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Component.get_gameObject () UIGamePanel.Hide () UIGamePanel.cs:73) UIGamePanel.HideActivePanels () UIGamePanel.cs:153)

my UIGamePanel.cs looks like this:

  1. #define USE_NGUI_2X
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public class UIGamePanel : MonoBehaviour {
  8.        
  9.         public const float UI_DELAY = 0.75f;
  10.         public const float UI_TRAVEL_DIST = 1.6f;
  11.        
  12.         public GameObject content;
  13.         public PanelType panelType;
  14.         public PanelType openFromPanelOnly;
  15.  
  16.         /**
  17.          * Position of the buttons when visible.
  18.          */
  19.         protected Vector3 showPosition;
  20.        
  21.         /**
  22.          * Position of the buttons when hidden.
  23.          */
  24.         protected Vector3 hidePosition;
  25.        
  26.         public static Dictionary <PanelType, UIGamePanel> panels;
  27.  
  28.         public PanelType[] IgnoreTypes;
  29.  
  30.         void Awake() {
  31.                 if (panels == null) panels = new Dictionary <PanelType, UIGamePanel> ();
  32.                 if (activePanels == null) activePanels = new List<UIGamePanel> (0);
  33.  
  34.                 panels.Add (panelType, this);
  35.                 showPosition = content.transform.position;
  36.                 hidePosition = content.transform.position - new Vector3(0, UI_TRAVEL_DIST, 0);
  37.                 if (panelType == PanelType.DEFAULT) {
  38.                         activePanels.Add(this);
  39.                 } else {
  40.                         content.transform.position = hidePosition;     
  41.                 }
  42.                
  43.                 Init ();
  44.         }
  45.  
  46.         virtual protected void Init() {
  47.         }
  48.        
  49.         virtual public void InitialiseWithBuilding(Building building) {
  50.         }
  51.        
  52.         virtual public void Show() {
  53.  
  54.                 if (panelType == PanelType.DEFAULT && GridView.Instance != null) GridView.Instance.NormalMode();
  55.                 if (panelType == PanelType.PLACE_BUILDING && GridView.Instance != null) GridView.Instance.BuildingMode();
  56.                 if (panelType == PanelType.EDIT_PATHS && GridView.Instance != null) GridView.Instance.PathMode();
  57.                 if (activePanels.Contains(this)) {
  58.                         StartCoroutine(DoReShow());
  59.                 } else if (activePanels.Count == 0 || IsPanelOpenedFromActivePanel () || openFromPanelOnly == PanelType.NONE) {
  60.                         HideActivePanels ();
  61.  
  62.                         gameObject.SendMessage ("OnShow", this, SendMessageOptions.DontRequireReceiver);
  63.                         StartCoroutine(DoShow());
  64.                         activePanels.Add (this);
  65.                 }
  66.         }
  67.  
  68.         virtual public void Hide() {
  69.  
  70.                 if (activePanels.Contains(this)) {
  71.                         activePanels.Remove (this);
  72.                 }
  73.                 gameObject.SendMessage ("OnHide", this, SendMessageOptions.DontRequireReceiver);
  74.                 StartCoroutine(DoHide());
  75.         }
  76.  
  77.         public static void ShowPanel(PanelType panelType) {
  78.                 if (panelType == PanelType.DEFAULT) BuildingManager.ActiveBuilding = null;
  79.                 if (panels.ContainsKey (panelType)) {
  80.                         //if (!activePanels.Contains(panels[panelType])) {
  81.                                 panels [panelType].Show ();
  82.                         //}
  83.                 }
  84.         }
  85.  
  86.         public static List<UIGamePanel> activePanels;
  87.                
  88.         /**
  89.          * Reshow the panel (i.e. same panel but for a different object/building).
  90.          */
  91.         virtual protected IEnumerator DoReShow() {
  92.                 gameObject.BroadcastMessage ("OnHide", SendMessageOptions.DontRequireReceiver);
  93.                 iTween.MoveTo(content, hidePosition, UI_DELAY);
  94.                 yield return new WaitForSeconds(UI_DELAY / 3.0f);
  95.  
  96.                 gameObject.BroadcastMessage ("OnShow", SendMessageOptions.DontRequireReceiver);
  97.                 iTween.MoveTo(content, showPosition, UI_DELAY);
  98.         }
  99.        
  100.        
  101.         /**
  102.          * Show the panel.
  103.          */
  104.         virtual protected IEnumerator DoShow() {
  105.                 yield return new WaitForSeconds(UI_DELAY / 3.0f);
  106.                 content.SetActive (true);
  107.  
  108.                 gameObject.BroadcastMessage ("OnShow", SendMessageOptions.DontRequireReceiver);
  109. #if USE_NGUI_3X
  110.                 yield return true;
  111.                 GetComponent<UIPanel>().Refresh();
  112. #endif
  113.                 iTween.MoveTo(content, showPosition, UI_DELAY);
  114.         }
  115.        
  116.         /**
  117.          * Hide the panel.
  118.          */
  119.         virtual protected IEnumerator DoHide() {       
  120.                 gameObject.BroadcastMessage ("OnHide", SendMessageOptions.DontRequireReceiver);
  121.  
  122.                 iTween.MoveTo(content, hidePosition, UI_DELAY);
  123.                 yield return new WaitForSeconds(UI_DELAY / 3.0f);
  124.                 content.SetActive (false);
  125.         }
  126.  
  127.         protected bool IsPanelOpenedFromActivePanel () {
  128.                 for (int i = 0; i < activePanels.Count; ++i) {
  129.                         if (activePanels[i].panelType == openFromPanelOnly) {
  130.                                 return true;
  131.                         }
  132.                 }
  133.  
  134.                 return false;
  135.         }
  136.  
  137.         protected void HideActivePanels () {
  138.                 if (activePanels != null) {
  139.                         for (int i = 0; i < activePanels.Count; ++i) {
  140.                                 UIGamePanel panel = activePanels[i];
  141.                                 bool hide = true;
  142.                                 if (IgnoreTypes != null) {
  143.                                         for (int j = 0; j < IgnoreTypes.Length; ++j) {
  144.                                                 if (IgnoreTypes[j] == panel.panelType) {
  145.                                                         hide = false;
  146.                                                         break;
  147.                                                 }
  148.                                         }
  149.                                 }
  150.                                
  151.                                 if (hide) {
  152.                                         activePanels.Remove (panel);
  153.                                         panel.Hide ();
  154.                                         --i;
  155.                                 }
  156.                         }
  157.                 }
  158.         }
  159. }

does anyone of you having this problem before?

2
Hey,

I have a weird Bug with NGUI. I wanted to create a Horizontal Scroll Panel where you can select some Buildings/Items/Objects.
I let the panel fade in from the bottom but somehow the first item is the middle.. or almost in the middle and not on the left side as it should. when i drag the scroll panel just a little bit to the left or to the right, it snaps to the right position (to the left side of the screen). Everything else from this Panel is on the right position (Tabs and close button for example)

I don't really know which value is responsable for that so i dont know which values i should post here. maybe some of you knows whats wrong or had this before.
feel free to ask me if you want to know which settings i used on a specific point

Cheers,
Kevin

3
Hey, thanks! that helped a lot :)

I have another question since i am just getting into all the input stuff in unity and iam messing a little bit around with the input manager. so lets say i have set up a fire button in the input manager (Fire1) and my code looks like this

  1. void Update() {
  2.         if (Input.GetButtonDown("Fire1"))
  3.             Instantiate(projectile, transform.position, transform.rotation) as GameObject;
  4.        
  5.     }
  6.  

how can i say that my NGUI button is the "Fire1" button?
i mean my positive button is left ctrl but cant i say somehow that that my alternative postive button is a ngui button or a game object?

4
not realy. i want it the other way around.
with the key binding you press the button by pressing Y
but i want that when i press a button it tells unity i pressed Y on the keyboard.

for example i have a box and when i click y on my keyboard it opens up. so what if i dont have a keyboard (mobile for example)? I want a y button on my screen that i can click and it performs the "if key Y go down" action. you know what i mean?

5
NGUI 3 Support / Is it possible to simulate a keypress/input in code?
« on: June 10, 2014, 09:03:47 AM »
Hey!

I have a simple question. is it possible to map a keyboard key to an NGUI onscreen button?
for example when i press an NGUI button unity gets told that i pressed Y on my keyboard?

6
NGUI 3 Support / Trigger NGUI Button pressing
« on: June 10, 2014, 03:13:15 AM »
Hey guys!

I have a question about how i can trigger an NGUI onscreen Button Press.

at the moment i have the following behavior:
I am entering a box collider with trigger and the red dot on top of the barrel is turning into the same graphic as the onscreen button, works perfect so far.




so, i have this red circle that indicates that you can interact with the object and when you are in the area of the trigger, it just gets bigger. what i want to do now is, that i can press the big A button on the down right and it throws out a debug message.

how can i let the NGUI button and the trigger interact with each other? I think i have to put "some" script on that trigger and not on the button right?

Greets,
Kevin

7
NGUI 3 Support / Re: NGUI: Draggable Camera and Scroll Panel
« on: April 15, 2014, 10:19:47 AM »
Hey!
works out pretty good. thanks for the help!

sadly the camera is jumping around pretty crazy. you can see the changes here:
http://pixelpizza.de/unity/nguidrag_v2.html

i changed the script to this:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ViewDrag : MonoBehaviour {
  5.         Vector3 hit_position = Vector3.zero;
  6.         Vector3 current_position = Vector3.zero;
  7.         Vector3 camera_position = Vector3.zero;
  8.         float z = 0.0f;
  9.        
  10.         // Use this for initialization
  11.         void Start () {
  12.                 UICamera.fallThrough = gameObject;
  13.         }
  14.        
  15.         void OnDrag(){
  16.                 if(Input.GetMouseButtonDown(0)){
  17.                         hit_position = Input.mousePosition;
  18.                         camera_position = transform.position;
  19.                        
  20.                 }
  21.                 if(Input.GetMouseButton(0)){
  22.                         current_position = Input.mousePosition;
  23.                         LeftMouseDrag();        
  24.                 }
  25.         }
  26.        
  27.         void LeftMouseDrag(){
  28.                 current_position.z = hit_position.z = camera_position.y;
  29.                 Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
  30.        
  31.                 direction = direction * -1;            
  32.                 Vector3 position = camera_position + direction;        
  33.                 transform.position = position;
  34.         }
  35. }
  36.  

8
NGUI 3 Support / NGUI: Draggable Camera and Scroll Panel
« on: April 15, 2014, 08:05:25 AM »
Hey Guys!

Iam having a problem...
I wanted to create an RTS kind of Game so i need a Draggable Camera. For the Troop Selection i wanted to use a Scrollable List.

now my biggest problem is, that when i use the scroll list, the whole background is scrolling. i think you can see the issue pretty clear when you look at this example:

http://pixelpizza.de/unity/nguidrag.html

does anybody know how i can solve this issue?

the code for the scroll view is the following:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ViewDrag : MonoBehaviour {
  5.     Vector3 hit_position = Vector3.zero;
  6.     Vector3 current_position = Vector3.zero;
  7.     Vector3 camera_position = Vector3.zero;
  8.     float z = 0.0f;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.  
  13.     }
  14.  
  15.     void Update(){
  16.        if(Input.GetMouseButtonDown(0)){
  17.          hit_position = Input.mousePosition;
  18.          camera_position = transform.position;
  19.  
  20.        }
  21.        if(Input.GetMouseButton(0)){
  22.          current_position = Input.mousePosition;
  23.          LeftMouseDrag();        
  24.        }
  25.     }
  26.  
  27.     void LeftMouseDrag(){
  28.        current_position.z = hit_position.z = camera_position.y;
  29.  
  30.        Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
  31.  
  32.        // Invert direction to that terrain appears to move with the mouse.
  33.        direction = direction * -1;
  34.  
  35.        Vector3 position = camera_position + direction;
  36.  
  37.        transform.position = position;
  38.     }
  39. }
  40.  

9
NGUI 3 Support / Re: How to adapt Scoreboard from OnGUI to NGUI?
« on: February 18, 2014, 03:19:51 AM »
ok. i tried to figure it out on my own. it looks like this now:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CashView : MonoBehaviour {
  5.        
  6.         public UILabel resourceLabel;
  7.         //private int displayedResources;
  8.  
  9.         private SpawnController m_spawnController                       = null;
  10.        
  11.         void Awake()
  12.         {
  13.                 m_spawnController = GameObject.FindWithTag("SpawnController").GetComponent<SpawnController>();
  14.         }
  15.        
  16.         public void UpdateResource(bool instant = false) {
  17.                 resourceLabel.text = "CASH: " + m_spawnController.m_playerCashh();
  18.                 }
  19.  
  20. }
  21.  
  22.  

but i get the error:
CashView.cs(17,64): error CS1955: The member `SpawnController.m_playerCash' cannot be used as method or delegate

btw here is the full old script:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CashViewOld : MonoBehaviour
  5. {
  6.                
  7.         private SpawnController m_spawnController                       = null;
  8.        
  9.         void Awake()
  10.         {
  11.                 m_spawnController = GameObject.FindWithTag("SpawnController").GetComponent<SpawnController>();
  12.                
  13.         }
  14.  
  15.  
  16.         void OnGUI()
  17.         {
  18.                 Vector2 buttonSize = new Vector2(120, 40);
  19.                 Rect startPosTop = new Rect(90, 30, buttonSize.x, buttonSize.y);
  20.  
  21.                 GUI.Label(new Rect(startPosTop.x + 80.0f, startPosTop.y - 25.0f, 100.0f, 30.0f), "CASH: " + m_spawnController.m_playerCash);
  22.         }
  23. }
  24.  

10
NGUI 3 Support / How to adapt Scoreboard from OnGUI to NGUI?
« on: February 17, 2014, 04:13:13 PM »
Hey. Iam just trying to adapt my old Unity GUI to NGUI and have somehow no clue how to display the cash amount of my game. with Unity GUI i do it like this:

  1. GUI.Label(new Rect(startPosTop.x + 80.0f, startPosTop.y - 25.0f, 100.0f, 30.0f), "CASH: " + m_spawnController.m_playerCash);
  2.                

can somebody tell me how i do this in NGUI?

Cheers,
Kev

Pages: [1]