LoadAll() public method

public LoadAll ( ) : Object[]
return Object[]
コード例 #1
2
ファイル: LuaHelper.cs プロジェクト: coder-han/hugula
 /// <summary>
 /// 刷新shader
 /// </summary>
 /// <param name="assetBundle"></param>
 public static void RefreshShader(AssetBundle assetBundle)
 {
     #if UNITY_5
     UnityEngine.Material[] materials = assetBundle.LoadAllAssets<Material>();
     #else
     UnityEngine.Object[] materials = assetBundle.LoadAll(typeof(Material));  //LoadAll<Material>();
     #endif
     foreach (UnityEngine.Object m in materials)
     {
         Material mat = m as Material;
         string shaderName = mat.shader.name;
         Shader newShader = Shader.Find(shaderName);
         if (newShader != null)
         {
             mat.shader = newShader;
         }
         else
         {
             Debug.LogWarning("unable to refresh shader: " + shaderName + " in material " + m.name);
         }
     }
 }
コード例 #2
0
    static int LoadAll(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle)))
            {
                UnityEngine.AssetBundle obj = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1);
                UnityEngine.Object[]    o   = obj.LoadAll();
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.AssetBundle), typeof(System.Type)))
            {
                UnityEngine.AssetBundle obj  = (UnityEngine.AssetBundle)ToLua.ToObject(L, 1);
                System.Type             arg0 = (System.Type)ToLua.ToObject(L, 2);
                UnityEngine.Object[]    o    = obj.LoadAll(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AssetBundle.LoadAll"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #3
0
 static public int LoadAll(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             var ret = self.LoadAll();
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.Type             a1;
             checkType(l, 2, out a1);
             var ret = self.LoadAll(a1);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #4
0
 static public int LoadAll(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(System.Type)))
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             System.Type             a1;
             checkType(l, 2, out a1);
             UnityEngine.Object[] ret = self.LoadAll(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 2))
         {
             UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
             UnityEngine.Object[]    ret  = self.LoadAll();
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #5
0
	// Use this for initialization
	void Start () 
	{
		if( true == m_LoadFromLocal )
		{
			m_Unity3DURL = m_LocalURLTag + m_LocalDirectory + m_LocalAssetBundleName ;
		}
		else
		{
			// use m_Unity3DURL as parameter
		}
		Debug.Log( m_Unity3DURL ) ;
	
		if( 0 == m_Unity3DURL.Length )
			return ;

		
		WWW download = WWW.LoadFromCacheOrDownload( m_Unity3DURL , 0 ) ;
		if( null == download )
		{
			Debug.LogError( "null == download" ) ;
		}
		else
		{
			
			// Try mark this line
			m_AssetBundle = download.assetBundle;
			
			if( null == m_AssetBundle )
			{
				Debug.Log( "null == assetBundle" ) ;
			}
			else
			{
				Debug.Log( "null != assetBundle" ) ;
				Object[] objs = m_AssetBundle.LoadAll() ;
				Debug.Log( "objNumbers" + objs.Length ) ;
				foreach( Object obj in objs )
				{
					Debug.Log( obj.name ) ;
				}
			}
		}
	}
コード例 #6
0
ファイル: FileHelper.cs プロジェクト: QinFangbi/hugula
    /// <summary>
    /// 
    /// </summary>
    /// <param name="ab"></param>
    /// <param name="luaFn"></param>
    public static void UnpackConfigAssetBundleFn(AssetBundle ab, LuaFunction luaFn)
    {
        callBackFn = luaFn;
#if UNITY_5
        UnityEngine.Object[] all = ab.LoadAllAssets();
#else
        UnityEngine.Object[] all = ab.LoadAll();
#endif
        foreach (UnityEngine.Object i in all)
        {
            if (i is TextAsset)
            {
                TextAsset a = (TextAsset)i;
                if (callBackFn != null)
                    callBackFn.call(a.name, a.text);
            }
        }
    }     
コード例 #7
0
    public override void OnXGUI()
    {
        //TODO List
        if(Selection.objects != null && Selection.objects.Length > 0){
            selectedObject = Selection.objects[0];
        }

        if(CreateSpaceButton("Packing Selected Objects")){
            Object[] objects = Selection.objects;

            string path = EditorUtility.SaveFilePanel("Create A Bundle", AssetDatabase.GetAssetPath(objects[0]), "newbundle.assetbundle", "assetbundle");
            if (path == "")
                return;

            CreateXMLWithDependencies(objects, path);

            BuildPipeline.BuildAssetBundle(
                null, objects,
                path ,
                BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle
                | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.Android);
        }

        if(CreateSpaceButton("GetObject")){
            string path = EditorUtility.OpenFilePanel("Open A Bundle", Application.streamingAssetsPath, "" );
            if (path == "")
                return;
            _bundlepath = "file://" + path;
            LoadingConfig = true;
            asset = null;
        //			AssetDatabase.Refresh();
            if(currBundle != null){
                currBundle.Unload(true);
            }
        }

        if(CreateSpaceButton("Clean Cache")){
            currentBundleObjects = null;
            Caching.CleanCache();
        }

        if( LoadingConfig ){
            XLogger.Log("start loading");
            if( null == asset )
                asset = new WWW(_bundlepath);
            LoadingConfig = false;
        }
        //		Logger.Log(string.Format("asset == null is {0}" , asset == null));
        if(asset != null ){
        //			Logger.Log("asset.isDone is " + asset.isDone);
        //			if(asset.isDone){

            XLogger.Log("end loading");
            currBundle = asset.assetBundle;
            if(currBundle == null){
                CreateNotification("Selected the asset bundle 's format is error.");
                LoadingConfig = false;
                asset = null;
                return;
            }
            #if UNITY_5_0
            currentBundleObjects = currBundle.LoadAllAssets();
            #endif
            #if UNITY_4_6
            currentBundleObjects = currBundle.LoadAll();
            #endif
            LoadingConfig = false;
            asset = null;
        //			}
        }

        if( null != currentBundleObjects ){
            for (int pos = 0; pos < currentBundleObjects.Length; pos++) {
                CreateObjectField(currentBundleObjects[pos].GetType().ToString(),currentBundleObjects[pos]);
            }
        }

        if(CreateSpaceButton("Add A AssetBundle")){
            allAssets.Add(new AssetBundleModel());
        }
        if(CreateSpaceButton("Clean All AssetBundle")){
            allAssets.Clear();
        }
        if(CreateSpaceButton("Collect") && allAssets.Count > 0){
            List<AssetBundleModel> AllChilds = new List<AssetBundleModel>();
            sortAssets.Clear();

            BundlePath = EditorUtility.SaveFolderPanel("Save Bundles", Application.streamingAssetsPath, "" );
            if(BundlePath == null){
                return;
            }
            BundlePath += "/";
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement root = xmlDoc.CreateElement("root");
            for(int pos = 0; pos < allAssets.Count; pos++){
                if(allAssets[pos].ParentName.Equals("")){
                    sortAssets.Add(allAssets[pos].ModelName, allAssets[pos]);
                    XmlElement child = xmlDoc.CreateElement(allAssets[pos].ModelName);
                    root.AppendChild(child);
                }else{
                    AllChilds.Add(allAssets[pos]);
                }
        //				allAssets.Remove(allAssets[pos]);
            }
            for(int pos = 0; pos < AllChilds.Count; pos++){
                sortAssets[AllChilds[pos].ParentName].Childs.Add(AllChilds[pos]);
                XmlElement child = xmlDoc.CreateElement(AllChilds[pos].ModelName);
                root.SelectSingleNode(AllChilds[pos].ParentName).AppendChild(child);
        //				allAssets.Remove(allAssets[pos]);
            }
            xmlDoc.AppendChild(root);
            xmlDoc.Save(BundlePath + "bundle.xml");
            foreach(var bundle in sortAssets){
                bundle.Value.PackingSelf();
            }
        //			allAssets.Clear();
            AssetDatabase.Refresh();
            CreateNotification("Create asset bundle success!");
        }

        for(int pos = 0; pos < allAssets.Count; pos++){
            AssetBundleModel Item = allAssets[pos];
            BeginHorizontal();
            Item.ModelName = CreateStringField("Name", allAssets[pos].ModelName);
            Item.ParentName = CreateStringField("Dependencies", allAssets[pos].ParentName);
            if( CreateSpaceButton("Add Asset") && null != selectedObject ){
                Item.Assets.AddRange(Selection.objects);
            }
            if( CreateSpaceButton("Remove Bundle") ){
                allAssets.RemoveAt(pos);
            }
            EndHorizontal();
            CreateSpaceBox();

            for(int idx = 0; idx < Item.Assets.Count; idx++){
                BeginHorizontal();
                CreateObjectField("child_" + idx, Item.Assets[idx]);
                if(CreateSpaceButton("Remove")){
                    Item.Assets.RemoveAt(idx);
                }
                EndHorizontal();
            }

            CreateSpaceBox();
        }
    }
コード例 #8
0
ファイル: AssetManager.cs プロジェクト: GHunique/MyU3dFrame
 public static void DefaultDownloadedCB(string name, AssetBundle bundle, Object obj, System.Object userData)
 {
     if (bundle != null)
         bundle.LoadAll();
 }
コード例 #9
0
    void Update()
    {
        if (null != m_www &&
            m_www.isDone)
        {
            if (null == m_www.assetBundle)
            {
                Debug.LogError("!!Asset bundle was not found");
                m_www = null;
                return;
            }

            m_assetBundle =
                m_www.assetBundle;

            m_www = null;

            Debug.Log("**Loading asset bundle assets");

            m_assetBundleObjects =
                m_assetBundle.LoadAll();

            m_assetBundleLoaded = true;
        }

        if (null != m_assetBundleObjects)
        {
            if ((m_objectIndex + 1) < m_assetBundleObjects.Length)
            {
                ++m_objectIndex;

                Object obj =
                    m_assetBundleObjects[m_objectIndex];

                InspectAndSaveObject(obj);
            }

            else if ((m_objectIndexPass2 + 1) < m_copiedGameObjects.Keys.Count)
            {
                int index = -1;
                foreach (string key in m_copiedGameObjects.Keys)
                {
                    ++index;

                    if (index < (m_objectIndexPass2+1))
                    {
                        continue;
                    }

                    ++m_objectIndexPass2;

                    if (string.IsNullOrEmpty(key))
                    {
                        Debug.LogError("**!!Empty object name skipping...");
                        continue;
                    }

                    Object obj =
                        (Object)m_copiedGameObjects[key];

                    if (null == obj)
                    {
                        Debug.LogError("**!!Null object skipping...");
                        continue;
                    }

                    if (obj.GetType() == typeof(Material))
                    {
                        Debug.Log("**Detected Material...");
                        Material material = obj as Material;

                        if (null == material)
                        {
                            Debug.Log("**Material reference is null");
                            continue;
                        }

                        if (null == material.shader)
                        {
                            Debug.Log("**Material shader reference is null");
                            continue;
                        }

                        Debug.Log(string.Format("**Need to fix shader reference to: {0}...", material.shader.name));
                        string findObject =
                            string.Format("{0}_{1}", GetShortType(material.shader), material.shader.name);
                        if (!m_copiedGameObjects.ContainsKey(findObject))
                        {
                            Debug.LogError(string.Format("!!Could not find referenced shader: {0}...", findObject));
                            continue;
                        }

                        Shader shader = m_copiedGameObjects[findObject] as Shader;

                        if (null == shader)
                        {
                            Debug.Log("**Shader is blank");
                            continue;
                        }

                        Debug.Log("**Fixing Shader Reference...");
                        material.shader = shader;

                        CopyTextures(material);
                    }
                }
            }

            else if ((m_objectIndexPass2 + 1) == m_copiedGameObjects.Keys.Count)
            {
                ++m_objectIndexPass2;

                Debug.Log("**Inspecting main asset...");

                Object obj =
                    m_assetBundle.mainAsset;

                string extension = "prefab";

                string assetPath =
                    string.Format("Assets/SavedAssets/{0}.{1}", obj.name, extension);

                Debug.Log("**Creating empty prefab");

                Object prefab =
                    EditorUtility.CreateEmptyPrefab(assetPath);

                Debug.Log(string.Format("**Replacing prefab with gameObject: {0}", obj.name));

                EditorUtility.ReplacePrefab((GameObject)obj, prefab, ReplacePrefabOptions.Default);

                Debug.Log(string.Format("**Inspected main asset: {0}", obj.name));
            }

            else
            {
                if (m_assetBundleLoaded)
                {
                    Debug.Log("**Saving assets...");
                    AssetDatabase.SaveAssets();

                    m_assetBundleLoaded = false;
                    Debug.Log("**Unloading Asset Bundle");
                    m_assetBundle.Unload(false);
                    m_assetBundleObjects = null;
                    m_assetBundle = null;

                    Debug.Log("**Assets saved successfully");
                }
            }
        }
    }