zoukankan      html  css  js  c++  java
  • go.IsActive() && go.GetTag() != 0 的报错

     这个问题原由于 OnEnable Awake  OnEnable OnLevelWasLoaded 这几个问题。

    具体的起因大致是 在OnEnable 中的代码执行的时候这个脚本已经激活了。

    开始我的起始脚本是 

    using UnityEngine;
    using System.Collections;
    /*
     *  游戏从这里开始 ,整个游戏的逻辑初始化开始
     */
    public class LogicWorld:MonoSingleton<LogicWorld>
    {
       
        // 这里有所有需要初始化的 逻辑管理器
        #region property
        public PlayerDatas globalPlayerData;
    
        #endregion
        protected override void OnAwake()
       {
            base.OnAwake();  
            DontDestroyOnLoad(this);
        }
        void Start()
        { 
            StartGame();
            UIMgr.SG.HandlerSence(SenceTypy.UIBackGround , UICommend.CommendType.CreateUIAndShow);
        }
        void StartGame()
        {
            globalPlayerData = RealtimeDataGet.GetData(); //获取本地存储的数据 单机版
           this.gameObject.AddComponent<LayerMgr>();
            this.gameObject.AddComponent<UIMgr>();
            this.gameObject.AddComponent<AppMgr>();
        }
    }

    在这里 我先把这几个 脚本初始化加载了 。 然后我的ResMgr 脚本的单例是这么写的

    public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
        {
            private static T instance=null;
            public static T Instance {
                get {
                       if(instance==null)
                       instance=GameObject.Find("GameElement").AddCompnent<T>();
                    return instance;
                }
            }
            
            void OnApplicationQuit () { if (instance != null) instance = null; }
            
            
        }

    导致再次使用时 ResMgr 已经激活

  • 相关阅读:
    poj 1840 简单哈希
    poj 2151概率dp
    poj 3349 简单hash
    poj3274 hash
    poj 1459 最大流 Dinic模板题
    poj 3436 最大流-拆点
    poj 3020 二分图最大匹配
    poj 1094 简单拓扑排序
    poj3687 反向建图拓扑排序
    poj 3267
  • 原文地址:https://www.cnblogs.com/bambomtan/p/5080713.html
Copyright © 2011-2022 走看看