Exemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="handleOnLoadComplete"></param>
        /// <returns></returns>
        public IEnumerator AsynLoad(Action <Object> handleOnLoadComplete)
        {
            while (true)
            {
                if (m_GameObject != null)
                {
                    if (handleOnLoadComplete != null)
                    {
                        handleOnLoadComplete(m_GameObject);
                    }
                    yield break;
                }

                try
                {
                    m_GameObject = Resources.LoadAssetAtPath(m_strPath, typeof(GameObject)) as GameObject;
                    if (m_GameObject == null)
                    {
                        BTDebug.Warning(string.Format("Editor Load {0} Failed, Record Path:{1}", m_strName, m_strPath), "RESOURCE");
                    }
                }
                catch (System.Exception ex)
                {
                    BTDebug.ExceptionEx(ex);
                }
                yield return(null);

                if (handleOnLoadComplete != null)
                {
                    handleOnLoadComplete(m_GameObject);
                }

                yield break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 开始请求
        /// </summary>
        /// <param name="strURL"></param>
        /// <param name="handleOnResponse"></param>
        /// <param name="postForm"></param>
        /// <param name="objSessionRequest"></param>
        /// <returns></returns>
        public bool StartGet(string strURL, HandleHTTPOnResponse handleOnResponse, WWWForm postForm = null, System.Object objSessionRequest = null)
        {
            if (m_bIsRequesting == true)
            {
                return(false);
            }
            try
            {
                m_WWWWorker = new WWW(strURL);
            }
            catch (System.Exception ex)
            {
                BTDebug.ExceptionEx(ex);
            }

            if (m_WWWWorker == null)
            {
                return(false);
            }
            m_HandleOnResponse  = handleOnResponse;
            m_ObjSessionRequest = objSessionRequest;
            m_bIsRequesting     = true;

            return(true);
        }
Exemplo n.º 3
0
    /// <summary>
    /// 加载数据
    /// </summary>
    /// <param name="dataType"></param>
    /// <param name="handleOnLoadComplete"></param>
    /// <param name="handleOnLoadError"></param>
    /// <param name="bClearIfLoaded"></param>
    /// <returns></returns>
    public bool StartLoadData(Type dataType, Action handleOnLoadComplete, Action <string> handleOnLoadError, bool bClearIfLoaded = false)
    {
        if (dataType == null)
        {
            return(false);
        }
        bool bRet         = false;
        Type gameDataType = GetGameDataCollectionType(dataType.BaseType);

        if (gameDataType == null)
        {
            BTDebug.Warning(string.Format("Load DataType:{0} Not AssignableFrom GameData", dataType.Name), "DATA");
            return(false);
        }

        if (mLoadedGameDataList.Contains(dataType))
        {
            if (bClearIfLoaded == true)
            {
                ClearData(dataType);
            }
            else
            {
                BTDebug.Warning(string.Format("Dup Load DataType:{0} ", dataType.Name), "DATA");
                return(false);
            }
        }

        System.Reflection.MethodInfo methodInfo = gameDataType.GetMethod(
            cStrGameDataLoadMethodName,
            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

        if (methodInfo == null)
        {
            BTDebug.Warning(string.Format("DataType:{0} No {1} Method", dataType.Name, cStrGameDataLoadMethodName), "DATA");
            return(false);
        }
        try
        {
            Object[] paramArray = { handleOnLoadComplete, handleOnLoadError };
            bRet = (bool)methodInfo.Invoke(null, paramArray);
        }
        catch (System.Exception ex)
        {
            BTDebug.ExceptionEx(ex);
            bRet = false;
        }
        if (bRet == true)
        {
            mLoadedGameDataList.Add(dataType);
        }
        return(bRet);
    }
Exemplo n.º 4
0
 /// <summary>
 /// 从流中读取数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="memStream"></param>
 /// <param name="rOutT"></param>
 /// <returns></returns>
 public static bool ReadPBFromStream <T>(MemoryStream memStream, ref T rOutT) where T : class
 {
     if (memStream == null)
     {
         return(false);
     }
     try
     {
         rOutT = ProtoBuf.Serializer.Deserialize <T>(memStream);
     }
     catch (System.Exception ex)
     {
         BTDebug.ExceptionEx(ex);
         rOutT = null;
     }
     return(true);
 }
Exemplo n.º 5
0
    /// <summary>
    /// 清除数据
    /// </summary>
    /// <param name="dataType"></param>
    /// <returns></returns>
    public bool ClearData(Type dataType)
    {
        if (mLoadedGameDataList == null)
        {
            return(false);
        }
        if (mLoadedGameDataList.Contains(dataType) == false)
        {
            return(false);
        }
        Type gameDataType = GetGameDataCollectionType(dataType.BaseType);

        if (gameDataType == null)
        {
            return(false);
        }
        System.Reflection.MethodInfo methodInfo = gameDataType.GetMethod(
            cStrGameDataClearMethodName,
            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

        if (methodInfo == null)
        {
            BTDebug.Warning(string.Format("DataType:{0} No {1} Method", dataType.Name, cStrGameDataClearMethodName), "DATA");
            return(false);
        }

        bool bRet = false;

        try
        {
            bRet = (bool)methodInfo.Invoke(null, null);
        }
        catch (System.Exception ex)
        {
            BTDebug.ExceptionEx(ex);
            bRet = false;
        }
        if (bRet == true)
        {
            mLoadedGameDataList.Remove(dataType);
        }
        return(bRet);
    }
Exemplo n.º 6
0
        protected static string GetDataFileKey()
        {
            var fileInfo = typeof(U).GetField(strFieldNameFileKey);

            if (fileInfo == null)
            {
                return(string.Empty);
            }
            string strFileKye = string.Empty;

            try
            {
                strFileKye = fileInfo.GetValue(null) as string;
            }
            catch (System.Exception ex)
            {
                BTDebug.ExceptionEx(ex);
                strFileKye = string.Empty;
            }
            return(strFileKye);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 将PB写入流
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="memStream"></param>
 /// <param name="objT"></param>
 /// <returns></returns>
 public static bool WritePBToStream <T>(ref MemoryStream memStream, T objT) where T : class
 {
     if (objT == null)
     {
         return(false);
     }
     if (memStream == null)
     {
         memStream = new MemoryStream();
     }
     try
     {
         ProtoBuf.Serializer.Serialize <T>(memStream, objT);
     }
     catch (System.Exception ex)
     {
         BTDebug.ExceptionEx(ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 8
0
            /// <summary>
            /// 触发回调
            /// </summary>
            /// <param name="objParam"></param>
            /// <returns></returns>
            public bool TriggerHandle(System.Object objParam)
            {
                if (CheckEventParamType(objParam) == false)
                {
                    BTDebug.Warning("Trigger Event With An Param Not Fit", "ACTION");
                    return(false);
                }

#if BTDEBUG
                m_cpuProfiler.StartNewCall();
#endif
                if (m_Handle == null)
                {
                    return(true);
                }
                Delegate[] delArray = m_Handle.GetInvocationList();
                Int32      nSize    = delArray == null ? 0 : delArray.Length;
                for (Int32 i = 0; i < nSize; ++i)
                {
                    try
                    {
                        HandleObjectAction handle = (HandleObjectAction)delArray[i];
                        if (handle == null)
                        {
                            continue;
                        }
                        handle(objParam);
                    }
                    catch (System.Exception ex)
                    {
                        BTDebug.ExceptionEx(ex);
                    }
                }
#if BTDEBUG
                m_cpuProfiler.EndCall();
#endif
                return(true);
            }