private void SettingsLoaded()
        {
            _assetBundleSettingsSettings = SettingsManager.Instance.Settings.AssetBundle;
            // Load the Asset bundles

            if (_assetBundleSettingsSettings.Name.StartsWith("http"))
            {
                StartCoroutine(LoadAssetBundle(_assetBundleSettingsSettings.Name));
            }
            else if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                StartCoroutine(LoadAssetBundle("AssetBundles/" + _assetBundleSettingsSettings.Name));
            }
            else
            {
#if UNITY_EDITOR
                _assetBundle = AssetBundle.LoadFromFile($"Assets/AssetBundles/{_assetBundleSettingsSettings.Name}");
#else
                _assetBundle = AssetBundle.LoadFromFile($"{Application.dataPath}/{_assetBundleSettingsSettings.Name}");
#endif
                OnAssetsLoaded();
            }


            // Invoke the event handler to let other managers know the assets bundle is loaded

            // Make lists of prefabs by a descending ordering
            _buildingPrefabs          = _assetBundleSettingsSettings.Buildings.OrderByDescending(x => x.MinSize);
            _vehiclePrefabs           = _assetBundleSettingsSettings.Vehicles.OrderByDescending(x => x.MinSize);
            _buildingDecayedThreshold = _assetBundleSettingsSettings.BuildingDecayAgeThreshold;
        }
Exemple #2
0
    public static void BuildAssetBundles(AssetBundleSettings assetBundleSettings, BuildAssetBundleOptions assetBundle, string location, BuildTarget buildTarget)
    {
        if (assetBundleSettings == null)
        {
            return;
        }

        //Prepare asset bundle build assets
        var assets = new List <AssetBundleBuild>();

        foreach (var map in assetBundleSettings.maps)
        {
            var scn = map.sceneAsset as UnityEditor.SceneAsset;
            if (scn != null)
            {
                assets.Add(new AssetBundleBuild()
                {
                    assetBundleName = "map_" + map.sceneAsset.name,
                    assetNames      = new string[] { AssetDatabase.GetAssetPath(map.sceneAsset), },
                });

                assets.Add(new AssetBundleBuild()
                {
                    assetBundleName  = "mapimage_" + map.sceneAsset.name,
                    assetNames       = new string[] { AssetDatabase.GetAssetPath(map.spriteImg), },
                    addressableNames = new string[] { "mapimage_" + map.sceneAsset.name, },
                });
            }
        }

        BuildScript.BuildAssetBundles(assets.ToArray(), assetBundle, location, buildTarget);
    }
 public void Init()
 {
     if (asset == null)
     {
         asset = AssetBundleSettings.Instance;
     }
     if (assetType == null)
     {
         assetType = asset.GetType();
     }
     if (resourceFoldersList == null)
     {
         List <AssetBundleSettings.ResourceFolder> resourceFolders = asset.resourceFolders;
         int selIndex = 0;
         resourceFoldersList = new ReorderableList(resourceFolders, typeof(AssetBundleSettings.ResourceFolder), true, true, true, true)
         {
             drawHeaderCallback = (rect) =>
                                  EditorGUI.LabelField(rect, new GUIContent("Resource Folders", "资源文件")),
             drawElementCallback = (rect, index, isActive, isFocused) =>
             {
                 AssetBundleSettings.ResourceFolder resourceFolder = resourceFolders[index];
                 if (selIndex == index)
                 {
                     resourceFolder.path = EditorGUI.TextField(rect, resourceFolder.path);
                 }
                 else
                 {
                     EditorGUI.LabelField(rect, resourceFolder.path);
                 }
             },
             onSelectCallback = (ReorderableList list) =>
             {
                 if (selIndex == -1)
                 {
                     selIndex = list.index;
                 }
                 else if (selIndex != list.index)
                 {
                     selIndex = -1;
                 }
             }
         };
     }
 }