二维码 501
发表时间:2018-01-31 23:16









   // rotation scripting mistake #1

   // the mistake here is that we are modifying the x value of a quaternion

   // this value does not represent an angle, and will not produce desired results

   void Update () {

       var rot = transform.rotation;

       rot.x += Time.deltaTime * 10;

       transform.rotation = rot;



  // rotation scripting mistake #2

   // the mistake here is that we are reading, modifying then writing the Euler

   // values from a quaternion. Because these values calculated from a Quaternion,

   // each new rotation may return very different Euler angles, which may suffer from gimbal lock.

   void Update () {

       var angles = transform.rotation.eulerAngles;

       angles.x += Time.deltaTime * 10;

       transform.rotation = Quaternion.Euler(angles);



// rotation scripting with Euler angles correctly.

   // here we store our Euler angle in a class variable, and only use it to

   // apply it as a Euler angle, but we never rely on reading the Euler back.

   float x;

   void Update () {

       x += Time.deltaTime * 10;

       transform.rotation = Quaternion.Euler(x,0,0);




windows:C:\Program Files\Unity\Editor\Data\Managed



   IEnumerator LoadFromMemoryAsync(string path)


       AssetBundleCreateRequest createRequest = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));

       yield return createRequest;

       AssetBundle bundle = createRequest.assetBundle;

       var prefab = bundle.LoadAsset.<GameObject>("MyObject");



这种方式是异步加载一组包含AssetBundle 数据的byte数组到内存中,可以添加CRC校验,如果使用了LZMA压缩,会自动解压


public class LoadFromFileExample extends MonoBehaviour {

   function Start() {

       var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle"));

       if (myLoadedAssetBundle == null) {

           Debug.Log("Failed to load AssetBundle!");



       var prefab = myLoadedAssetBundle.LoadAsset.<GameObject>("MyObject");




Note: On Android devices with Unity 5.3 or older, this API will fail when trying to load AssetBundles from the Streaming Assets path. This is because the contents of that path will reside inside a compressed .jar file. Unity 5.4 and newer can use this API call with Streaming Assets just fine


using UnityEngine;

using System.Collections;

public class LoadFromCacheOrDownloadExample : MonoBehaviour


   IEnumerator Start ()


           while (!Caching.ready)

                   yield return null;

       var www = WWW.LoadFromCacheOrDownload("http://myserver.com/myassetBundle", 5);

       yield return www;




           yield return;


       var myLoadedAssetBundle = www.assetBundle;

       var asset = myLoadedAssetBundle.mainAsset;




The UnityWebRequest has a specific API call to deal with AssetBundles. To begin, you’ll need to create your web request using UnityWebRequest.GetAssetBundle. After returning the request, pass the request object into DownloadHandlerAssetBundle.GetContent(UnityWebRequest). This GetContent call will return your AssetBundle object.

You can also use the assetBundle property on the DownloadHandlerAssetBundle class after downloading the bundle to load the AssetBundle with the efficiency of AssetBundle.LoadFromFile.

Here’s an example of how to load an AssetBundle that contains two GameObjects and Instantiate them. To begin this process, we’d just need to call StartCoroutine(InstantiateObject());

IEnumerator InstantiateObject()


       string uri = "file:///" + Application.dataPath + "/AssetBundles/" + assetBundleName;        UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 0);

       yield return request.Send();

       AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);

       GameObject cube = bundle.LoadAsset<GameObject>("Cube");

       GameObject sprite = bundle.LoadAsset<GameObject>("Sprite");





This information is available in the Editor Log just after you have performed the build. Go to the Console window (menu: Window < Console), click the small drop-down panel in the top right, and select Open Editor Log.


try to reduce the physical size (in pixels) of the Texture images. To do this without modifying the actual source content, select the Texture in the Project view, and in the Inspector window reduce the Max Size. To see how this looks in-game, zoom in on a GameObject that uses the Texture, then adjust the Max Size until it starts looking worse in the Scene view. Changing the maximum Texture size does not affect your Texture Asset, just its resolution in the game.

By default, Unity compresses all Textures when importing. For faster workflow in the Editor, go to Unity < Preferences and untick the checkbox for Compress Assets on Import. All Textures are compressed in the build, regardless of this setting.