コード例 #1
0
        public void OnPreprocessBuild(BuildReport report)
        {
            var settings = AssetbundleBuildSettings.EditorInstance;

            //no instance found
            if (settings == null)
            {
                return;
            }
            if (Directory.Exists(AssetbundleBuildSettings.LocalBundleRuntimePath))
            {
                Directory.Delete(AssetbundleBuildSettings.LocalBundleRuntimePath, true);
            }
            if (!Directory.Exists(Application.streamingAssetsPath))
            {
                Directory.CreateDirectory(Application.streamingAssetsPath);
            }


            var localBundleSourcePath = Utility.CombinePath(settings.LocalOutputPath, EditorUserBuildSettings.activeBuildTarget.ToString());

            if (!Directory.Exists(localBundleSourcePath))
            {
                if (Application.isBatchMode)
                {
                    Debug.LogError("Missing built local bundle directory, Locus bundle system won't work properly.");
                    return; //we can't build now as it's in batchmode
                }
                else
                {
                    var buildNow = EditorUtility.DisplayDialog("LocusBundleSystem", "Warning - Missing built local bundle directory, would you like to build now?", "Yes", "Not now");
                    if (!buildNow)
                    {
                        return;           //user declined
                    }
                    AssetbundleBuilder.BuildAssetBundles(BuildType.Local);
                }
            }

            FileUtil.CopyFileOrDirectory(Utility.CombinePath(settings.LocalOutputPath, EditorUserBuildSettings.activeBuildTarget.ToString()), AssetbundleBuildSettings.LocalBundleRuntimePath);
            AssetDatabase.Refresh();
        }
        public override void OnInspectorGUI()
        {
            var settings = target as AssetbundleBuildSettings;

            list.DoLayoutList();
            bool allowBuild = true;

            if (!settings.IsValid())
            {
                GUILayout.Label("Duplicate or Empty BundleName detected");
                allowBuild = false;
            }

            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(m_AutoCreateSharedBundles);
            if (allowBuild && GUILayout.Button("Get Expected Sharedbundle List"))
            {
                AssetbundleBuilder.WriteExpectedSharedBundles(settings);
                GUIUtility.ExitGUI();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(m_RemoteOutputPath);
            if (GUILayout.Button("Open", GUILayout.ExpandWidth(false)))
            {
                OpenFolder(Path.Combine(settings.RemoteOutputPath, EditorUserBuildSettings.activeBuildTarget.ToString()));
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(m_LocalOutputPath);
            if (GUILayout.Button("Open", GUILayout.ExpandWidth(false)))
            {
                OpenFolder(Path.Combine(settings.LocalOutputPath, EditorUserBuildSettings.activeBuildTarget.ToString()));
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(m_RemoteURL);
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(m_ConstStringPath);
            if (GUILayout.Button("Open", GUILayout.ExpandWidth(false)))
            {
                OpenFolder(settings.ConstStringFilePath);
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(m_ConstStringName);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_EmulateBundle);
            EditorGUILayout.PropertyField(m_EmulateUseRemoteFolder);
            GUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(m_CleanCache);
            if (GUILayout.Button("Open", GUILayout.ExpandWidth(false)))
            {
                OpenFolder(Caching.defaultCache.path);
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(m_ForceRebuld);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(m_UseCacheServer);
            if (m_UseCacheServer.boolValue)
            {
                EditorGUILayout.PropertyField(m_CacheServerHost);
                EditorGUILayout.PropertyField(m_CacheServerPort);
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_UseFtp);
            if (m_UseFtp.boolValue)
            {
                EditorGUILayout.PropertyField(m_FtpHost);
                EditorGUILayout.PropertyField(m_FtpUser);
                m_FtpPass.stringValue = EditorGUILayout.PasswordField("Ftp Password", m_FtpPass.stringValue);
            }

            GUILayout.Label($"Local Output folder : { settings.LocalOutputPath }");
            GUILayout.Label($"Remote Output folder : { settings.RemoteOutputPath }");

            serializedObject.ApplyModifiedProperties();

            if (AssetbundleBuildSettings.EditorInstance == settings)
            {
                EditorGUILayout.BeginHorizontal();
                if (allowBuild && GUILayout.Button("Build Remote"))
                {
                    AssetbundleBuilder.BuildAssetBundles(settings, BuildType.Remote);
                    GUIUtility.ExitGUI();
                }

                if (allowBuild && GUILayout.Button("Build Local"))
                {
                    AssetbundleBuilder.BuildAssetBundles(settings, BuildType.Local);
                    GUIUtility.ExitGUI();
                }

                EditorGUI.BeginDisabledGroup(!settings.UseFtp);
                if (allowBuild && GUILayout.Button("Upload(FTP)"))
                {
                    AssetbundleUploader.UploadAllRemoteFiles(settings);
                    GUIUtility.ExitGUI();
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();


                EditorGUILayout.BeginHorizontal();
                if (allowBuild && GUILayout.Button("Generate Const String Source"))
                {
                    AssetbundleBuilder.WriteConstStringBundles(settings);
                    GUIUtility.ExitGUI();
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                if (GUILayout.Button("Set as active setting"))
                {
                    AssetbundleBuildSettings.EditorInstance = settings;
                }
            }
        }
        public override void OnInspectorGUI()
        {
            var settings = target as AssetbundleBuildSettings;

            list.DoLayoutList();
            EditorGUILayout.PropertyField(m_RemoteOutputPath);
            EditorGUILayout.PropertyField(m_LocalOutputPath);
            EditorGUILayout.PropertyField(m_RemoteURL);
            EditorGUILayout.Space(10);
            EditorGUILayout.PropertyField(m_EmulateBundle);
            EditorGUILayout.PropertyField(m_EmulateUseRemoteFolder);
            EditorGUILayout.PropertyField(m_CleanCache);
            EditorGUILayout.PropertyField(m_ForceRebuld);
            EditorGUILayout.Space(10);
            m_UseCacheServer.boolValue = EditorGUILayout.BeginToggleGroup("Cache Server", m_UseCacheServer.boolValue);
            EditorGUILayout.PropertyField(m_CacheServerHost);
            EditorGUILayout.PropertyField(m_CacheServerPort);
            EditorGUILayout.EndToggleGroup();

            m_UseFtp.boolValue = EditorGUILayout.BeginToggleGroup("Ftp", m_UseFtp.boolValue);
            EditorGUILayout.PropertyField(m_FtpHost);
            EditorGUILayout.PropertyField(m_FtpUser);
            m_FtpPass.stringValue = EditorGUILayout.PasswordField("Ftp Password", m_FtpPass.stringValue);
            EditorGUILayout.EndToggleGroup();

            bool allowBuild = true;

            if (!settings.IsValid())
            {
                GUILayout.Label("Duplicate or Empty BundleName detected");
                allowBuild = false;
            }

            GUILayout.Label($"Local Output folder : { settings.LocalOutputPath }");
            GUILayout.Label($"Remote Output folder : { settings.RemoteOutputPath }");
            serializedObject.ApplyModifiedProperties();

            if (AssetbundleBuildSettings.EditorInstance == settings)
            {
                EditorGUILayout.BeginHorizontal();
                if (allowBuild && GUILayout.Button("Build Remote"))
                {
                    AssetbundleBuilder.BuildAssetBundles(settings);
                    GUIUtility.ExitGUI();
                }

                if (allowBuild && GUILayout.Button("Build Local"))
                {
                    AssetbundleBuilder.BuildAssetBundles(settings, true);
                    GUIUtility.ExitGUI();
                }

                EditorGUI.BeginDisabledGroup(!settings.UseFtp);
                if (allowBuild && GUILayout.Button("Upload(FTP)"))
                {
                    AssetbundleUploader.UploadAllRemoteFiles(settings);
                    GUIUtility.ExitGUI();
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
            }
            else
            {
                if (GUILayout.Button("Set as active setting"))
                {
                    AssetbundleBuildSettings.EditorInstance = settings;
                }
            }
        }