1
NGUI 3 Support / MissingReferenceException: The object of type 'UIGamePanel' has been destr
« on: October 14, 2014, 10:33:12 AM »
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:
does anyone of you having this problem before?
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:
- #define USE_NGUI_2X
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class UIGamePanel : MonoBehaviour {
- public const float UI_DELAY = 0.75f;
- public const float UI_TRAVEL_DIST = 1.6f;
- public GameObject content;
- public PanelType panelType;
- public PanelType openFromPanelOnly;
- /**
- * Position of the buttons when visible.
- */
- protected Vector3 showPosition;
- /**
- * Position of the buttons when hidden.
- */
- protected Vector3 hidePosition;
- public static Dictionary <PanelType, UIGamePanel> panels;
- public PanelType[] IgnoreTypes;
- void Awake() {
- panels.Add (panelType, this);
- showPosition = content.transform.position;
- if (panelType == PanelType.DEFAULT) {
- activePanels.Add(this);
- } else {
- content.transform.position = hidePosition;
- }
- Init ();
- }
- virtual protected void Init() {
- }
- virtual public void InitialiseWithBuilding(Building building) {
- }
- virtual public void Show() {
- if (panelType == PanelType.DEFAULT && GridView.Instance != null) GridView.Instance.NormalMode();
- if (panelType == PanelType.PLACE_BUILDING && GridView.Instance != null) GridView.Instance.BuildingMode();
- if (panelType == PanelType.EDIT_PATHS && GridView.Instance != null) GridView.Instance.PathMode();
- if (activePanels.Contains(this)) {
- StartCoroutine(DoReShow());
- } else if (activePanels.Count == 0 || IsPanelOpenedFromActivePanel () || openFromPanelOnly == PanelType.NONE) {
- HideActivePanels ();
- gameObject.SendMessage ("OnShow", this, SendMessageOptions.DontRequireReceiver);
- StartCoroutine(DoShow());
- activePanels.Add (this);
- }
- }
- virtual public void Hide() {
- if (activePanels.Contains(this)) {
- activePanels.Remove (this);
- }
- gameObject.SendMessage ("OnHide", this, SendMessageOptions.DontRequireReceiver);
- StartCoroutine(DoHide());
- }
- public static void ShowPanel(PanelType panelType) {
- if (panelType == PanelType.DEFAULT) BuildingManager.ActiveBuilding = null;
- if (panels.ContainsKey (panelType)) {
- //if (!activePanels.Contains(panels[panelType])) {
- panels [panelType].Show ();
- //}
- }
- }
- public static List<UIGamePanel> activePanels;
- /**
- * Reshow the panel (i.e. same panel but for a different object/building).
- */
- virtual protected IEnumerator DoReShow() {
- gameObject.BroadcastMessage ("OnHide", SendMessageOptions.DontRequireReceiver);
- iTween.MoveTo(content, hidePosition, UI_DELAY);
- gameObject.BroadcastMessage ("OnShow", SendMessageOptions.DontRequireReceiver);
- iTween.MoveTo(content, showPosition, UI_DELAY);
- }
- /**
- * Show the panel.
- */
- virtual protected IEnumerator DoShow() {
- content.SetActive (true);
- gameObject.BroadcastMessage ("OnShow", SendMessageOptions.DontRequireReceiver);
- #if USE_NGUI_3X
- yield return true;
- GetComponent<UIPanel>().Refresh();
- #endif
- iTween.MoveTo(content, showPosition, UI_DELAY);
- }
- /**
- * Hide the panel.
- */
- virtual protected IEnumerator DoHide() {
- gameObject.BroadcastMessage ("OnHide", SendMessageOptions.DontRequireReceiver);
- iTween.MoveTo(content, hidePosition, UI_DELAY);
- content.SetActive (false);
- }
- protected bool IsPanelOpenedFromActivePanel () {
- for (int i = 0; i < activePanels.Count; ++i) {
- if (activePanels[i].panelType == openFromPanelOnly) {
- return true;
- }
- }
- return false;
- }
- protected void HideActivePanels () {
- if (activePanels != null) {
- for (int i = 0; i < activePanels.Count; ++i) {
- UIGamePanel panel = activePanels[i];
- bool hide = true;
- if (IgnoreTypes != null) {
- for (int j = 0; j < IgnoreTypes.Length; ++j) {
- if (IgnoreTypes[j] == panel.panelType) {
- hide = false;
- break;
- }
- }
- }
- if (hide) {
- activePanels.Remove (panel);
- panel.Hide ();
- --i;
- }
- }
- }
- }
- }
does anyone of you having this problem before?


