Beispiel #1
0
    public void _Create()
    {
        Debuger.Log("ABDataScene.CreateSync");

        float counttime = Time.realtimeSinceStartup;

        {
            _scene      = (GameObject)GameObject.Instantiate(mLoadScene.scene);
            _scene.name = mLoadScene.scene.name;

            counttime = StampTime(counttime, "ABDataScene._Create  mLoadScene.scene");

            mProgress++;

            {
                AssetBundleRequest request = null;
                Dictionary <AssetBundleRequest, Material> dicRequestMat = new Dictionary <AssetBundleRequest, Material>();
                Material material = null;
                Dictionary <string, Material> dicStringMat = new Dictionary <string, Material>();
                Transform trans = null;

                Debuger.Log("ABDataScene.CreateSync " + mLoadScene.asset.material.Length.ToString());

                Debuger.Log("mLoadScene.asset.material = " + mLoadScene.asset.material.Length);


                Material tmpMat = null;

                for (int i = 0; i < mLoadScene.asset.material.Length; ++i)
                {
                    counttime = Time.realtimeSinceStartup;

                    StringPrefabMaterial e = (StringPrefabMaterial)mLoadScene.asset.material[i];

                    mProgress++;

                    trans = _scene.transform.Find(e.meshrendererGameObject.Substring(_scene.name.Length + 1));
#if 异步
                    request = (AssetBundleRequest)mLoadScene.mAssetBundleRequestObject[e.assetbundlePath];

                    if (request == null)
                    {
                        Debug.LogError(_scene.name + " request == null" + e.meshrendererGameObject);

                        continue;
                    }

                    if (dicMat.TryGetValue(request, out tmpMat))
                    {
                    }
                    else
                    {
                        if (request.asset == null)
                        {
                            Debug.LogError(_scene.name + " request.asset == null" + e.meshrendererGameObject);

                            continue;
                        }

                        //
                        if (!e.meshrendererGameObject.StartsWith(_scene.name))
                        {
                            Debug.LogError(_scene.name + " No StartWith " + e.meshrendererGameObject);

                            continue;
                        }

                        tmpMat = (Material)GameObject.Instantiate(request.asset);

                        dicMat.Add(request, tmpMat);
                    }
#else
                    if (dicStringMat.TryGetValue(e.assetbundlePath, out tmpMat))
                    {
                    }
                    else
                    {
                        material = (Material)mLoadScene.mMaterialObject[e.assetbundlePath];

                        if (material != null)
                        {
                            tmpMat = (Material)GameObject.Instantiate((Material)mLoadScene.mMaterialObject[e.assetbundlePath]);

                            dicStringMat.Add(e.assetbundlePath, tmpMat);
                        }
                    }
#endif

                    if (trans != null)
                    {
                        MeshRenderer mr = trans.gameObject.GetComponent <MeshRenderer>();

                        mr.material = tmpMat;

                        counttime = StampTime(counttime, "\tABDataScene._Create GetComponent<MeshRenderer>" + e.meshrendererGameObject);
                    }
                    //buger.Log("ABDataScene.CreateSync " + e.meshrendererGameObject + " " + (Time.realtimeSinceStartup - counttime).ToString());
                }

                dicRequestMat.Clear();
                dicRequestMat = null;
            }

            counttime = StampTime(counttime, "ABDataScene._Create mLoadScene.asset.material.Length");

            _ABLoadGoMono          = _scene.AddComponent <ABLoadGoMono>();
            _ABLoadGoMono.EnablePS = AssetBundleUti.ShowParticleSys;
        }

        {
            if (mLoadScene.nav != null)
            {
                _nav      = (GameObject)GameObject.Instantiate(mLoadScene.nav);
                _nav.name = mLoadScene.scene.name + ABLoadScene.Nav;
                _nav.AddComponent <ABLoadGoMono>();
            }

            counttime = StampTime(counttime, "ABDataScene._Create Instantiate(mLoadScene.nav)");

            mProgress++;
        }

        {
            _lightmap = mLoadScene.lightmap;

            mProgress++;
        }

        {
            _asset = mLoadScene.asset;

            mProgress++;
        }

        //{
        //    _lightmap = mLoadScene.lightmap;

        //    mProgress++;

        //}

        mLoadScene.Release(true);

        counttime = StampTime(counttime, "ABDataScene._Create mLoadScene.Release(true)");

        Debuger.Log("ABDataScene.CreateSync " + (Time.realtimeSinceStartup - counttime).ToString("f5"));
    }
Beispiel #2
0
        /// <summary>
        /// 针对传入的硬盘对象,创建一个纹理配置文件asset
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        void DecomposeMaterialAsset(Object obj)
        {
            //  输出目录
            string folder = AssetDatabase.GetAssetPath(obj);

            folder = Path.GetDirectoryName(folder);

            //
            ArrayList listMatNames = new ArrayList();
            Dictionary <string, int> dicListMatNames = new Dictionary <string, int>();

            GameObject characterClone = (GameObject)Object.Instantiate(obj);

            characterClone.name = obj.name;

            //  搜寻所有的MeshRender.
            foreach (MeshRenderer ren in characterClone.GetComponentsInChildren <MeshRenderer>())
            {
                {
                    //  sharedMaterials
                    if (ren.sharedMaterials != null)
                    {
                        int count = ren.sharedMaterials.Length;

                        for (int i = count - 1; i >= 0; i--)
                        {
                            Material m = (Material)ren.sharedMaterials[i];

                            if (m == null)
                            {
                                Debug.LogError("Missing " + ren.gameObject.name + " -> Material in " + characterClone.name);
                            }
                            else
                            {
                                //Debug.Log(characterClone.name + "/" + ren.gameObject.name + "/" + m.name);

                                StringPrefabMaterial prefabmat = new StringPrefabMaterial();
                                //  挂载的对象.
                                prefabmat.meshrendererGameObject = ABTools.GetParentPath(ren.gameObject) + "_" + ren.gameObject.GetInstanceID();
                                //
                                ren.gameObject.name += "_" + ren.gameObject.GetInstanceID();
                                //  资源名称.
                                prefabmat.assetname = m.name;
                                //  资源对象.
                                prefabmat.assetbundlePath = GetDepencyPath(m.name, ren.gameObject);
                                //  纹理的AB.
                                prefabmat.assetbundlePath = CreateMaterialAB(prefabmat.assetbundlePath);

                                listMatNames.Add(prefabmat);

                                //	Count Times
                                int curcount = -1;

                                if (dicListMatNames.TryGetValue(prefabmat.assetbundlePath, out curcount))
                                {
                                    curcount++;
                                }
                                else
                                {
                                    curcount = 1;
                                }

                                dicListMatNames[prefabmat.assetbundlePath] = curcount;
                            }
                        }

                        ren.sharedMaterials = new Material[0];
                    }
                }
            }


            //  创建一个不带Material的Prefab.
            string nomaterialscenePath = folder + "/" + obj.name + "_nomaterial.prefab";
            Object o = PrefabUtility.CreateEmptyPrefab(nomaterialscenePath);

            PrefabUtility.ReplacePrefab(characterClone, o);

            //{
            //    //
            //    ArrayList listLightmaps = new ArrayList();

            //    Renderer[] rs = characterClone.GetComponentsInChildren<Renderer>();
            //    foreach (Renderer r in rs)
            //    {
            //        StringPrefabLightmap slmp = new StringPrefabLightmap();
            //        slmp.lightmapIndex = r.lightmapIndex;
            //        slmp.lightmapScaleOffset = r.lightmapScaleOffset;

            //        Debug.Log(r.gameObject.name + " " + r.lightmapIndex + " " + r.lightmapScaleOffset);

            //        listLightmaps.Add(slmp);
            //    }

            //}

            //  创建配置文件
            StringPrefab holder = ScriptableObject.CreateInstance <StringPrefab>();

            holder.material = (StringPrefabMaterial[])listMatNames.ToArray(typeof(StringPrefabMaterial));
            //holder.lightmap = (StringPrefabLightmap[])listLightmaps.ToArray(typeof(StringPrefabLightmap));
            string materialassetPath = folder + "/" + obj.name + "_material.asset";

            AssetDatabase.CreateAsset(holder, materialassetPath);

            //
            string txtPath = mDestFolder + "/" + obj.name + ".txt";
            string content = string.Empty;

            foreach (KeyValuePair <string, int> e in dicListMatNames)
            {
                content += e.Value;
                content += "\t";
                content += e.Key;
                content += "\r\n";
            }
            File.WriteAllText(txtPath, content);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            GameObject.DestroyImmediate(characterClone);

            nomaterialscene = (GameObject)AssetDatabase.LoadAssetAtPath(nomaterialscenePath, typeof(GameObject));
            materialasset   = (StringPrefab)AssetDatabase.LoadAssetAtPath(materialassetPath, typeof(StringPrefab));
        }
Beispiel #3
0
        /// <summary>
        /// 针对传入的硬盘对象,创建一个纹理配置文件asset
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        void DecomposeMaterialAsset(Object obj)
        {
            //  输出目录
            string folder = AssetDatabase.GetAssetPath(obj);
            folder = Path.GetDirectoryName(folder);

            ArrayList listMatNames = new ArrayList();
			Dictionary<string, int> dicListMatNames = new Dictionary<string, int>();

            GameObject characterClone = (GameObject)Object.Instantiate(obj);

            characterClone.name = obj.name;

            //  搜寻所有的MeshRender.
            foreach (MeshRenderer ren in characterClone.GetComponentsInChildren<MeshRenderer>())
            {
                {
                    //  sharedMaterials
                    if (ren.sharedMaterials != null)
                    {
                        int count = ren.sharedMaterials.Length;

                        for (int i = count - 1; i >= 0; i--)
                        {
                            Material m = (Material)ren.sharedMaterials[i];

                            if (m == null)
								Debug.LogError("Missing " + ren.gameObject.name + " -> Material in " + characterClone.name);
                            else
                            {
                                //Debug.Log(characterClone.name + "/" + ren.gameObject.name + "/" + m.name);

                                StringPrefabMaterial prefabmat = new StringPrefabMaterial();
                                //  挂载的对象.
                                prefabmat.meshrendererGameObject = ABTools.GetParentPath(ren.gameObject) + "_" + ren.gameObject.GetInstanceID();
								//
								ren.gameObject.name += "_" + ren.gameObject.GetInstanceID();
                               //  资源名称.
                                prefabmat.assetname = m.name;
                                //  资源对象.
                                prefabmat.assetbundlePath = GetDepencyPath(m.name, ren.gameObject);
                                //  纹理的AB.
                                prefabmat.assetbundlePath = CreateMaterialAB(prefabmat.assetbundlePath);

                                listMatNames.Add(prefabmat);

								//	Count Times
								int curcount = -1;

								if (dicListMatNames.TryGetValue(prefabmat.assetbundlePath, out curcount))
									curcount++;
								else
									curcount = 1;

								dicListMatNames[prefabmat.assetbundlePath] = curcount;
                            }
                        }

                        ren.sharedMaterials = new Material[0];
                    }
                }
            }


            //  创建一个不带Material的Prefab.
            string nomaterialscenePath = folder + "/" + obj.name + "_nomaterial.prefab";
            Object o = PrefabUtility.CreateEmptyPrefab(nomaterialscenePath);
            PrefabUtility.ReplacePrefab(characterClone, o);

            //  创建配置文件
            StringPrefab holder = ScriptableObject.CreateInstance<StringPrefab>();
            holder.material = (StringPrefabMaterial[])listMatNames.ToArray(typeof(StringPrefabMaterial));
            string materialassetPath = folder + "/" + obj.name + "_material.asset";
            AssetDatabase.CreateAsset(holder, materialassetPath);

			//	
			string txtPath = mDestFolder + "/" + obj.name + ".txt";
			string content = string.Empty;
			foreach(KeyValuePair<string, int> e in dicListMatNames)
			{
				content += e.Value;
				content += "\t";
				content += e.Key;
				content += "\r\n";
			}
			File.WriteAllText(txtPath, content);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            GameObject.DestroyImmediate(characterClone);

            nomaterialscene = (GameObject)AssetDatabase.LoadAssetAtPath(nomaterialscenePath, typeof(GameObject));
            materialasset = (StringPrefab)AssetDatabase.LoadAssetAtPath(materialassetPath, typeof(StringPrefab));
        }
        static void CreateFromPrefab_Scene(PLATFORM p)
        {
            Debug.Log("CreateAssetbundles CreateFromPrefab_Scene");

            CreateAssetBundlePath();

            ArrayList listMatNames = new ArrayList();

            foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
            {
                // filters
                if (!(obj is GameObject))
                {
                    continue;
                }
                //
                GameObject characterClone = (GameObject)Object.Instantiate(obj);

                characterClone.name = obj.name;

                //  搜寻所有的MeshRender.
                foreach (MeshRenderer ren in characterClone.GetComponentsInChildren <MeshRenderer>())
                {
                    {
                        //  sharedMaterials
                        if (ren.sharedMaterials != null)
                        {
                            int count = ren.sharedMaterials.Length;

                            for (int i = count - 1; i >= 0; i--)
                            {
                                Material m = (Material)ren.sharedMaterials[i];

                                if (m == null)
                                {
                                    Debug.LogError("Missing " + obj.name + " -> Material");
                                }
                                else
                                {
                                    //Debug.Log(characterClone.name + "/" + ren.gameObject.name + "/" + m.name);

                                    StringPrefabMaterial prefabmat = new StringPrefabMaterial();
                                    //  资源名称.
                                    prefabmat.assetname = m.name;
                                    //  挂载的对象.
                                    prefabmat.meshrendererGameObject = ABTools.GetParentPath(ren.gameObject);
                                    //  资源对象.
                                    prefabmat.assetbundlePath = GetDepencyPath(m.name);

                                    listMatNames.Add(prefabmat);
                                }
                            }

                            ren.sharedMaterials = new Material[0];
                        }
                    }
                }

                //  创建一个不带Material的Prefab.
                Object o = PrefabUtility.CreateEmptyPrefab(ASSETBUNDLE_PATH + "/" + obj.name + "_nomaterial.prefab");
                PrefabUtility.ReplacePrefab(characterClone, o);

                //  创建配置文件
                StringPrefab holder = ScriptableObject.CreateInstance <StringPrefab>();
                holder.material = (StringPrefabMaterial[])listMatNames.ToArray(typeof(StringPrefabMaterial));
                AssetDatabase.CreateAsset(holder, ASSETBUNDLE_PATH + "/" + obj.name + "_material.asset");

                GameObject.DestroyImmediate(characterClone);
            }
        }
        static void CreateFromPrefab_Scene(PLATFORM p)
        {
            Debug.Log("CreateAssetbundles CreateFromPrefab_Scene");

            CreateAssetBundlePath();

            ArrayList listMatNames = new ArrayList();

            foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
            {
                // filters
                if (!(obj is GameObject))
                    continue;
                //  
                GameObject characterClone = (GameObject)Object.Instantiate(obj);

                characterClone.name = obj.name;

                //  搜寻所有的MeshRender.
                foreach (MeshRenderer ren in characterClone.GetComponentsInChildren<MeshRenderer>())
                {
                    {
                        //  sharedMaterials
                        if (ren.sharedMaterials != null)
                        {
                            int count = ren.sharedMaterials.Length;

                            for (int i = count - 1; i >= 0; i--)
                            {
                                Material m = (Material)ren.sharedMaterials[i];

                                if (m == null)
                                    Debug.LogError("Missing " + obj.name + " -> Material");
                                else
                                {
                                    //Debug.Log(characterClone.name + "/" + ren.gameObject.name + "/" + m.name);

                                    StringPrefabMaterial prefabmat = new StringPrefabMaterial();
                                    //  资源名称.
                                    prefabmat.assetname = m.name;
                                    //  挂载的对象.
                                    prefabmat.meshrendererGameObject = ABTools.GetParentPath(ren.gameObject);
                                    //  资源对象.
                                    prefabmat.assetbundlePath = GetDepencyPath(m.name);

                                    listMatNames.Add(prefabmat);

                                }

                            }

                            ren.sharedMaterials = new Material[0];
                        }

                    }
                }

                //  创建一个不带Material的Prefab.
                Object o = PrefabUtility.CreateEmptyPrefab(ASSETBUNDLE_PATH + "/" + obj.name + "_nomaterial.prefab");
                PrefabUtility.ReplacePrefab(characterClone, o);

                //  创建配置文件
                StringPrefab holder = ScriptableObject.CreateInstance<StringPrefab>();
                holder.material = (StringPrefabMaterial[])listMatNames.ToArray(typeof(StringPrefabMaterial));
                AssetDatabase.CreateAsset(holder, ASSETBUNDLE_PATH + "/" + obj.name + "_material.asset");

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                GameObject.DestroyImmediate(characterClone);
            }
        }