Пример #1
0
        // Initializes asset bundle namager and starts download of manifest asset bundle.
        // Returns the manifest asset bundle downolad operation object.
        public static AssetBundleLoadManifestOperation Initialize(string manifestAssetBundleName)
        {
            #if UNITY_EDITOR
            Log(LogType.Info, "Simulation Mode: " + (SimulateAssetBundleInEditor ? "Enabled" : "Disabled"));
            #endif

            var go = new GameObject("AssetBundleManager", typeof(AssetBundleManager));
            GameObject.DontDestroyOnLoad(go);

            // puting this gameobject under the singleton container
            go.transform.SetParent(SingletonUtil.GetSingletonContainer());

            #if UNITY_EDITOR
            // If we're in Editor simulation mode, we don't need the manifest assetBundle.
            if (SimulateAssetBundleInEditor)
            {
                return(null);
            }
            #endif

            LoadAssetBundle(manifestAssetBundleName, true);
            var operation = new AssetBundleLoadManifestOperation(manifestAssetBundleName, "AssetBundleManifest", typeof(AssetBundleManifest));
            inProgressOperations.Add(operation);
            return(operation);
        }
Пример #2
0
        /// <summary>
        /// Should be called before you use this Singleton GameObject.
        /// </summary>
        public static void Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            // highly unlikely this would need a lock since all unity calls need to happen on the main thread, but hey, being safe
            lock (instanceLock)
            {
                if (IsInitialized)
                {
                    return;
                }

                T[]    objects   = GameObject.FindObjectsOfType <T>();
                string className = typeof(T).Name;

                if (objects != null && objects.Length != 0)
                {
                    Debug.LogErrorFormat(objects[0], "An object of type {0} already exists and wasn't created with Initialize function.", className);
                }
                else
                {
                    // constructing the singleton object
                    GameObject singleton = new GameObject(className, typeof(T));
                    singleton.transform.parent = SingletonUtil.GetSingletonContainer();
                    singleton.transform.Reset();

                    instance = singleton.GetComponent <T>();
                }
            }
        }
Пример #3
0
        public Pool(GameObject prefab, int initialCount = 0)
        {
            this.PrefabName = prefab.name;
            this.InstanceId = prefab.GetInstanceID();

            this.inactivePoolParent = new GameObject(string.Format("{0} ({1})", this.PrefabName, this.InstanceId)).transform;
            this.inactivePoolParent.SetParent(SingletonUtil.GetOrCreateSingletonChildObject("Pool"));

            if (initialCount < 1)
            {
                return;
            }

            var initialPooledObjects = new List <PooledObject>(initialCount);

            for (int i = 0; i < initialCount; i++)
            {
                initialPooledObjects.Add(this.GetObjectFromPool(prefab).GetComponent <PooledObject>());
            }

            for (int i = 0; i < initialCount; i++)
            {
                initialPooledObjects[i].Recycle();
            }
        }
Пример #4
0
        /// <summary>
        /// Should be called before you use this Singleton GameObject.
        /// </summary>
        public static void Initialize()
        {
            if (Platform.IsApplicationQuitting)
            {
                Debug.LogErrorFormat("Tried initializing a SingletonResource {0} while application was quitting.", typeof(T).Name);
                return;
            }

            if (IsInitialized)
            {
                return;
            }

            // highly unlikely this would need a lock since all unity calls need to happen on the main thread, but hey, being safe
            lock (instanceLock)
            {
                if (IsInitialized)
                {
                    return;
                }

                T[]    objects   = GameObject.FindObjectsOfType <T>();
                string className = typeof(T).Name;

                if (objects != null && objects.Length != 0)
                {
                    Debug.LogErrorFormat(objects[0], "An object of type {0} already exists and wasn't created with Initialize function.", className);
                }
                else
                {
                    // constructing the singleton object
                    instance = GameObject.Instantiate <T>(Resources.Load <T>(className));

                    if (instance == null)
                    {
                        Debug.LogErrorFormat("Couldn't load Dialog {0}.  Is there a resource named \"{0}\" with a component of type {0} in the project?", className);
                        return;
                    }

                    instance.name = className;
                    instance.transform.SetParent(SingletonUtil.GetSingletonContainer());
                    instance.transform.Reset();
                }
            }
        }