Exemple #1
0
        /// <summary>
        /// 调用操作接收器
        /// </summary>
        /// <param name="pararms">参数</param>
        /// <returns>返回是否中断剩余事件分发/返回Action是否成功</returns>
        public GameActionCallResult CallActionHandler(params object[] pararms)
        {
            GameActionCallResult result = null;
            object rso = null;

            if (Type == GameHandlerType.CSKernel)
            {
                result = DelegateActionHandler(pararms);
            }
            else if (Type == GameHandlerType.LuaModul)
            {
                result = LuaModulHandlerFunc.RunActionHandler(pararms);
            }
            else if (Type == GameHandlerType.LuaFun)
            {
                if (LuaSelf != null)
                {
                    rso = LuaFunction.call(LuaSelf, pararms);
                }
                else
                {
                    rso = LuaFunction.call(pararms);
                }
                if (rso != null && rso is GameActionCallResult)
                {
                    result = rso as GameActionCallResult;
                }
            }
            if (result == null)
            {
                return(GameActionCallResult.CreateActionCallResult(false));
            }
            return(result);
        }
Exemple #2
0
 public GameActionCallResult RunActionHandler(params object[] pararms)
 {
     if (initSuccess)
     {
         GameActionCallResult rs = null;
         object   rso            = null;
         object[] pararms2       = new object[pararms.Length + handlerArgs.Length];
         for (int i = 0; i < pararms.Length; i++)
         {
             pararms2[i] = pararms[i];
         }
         for (int i = 0; i < handlerArgs.Length; i++)
         {
             pararms2[i + pararms.Length] = handlerArgs[i];
         }
         if (targetObject != null)
         {
             rso = handlerFunc.call(targetObject.LuaSelf, pararms2);
         }
         else
         {
             rso = handlerFunc.call(pararms2);
         }
         if (rso is GameActionCallResult)
         {
             rs = rso as GameActionCallResult;
         }
         return(rs);
     }
     return(null);
 }
Exemple #3
0
        /// <summary>
        /// 调用操作
        /// </summary>
        /// <param name="name">目标操作名称</param>
        /// <param name="param">调用参数</param>
        /// <returns>返回操作调用结果,如果未找到操作,则返回 GameActionCallResult.FailResult </returns>
        public GameActionCallResult CallAction(string name, params object[] param)
        {
            GameActionCallResult result = GameActionCallResult.FailResult;

            if (string.IsNullOrEmpty(name))
            {
                GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "CallAction name 参数未提供");
                return(result);
            }

            GameAction gameAction;

            if (IsActionRegistered(name, out gameAction))
            {
                return(CallAction(gameAction, param));
            }
            else
            {
                GameErrorManager.SetLastErrorAndLog(GameError.NotRegister, TAG, "操作 {0} 未注册", name);
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 调用操作
        /// </summary>
        /// <param name="action">目标操作实例</param>
        /// <param name="param">调用参数</param>
        /// <returns>返回操作调用结果,如果未找到操作,则返回 GameActionCallResult.FailResult </returns>
        public GameActionCallResult CallAction(GameAction action, params object[] param)
        {
            GameErrorManager.LastError = GameError.None;
            GameActionCallResult result = GameActionCallResult.FailResult;

            if (action == null)
            {
                GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "CallAction action 参数为空");
                return(result);
            }
            if (action.Name == GameAction.Empty.Name)
            {
                GameErrorManager.SetLastErrorAndLog(GameError.Empty, TAG, "CallAction action 为空");
                return(result);
            }
            if (action.CallTypeCheck != null && action.CallTypeCheck.Length > 0)
            {
                //参数类型检查
                int argCount = action.CallTypeCheck.Length;
                if (argCount > param.Length)
                {
                    GameLogger.Warning(TAG, "操作 {0} 至少需要 {1} 个参数", action.Name, argCount);
                    return(result);
                }
                string allowType, typeName;
                for (int i = 0; i < argCount; i++)
                {
                    allowType = action.CallTypeCheck[i];
                    if (param[i] == null)
                    {
                        if (allowType != "null" &&
                            (!allowType.Contains("/") && !allowType.Contains("null")))
                        {
                            GameLogger.Warning(TAG, "操作 {0} 参数 {1} 不能为null", action.Name, i);
                            return(result);
                        }
                    }
                    else
                    {
                        typeName = param[i].GetType().Name;
                        if (allowType != typeName &&
                            (!allowType.Contains("/") && !allowType.Contains(typeName)))
                        {
                            GameLogger.Warning(TAG, "操作 {0} 参数 {1} 类型必须是 {2}", action.Name, i, action.CallTypeCheck[i]);
                            return(result);
                        }
                    }
                }
            }

            param = LuaUtils.LuaTableArrayToObjectArray(param);

            //GameLogger.Log(TAG, "CallAction {0} -> {1}", action.Name, StringUtils.ValueArrayToString(param));

            result = action.GameHandler.CallActionHandler(param);
            if (!result.Success)
            {
                GameLogger.Warning(TAG, "操作 {0} 执行失败 {1}", action.Name, GameErrorManager.LastError);
            }

            return(result);
        }