Esempio n. 1
0
    private static void CompressAssetBundles(string strPath)
    {
        string strMD5Path = strPath.Replace(Application.dataPath, "");

        strMD5Path = strMD5Path.Substring(1);

        string strOldMD5 = GetBundleMD5(strMD5Path);
        string strNewMD5 = CUility.GetFileMD5(strPath);

        if (null == strOldMD5 || strOldMD5 != strNewMD5)
        {
            string strCompress  = GetCompressPath(strPath);
            string strDirectory = strCompress.Substring(0, strCompress.LastIndexOf('/'));
            if (!Directory.Exists(strDirectory))
            {
                Directory.CreateDirectory(strDirectory);
            }
            GzipHelper.GZipFile(strPath, strCompress);
        }

        MD5Info cMD5 = new MD5Info();

        cMD5.strMD5  = strNewMD5;
        cMD5.strPath = strMD5Path.Replace("AssetBundles", "StreamingAssets");

        m_lstNewFileMD5.Add(cMD5);
    }
Esempio n. 2
0
    public static GameConfig LoadGameConfig()
    {
        GameConfig gameCfg = (GameConfig)CUility.DeSerializerObjectFromAssert(cConfigPath, typeof(GameConfig));

        string gameCfgPath = Application.persistentDataPath + "/" + cConfigPath;

        if (System.IO.File.Exists(gameCfgPath))
        {
            gameCfg = (GameConfig)CUility.DeSerializerObject(gameCfgPath, typeof(GameConfig));
        }
        return(gameCfg);
    }
Esempio n. 3
0
    static void GenCompressAssetBundles()
    {
        m_lstOldFileMD5 = null;
        m_lstNewFileMD5 = null;
        string strMD5Cfg = m_strCompressDirectoryPath + "MD5Config.xml";

        if (File.Exists(strMD5Cfg))
        {
            m_lstOldFileMD5 = (List <MD5Info>)CUility.DeSerializerObject(strMD5Cfg, typeof(List <MD5Info>));
        }

        m_lstNewFileMD5 = new List <MD5Info>();

        IterFile(m_strBundleDirectoryPath, CompressAssetBundles);

        CUility.SerializerObject(strMD5Cfg, m_lstNewFileMD5);
    }
Esempio n. 4
0
    public static uint BytesToUInt(byte[] numInByte)
    {
        string strResId = CUility.PbBytesToString(numInByte);

        return(Convert.ToUInt32(strResId));
    }
Esempio n. 5
0
    public override IEnumerator SysEnterCo()
    {
        SetProgress(0);

#if !UNITY_EDITOR || BUNDLE_MODE
#if UNITY_IPHONE
        string strMd5ConfigURL = GetURLRoot() + "/IOSAssetsMD5Config.xml";
#elif UNITY_EDITOR
        string strMd5ConfigURL = GetURLRoot() + "/StreamingAssets/AndroidAssetsMD5Config.xml";
#else
        string strMd5ConfigURL = GetURLRoot() + "/AndroidAssetsMD5Config.xml";
#endif

        WWW www = new WWW(strMd5ConfigURL);
        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError("下载资源配置出错!");
            yield break;
        }

        List <MD5Info> lstFileMD5 = (List <MD5Info>)CUility.DeSerializerObjectFromBuff(www.bytes, typeof(List <MD5Info>));

        www.Dispose();

        for (int i = 0; i != lstFileMD5.Count; ++i)
        {
            MD5Info md5Info      = lstFileMD5[i];
            string  strLocalPath = Application.persistentDataPath + md5Info.strPath.Substring(md5Info.strPath.IndexOf('/'));
            bool    bNeedUpdate  = true;
            if (File.Exists(strLocalPath))
            {
                string strFileMd5 = CUility.GetFileMD5(strLocalPath);
                if (strFileMd5 == md5Info.strMD5)
                {
                    bNeedUpdate = false;
                }
            }
            if (bNeedUpdate)
            {
                string strURL = GetURL(md5Info.strPath);
                www = new WWW(strURL);
                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    Debug.LogError("下载资源出错!");
                    yield break;
                }

                byte[] arrData      = GzipHelper.GzipDecompress(www.bytes);
                string strDirectory = strLocalPath.Substring(0, strLocalPath.LastIndexOf('/'));
                if (!Directory.Exists(strDirectory))
                {
                    Directory.CreateDirectory(strDirectory);
                }
                using (FileStream destFile = File.Open(strLocalPath, FileMode.Create, FileAccess.Write))
                {
                    destFile.Write(arrData, 0, arrData.Length);
                    destFile.Close();
                }
                www.Dispose();
            }
        }
        CResourceSys.Instance.GenManifestBundle();
#endif

        SetProgress(1.0f);

#if !UNITY_EDITOR
#if UNITY_IPHONE
        string strCompressDir = Application.dataPath + "/StreamingAssets/IOSAssetsCompress";
#else
        string strCompressDir = Application.dataPath + "/StreamingAssets/AndroidAssetsCompress";
#endif
        if (Directory.Exists(strCompressDir))
        {
            Directory.Delete(strCompressDir, true);
        }
#endif

        CGameRoot.SwitchToState(EStateType.GamePreLoading);

        yield return(null);
    }
Esempio n. 6
0
    private IEnumerator _SwitchToStateCo(EStateType newState)
    {
        mWillStateType = newState;
        if (mOldState == newState)
        {
            //Debug.LogWarning("SwitchState oldState == newState: " + newState);
            yield break;
        }

        CUility.Log("Begin: SwitchToStateCo " + newState);

        try
        {
            if (OnPreStateChange != null)
            {
                OnPreStateChange(newState, mOldState);
            }
        }
        catch (Exception ex)
        {
            CUility.LogError("Exception in OnPreStateChange: {0}", ex.ToString());
        }

        CGameState[] oldStates = mConfig.mStateMap[mOldState];
        CGameState[] newStates = mConfig.mStateMap[newState];

        int sameDepth = -1;

        while (sameDepth + 1 < newStates.Length && sameDepth + 1 < oldStates.Length &&
               newStates[sameDepth + 1] == oldStates[sameDepth + 1])
        {
            ++sameDepth;
        }
        //Debug.Log(sameDepth);

        //Debug.Log("Leave old system");
        List <CGameSystem> leaveSystems = new List <CGameSystem>();

        for (int i = oldStates.Length - 1; i > sameDepth; --i)
        {
            foreach (Type sysType in oldStates[i].mSystems)
            {
                leaveSystems.Add(mSystemMap[sysType]);
            }
        }

        foreach (CGameSystem leaveSystem in leaveSystems)
        {
            CUility.Log("Leave System {0}", leaveSystem.Name);
            try
            {
                leaveSystem._SysLeave();
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format("Exception in {1}'s SysLeave: {0}", ex.ToString(), leaveSystem.Name));
            }
        }

        CUility.Log("Leave System Finish");

        try
        {
            if (OnStateChange != null)
            {
                OnStateChange(newState, mOldState);
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(string.Format("Exception in OnStateChange: {0}", ex.ToString()));
        }

        CUility.Log("Start EnterSystem");

        //Debug.Log("Enter new system");
        List <CGameSystem> enterSystems = new List <CGameSystem>();

        for (int i = sameDepth + 1; i < newStates.Length; ++i)
        {
            foreach (Type sysType in newStates[i].mSystems)
            {
                if (!mSystemMap.ContainsKey(sysType))
                {
                    throw new Exception(string.Format("SystemMap.ContainsKey({0}) == false", sysType.Name));
                }

                mSystemMap[sysType].EnableInState = newStates[i].mStateType;
                enterSystems.Add(mSystemMap[sysType]);
            }
        }


        for (int i = 0; i < enterSystems.Count; ++i)
        //foreach (CGameSystem enterSystem in enterSystems)
        {
            CGameSystem enterSystem = enterSystems[i];

            CUility.Log("{0} SysEnter Start", enterSystem.Name);

            bool haveEnterCo = false;
            try
            {
                haveEnterCo = enterSystem._SysEnter();
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Format("Exception in {1}'s SysEnter: {0}", ex.ToString(), enterSystem.Name));
            }

            if (haveEnterCo)
            {
                yield return(StartCoroutine(enterSystem.SysEnterCo()));
            }

            enterSystem._EnterFinish();

            //CLogSys.Log(ELogLevel.Verbose, ELogTag.GameRoot, string.Format("{0} SysEnter Finish", enterSystem.Name));
        }

        //Debug.Log("Add new system...............Finish");


        //Debug.Log("Remove old system once more");

        //加入了新系统之后,再给旧系统一次清理的机会。
        foreach (CGameSystem leaveSystem in leaveSystems)
        {
            leaveSystem.SysLastLeave();
        }

        //Debug.Log("Remove old system once more...............Finish");

        foreach (CGameSystem enterSystem in enterSystems)
        {
            try
            {
                enterSystem.OnStateChangeFinish();
            }
            catch (Exception ex)
            {
                Debug.LogError("Exception in OnStateChangeFinish: +" + ex.ToString());
            }
        }

        //Debug.Log(string.Format("Enter State {0} from {1}", newState, mOldState));

        mPreState = mOldState;
        mOldState = newState;

        try
        {
            if (OnPostStateChange != null)
            {
                OnPostStateChange(newState, mPreState);
            }
        }
        catch (Exception ex)
        {
            Debug.Log(string.Format("Exception in OnPostStateChange: " + ex.ToString()));
        }

        CUility.Log("End: SwitchToStateCo " + newState);
    }