static void CreateIfNeeded()
        {
            if (exists)
            {
                return;
            }

            singleton = new GameObject("Game State Pipe <" + typeof(T).ToString() + ">").AddComponent <GameStatePipeObject>();
            MonoBehaviour.DontDestroyOnLoad(singleton.gameObject);
        }
Пример #2
0
    public UIManager()
    {
        GameObject ui = GameObject.Find("UI");

        MonoBehaviour.DontDestroyOnLoad(ui);

        _canvas = ui.transform.Find("Canvas");

        _uiCamera = ui.transform.Find("Camera").GetComponent <Camera>();
    }
Пример #3
0
 public void DontDestroyElseKill(MonoBehaviour mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(mb);               //GO may contain useful scripts
     }
 }
Пример #4
0
 public static void DontDestroyOnLoad(this GameObject g, bool checkIfRootObject)
 {
     if (checkIfRootObject)
     {
         if (g.transform.parent == null)
         {
             dontDestroyOnLoadRootObjects.Add(g);
         }
     }
     MonoBehaviour.DontDestroyOnLoad(g);
 }
Пример #5
0
    private void PlayAudioClip(int index)
    {
        GameObject go = new GameObject("AudioClip");

        MonoBehaviour.DontDestroyOnLoad(go);;
        AudioSource source = go.AddComponent <AudioSource>();

        source.clip = sounds[index];
        source.Play();
        MonoBehaviour.Destroy(go, sounds[index].length);
    }
Пример #6
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This is most often done in Awake().
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public static void DontDestroyElseKill(SingletonBehaviour <T> mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(mb);
     }
 }
Пример #7
0
        public override void Init()
        {
            base.Init();
            var gameObject = GameObject.Find(UIConst.UIManager_Path);

            graphicComponent.SetGameObject(gameObject, true);
            if (Application.isPlaying)
            {
                MonoBehaviour.DontDestroyOnLoad(graphicComponent.gameObject);
            }
        }
Пример #8
0
    private void Start()
    {
        GameObject gameBase = new GameObject("GameBase");

        gameBase.AddMissComponent <ScenesManager>();
        MonoBehaviour.DontDestroyOnLoad(gameBase);

        //创建游戏基础物件
        UITools.CreatUIRoot();
        ScenesManager.Instance.LoadLevel("InfiniteScrollRect", SceneType.Main);
    }
Пример #9
0
        private void Initialize()
        {
            // First, create a GameObject instance...
            GameObject gameObject = new GameObject("Fluffy Lib");

            // Second, attach our logic to it...
            gameObject.AddComponent <Controller>();

            // Finally, make sure Unity doesn't destroy this object on level changes.
            MonoBehaviour.DontDestroyOnLoad(gameObject);
        }
Пример #10
0
 // Makes this object a persistent singleton unless the singleton already exists in which case
 // this object is destroyed
 protected void DontDestroy()
 {
     if (this == Instance)
     {
         MonoBehaviour.DontDestroyOnLoad(Instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(this);
     }
 }
Пример #11
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public void DontDestroyElseKill(MonoBehaviour mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(mb);
     }
 }
Пример #12
0
    private static GameObject GetAudioRoot()
    {
        if (_audioRoot == null)
        {
            _audioRoot      = new GameObject();
            _audioRoot.name = "AudioObjectsRoot";
            MonoBehaviour.DontDestroyOnLoad(_audioRoot);
        }

        return(_audioRoot);
    }
Пример #13
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public static void DontDestroyElseKill(MonoBehaviour mb)
 {
     if (instance == null)
     {
         MonoBehaviour.DontDestroyOnLoad(mb.gameObject);
         instance = (T)mb;
     }
     else
     {
         MonoBehaviour.Destroy(mb);
     }
 }
Пример #14
0
        T CreateInstance(T prefab, List <T> pool, Vector3 position, Quaternion rotation, Action <T> onCreateNew)
        {
            T newInstance = GameObject.Instantiate(prefab, position, rotation);

            MonoBehaviour.DontDestroyOnLoad(newInstance.gameObject);
            if (onCreateNew != null)
            {
                onCreateNew(newInstance);
            }
            pool.Add(newInstance);
            return(newInstance);
        }
Пример #15
0
        public static GameObject LoadProgress()
        {
            ResourceItem LoadPregressUnit = ResourcesManager.Instance.loadImmediate(GameConstDefine.LoadProsPath, ResourceType.PREFAB);
            GameObject   LoadPregress     = GameObject.Instantiate(LoadPregressUnit.Asset) as GameObject;


            MonoBehaviour.DontDestroyOnLoad(LoadPregress);
            LoadPregress.transform.parent        = GetUiCamera.transform;
            LoadPregress.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);
            LoadPregress.transform.localPosition = Vector3.zero;
            return(LoadPregress);
        }
Пример #16
0
        /// <summary>
        /// Creates a ViewController of type T, and marks it to not be destroyed.
        /// </summary>
        /// <typeparam name="T">The variation of ViewController you want to create.</typeparam>
        /// <returns>The newly created ViewController of type T.</returns>
        public static T CreateViewController <T>() where T : ViewController
        {
            T vc = new GameObject("BSMLViewController").AddComponent <T>();

            MonoBehaviour.DontDestroyOnLoad(vc.gameObject);

            vc.rectTransform.anchorMin        = new Vector2(0f, 0f);
            vc.rectTransform.anchorMax        = new Vector2(1f, 1f);
            vc.rectTransform.sizeDelta        = new Vector2(0f, 0f);
            vc.rectTransform.anchoredPosition = new Vector2(0f, 0f);
            return(vc);
        }
Пример #17
0
    /// <summary>
    /// 初始化
    /// </summary>
    private void Init()
    {
        this.timerPool = new ObjectPool <Timer> (poolCapacity, createTimer, DestroyTimer);

        this._Timers  = new List <Timer> ();
        this._Removes = new List <Timer> ();

#if UNITY_EDITOR
        TimeMgrVirtual = new GameObject("[TimerRuntime (0)|Pool (0/0)]");
        MonoBehaviour.DontDestroyOnLoad(TimeMgrVirtual);
#endif
    }
Пример #18
0
        protected override void InitializeServer()
        {
            base.InitializeServer();



            vsConnectFixupdateObject      = new GameObject();
            vsConnectFixupdateObject.name = "VSConnectTickGameObject";
            vsConnectFixupdateObject.AddComponent(typeof(VsUnity.VSConnectTickComponent));
            vsConnectFixupdateObject.isStatic = true;
            MonoBehaviour.DontDestroyOnLoad(vsConnectFixupdateObject);
        }
            private PoolableElement Instantiate()
            {
                var randomPrefabIndex = UnityEngine.Random.Range(0, elementPrefabs.Count);
                var element           = UnityEngine.Object.Instantiate(elementPrefabs[randomPrefabIndex]);

                MonoBehaviour.DontDestroyOnLoad(element);
                element.name = elementPrefabs[randomPrefabIndex].name;
                element.transform.SetParent(holder.transform, false);
                element.Deactivate();

                return(element);
            }
Пример #20
0
    static public AudioScript getAudioScript()
    {
        if (!s_audioObj)
        {
            s_audioObj = new GameObject();
            MonoBehaviour.DontDestroyOnLoad(s_audioObj);
            s_audioScript = s_audioObj.AddComponent <AudioScript>();
            s_audioScript.init();
        }

        return(s_audioScript);
    }
Пример #21
0
 public void Initialize(MonoBehaviour instance, MonoBehaviour self)
 {
     //Check if instance already exists
     if (instance == null)
         //if not, set instance to this
         instance = self;
     //If instance already exists and it's not this:
     else if (instance != self)
         //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
         MonoBehaviour.Destroy(gameObject);
     //Sets this to not be destroyed when reloading scene
     MonoBehaviour.DontDestroyOnLoad(self);
 }
Пример #22
0
 // Makes this object a persistent singleton unless the singleton already exists in which case
 // the this object is destroyed
 protected void DontDestroy()
 {
     if (this == Instance)
     {
         // needs to be a root object before calling DontDestroyOnLoad
         Instance.transform.parent = null;
         MonoBehaviour.DontDestroyOnLoad(Instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(this);
     }
 }
Пример #23
0
        public static TcpObject StartTcp(string name)
        {
            if (netObject == null)
            {
                netObject = new GameObject("Net");
                MonoBehaviour.DontDestroyOnLoad(netObject);
            }
            GameObject go = new GameObject(name);

            MonoBehaviour.DontDestroyOnLoad(go);
            go.transform.parent = netObject.transform;
            return(go.AddComponent <TcpObject>());
        }
Пример #24
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This is most often done in Awake().
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public static bool DontDestroyElseKill(Singleton <T> mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
         return(true);
     }
     else
     {
         MonoBehaviour.Destroy(mb.gameObject);
         return(false);
     }
 }
Пример #25
0
    public static HttpReqUtil getInstance()
    {
        if (s_instance == null)
        {
            s_instance = new HttpReqUtil();
            GameObject obj = new GameObject("HttpReqUtil");
            obj.transform.name = "HttpReqUtil";
            MonoBehaviour.DontDestroyOnLoad(obj);
            s_instance = obj.AddComponent <HttpReqUtil>();
        }

        return(s_instance);
    }
Пример #26
0
        public UISystem(IUILoader uiLoader)
        {
            UILoader = uiLoader;

            GameObject go = UILoader.LoadUI <GameObject>(eUIPrefab.UIRoot);

            go                  = MonoBehaviour.Instantiate(go);
            rootCanvas          = go.GetComponent <Canvas>();
            rootCanvasTransform = go.GetComponent <Transform>();
            MonoBehaviour.DontDestroyOnLoad(go);

            uiGroup = new List <GameObject>();
        }
Пример #27
0
        // Makes this object a persistent singleton unless the singleton already exists in which case
        // the this object is destroyed
        protected void DontDestroy()
        {
            this.gameObject.transform.SetParent(null);

            if (this == Instance)
            {
                MonoBehaviour.DontDestroyOnLoad(Instance.gameObject);
            }
            else
            {
                MonoBehaviour.Destroy(this);
            }
        }
Пример #28
0
    private IEnumerator InitEventSystem()
    {
        AssetInfo mAssetInfo = ResourceABsFolder.Instance.getAsseetInfo("manager", "ObjectRoot");

        yield return(AssetBundleManager.Instance.AsyncLoadAsset(mAssetInfo));

        GameObject obj         = AssetBundleManager.Instance.LoadAsset(mAssetInfo) as GameObject;
        ObjectRoot mObjectRoot = obj.GetComponent <ObjectRoot>();

        mObjectRoot.Init();
        obj.SetActive(true);
        MonoBehaviour.DontDestroyOnLoad(obj);
    }
Пример #29
0
        public static void Init()
        {
            tempChild  = (new GameObject("Math3d_TempChild")).transform;
            tempParent = (new GameObject("Math3d_TempParent")).transform;

            tempChild.gameObject.hideFlags = HideFlags.HideAndDontSave;
            MonoBehaviour.DontDestroyOnLoad(tempChild.gameObject);

            tempParent.gameObject.hideFlags = HideFlags.HideAndDontSave;
            MonoBehaviour.DontDestroyOnLoad(tempParent.gameObject);

            //set the parent
            tempChild.parent = tempParent;
        }
Пример #30
0
        public Bootstrap()
        {
            Log.Message("I AM HERE:\n" + System.Environment.StackTrace);

            LongEventHandler.ExecuteWhenFinished(delegate
            {
                Log.Message("I AM NOW HERE:\n" + System.Environment.StackTrace);

                // create a game object.
                GameObject gameObject = new GameObject(Controller.GameObjectName);
                MonoBehaviour.DontDestroyOnLoad(gameObject);
                gameObject.AddComponent <Controller>();
            });
        }