public IEnumerator FindRuntimeMaterialsFromAddresses(MB2_TextureBakeResults texBakeResult, MB2_TextureBakeResults.CoroutineResult isComplete)
        {
#if MB_USING_ADDRESSABLES
            Debug.LogError("Currently the runtimeMaterial is not used. This may change in the future.");

            /*
             * if (!Application.isPlaying)
             * {
             *  Debug.LogError("FindRuntimeMaterialsFromAddresses is a coroutine. It is only necessary to use this at runtime.");
             *  yield break;
             * }
             *
             * // Find a distinct set of addressable keys from the TextureBakeResult.
             * List<MB_MaterialAndUVRect> distinctMats = new List<MB_MaterialAndUVRect>();
             * for (int i = 0; i < texBakeResult.materialsAndUVRects.Length; i++)
             * {
             *  int idx = distinctMats.FindIndex(0, distinctMats.Count, x => x.material == texBakeResult.materialsAndUVRects[i].material);
             *  if (idx == -1)
             *  {
             *      distinctMats.Add(texBakeResult.materialsAndUVRects[i]);
             *      idx = distinctMats.Count - 1;
             *  }
             * }
             *
             * List<string> keys = new List<string>();
             * for (int i = 0; i < distinctMats.Count; i++)
             * {
             *  if (distinctMats[i].matAddressablesPKey != null && distinctMats[i].matAddressablesPKey != "")
             *  keys.Add(distinctMats[i].matAddressablesPKey);
             * }
             *
             * // Look up the locations for these keys.
             * AsyncOperationHandle<IList<IResourceLocation>> locations = Addressables.LoadResourceLocationsAsync((IEnumerable) keys, Addressables.MergeMode.Union, typeof(Material));
             * yield return locations;
             *
             * // Look up the materials for these locations.
             * Dictionary<string, Material> address_2_material_map = new Dictionary<string, Material>();
             * int numCalled = 0;
             * foreach (IResourceLocation location in locations.Result)
             * {
             *  AsyncOperationHandle<Material> handle =
             *      Addressables.LoadAssetAsync<Material>(location);
             *  handle.Completed += obj => address_2_material_map.Add(location.PrimaryKey, obj.Result);
             *  yield return handle;
             *  numCalled++;
             * }
             *
             * // Assign the found materials to the TextureBakeResult.
             * int numRuntimeMatsMapped = 0;
             * for (int i = 0; i < texBakeResult.materialsAndUVRects.Length; i++)
             * {
             *  if (address_2_material_map.ContainsKey(texBakeResult.materialsAndUVRects[i].matAddressablesPKey))
             *  {
             *      texBakeResult.materialsAndUVRects[i].runtimeMaterial = address_2_material_map[texBakeResult.materialsAndUVRects[i].matAddressablesPKey];
             *      numRuntimeMatsMapped++;
             *  }
             * }
             */

            isComplete.isComplete = true;
            yield break;
#else
            if (!Application.isPlaying)
            {
                Debug.LogError("FindRuntimeMaterialsFromAddresses is a coroutine. It is only necessary to use this at runtime.");
            }
            Debug.LogError("The MB_USING_ADDRESSABLES define was not set in PlayerSettings -> Script Define Symbols. If you are using addressables and you want to use this method, that must be set.");
            isComplete.isComplete = true;
            yield break;
#endif
        }
Beispiel #2
0
 internal static IEnumerator FindRuntimeMaterialsFromAddresses(MB2_TextureBakeResults textureBakeResult, MB2_TextureBakeResults.CoroutineResult isComplete)
 {
     if (_MBVersion == null)
     {
         _MBVersion = _CreateMBVersionConcrete();
     }
     yield return(_MBVersion.FindRuntimeMaterialsFromAddresses(textureBakeResult, isComplete));
 }