Scene Build System

Synopsis

Scene Build System is an automatic workflow for you to build Assetbundles for your scenes. 

You can purchase it from http://u3d.as/HiT

1.0 Startup

Scene Build System works with the IEnumerator,so the scripts only work on active MonoBehaviour objects.

We have to tell the tool to set the object which coroutine runs on. We just need to add the following three lines of codes.

You can check for DemoLoader.cs for details.

            DontDestroyOnLoad(this.gameObject); //Coroutine need this gameobject to keep active! 

            //Set the object which coroutine runs on.
            SubBuild_AssetBundleManager.Init(this);


            StartCoroutine(SubBuild_AssetBundleManager.AssetBundleLoop());

 

1.1 Load a cooked scene

We have implement a powerful and easy to use API (SceneLoader.RequestScene(“YourSceneName”,callback=>{})) to allow you load any cooked scene easily.

But you have to get all AssetBunldes dependence infos by calling SubBuild_AssetBundleManager.GetAssetBundleInfos first.

You can check for DemoLoader.cs for details.

            //Get all the dependence info.
            SubBuild_AssetBundleManager.GetAssetBundleInfos(() =>
            {
                StartCoroutine(SceneLoader.RequestScene("DemoSimple", (onLoaded) =>
                {
                    //On loading is finish,the following scripts will run.
                    Debug.Log("Scene is Loaded!");

                }));
            });

 

1.2 Load other objects (Game player for example)

Apart from loading the entire scene, this tool can also load any AssetBundles.

For example ,we want to load a character during the game from an AssetBundle.

We set the AssetBundle label by hand. And we build it with our tool.

Then, we can load it with our tool.

You can check for DemoAssetCharacterLoader.cs for details.

	    //Get AssetBundle Dependences.
            SubBuild_AssetBundleManager.GetAssetBundleInfos(() =>
            {
		//Request Asset
                SubBuild_AssetBundleManager.LoadAssetFromAssetBundle(new AssetRequestTask()
                {
                    currentAssetName = "player.actor",
		    //Loaded CallBack.
                    onAssetLoaded = (myCharacter) =>
                    {
                        GameObject player = Instantiate<GameObject>((GameObject)myCharacter);//Instantiate the object 
                    }
                });
            });

1.3 Serialize scene objects ‘ properties

We often have scripts on the scene prefabs and will change their properties during the developing.

Our tool would ignore these changed properties and use the default value in the previous version.

Now, we support serialize these properties now.

First, you need to import our interface.

using ShanghaiWindy.Interface;

Then, you need to implement the interface.

public class YourClass: MonoBehaviour, ISceneProperty{
}

The following is our example.

You can check for SceneObjectProperty.cs for details.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ShanghaiWindy.Interface;

public class SceneObjectProperty : MonoBehaviour, ISceneProperty
{
    public string TestText;
    public bool TestBool;

    public void OnSerialize(System.Action<Dictionary<string, object>,Transform> onSeralized)
    {
        Dictionary<string, object> data = new Dictionary<string, object>(){
            {"TestText",TestText},
            {"TestBool",TestBool}
        };
		onSeralized(data,transform);
    }
    public void OnDeserialize(Dictionary<string, object> variableData)
    {
		TestText = (string)variableData["TestText"];
		TestBool = (bool)variableData["TestBool"];
    }
}

 

1.4 Load scene assets dynamically.

By calling the following code, you can load any serialized scene assets in the scene.

GetComponent<SceneAssetPrefab>().LoadAsset();

But ,you should load the scene by calling Unity internal method to load the scene.

                UnityEngine.SceneManagement.SceneManager.LoadScene("YourScene_Cooked");

If you call our method to load the scene, you will get all the scene loaded instead of loading dynamically.

And here is an example.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ShanghaiWindy.AssetLoader;

public class DemoDynamicLoading : MonoBehaviour {
    public float distance = 5;

    private SceneAssetPrefab[] allSceneAssets;

	void Start () {
        allSceneAssets = FindObjectsOfType<SceneAssetPrefab>();

        InvokeRepeating("check",1,1);
	}

    void check(){
        for (int i = 0; i < allSceneAssets.Length;i++){
            if (allSceneAssets[i].inLoading || allSceneAssets[i].LoadingDone)
                continue;
            
            if(Vector3.Distance(transform.position,allSceneAssets[i].transform.position)<distance){
                allSceneAssets[i].LoadAsset();
            }
        }
    }
}

 

分类: Unity3D

1 条评论

Scene Build System Manual – ShanghaiWindy's Blog · 2018年1月17日 下午2:16

[…] Check how to load the scene by scripts here. […]

发表评论

电子邮件地址不会被公开。