/// <summary> /// Creates the default <see cref="Creator"/> for the prefab and returns it. /// </summary> /// <param name="prefab">The prefab that you want to create a creator for.</param> /// <returns>The creator method.</returns> public static Creator CreateDefaultCreator(GameObject prefab) { var views = NetworkInstantiatorUtility.GetComponentsInChildren <NetworkView>(prefab.transform); if (views.Count == 0) { Log.Error(NetworkLogFlags.Instantiate, "Prefab '", prefab.GetName(), "' must at least have one NetworkView"); return(null); } return(_CreateDefaultCreator(prefab, views)); }
/// <summary> /// Registers all prefabs in the asset bundle that does have a NetworkView component. /// This makes sure they can be instantiated later with /// <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see> /// </summary> /// <param name="assetBundle">The asset bundle that you want to register its prefabs.</param> /// <param name="replaceIfExists">if <c>true</c> then prefabs with the same name will be replaced by the new ones in the asset bundle.</param> /// <remarks> /// This is a convenience method that calls <see cref="O:uLink.NetworkInstantiator.AddPrefab"/> /// for all prefabs in the asset bundle that has a network view component. /// <para> /// It is common for developers to minimize the download time for the Unity game at startup by putting /// some prefabs in asset bundles and then download the asset bundles when needed in the game. /// We recommend writing code that downloads the asset bundle, loads the prefabs, registers them with this method, /// and finally makes the calls to <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see>. /// If it is an authoritative server the call to <see cref="O:uLink.Network.Instantiate">uLink.Network.Instantiate</see> /// has to be done on the server. /// </para> /// </remarks> public static void AddAssetBundle(AssetBundle assetBundle, bool replaceIfExists) { #if UNITY_4 var prefabs = assetBundle.LoadAll(typeof(GameObject)) as GameObject[]; #else var prefabs = assetBundle.LoadAllAssets <GameObject>(); #endif foreach (var prefab in prefabs) { var views = NetworkInstantiatorUtility.GetComponentsInChildren <NetworkView>(prefab.transform); if (views.Count != 0) { Add(prefab.GetName(), _CreateDefault(prefab, views), replaceIfExists); } } }