Example #1
0
    public bool Load(string packName, string tabName)
    {
        PacketRouting packetRouting = PacketManage.Single.GetPacket(packName);

        if (packetRouting == null)
        {
            return(false);
        }

        byte[] byteFile = packetRouting.LoadBytes(tabName);
        if (byteFile == null)
        {
            return(false);
        }

        int byteStartIndex = 0;

        if (byteFile.Length >= 3)
        {
            if (byteFile[0] == 0xEF && byteFile[1] == 0xBB && byteFile[2] == 0xBF)
            {
                byteStartIndex = 3;//跳过utf8文件头
            }
        }

        m_Tab.Deserialization(byteFile, byteStartIndex, byteFile.Length - byteStartIndex);
        return(true);
    }
Example #2
0
    public bool Load(string packName, string tabName)
    {
        CSVDoc doc = new CSVDoc();
        // doc.LoadCsvFile(packName, tabName);


        //对数据的有效性进行验证
        PacketRouting pack = PacketManage.Single.GetPacket(packName);

        if (pack == null)
        {
            Debug.LogError("LoadCsvFile 包不存在" + packName);
            return(false);
        }

        string csvcontent = pack.LoadString(tabName);

        if (csvcontent == null)
        {
            Debug.LogError(string.Format("LoadCsvFile 文件不存在 {0}/{1}", packName, tabName));
            return(false);
        }
        doc.LoadCsvFromMem(csvcontent);



        m_reader = new CSVReader(doc);
        return(true);
    }
Example #3
0
    //包 装载完成通知
    public void OnPacketLoadDone(string packetName, PacketRouting bundle, Action <bool> DoneEvent)
    {
        m_packets.Remove(packetName);
        if (m_Result == ResultEnum.Error)
        {
            return;
        }

        if (!string.IsNullOrEmpty(packetName) && bundle == null)
        {
            m_Result = ResultEnum.Error;
            if (DoneEvent != null)
            {
                DoneEvent(false);
            }
        }

        if (m_packets.Count <= 0 && m_waitPackets.Count <= 0)
        {
            if (m_LoadingProgress.ContainsKey(packetName))
            {
                m_LoadingProgress[packetName] = 1.0f;//该包装载进度100%
            }
            m_Result = ResultEnum.Done;
            if (DoneEvent != null)
            {
                DoneEvent(true);
            }
        }
    }
Example #4
0
    IEnumerator _coPlay(string packname, string clipname, float fadeOutTime)
    {
        //装入资源包
        List <string> pkList = new List <string>();

        pkList.Add(packname);
        PacketLoader pkLoader = new PacketLoader();

        pkLoader.Start(PackType.Res, pkList, null);
        IEnumerator pkIt     = pkLoader.Wait();
        bool        needWait = true;

        while (needWait)
        {
            try
            {
                needWait = pkIt.MoveNext();
            }
            catch (Exception)
            {
                //装载资源遇到问题
                Debug.Log(string.Format("BackgroundMusic 装载包遇到错误 包:{0}", packname));
                yield break;
            }

            yield return(null);
        }
        //将包加入资源引用管理
        ResourceRefManage.Single.AddRef(packname);

        PacketRouting packetRouting = PacketManage.Single.GetPacket(packname);

        if (packetRouting == null)
        {
            Debug.LogError(string.Format("BackgroundMusicManage.Play 不存在的包 packname:{0} clipname:{1}", packname, clipname));
            yield break;//包不存在
        }
        AudioClip clip = packetRouting.Load(clipname) as AudioClip;

        if (clip == null)
        {
            Debug.LogError(string.Format("BackgroundMusicManage.Play 不存在的音频剪辑 packname:{0} clipname:{1}", packname, clipname));
            yield break;//音频剪辑无效
        }
        if (m_BackgroundMusicObj == null)
        {
            m_BackgroundMusicObj = new GameObject("BackgroundMusic");
            GameObject.DontDestroyOnLoad(m_BackgroundMusicObj);
        }
        //创建一个新的AudioSource来播放
        m_CurrPackname               = packname;
        m_CurrClipname               = clipname;
        m_CurrBackgroundMusic        = m_BackgroundMusicObj.AddComponent <AudioSource>();
        m_CurrBackgroundMusic.clip   = clip;
        m_CurrBackgroundMusic.loop   = true;
        m_CurrBackgroundMusic.volume = 0;
        m_CurrBackgroundMusic.Play();
        CoroutineManage.Single.StartCoroutine(coFadeInBackgroundMusic(fadeOutTime));//淡入背景音
    }
Example #5
0
    /// <summary>
    /// 设置纹理
    /// </summary>
    /// <param name="lodLevel">0-n  近-远</param>
    /// <param name="textureName">新的纹理名</param>
    public void SetTexture(int lodLevel, string textureName)
    {
        //强制重新设置材质
        IsSetMateriald = false;
        m_CurrMeshLod  = -1;

        var           matIndex = EnableLodTexture ? lodLevel : 0;
        PacketRouting pack     = PacketManage.Single.GetPacket(TexturePackName);

        m_LodMaterial[matIndex] =
            MFAModelManage.Single.GetMaterial(m_LodMaterial[matIndex].shader, pack.Load(textureName) as Texture);
    }
Example #6
0
    /*
     * 只在编辑器下有效
     * Object cloneSrc = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Sphere.prefab", typeof(GameObject));
     */


    PacketRouting AddPacket(string packName, IPacket packetObj)
    {
        if (!m_DonePacks.ContainsKey(packName))
        {
            m_DonePacks.Add(packName, new PacketRouting());
        }

        PacketRouting re = m_DonePacks[packName];

        re.Add(packetObj);
        return(re);
    }
Example #7
0
    public void UnLoadPacket(string packName)
    {
        if (!m_DonePacks.ContainsKey(packName))
        {
            Debug.LogWarning(string.Format("资源包 {0} 不存在,不能卸载", packName));
            return;
        }

        PacketRouting pkr = m_DonePacks[packName];

        pkr.UnLoad();
        m_DonePacks.Remove(packName);
    }
Example #8
0
 static int UnLoad(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         PacketRouting obj = (PacketRouting)ToLua.CheckObject(L, 1, typeof(PacketRouting));
         obj.UnLoad();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #9
0
 static int Add(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         PacketRouting obj  = (PacketRouting)ToLua.CheckObject(L, 1, typeof(PacketRouting));
         IPacket       arg0 = (IPacket)ToLua.CheckObject(L, 2, typeof(IPacket));
         obj.Add(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #10
0
 static int GetPacket(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         PacketManage  obj  = (PacketManage)ToLua.CheckObject(L, 1, typeof(PacketManage));
         string        arg0 = ToLua.CheckString(L, 2);
         PacketRouting o    = obj.GetPacket(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #11
0
    //Dictionary<Shader, Dictionary<Texture, Dictionary<Color, Material>>> m_Mats = new Dictionary<Shader, Dictionary<Texture, Dictionary<Color, Material>>>();

    public MFAModel GetModel(string packName, string modelName)
    {
        /*
         * if (!m_Models.ContainsKey(packName))
         * {
         *  //装载包
         *  if (!m_NeedLoadPacks.Contains(packName))
         *  {
         *      m_NeedLoadPacks.Add(packName);
         *      AutoStartLoadCo();
         *  }
         *  return null;
         * }*/
        if (!m_Models.ContainsKey(packName))
        {
            m_Models.Add(packName, new Dictionary <string, MFAModel>());
            ResourceRefManage.Single.AddRef(packName);
        }

        Dictionary <string, MFAModel> models = m_Models[packName];

        if (!models.ContainsKey(modelName))
        {
            PacketRouting pack = PacketManage.Single.GetPacket(packName);
            if (pack == null)
            {
                Debug.LogError(string.Format("YQ2ModelManage 无法装载包 {0}", packName));
            }
            byte[] modelData = pack.LoadBytes(modelName + ".bytes");

            if (modelData == null)
            {
                return(null);
            }

            MFAModel new_model = new MFAModel();
            using (MemoryStream stream = new MemoryStream(modelData))
            {
                new_model.Deserialize(stream);
            }
            //YQ2Model new_model = new YQ2Model( pack.Load(modelName) as GameObject);
            models.Add(modelName, new_model);
            return(new_model);
        }
        return(models[modelName]);
    }
Example #12
0
    public static GameObject InstantiateFromPacket(string packName, string preObjName, GameObject parent)
    {
        PacketRouting corePack = PacketManage.Single.GetPacket(packName);

        if (corePack == null)
        {
            Debug.LogError(string.Format("_InstantiateFromPacket 包尚未就绪:{0}", packName));
        }

        UnityEngine.Object preObj = corePack.Load(preObjName);
        if (preObj == null)
        {
            Debug.LogError(String.Format("实例化对象错误, packet:{0} preObjName:{1}", packName, preObjName));
        }

        return(InstantiateFromPreobj(preObj, parent));
    }
Example #13
0
 static int LoadString(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         PacketRouting           obj  = (PacketRouting)ToLua.CheckObject(L, 1, typeof(PacketRouting));
         string                  arg0 = ToLua.CheckString(L, 2);
         FileSystem.RES_LOCATION arg1 = (FileSystem.RES_LOCATION)ToLua.CheckObject(L, 3, typeof(FileSystem.RES_LOCATION));
         string                  o    = obj.LoadString(arg0, arg1);
         LuaDLL.lua_pushstring(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #14
0
    static Material Avatar_Mats_N;                                                                   //角色渲染材质

    public static void Init()
    {
        GameObject Prefabs = GameObject.Find("/Prefabs");

        //Infantry 步兵 Cavalry 骑兵
        //var scene_mainPacket = PacketManage.Single.GetPacket("scene_main");
        //scene_mainPacket.Load("spotlight") as GameObject
        Object3D_Prefabs.Add("spotlight", null);



        PacketRouting pk = PacketManage.Single.GetPacket("core");

        Avatar_ColorMat_N = pk.Load("Avatar_N_Color.mat") as Material;
        Avatar_Mats_N     = pk.Load("Avatar_N.mat") as Material;

        m_AvatarLayer = LayerMask.NameToLayer("Avatar");

        //绑定主场景事件
        DP_BattlefieldDraw.Single.BindMainSceneEvent();
    }
Example #15
0
    static int _CreatePacketRouting(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                PacketRouting obj = new PacketRouting();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: PacketRouting.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #16
0
    /// <summary>
    /// 装载包
    /// </summary>
    /// <param name="pkType"></param>
    /// <param name="packName"></param>
    /// <param name="OnPacketLoadDone">包装载完成通知 包名,包路由对象</param>
    /// <param name="OnPacketLoadingProgress">包装载进度通知 包名,进度</param>
    public void LoadPacket(
        PackType pkType, string packName,
        Action <string, PacketRouting> OnPacketLoadDone,
        Action <string, float> OnPacketLoadingProgress,
        bool FoceLoadInternalPack = false//强制装内部包
        )
    {
        //已经装载完成,直接返回装载结果
        if (m_DonePacks.ContainsKey(packName))
        {
            OnPacketLoadDone(packName, m_DonePacks[packName]);
            return;
        }

        //当前处于下载中
        if (m_DownloadPacks.ContainsKey(packName))
        {
            DownloadInfo info = m_DownloadPacks[packName];
            if (OnPacketLoadDone != null && !info.listener_OnPacketLoadDone.Contains(OnPacketLoadDone))
            {
                info.listener_OnPacketLoadDone.Add(OnPacketLoadDone);
            }

            if (OnPacketLoadingProgress != null && !info.listener_OnPacketLoadingProgress.Contains(OnPacketLoadingProgress))
            {
                info.listener_OnPacketLoadingProgress.Add(OnPacketLoadingProgress);
            }
            return;
        }

        if (WorkInResourcesEditor)//当前处于资源编辑器中
        {
            Packet_ResourcesEditor bundle = new Packet_ResourcesEditor(packName);
            PacketRouting          pk     = AddPacket(packName, bundle);
            OnPacketLoadDone(packName, pk);
            return;
        }

        FileSystem.RES_LOCATION srcType;
        string devPackDir;
        string url = FileSystem.RrelativePath2Absolute_Packet(pkType == PackType.Res ? "pack_res" : "pack_script", packName + packetSuffix, false, out srcType, out devPackDir);

        //存在研发调试资源
        if (!string.IsNullOrEmpty(devPackDir))
        {
            Packet_Dir bundle = new Packet_Dir(devPackDir);
            AddPacket(packName, bundle);
        }

        switch (srcType)
        {
        case FileSystem.RES_LOCATION.fileSystem:    //文件系统
        {
            Packet_Dir bundle = new Packet_Dir(url);

            PacketRouting pk = AddPacket(packName, bundle);
            OnPacketLoadDone(packName, pk);
        }
        break;

        case FileSystem.RES_LOCATION.externalPack:    //外部包
        {
            //##############################################解密包数据############################################
            //DateTime startTime = DateTime.Now;
            long          FileSize;
            Packet_Bundle bundle;
            {
                byte[] encryptedData;

                using (FileStream kk = new FileStream(url, FileMode.Open))
                {
                    FileSize      = kk.Length;
                    encryptedData = new byte[FileSize];
                    kk.Read(encryptedData, 0, (int)kk.Length);
                }

                if (DefsDate.bundleJudge(encryptedData))
                {
                    bool li = DefsDate.SupDecToStream(encryptedData);
                    //Debug.Log("解密是否成功 = " + li);
                }
                //else
                //{
                //    Debug.Log("解密不了的包或非加密包");
                //}
                AssetBundle assetBundle = AssetBundle.LoadFromMemory(encryptedData);
                bundle = new Packet_Bundle(packName, assetBundle, FileSystem.RES_LOCATION.internalPack);
            }

            AutoGC(FileSize);

            //Debug.Log("加载时间 = " + (DateTime.Now - startTime).ToString());
            //##############################################解密包数据############################################

            //AssetBundle assetBundle = AssetBundle.LoadFromFile(url);

            //Packet_Bundle bundle = new Packet_Bundle(packName,assetBundle, FileSystem.RES_LOCATION.externalPack);
            PacketRouting pk = AddPacket(packName, bundle);
            if (FoceLoadInternalPack)
            {
                url = FileSystem.RrelativePath2Absolute_Packet(pkType == PackType.Res ? "pack_res" : "pack_script", packName + packetSuffix, false, out srcType, out devPackDir, true);
                LoadInternalPack(url, packName, OnPacketLoadDone, OnPacketLoadingProgress);
            }
            else
            {
                OnPacketLoadDone(packName, pk);
            }
        }
        break;

        case FileSystem.RES_LOCATION.internalPack:    //内部包
        {
            LoadInternalPack(url, packName, OnPacketLoadDone, OnPacketLoadingProgress);
        }
        break;
        }
    }
Example #17
0
    void IUpdate()
    {
        needRemoveDownloading.Clear();
        foreach (KeyValuePair <string, DownloadInfo> curr in m_DownloadPacks)
        {
            DownloadInfo info     = curr.Value;
            string       packName = curr.Key;
            if (info.www.error != null)
            {
                /*
                 * //加载失败时读取包内资源
                 * Packet_Sealed packet = new Packet_Sealed(packName);
                 * m_DonePacks.Add(packName, packet);
                 *
                 * foreach (IPacketLoadingListener listener in info.listeners)
                 *  listener.OnPacketLoadDone(packName, packet);
                 *
                 * needRemoveDownloading.Add(packName);
                 */
                if (m_DonePacks.ContainsKey(packName))//存在研发目录
                {
                    PacketRouting pk = m_DonePacks[packName];
                    foreach (var OnPacketLoadDone in info.listener_OnPacketLoadDone)
                    {
                        OnPacketLoadDone(packName, pk);
                    }
                }
                else
                {
                    Debug.LogError("包装载失败 " + packName);
                    Debug.Log("包装载失败路径 " + info.www.url);
                    foreach (var OnPacketLoadDone in info.listener_OnPacketLoadDone)
                    {
                        OnPacketLoadDone(packName, null);
                    }
                }
                needRemoveDownloading.Add(packName);
            }
            else if (info.www.isDone)
            {
                //Debug.Log("内部包加载完成" + packName);

                //##############################################解密包数据############################################
                byte[] encryptedData = info.www.bytes;
                //DateTime startTime = DateTime.Now;
                Packet_Bundle bundle;
                if (DefsDate.bundleJudge(encryptedData))
                {
                    bool li = DefsDate.SupDecToStream(encryptedData);
                    //Debug.Log("解密是否成功 = " + li);
                    AssetBundle assetBundle = AssetBundle.LoadFromMemory(encryptedData);
                    bundle = new Packet_Bundle(packName, assetBundle, FileSystem.RES_LOCATION.internalPack);
                }
                else
                {
                    //Debug.Log("解密不了的包或非加密包");
                    bundle = new Packet_Bundle(packName, info.www.assetBundle, FileSystem.RES_LOCATION.internalPack);
                }
                //Debug.Log("加载时间 = " + (DateTime.Now - startTime).ToString());
                //##############################################解密包数据############################################

                PacketRouting pk = AddPacket(packName, bundle);

                foreach (var OnPacketLoadDone in info.listener_OnPacketLoadDone)
                {
                    OnPacketLoadDone(packName, pk);
                }

                needRemoveDownloading.Add(packName);
            }
            else
            {
                foreach (var OnPacketLoadingProgress in info.listener_OnPacketLoadingProgress)
                {
                    OnPacketLoadingProgress(packName, info.www.progress);
                }
            }
        }

        if (needRemoveDownloading.Count > 0)
        {
            int size = 0;
            foreach (string packName in needRemoveDownloading)
            {
                size += m_DownloadPacks[packName].www.bytes.Length;
                m_DownloadPacks[packName].www.Dispose();
                m_DownloadPacks.Remove(packName);
            }

            AutoGC(size);
        }
    }