Unity game framework to build 2019 (d) Export UnityPackage

In the last article we get the merger of functions. So in this article we then continue.

Our current export listed first step:

  1. Click on the menu bar QFramework / 3. Generates a file name to the clipboard.
  2. QFramework Right-click the folder, and then select ExportPackage.
  3. Then make sure to deselect Include Dependency.
  4. Paste the name, and then exported to the specified directory.

The first operation currently has no room for optimization.
Then we look at the second step: QFramework right-click the folder, and then select ExportPackage.

ExportPackage Unity editor is provided Assets menu. Then we can look for, there is not a corresponding UnityEditor API.
Very Fortunately, search for the keyword "unity exportpackage" directly on bing.con search engines to find.

API is:

public static void ExportPackage(string assetPathName, string fileName, ExportPackageOptions flags);

The first parameter assetPathName: can be drawn by name, is to pack the path name, is our QFramework path.

The second parameter fileName should be the name of the exported file, the corresponding life example we generated name.
The third parameter should be some options. We look directly at his definition.

using System;

namespace UnityEditor
{
  /// <summary>
  ///   <para>Export package option. Multiple options can be combined together using the | operator.</para>
  /// </summary>
  [Flags]
  public enum ExportPackageOptions
  {
    /// <summary>
    ///   <para>Default mode. Will not include dependencies or subdirectories nor include Library assets unless specifically included in the asset list.</para>
    /// </summary>
    Default = 0,
    /// <summary>
    ///   <para>The export operation will be run asynchronously and reveal the exported package file in a file browser window after the export is finished.</para>
    /// </summary>
    Interactive = 1,
    /// <summary>
    ///   <para>Will recurse through any subdirectories listed and include all assets inside them.</para>
    /// </summary>
    Recurse = 2,
    /// <summary>
    ///   <para>In addition to the assets paths listed, all dependent assets will be included as well.</para>
    /// </summary>
    IncludeDependencies = 4,
    /// <summary>
    ///   <para>The exported package will include all library assets, ie. the project settings located in the Library folder of the project.</para>
    /// </summary>
    IncludeLibraryAssets = 8,
  }
}

There are five:

  1. Default: the default mode, Include Dependencies is false, not including subdirectories. So this is not what we want.
  2. Interactive: interactive option, a pop-up window, and we directly use the default export compared to nothing different. So this is not what we want.
  3. Recurse: recursive option, meaning that include subdirectories. We use this.
  4. IncludeDependencies: contains dependent, not what we need.
  5. IncludeLibraryAssets: contains ProjectSetting option, nor is it what we want.

Analysis of some, and the third is what we want.

OK, this parameter are determined. Today's sample code below.

using System;
#if UNITY_EDITOR
using UnityEditor;
#endif

using UnityEngine;

namespace QFramework
{
    public class ExportUnityPackage : MonoBehaviour
    {
#if UNITY_EDITOR
        [MenuItem("QFramework/4.导出 UnityPackage")]
        private static void MenuClicked()
        {
            var assetPathName = "Assets/QFramework";
            var fileName = "QFramework_" + DateTime.Now.ToString("yyyyMMdd_hh") + ".unitypackage";
            AssetDatabase.ExportPackage(assetPathName, fileName, ExportPackageOptions.Recurse);
        }
#endif
    }
}

Here we must note, fileName to add .unitypacakge suffix.

This code is to be created in QFramework / 4. Export under UnityPackage / directory.

The results would be: When clicking on the menu bar QFramework / 4 after export UnityPackage, under the project directory (one level Assets directory) will generate our UnityPackage.

We currently export steps:

  1. Click on the menu bar QFramework / 4. Export UnityPackage.

step…

If every step to save five seconds, then 15 seconds to save, if the knowledge accumulated 1000 points, you can earn about 390 dollars. ok, and today it earned.

Although the right a bit exaggerated, but childhood teacher told us a simple truth: "Time is money."

Address reprint please specify: sandals notes: liangxiegame.com

more content

Guess you like

Origin www.cnblogs.com/liangxiegame/p/12544398.html