unity打包的时候会把prefabsunity 脚本打包dll的信息打包么

(来自官网的
Create a project 如何创建一个工程After you have installed the package, create a new project in Unity.在Unity下创建一个新的工程Select vuforia-unity-android-ios-xx-yy-zz.unitypackage from the list of Import the following packages.导入vuforia-unity-android-ios-xx-yy-zz.unitypackage到新的工程中.(ps)
OR 或者Right-click in the Project view of an open project and choose Import Package…Browse to the vuforia-unity-android-ios-xx-yy-zz.unitypackage you just installed and import it or double-click on the downloaded package. When creating the Unity project, avoid using spaces in the name if targeting iOS because this causes problems later when you build with Xcode. Note that by double-clicking on a package, you can selectively import parts of that package.当创建的工程目标平台是iOS时,工程名中不要包含空格字符,因为之后工程转到Xcode中会出问题。Note: If you do not see the Vuforia package in the list, go back to Step 1 and manually install the packages.Next, you need to add a Device Database to your project. You can do this in two ways:接下来,你需要给你的工程添加一个Device Database。你有两个方法做到这点:Create a target on the Target Manager用线上的Target Manager来创建一个目标
OR 或Use existing targets from other projects使用其它工程中现有的目标To use the Target Manager method, see the Target Manager to create and download a package. 使用Target Manager的方式,来创建并下载一个package。详见Target Manager。Double-click the downloaded package, or right-click on Unity Project for “Import Package“ and "Custom Package.”Select the downloaded package.Click Import to import the target Device Database.2--4点就说:将包含创建好的并已经下载下来的包含目标的包,导入你的工程。If you are copying the Device Database files from another project, be sure to copy any files located in the Editor/QCAR/ImageTargetTextures folder. These will be used to texture the target plane in the Unity editor.如果你用从其它工程复制Device Database文件方式的话,请确保复制Editor/QCAR/ImageTargetTextures文件夹下所有的文件。You should now see the following folder structure inside Unity:这时,你在Unity中应该能看到如下图显示一个目录结构:Following is a summary of the folder contents:下面总结了文件夹的内容:Editor - Contains the scripts required to interact dynamically with Target data in the Unity editor包含一些在unity编辑器中,与目标数据动态交互的,脚本。Plugins - Contains Java and native binaries that integrate the Vuforia AR SDK with the Unity Android or Unity iOS application包含Java和本地二进制文件,用于整合Vuforia AR SDK与Unity Android或Unity OS应用程序。Qualcomm Augmented Reality - Contains the prefabs and scripts required to bring augmented reality to your Unity application包含一些prefabs和一些脚本。这些被用来将增强现实到Unity应用程序上。Streaming Assets - Contains the Device Database configuration XML and DAT files downloaded from the online Target Manager包一些从线上Target Manager中下载下来的xml和dat格式的 Device Database的配置文件Add AR assets and prefabs to scene添加AR资源和预设到场景中去Now that you have imported the Vuforia AR Extension for Unity, you can easily adapt your project to use augmented reality.Expand the Qualcomm Augmented Reality folder, and expand the Prefabs folder.展开Qualcomm Augmented Reality文件夹,接着展开其中的Prefabs文件夹。Delete the “Main Camera” in your current scene hierarchy, and drag an instance of the ARCamera prefab into your scene. The ARCamera is responsible for rendering the camera image in the background and manipulating scene objects to react to tracking data.删除场景中的Main Camera对象,并拖曳一个ARCamera预设到场景中。ARCamera负责渲染摄像头图像在背景上和操作场景对象对跟踪数据做出反应。With the ARCamera in place and the target assets available in the StreamingAssets/QCAR folder, run the application on a supported device, and see the live video in the background.以上几步都做好了的话,就要可运行程序了,背景就个视频直播了。Inspector view of the ARCamera 上图是一个[b]ARCamera的检视器的视图[/b]Drag an instance of the ImageTarget prefab into your scene. This prefab represents a single instance of an Image Target object.拖拽一个 ImageTarget预设到你的场景中Select the ImageTarget object in your scene, and look at the Inspector. There should be an Image Target Behaviour attached, with a property named Data Set. This property contains a drop-down list of all available Data Sets for this project. When a Data Set is selected, the Image Target property drop-down is filled with a list of the targets available in that Data Set. ImageTarget对象有一个Target Behaviour组件,其它有两个属性 Data Sets和Image Target。Select the Data Set and Image Target from your StreamingAssets/QCAR project. In this example, we choose "StonesAndChips".
(It is automatically populated from the Device Database XML file that is downloaded from the online Target Manager). The Unity sample apps come with several Image Targets . To use them, copy them from the ImageTargets sample, or create your own at the Target Manager section of this site.Inspector view of the ImageTargetNote: When you added the Image Target object to your scene, a gray plane object appeared. This object is a placeholder for actual Image Targets. In the inspector view of the Image Target there is a pop-up list called Image Target. From this list, you can choose any Image Target that has been defined in one of theStreamingAssets/QCAR datasets so that the Image Target object in your scene adopts the size and shape from the Image Target it represents. The object is also textured with the same image from which the Image Target was created.Add 3D objects to scene and attach to trackablesNow you can bind 3D content to your Image Target.As a test, create a simple Cube object (GameObject & Create Other & Cube).Add the cube as a child of the ImageTarget object by selecting it in the Hierarchy list and dragging it onto the ImageTarget item.Move the cube in the scene until it is centered on the Image Target. You can also add a Directional Light to the scene (GameObject & Create Other & Directional Light).TrackableEventHandlerThe Default Trackable Event Handler (DefaultTrackableEventHandler) is a script component of the Image Target that causes the cube you just drew to appear or disappear automatically – an automatic reaction to the appearance of the target in the video.You can override this default behavior – one could also imagine playing a fade-out animation, showing an info screen or playing a sound for example. For a more detailed description of the ITrackableEventHandler interface, please see
'Responding to Tracking Events' in the section.Adding Dataset load to cameraThe Vuforia SDK has the ability to use multiple active Device Databases simultaneously. To demonstrate this capability, you can borrow the StonesAndChips and Tarmac Device Databases from the ImageTargets sample and configure both to load and activate in the ARCamera’s Inspector panel. This allows you to use targets from both Device Databases at the same time in your Unity scene.Deploy the applicationThe next step is to deploy your application to a supported device.Android deployment processUnity provides a number of settings when building for Android devices – select from the menu (File & Build Settings… & Player Settings…) to see the current settings. Also, choose your platform now – Android or iOS.Click
Resolution and Presentation to select the required Default Orientation. Note: the Vuforia AR Extension now supports Auto Rotation.Click
Icon to set your application icon.Click Other Settings.
Set the Minimum API Level to Android 2.3 'Gingerbread' (API level 9) or higher. Set Bundle Identifier to a valid name (e.g., com.mycompany.firstARapp).Save your scene (File & Save Scene). Open the build menu (File & Build Settings…). Make sure that your scene is part of Scenes in Build. If not, do one of the following:Use Add Current to add the currently active scene.Drag and drop your saved AR scene from the project view into the Window.You can now build the application. Attach your Android device and then click Build And Run to initialize the deployment process.iOS deployment processUnity provides a number of settings when building for iOS devices (File & Build Settings & Platform & iOS icon).Before building, select the required Default Orientation.
Note:The Vuforia AR Extension now supportsAuto Rotation.
Make sure that Target Platform is not set to armv6 (OpenGL ES 1.1). This version of the extension supports only OpenGL-ES 2.0. Make sure that Bundle Identifier is set to the correct value for your iOS developer profile.Now you can choose to build the application. First, save your scene (File & Save Scene).Open the build menu (File & Build Settings…).Make sure that your scene is part of Scenes in Build. If this is not the case:a. Use Add Current to add the currently active scene. ORb. Drag and drop your saved AR scene from the project view into the Window.Press Build And Run to initialize the deployment process.When building and running apps for iOS, Unity generates an Xcode project. It launches Xcode and loads this project. The Vuforia AR Extension includes a PostProcessBuildPlayer script that performs the task of integrating the Vuforia library into the generated Xcode project. This is run automatically when you select Build from within Unity. Be aware that if you manually change the generated Xcode project, you may need to update thePostProcessBuildPlayer script to avoid overwriting your changes.The generated Xcode project includes a file called AppController.mm. There are Unity provided options in this file to tailor the performance of the app for your own purpose. The PostProcessBuildPlayer script sets theTHREAD_BASED_LOOP as a default because it gives the best visible performance with the samples provided alongside the Vuforia AR Extension. Consider changing these options to whatever gives the best performance for your own application.Created AR sceneUsing the applicationYou should have a printout of the appropriate Image Target in front of you. If you are working with a target from one of the sample apps, the PDFs are located at Editor/QCAR/ForPrint/*.pdf. Otherwise, print out the image that you uploaded to the Target Manager and make sure that the aspect ratio doesn’t change. When you look at the target using the device camera, you should see your cube object bound to the target. Congratulations, you have successfully augmented reality!Running in the editorThe Vuforia Unity Extension supports the Play Mode feature, which provides AR application emulation through the Unity Pro Editor using a webcam. Configure this feature through the Web Cam Behaviour component of the ARCamera in the Inspector.To use Play Mode for Vuforia in Unity Pro, simply select the attached, or built-in, webcam that you want to use from the Camera Device menu, and activate Play Mode using the Play button at the top of the Editor UI.You can also use the standard Unity Play Mode with non-Pro Unity versions and by set ‘Don’t use for Play Mode’ in the Web Cam Behaviour component.To use standard Play Mode, adjust the transform of the ARCamera object to get your entire scene in view, and then run the application in the Unity editor. There is no live camera image or tracking in standard Play M instead, all Targets are assumed to be visible. This allows you to test the non-AR components of your application, such as scripts and animations, without having to deploy to the device each time.【代码片-1】 Unity5打包assetbundle
标签:assetbundle&&&&打包&&&&unity&&&&&&&&
using System.Collections.G
using System.IO;
using UnityE
using UnityE
public class AssetBundleExporterGUI
private static readonly string BUNDLE_PATH_ART = System.Environment.CurrentDirectory +
&/../../../../../starts-art/Assetbundles/&;
private static readonly string BUNDLE_PATH_GAME = System.Environment.CurrentDirectory +
&/../../../../../starts-game-assets/trunk/assetbundles/&;
private const string IOS_BUNDLE_PATH = &ios/&;
private const string ANDROID_BUNDLE_PATH = &android/&;
private const string WEBPLAYER_BUNDLE_PATH = &webplayer/&;
private const string ASSETBUNDLE_EXT = &.assetbundle&;
private const string PREFAB_PATH = &Assets/_prefabs/{0}.prefab&;
// This is our one-and-only dependency bundle. Any downloaded bundle can reference this,
// which means any assets within it won't be duplicated in any dependent bundle.
private static string PREFAB_EXT = &.prefab&;
private static string SHARED_PREFAB = &gui_shared&;
private static string SHARED_PREFAB_PATH = &Assets/_prefabs/& + SHARED_PREFAB;
private const string SHARED_BUNDLE = &gui_shared&;
// These are the bundles that do not have any dependency. These bundles are intended to be
// loaded on-demand on the client because they can contain textures that we do not want to
// have always loaded in memory.
// IMPORTANT: None of these bundles should be in GUI_PRELOADED_SCREENS in AssetConstants.cs
// located in the starts client codebase. If you are adding a new independent bundle, please
// ensure this or communicate this to the dev implementing it.
// Bundles come in two categories:
1. always-loaded, does not contain its own textures, depends on gui_shared
2. loaded on-demand, does not depend on gui_shared
// All of the following are true:
&If a bundle is always loaded, then it's dependent on gui_shared&
&If a bundle is not always loaded, then it's not dependent on gui_shared&
&If a bundle is dependent on gui_shared, then it's always loaded&
&If a bundle is not dependent on gui_shared, then it's not always loaded&
// We have 1 exception:
gui_hud depends on gui_shared and also has a few textures
private static readonly string[] independentBundles = new string[]
// The shared bundle doesn't depend on itself.
SHARED_BUNDLE,
&gui_xxxxxxxxx&,
private const string HUD_BUNDLE = &gui_hud&;
private static string selectedP
[MenuItem(&Assets/StaRTS/Build Selected AssetBundle(s) - Android&, false, 1)]
public static void ExportSelectionAndroid()
ExportSelectionTarget(BuildTarget.Android);
[MenuItem(&Assets/StaRTS/Build Selected AssetBundle(s) - iOS&, false, 2)]
public static void ExportSelectionIOS()
ExportSelectionTarget(BuildTarget.iOS);
[MenuItem(&Assets/StaRTS/Build Selected AssetBundle(s) - WebPlayer&, false, 3)]
public static void ExportSelectionWebPlayer()
ExportSelectionTarget(BuildTarget.WebPlayer);
// Useful for when you only want to export to a single target and no others.
private static void ExportSelectionTarget(BuildTarget target)
if (!Start())
/*UnityEngine.Object[]
List&string&
if (!GetSelectedPrefabs(out prefabs, out dependencies))
UnityEngine.Object[] prefabs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
if (!ExportPrefabs(prefabs, target))
Success();
// Useful for when you want all targets.
It makes sure to order the targets smartly.
[MenuItem(&Assets/StaRTS/Build Selected AssetBundle(s) - All Platforms&, false, 4)]
public static void ExportSelectionAll()
if (!Start())
/*UnityEngine.Object[]
List&string&
if (!GetSelectedPrefabs(out prefabs, out dependencies))
List&BuildTarget& targets = new List&BuildTarget&();
targets.Add(BuildTarget.Android);
targets.Add(BuildTarget.iOS);
targets.Add(BuildTarget.WebPlayer);
// Ensure that the current build target is the first target in the
// list to minimize the amount of asset re-importing that is done.
// Whichever was used last will be used first in the subsequent export
for (int i = 0; i & targets.C i++)
if (targets[i] == EditorUserBuildSettings.activeBuildTarget)
if (i != 0)
targets.Insert(0, targets[i]);
targets.RemoveAt(i + 1);
UnityEngine.Object[] prefabs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
for (int i = 0; i & targets.C i++)
if (!ExportPrefabs(prefabs, targets[i]))
Success();
static private bool GetSelectedPrefabs(out UnityEngine.Object[] prefabs, out List&string& dependencies)
dependencies = new List&string&();
// Begin() already ensured this was non-empty.
UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
// Store prefab objects in a new array for multiple target
// exports. When the editor re-imports assets for a new target,
// the selection is lost.
prefabs = new UnityEngine.Object[selection.Length];
for (int i = 0; i & selection.L i++)
string bundleName = selection[i].
List&string& deps = new List&string&();
deps.Add(SHARED_BUNDLE);
for (int j = 0, jlen = independentBundles.L j & j++)
if (bundleName == independentBundles[j])
deps.Clear();
if (i == 0)
dependencies.AddRange(deps);
bool matches = deps.Count == dependencies.C
if (matches)
for (int j = 0; j & deps.C j++)
if (dependencies[j].IndexOf(deps[j]) & 0)
if (!matches)
// We require that all bundles to be built have the same dependencies.
Error(&The selected bundles don't have the same dependencies.\n& +
&Try building self-contained bundles separately & +
&from those that depend on the shared bundle.&);
prefabs[i] = selection[i];
private static bool ExportPrefabs(
UnityEngine.Object[] prefabs, BuildTarget target)
Debug.Log(&Exporting bundles for & + target);
EditorUserBuildSettings.SwitchActiveBuildTarget(target);
SetPathAndExportBundle(prefabs, target);
// Returns true if the given prefab has no textures of its own,
// outside of the given dependency prefab.
// If returns false, assetNames will be set to a newline-separated list of offending assets.
private static bool IsValidDependency(UnityEngine.Object prefab, UnityEngine.Object dependencyPrefab,
out string assetNames)
bool valid =
assetNames =
string[] prefabPaths = new string[] { string.Format(PREFAB_PATH, prefab.name) };
string[] prefabAssets = AssetDatabase.GetDependencies(prefabPaths);
string[] dependencyPaths = new string[]
{ string.Format(PREFAB_PATH, dependencyPrefab.name) };
string[] dependencyAssets = AssetDatabase.GetDependencies(dependencyPaths);
// If everything in the prefab is also in the dependency bundle, then none of it will
// actually get bundled with the prefab, and that's the goal.
for (int i = 0, iCount = prefabAssets.L i & iC i++)
string assetName = prefabAssets[i];
// These are the legal asset types.
Anything else is considered illegal to have in an
// depdendent bundle that isn't also inside the depdendency bundle.
// NOTE: Mainly we want to check .png, .ttf, .prefab, .shader, but rather than only
// checking those, it's safer to do the reverse: allow known legal assets to be skipped.
// That way, any new type of asset that we find will not be skipped and either it's a
// proper dependency, or it'll cause the error to pop, and we'll consider what to do
// about it.
Either fix the asset, or add the new extension to our &legal& list.
if (assetName == prefabPaths[0] || // Ignore the root object.
assetName.EndsWith(&.cs&) ||
// Scripts only have references bundled.
assetName.EndsWith(&.mat&) ||
// Materials are lightweight, they reference shaders
// and textures, which themselves are prevented.
assetName.EndsWith(&.controller&) ||
assetName.EndsWith(&.anim&) ||
assetName.EndsWith(&.fbx&))
bool found =
for (int j = 0, jCount = dependencyAssets.L j & jC j++)
if (assetName == dependencyAssets[j])
if (!found)
assetNames = assetNames == null ? assetName : assetNames + &\n& + assetN
private static bool Start()
UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
if (selection.Length & 1)
Debug.Log(&No prefabs were selected to bundle!&);
return AskForExportPath();
private static void Success()
EditorUtility.DisplayDialog(&Export complete!&, string.Empty , &OK&, string.Empty );
private static void Error(string error)
Debug.LogError(error);
EditorUtility.DisplayDialog(&Error&, error, &OK&, string.Empty);
private static bool AskForExportPath()
int option = EditorUtility.DisplayDialogComplex(
&Where would you like the bundles saved?&,
&Choose starts-art to export the bundle for an engineer to grab & +
&for integration. Choose starts-game-assets to test the bundle & +
&locally and potentially commit to production.&,
&starts-art&,
&starts-game-assets&);
string baseDirectory = string.E
switch (option)
baseDirectory = BUNDLE_PATH_ART;
baseDirectory = EditorUtility.OpenFolderPanel(
&Select the base export directory&, string.Empty , string.Empty) + &/&;
baseDirectory = BUNDLE_PATH_GAME;
Debug.Log(&Invalid selection for export.&); // Shouldn't be possible.
// Verify path exists
if (baseDirectory == string.Empty || !Directory.Exists(baseDirectory))
Error(&Base directory does not exist: & + baseDirectory);
selectedPath = baseD
// Create subdirectories if they do not exist
if (!Directory.Exists(baseDirectory + ANDROID_BUNDLE_PATH))
Directory.CreateDirectory(baseDirectory + ANDROID_BUNDLE_PATH);
if (!Directory.Exists(baseDirectory + IOS_BUNDLE_PATH))
Directory.CreateDirectory(baseDirectory + IOS_BUNDLE_PATH);
if (!Directory.Exists(baseDirectory + WEBPLAYER_BUNDLE_PATH))
Directory.CreateDirectory(baseDirectory + WEBPLAYER_BUNDLE_PATH);
private static void SetPathAndExportBundle(UnityEngine.Object[] prefabs, BuildTarget target)
string path = selectedP
switch (target)
case BuildTarget.iOS:
path += IOS_BUNDLE_PATH;
case BuildTarget.Android:
path += ANDROID_BUNDLE_PATH;
case BuildTarget.WebPlayer:
path += WEBPLAYER_BUNDLE_PATH;
ExportBundle(prefabs, path, target, false);
static private bool ExportBundle(UnityEngine.Object[] prefab, string path, BuildTarget target, bool combined)
string directoryPath = Path.GetDirectoryName(path);
if (!Directory.Exists(directoryPath))
Directory.CreateDirectory(directoryPath);
AssetBundleBuild[] buildM
List&UnityEngine.Object& independentBundles = new List&UnityEngine.Object&();
string prefabP
if (combined)
buildMap = new AssetBundleBuild[2];
buildMap[0].assetBundleName = SHARED_PREFAB + ASSETBUNDLE_EXT;
buildMap[0].assetNames = AssetDatabase.GetDependencies(new string[]{SHARED_PREFAB_PATH + PREFAB_EXT});
buildMap[1].assetBundleName = prefab[0].name + ASSETBUNDLE_EXT;
for (int i = 0; i & prefab.L i++)
prefabPath = AssetDatabase.GetAssetPath(prefab[i]);
buildMap[1].assetNames = new string[]{prefabPath};
buildMap = new AssetBundleBuild[prefab.Length + 1];
buildMap[0].assetBundleName = SHARED_PREFAB + ASSETBUNDLE_EXT;
buildMap[0].assetNames = AssetDatabase.GetDependencies(new string[] {SHARED_PREFAB_PATH + PREFAB_EXT});
for (int i = 0; i & prefab.L i++)
prefabPath = AssetDatabase.GetAssetPath(prefab[i]);
if (IsIndependentBundle(prefab[i].name))
independentBundles.Add(prefab[i]);
buildMap[i + 1].assetBundleName = prefab[i].name + ASSETBUNDLE_EXT;
buildMap[i + 1].assetNames = new string[]{prefabPath};
BuildPipeline.BuildAssetBundles(directoryPath, buildMap, BuildAssetBundleOptions.ForceRebuildAssetBundle, target);
if (independentBundles.Count & 0)
buildMap = new AssetBundleBuild[independentBundles.Count];
for (int i = 0; i & independentBundles.C i++)
prefabPath = AssetDatabase.GetAssetPath(independentBundles[i]);
buildMap[i].assetBundleName = independentBundles[i].name + ASSETBUNDLE_EXT;
buildMap[i].assetNames = new string[]{prefabPath};
BuildPipeline.BuildAssetBundles(directoryPath, buildMap, BuildAssetBundleOptions.ForceRebuildAssetBundle, target);
static private bool IsIndependentBundle(string prefabName)
int index = Array.FindIndex(independentBundles, item =& item.Equals(prefabName));
if (index & 0)
我要留言技术领域:
取消收藏确定要取消收藏吗?
删除图谱提示你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?
删除节点提示无法删除该知识节点,因该节点下仍保存有相关知识内容!
删除节点提示你确定要删除该知识节点吗?}

我要回帖

更多关于 unity 打包脚本 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信