Exemplo n.º 1
0
    internal UnityEngine.Object GetSharedResource(string res, EResType ResGroup, Action <UnityEngine.Object[]> func = null)
    {
        UnityEngine.Object obj     = null;
        string             abName  = string.Empty;
        string             resName = string.Empty;

        UnityEngine.Object retObj = null;
        if (string.IsNullOrEmpty(res))
        {
            return(obj);
        }
        if (kLoadedPrefabs.ContainsKey(res))
        {
            retObj = kLoadedPrefabs[res];
        }
        else
        {
            string ResName       = ResDefine.GetResourceType(ResGroup);
            string ResFolderName = ResName + "/";
            string abPath        = string.Empty;
            if (AppConst.PublishMode)
            {
                abName = string.Empty;
                abPath = Path.GetDirectoryName(res);
                if (string.IsNullOrEmpty(abPath))
                {
                    abName = ResFolderName + ResName + ResDefine.ExtName;
                }
                else
                {
                    abPath = abPath.Replace("/", "_");
                    abName = ResFolderName + abPath + ResDefine.ExtName;
                }
                resName = Path.GetFileName(res);
                obj     = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset <UnityEngine.Object>(abName, resName);
            }
            if (obj == null)
            {
                abPath = ResFolderName + res;
                obj    = Resources.Load(abPath);
            }
            if (obj != null)
            {
                retObj = UnityEngine.Object.Instantiate(obj);

                kLoadedPrefabs.Add(res, retObj);
                AssetsLoaderManager assetLoader = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader);
                if (assetLoader != null)
                {
                    assetLoader.UnloadSyncAssetBundle(abName);
                }
            }
            else
            {
                UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
            }
        }
        return(retObj);
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        RectTransform rect = target as RectTransform;

        if (rect == null)
        {
            base.OnInspectorGUI();
            return;
        }
        string assetPath = AssetDatabase.GetAssetPath(rect.gameObject);
        string asset     = PsdLayoutTool.PsdImporter.GetRelativePath(ResDefine.GetResPath(EResType.eResUI));

        if (assetPath.Contains(asset))
        {
            base.OnInspectorGUI();

            GUILayout.Space(3);
            GUILayout.Box(string.Empty, GUILayout.Height(1), GUILayout.MaxWidth(Screen.width - 30));
            GUILayout.Space(3);
            GUIContent autoBind = new GUIContent("autoBindView", "auto bind view to prefab");
            BindView.AutoBindView = EditorGUILayout.Toggle(autoBind, BindView.AutoBindView);

            //if (GUILayout.Button("Generate CS View Script"))
            //{
            //    string prefabFullPath = GetPrefabFullPath(assetPath);
            //    if (!System.IO.File.Exists(prefabFullPath))
            //    {
            //        UnityEditor.EditorUtility.DisplayDialog("提示", "没有找到prefab文件,请先生成prefab", "确定");
            //        return;
            //    }
            //    BindView.GenerateView(assetPath, ScriptType.eCSharp);
            //}
            //GUILayout.Space(3);

            if (GUILayout.Button("Generate Lua View Script"))
            {
                BindView.GenerateView(assetPath, ScriptType.eLua);
            }
            if (GUILayout.Button("Delete bind Script"))
            {
                //string CSAssetPath = BindView.UICSViewPath + System.IO.Path.GetFileNameWithoutExtension(assetPath);
                //bool ret = AssetDatabase.DeleteAsset(CSAssetPath + ".cs");

                string LuaAssetPath = BindView.UILuaViewPath + System.IO.Path.GetFileNameWithoutExtension(assetPath);
                bool   ret          = AssetDatabase.DeleteAsset(LuaAssetPath + ".lua");
                if (ret)
                {
                    AssetDatabase.Refresh();
                }
            }
            if (GUILayout.Button("Delete Repeat sprites"))
            {
                PsdLayoutTool.PsdImporter.DeleteCurrentPsdRepeatSprites(System.IO.Path.GetFileNameWithoutExtension(assetPath), false);
            }
        }
        else
        {
            base.OnInspectorGUI();
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// 添加打入Lua代码的AssetBundle
    /// </summary>
    /// <param name="bundle"></param>
    public void AddBundle(string bundleName)
    {
        byte[] stream = null;
        string url    = Util.DataPath + bundleName.ToLower();

        if (File.Exists(url))
        {
            stream = File.ReadAllBytes(url);
            byte[]      assetBytes = ResDefine.DecryptAssetbundle(stream);
            AssetBundle bundle     = AssetBundle.LoadFromMemory(assetBytes);
            if (bundle != null)
            {
                bundleName = bundleName.Replace("lua/", "").Replace(".unity3d", "");
                base.AddSearchBundle(bundleName.ToLower(), bundle);
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// 载入AssetBundle
    /// </summary>
    /// <param name="abname"></param>
    /// <returns></returns>
    public AssetBundle LoadAssetBundle(string abname)
    {
        abname = abname.ToLower();
        if (!abname.EndsWith(ResDefine.ExtName))
        {
            abname += ResDefine.ExtName;
        }
        AssetBundleInfo bundle = null;

        if (m_AssetBundleManifest == null)
        {
            return(bundle.m_AssetBundle);
        }
        if (!m_LoadedAssetBundles.ContainsKey(abname))
        {
            byte[] stream = null;
            string uri    = Util.DataPath + abname;
            if (!File.Exists(uri))
            {
                Debug.LogError(uri + " not exist ");
                return(null);
            }

            LoadDependencies(abname);

            stream = File.ReadAllBytes(uri);
            if (stream.Length == 0)
            {
                Debug.LogError("load error " + abname);
                return(null);
            }
            byte[]      assetBytes = ResDefine.DecryptAssetbundle(stream);
            AssetBundle bundleObj  = AssetBundle.LoadFromMemory(assetBytes);
            if (bundleObj != null)
            {
                m_LoadedAssetBundles.Add(abname, new AssetBundleInfo(bundleObj));
            }
            return(bundleObj);
        }
        else
        {
            m_LoadedAssetBundles.TryGetValue(abname, out bundle);
            return(bundle.m_AssetBundle);
        }
    }
Exemplo n.º 5
0
    static void HandleResourceBundle(EResType eResType)
    {
        EResType kResGroup = eResType;
        string   path      = ResDefine.GetResPath(kResGroup);

        if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
        {
            return;
        }
        string ResName       = ResDefine.GetResourceType(kResGroup);
        string ResFolderName = ResName + "/";
        string Dirpath       = "";

        List <string> kExtList = new List <string>();

        ResDefine.GetResTypeFileExtList(kResGroup, ref kExtList);


        string[] dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
        for (int j = 0; j < dirs.Length; j++)
        {
            string fPath = path;
            if (target == BuildTarget.iOS)
            {
                fPath = path + "/";
            }
            string name = dirs[j].Replace(fPath, string.Empty).TrimStart(new char[] { '\\' });
            name = name.Replace('\\', '_').Replace('/', '_');
            name = name.ToLower() + ResDefine.ExtName;

            Dirpath = "Assets" + dirs[j].Replace(Application.dataPath, "");
            AddBuildMap(ResFolderName + name, kExtList, Dirpath);
        }
        if (kResGroup != EResType.eResScene)  //资源根目录打包
        {
            string DirName = Path.GetFileName(path);
            AddBuildMap(ResFolderName + DirName + ResDefine.ExtName, kExtList, "Assets" + path.Replace(Application.dataPath, ""));
        }
    }
Exemplo n.º 6
0
    static void AddBuildMap(string bundleName, List <string> pattern, string path)
    {
        // string[] files = Directory.GetFiles(path, pattern);

        ArrayList ArraryFiles = ResDefine.GetResourceFiles(path, pattern);

        if (ArraryFiles.Count == 0)
        {
            return;
        }
        string[] files = new string[ArraryFiles.Count];
        ArraryFiles.CopyTo(files);
        for (int i = 0; i < files.Length; i++)
        {
            files[i] = files[i].Replace('\\', '/');
        }
        AssetBundleBuild build = new AssetBundleBuild();

        build.assetBundleName = bundleName;
        build.assetNames      = files;
        maps.Add(build);
    }
Exemplo n.º 7
0
 void loadSenenBundle(string name)
 {
     if (AppConst.PublishMode)
     {
         string bundleName = string.Empty;
         if (!name.Contains("loading") && !name.Contains("Login") && !name.Contains("SelectActorScence"))//排除loading login等几个场景
         {
             string ResName = ResDefine.GetResourceType(EResType.eResScene);
             ResName += "/";
             if (name.Contains("_"))
             {
                 int i = name.LastIndexOf('_');
                 bundleName = name.Substring(0, i);
             }
             else
             {
                 bundleName = name;
             }
             //   bundle = AppFacade.Instance.GetManager<AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAssetBundle(ResName + bundleName);
         }
     }
 }
Exemplo n.º 8
0
    void FillContents()
    {
        int index = 0;
        SortedList <int, MapResProperty> Lists = MapDataProccess.instance.ResList;
        IList <int> ilistValues = MapDataProccess.instance.ResList.Keys;

        for (int i = ilistValues.Count - 1; i > -1; --i)
        {
            MapResProperty resProp = Lists[ilistValues[i]];
            if (resProp.GetEid() == currentProp.GetEid())
            {
                continue;                                           //排除自身
            }
            index = GetIdFormType(resProp.GetResType());
            AddResToolItem(resProp, index);
        }
        string        path     = ResDefine.GetResPath(EResType.eResScene);
        List <string> kExtList = new List <string>();

        ResDefine.GetResTypeFileExtList(EResType.eResScene, ref kExtList);
        DirectoryInfo dir = new DirectoryInfo(path);

        string[] dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
        index = 10101;
        for (int k = 0; k < dirs.Length; k++)
        {
            ArrayList ArraryFiles = ResDefine.GetResourceFiles(dirs[k].ToString(), kExtList);
            string[]  files       = new string[ArraryFiles.Count];
            ArraryFiles.CopyTo(files);
            for (int i = 0; i < files.Length; i++)
            {
                FileInfo       fi      = new FileInfo(files[i]);
                MapResProperty resProp = new MapResProperty();
                resProp.SetName(fi.Name.Replace(".unity", ""));
                resProp.SetEid(index++);
                AddResToolItem(resProp, 4);
            }
        }
    }
Exemplo n.º 9
0
    static void BuildFileIndex()
    {
        string resPath = AppDataPath + "/StreamingAssets/";
        ///----------------------创建文件列表-----------------------
        string newFilePath = resPath + AppConst.PatchList;

        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        paths.Clear(); files.Clear();
        Recursive(resPath);

        List <ResInfo> ResInfoList = new List <ResInfo>();
        ResInfo        resInfo;

        for (int i = 0; i < files.Count; i++)
        {
            string file = files[i];
            string ext  = Path.GetExtension(file);
            if (file.EndsWith(".meta") || file.Contains(".DS_Store"))
            {
                continue;
            }

            ResDefine.EncryptAssetbundle(file);
            string md5   = Util.md5file(file);
            string value = file.Replace(resPath, string.Empty);
            resInfo         = new ResInfo();
            resInfo.ResName = value;
            resInfo.md5     = md5;

            ResInfoList.Add(resInfo);
        }

        FileJasonBuild(ResInfoList);
    }
Exemplo n.º 10
0
    internal void NewObject(string res, EResType resType, float timeToRecycle, float timeToDestory, Action <UnityEngine.Object> func = null)
    {
        UnityEngine.Object obj     = null;
        UnityEngine.Object retObj  = null;
        string             abName  = string.Empty;
        string             resName = string.Empty;

        if (kLoadedPrefabs.ContainsKey(res) && kLoadedPrefabs[res] != null)
        {
            obj = kLoadedPrefabs[res];
            if (obj != null)
            {
                retObj = NewObject(res, obj, timeToRecycle, timeToDestory);
                if (func != null)
                {
                    func(retObj);
                }
            }
        }
        else
        {
            string ResName       = ResDefine.GetResourceType(resType);
            string ResFolderName = ResName + "/";
            string abPath        = string.Empty;
            if (AppConst.PublishMode && resType != EResType.eSceneLoadRes)
            {
                abName = string.Empty;
                abPath = Path.GetDirectoryName(res);
                if (string.IsNullOrEmpty(abPath))
                {
                    abName = ResFolderName + ResName + ResDefine.ExtName;
                }
                else
                {
                    abPath = abPath.Replace("/", "_");
                    abName = ResFolderName + abPath + ResDefine.ExtName;
                }
                resName = Path.GetFileName(res);
                AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset(abName, resName, delegate(UnityEngine.Object[] uObj)
                {
                    if (uObj == null || uObj[0] == null)
                    {
                        UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                        UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
                    }
                    else
                    {
                        retObj = NewObject(res, uObj[0], timeToRecycle, timeToDestory);
                        if (func != null)
                        {
                            func(retObj);
                        }
                        if (!kLoadedPrefabs.ContainsKey(res))
                        {
                            kLoadedPrefabs.Add(res, retObj);
                        }
                    }
                }
                                                                                                        );
            }
            else
            {
                if (obj == null)
                {
                    abPath = ResFolderName + res;
                    // obj = Resources.Load(abPath);
                    AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadRes(abPath, delegate(UnityEngine.Object uObj)
                    {
                        if (uObj == null)
                        {
                            UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                            UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
                        }
                        retObj = NewObject(res, uObj, timeToRecycle, timeToDestory);
                        if (func != null)
                        {
                            func(retObj);
                        }
                        if (!kLoadedPrefabs.ContainsKey(res))
                        {
                            kLoadedPrefabs.Add(res, retObj);
                        }
                    });
                }
            }
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// 生成绑定素材
    /// </summary>
    public static void BuildAssetResource(BuildTarget target, PackagerResType pRtype = PackagerResType.eALLRES)
    {
        if (Directory.Exists(Util.DataPath))
        {
            Directory.Delete(Util.DataPath, true);
        }
        string streamPath = Application.streamingAssetsPath;

        if (Directory.Exists(streamPath))
        {
            Directory.Delete(streamPath, true);
        }
        Directory.CreateDirectory(streamPath);
        AssetDatabase.Refresh();
        string Serverpath    = Application.dataPath + "/PublishRes/" + AppConst.PublishServerList;
        string outServerpath = streamPath + "/" + AppConst.PublishServerList;

        File.Copy(Serverpath, outServerpath, true);
        ClearAssetBundlesName();
        maps.Clear();
        if (pRtype == PackagerResType.eALLRES || pRtype == PackagerResType.eLUA)
        {
            HandleLuaBundle();
        }

        if (pRtype == PackagerResType.eALLRES)
        {
            HandleResourceBundle();
        }
        else if (pRtype == PackagerResType.eSCENE)
        {
            HandleResourceBundle(EResType.eResScene);
        }
        else if (pRtype == PackagerResType.eCHARACTER)
        {
            HandleResourceBundle(EResType.eResMonster);
            HandleResourceBundle(EResType.eResPet);
            HandleResourceBundle(EResType.eResBoss);
            HandleResourceBundle(EResType.eResCharacter);
        }
        else if (pRtype == PackagerResType.eUI)
        {
            HandleResourceBundle(EResType.eResUI);
        }


        string resPath = "Assets/" + AppConst.AssetDir;
        BuildAssetBundleOptions options = BuildAssetBundleOptions.DeterministicAssetBundle |
                                          BuildAssetBundleOptions.ChunkBasedCompression;

        BuildPipeline.BuildAssetBundles(resPath, maps.ToArray(), options, target);
        BuildFileIndex();


        string streamDir = Application.dataPath + "/" + AppConst.LuaTempDir;

        if (Directory.Exists(streamDir))
        {
            Directory.Delete(streamDir, true);
        }


        for (int i = 0; i < (int)EResType.eResCount; i++)
        {
            EResType kResGroup = (EResType)i;
            if (kResGroup == EResType.eResFont || kResGroup == EResType.eResLua || kResGroup == EResType.eResShader ||
                kResGroup == EResType.eResScene || kResGroup == EResType.eResPicture || kResGroup == EResType.eSceneLoadRes)
            {
                continue;
            }
            string path = ResDefine.GetResPath(kResGroup);
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);                        //打包完成删除源资源
            }
        }
        AssetDatabase.Refresh();
    }
Exemplo n.º 12
0
    IEnumerator OnLoadAssetBundle(string abName, Type type)
    {
        string url = Util.GetRelativePath() + abName;
        //AssetBundleCreateRequest asset = null;
        WWW download = null;

        if (type == typeof(AssetBundleManifest))
        {
            download = new WWW(url);
        }
        else
        {
            string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName);
            if (dependencies.Length > 0)
            {
                if (!m_Dependencies.ContainsKey(abName))
                {
                    m_Dependencies.Add(abName, dependencies);
                }
                for (int i = 0; i < dependencies.Length; i++)
                {
                    string          depName    = dependencies[i];
                    AssetBundleInfo bundleInfo = null;
                    if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo))
                    {
                        bundleInfo.m_ReferencedCount++;
                    }
                    else if (!m_LoadRequests.ContainsKey(depName))
                    {
                        yield return(StartCoroutine(OnLoadAssetBundle(depName, type)));
                    }
                }
            }
            if (m_LoadedAssetBundles.ContainsKey(abName))
            {
                yield break;
            }

            download = new WWW(url);
            download.threadPriority = ThreadPriority.BelowNormal;
        }
        yield return(download);

        if (download.error != null)
        {
            Debug.LogError(url);
            Debug.LogError(download.error);
            yield break;
        }
        AssetBundleInfo kbundleInfo = null;

        if (m_LoadedAssetBundles.TryGetValue(abName, out kbundleInfo))
        {
            kbundleInfo.m_ReferencedCount++;
        }
        else
        {
            if (download.bytes.Length == 0)
            {
                Debug.LogError("load error " + abName);
            }
            byte[]      assetBytes = ResDefine.DecryptAssetbundle(download.bytes);
            AssetBundle assetObj   = AssetBundle.LoadFromMemory(assetBytes);
            if (assetObj != null)
            {
                m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj));
            }
        }
        download.Dispose();
        download = null;
    }