private void ReadLevelDefCompatibility(XmlNode nodeCompatibility) { foreach (XmlNode node in nodeCompatibility.ChildNodes) { switch (node.Name) { case "MinVersion": if (!int.TryParse(node.InnerText, out levelCompatibilityInfo.MinVersion)) { GameLogger.Warning(TAG, "Bad MinVersion : {0}", node.InnerText); } break; case "TargetVersion": if (!int.TryParse(node.InnerText, out levelCompatibilityInfo.TargetVersion)) { GameLogger.Warning(TAG, "Bad TargetVersion : {0}", node.InnerText); } break; case "MaxVersion": if (!int.TryParse(node.InnerText, out levelCompatibilityInfo.MaxVersion)) { GameLogger.Warning(TAG, "Bad MaxVersion : {0}", node.InnerText); } break; } } }
/// <summary> /// 加载模组包中的音乐资源 /// </summary> /// <param name="assets">资源路径(模组包:音乐路径)</param> /// <returns></returns> public AudioClip LoadAudioResource(string assets) { string[] names = assets.Split(':'); GameMod mod = ModManager.FindGameModByAssetStr(names[0]); if (mod == null) { GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为未找到模组包 {1}", assets, names[0]); GameErrorManager.LastError = GameError.NotRegister; return(null); } if (mod.LoadStatus != GameModStatus.InitializeSuccess) { GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为模组包 {1} ({2}) 未初始化", assets, names[0], mod.Uid); GameErrorManager.LastError = GameError.NotInitialize; return(null); } AudioClip clip = mod.GetAsset <AudioClip>(names[1]); if (clip != null) { clip.name = GamePathManager.GetFileNameWithoutExt(names[1]); } else { GameLogger.Warning(TAG, "未找到声音文件 {0} ,在模组包 {1}", assets, names[0]); GameErrorManager.LastError = GameError.AssetsNotFound; } return(clip); }
public CharacterAnimation(Animation anim) { if (anim == null) { GameLogger.Warning("Animation is null."); return; } _animation = anim; }
//球管理 //============================ /// <summary> /// 注册球 /// </summary> /// <param name="name">球类型名称</param> /// <param name="ball">附加了GameBall组件的球实例</param> private bool RegisterBall(string name, GameBall ball) { if (ball == null) { GameLogger.Warning(TAG, "要注册的球 {0} 为空", name); GameErrorManager.LastError = GameError.ParamNotProvide; return(false); } return(RegisterBall(name, ball, ball.Pieces)); }
/// <summary> /// 添加元素 /// </summary> protected void AddElement(int key, ConfigTable element) { if (_tables.ContainsKey(key)) { GameLogger.Warning($"{this.GetType().Name} Element is already exsit, Key is {key}"); return; } _tables.Add(key, element); }
private bool OnCommandLoadMod(string keyword, string fullCmd, string[] args) { GameMod mod = LoadGameMod(args[0], args.Length >= 2 ? args[1] == "true" : false); if (mod == null) { GameLogger.Warning(TAG, "模组 {0} 加载失败", args[0]); return(false); } GameLogger.Log(TAG, "模组已加载 {0} ({1})", mod.PackageName, mod.Uid); return(true); }
/// <summary> /// 获取模组包是否正在加载 /// </summary> /// <param name="packageName">模组包名</param> /// <returns>返回操作是否成功</returns> public bool IsGameModLoading(string packageName) { GameMod mod = FindGameMod(packageName); if (mod == null) { GameLogger.Warning(TAG, "无法卸载模组 (UID: {0}) ,因为没有加载", packageName); GameErrorManager.LastError = GameError.NotRegister; return(false); } return(mod.LoadStatus == GameModStatus.Loading); }
/// <summary> /// 获取数据,如果不存在报警告 /// </summary> public ConfigTable GetTable(int key) { if (_tables.ContainsKey(key)) { return(_tables[key]); } else { GameLogger.Warning($"Faild to get tab. File is {this.GetType().Name}, key is {key}"); return(null); } }
/// <summary> /// 卸载模组包 /// </summary> /// <param name="modUid"></param> /// <returns></returns> public bool UnInitializeLoadGameMod(string modPackageName) { GameMod m = FindGameMod(modPackageName); if (m == null) { GameLogger.Warning(TAG, "无法卸载模组包 {0} ,因为没有注册", modPackageName); GameErrorManager.LastError = GameError.NotRegister; return(false); } return(UnInitializeLoadGameMod(m)); }
/// <summary> /// 执行模组包代码 /// </summary> /// <param name="modUid">模组包UID</param> /// <returns>返回操作是否成功</returns> public bool RunGameMod(string packageName) { GameMod m = FindGameMod(packageName); if (m == null) { GameLogger.Warning(TAG, "无法执行化模组包 {0} ,因为没有加载", packageName); GameErrorManager.LastError = GameError.NotRegister; return(false); } return(RunGameMod(m)); }
/// <summary> /// 卸载模组包 /// </summary> /// <param name="modUid"></param> /// <returns></returns> public bool UnInitializeLoadGameMod(GameMod m) { if (m.LoadStatus == GameModStatus.InitializeSuccess) { m.UnLoad(); return(true); } else { GameLogger.Warning(TAG, "无法卸载模组包 {0} ,因为没有加载", m.PackageName); GameErrorManager.LastError = GameError.NotInitialize; return(false); } }
public static string GetLanguage(string key) { var table = CfgUILanguage.Instance.GetConfigTable(key.GetHashCode()); if (table != null) { return(table.Lang); } else { GameLogger.Warning($"Not found UILanguage {key}"); return(key); } }
/// <summary> /// 根据全路径获取UI元素 /// </summary> public Transform GetUIElement(string path) { if (string.IsNullOrEmpty(path)) { return(null); } Transform result = null; if (_runtimeDic.TryGetValue(path, out result) == false) { GameLogger.Warning($"Not found ui element : {path}"); } return(result); }
public LevelFloorGroup RegisterFloorType(LevelFloorGroup floorGroup) { LevelFloorGroup g = FindFloorType(floorGroup.GroupName); if (g == null) { g = floorGroup; floorGroups.Add(g); } else { GameLogger.Warning(TAG, "RegisterFloorType : floor type {0} alreday exists ! ", floorGroup.GroupName); } return(g); }
/// <summary> /// 执行模组包代码 /// </summary> /// <param name="modUid">模组包UID</param> /// <returns>返回操作是否成功</returns> public bool RunGameMod(GameMod m) { if (m == null) { GameErrorManager.LastError = GameError.ParamNotProvide; return(false); } if (m.LoadStatus == GameModStatus.InitializeSuccess) { return(m.Run()); } GameLogger.Warning(TAG, "无法执行化模组包 {0},因为没有初始化", m.PackageName); GameErrorManager.LastError = GameError.NotInitialize; return(false); }
/// <summary> /// 加载模组包 /// </summary> /// <param name="packagePath">模组包路径</param> /// <param name="initialize">是否立即初始化模组包</param> /// <returns>返回模组包UID</returns> public GameMod LoadGameMod(string packagePath, bool initialize = true) { GameMod mod = FindGameModByPath(packagePath); if (mod != null) { GameLogger.Warning(TAG, "Mod \"{0}\" already registered, skip", packagePath); return(mod); } //路径处理 if (StringUtils.IsUrl(packagePath)) { GameLogger.Error(TAG, "不支持从 URL 加载模组包 \"{0}\" ,请将其先下载至 streamingAssetsPath 后再加载。", packagePath); return(null); } //处理路径至mod文件夹路径 if (!File.Exists(packagePath) && !GamePathManager.IsAbsolutePath(packagePath)) { packagePath = GamePathManager.GetResRealPath("mod", packagePath); } if (!File.Exists(packagePath)) { GameLogger.Error(TAG, "Mod file \"{0}\" not exists", packagePath); return(null); } mod = new GameMod(packagePath, this); if (!mod.Init()) { return(null); } if (!gameMods.Contains(mod)) { gameMods.Add(mod); } GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_REGISTERED, "*", mod.PackageName, mod); GameLogger.Log(TAG, "Register mod \"{0}\"", packagePath); if (initialize) { mod.Load(this); } return(mod); }
/// <summary> /// 根据全路径获取UI组件 /// </summary> public T GetUIComponent <T>(string path) where T : UnityEngine.Component { Transform element = GetUIElement(path); if (element == null) { return(null); } Component component = element.GetComponent <T>(); if (component == null) { GameLogger.Warning($"Not found ui component : {path}, {typeof(T)}"); } return(component as T); }
/// <summary> /// 移除模组包 /// </summary> /// <param name="modUid">模组包UID</param> /// <returns>返回操作是否成功</returns> public bool UnLoadGameMod(string packageName) { GameMod mod = FindGameMod(packageName); if (mod == null) { GameLogger.Warning(TAG, "无法卸载模组 {0},因为没有加载", packageName); GameErrorManager.LastError = GameError.NotRegister; return(false); } mod.Destroy(); gameMods.Remove(mod); GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_UNLOAD, "*", mod.PackageName, mod); return(true); }
/// <summary> /// 根据全路径获取UI组件 /// </summary> public Component GetUIComponent(string path, string typeName) { Transform element = GetUIElement(path); if (element == null) { return(null); } Component component = element.GetComponent(typeName); if (component == null) { GameLogger.Warning($"Not found ui component : {path}, {typeName}"); } return(component); }
/// <summary> /// 取消注册球 /// </summary> /// <param name="name">球类型名称</param> private bool UnRegisterBall(string name) { GameBall targetBall = GetRegisteredBall(name); if (targetBall != null) { ballTypes.Remove(targetBall); targetBall.Destroy(); return(true); } else { GameLogger.Warning(TAG, "无法取消注册球 {0} 因为它没有注册", name); GameErrorManager.LastError = GameError.NotRegister; return(false); } }
/// <summary> /// 注册球 /// </summary> /// <param name="name">球类型名称</param> /// <param name="ball">附加了GameBall组件的球实例</param> /// <param name="pieces">球碎片组</param> private bool RegisterBall(string name, GameBall ball, GameObject pieces) { if (ball == null) { GameLogger.Warning(TAG, "要注册的球 {0} 为空", name); GameErrorManager.LastError = GameError.ParamNotProvide; return(false); } if (GetRegisteredBall(name) != null) { GameLogger.Log(TAG, "球 {0} 已经注册", name); GameErrorManager.LastError = GameError.AlredayRegistered; return(false); } ball.TypeName = name; if (pieces != null) { ball.Pieces = pieces; } ballTypes.Add(ball); if (pieces != null) { GameBallPiecesControl ballPiecesControl = pieces.GetComponent <GameBallPiecesControl>(); if (ballPiecesControl != null) { ballPiecesControl.Ball = ball; ball.BallPiecesControl = ballPiecesControl; } if (pieces.activeSelf) { pieces.SetActive(false); } } if (ball.gameObject.activeSelf) { ball.gameObject.SetActive(false); } return(ball.Init()); }
// ------------------------------------------------------------------------------------------------------------------- private void FixedUpdate() { // TODO: Temporary solution for co-existance of single/multi player if (m_state == State.RunningSinglePlayer) { if (m_commandQueueMine.Count > 0) { m_commandQueueMine.Dequeue().Execute(); } UpdateSimulation(); return; } else if (m_state == State.RunningMultiplayer) { if ((m_simulationCount % m_lockStepSize) == 0) // Time to perform lockstep (if ready) { // Do no simulation and do not update simulation count if we were not ready if (!m_confirmedCommands.ReadyForNextTurn(m_lockStepTurnId) || !m_pendingCommands.ReadyForNextTurn(m_lockStepTurnId)) { logger.Warning("Lockstep turn failed, too fast?"); return; } m_confirmedCommands.NewTurn(); m_pendingCommands.NewTurn(); if (m_lockStepTurnId >= 3) { m_pendingCommands.ExecuteCurrentCommands(); } m_lockStepTurnId++; logger.PopContext(); logger.PushContext("T" + m_lockStepTurnId); HandleOneOfMyCommands(); } UpdateSimulation(); } }
/// <summary> /// 运行命令 /// </summary> /// <param name="cmd">命令字符串</param> /// <returns>返回是否成功</returns> public bool RunCommand(string cmd) { if (string.IsNullOrEmpty(cmd)) { return(false); } StringSpliter sp = new StringSpliter(cmd, ' ', true); if (sp.Count >= 1) { foreach (CmdItem cmdItem in commands) { if (cmdItem.Keyword == sp.Result[0]) { //arg if (cmdItem.LimitArgCount > 0 && sp.Count < cmdItem.LimitArgCount - 1) { GameLogger.Log(TAG, "命令 {0} 至少需要 {1} 个参数", sp.Result[0], cmdItem.LimitArgCount); return(false); } List <string> arglist = new List <string>(sp.Result); arglist.RemoveAt(0); //Kernel hander if (cmdItem.KernelCallback != null) { return(cmdItem.KernelCallback(sp.Result[0], cmd, arglist.ToArray())); } //Modul handler if (!string.IsNullOrEmpty(cmdItem.Handler) && cmdItem.HandlerInternal != null) { return(cmdItem.HandlerInternal.RunCommandHandler(sp.Result[0], sp.Count, cmd, arglist.ToArray())); } } } GameLogger.Warning(TAG, "未找到命令 {0}", sp.Result[0]); } return(false); }
private GameMod LoadModInEditor(string pathInEditorMods, string packageName) { #if UNITY_EDITOR GameLogger.Warning(TAG, "LoadModInEditor : {0} ({1})", packageName, pathInEditorMods); GameMod mod = null; TextAsset modDef = AssetDatabase.LoadAssetAtPath <TextAsset>(pathInEditorMods + "/ModDef.xml"); if (modDef == null) { GameLogger.Warning(TAG, "模组无效 {0} ,未找到 ModDef.xml ", pathInEditorMods); GameErrorManager.LastError = GameError.FileNotFound; return(null); } mod = new GameMod(pathInEditorMods, this, packageName); mod.IsEditorPack = true; mod.ForceLoadEditorPack(modDef); return(mod); #else throw new System.Exception("LoadModInEditor can only use in editor mode!"); #endif }
private void DoInit() { ModManager = ((IModManager)GameManager.GetManager("ModManager")); if (!LuaInit()) { enabled = false; GameLogger.Warning(TAG + ":" + Name, "LuaObject {0} disabled because load error", Name); } else { if (awakeCalledBeforeInit && awake != null) { awake(self); } if (startCalledBeforeInit && start != null) { start(self, gameObject); } } }
/// <summary> /// 取消注册操作 /// </summary> /// <param name="name">操作名称</param> public void UnRegisterAction(string name) { if (string.IsNullOrEmpty(name)) { GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "UnRegisterAction name 参数未提供"); return; } GameAction gameAction; if (IsActionRegistered(name, out gameAction)) { gameAction.Dispose(); actions.Remove(name); } else { GameLogger.Warning(TAG, "操作 {0} 未注册", name); GameErrorManager.LastError = GameError.NotRegister; } }
/// <summary> /// 注册操作 /// </summary> /// <param name="name">操作名称</param> /// <param name="handler">接收器</param> /// <param name="callTypeCheck">函数参数检查,数组长度规定了操作需要的参数, /// 组值是一个或多个允许的类型名字,例如 UnityEngine.GameObject System.String 。 /// 如果一个参数允许多种类型,可使用/分隔。 /// 如果不需要参数检查,也可以为null,则当前操作将不会进行类型检查 /// </param> /// <returns>返回注册的操作实例,如果注册失败则返回 null ,请查看 LastError 的值</returns> public GameAction RegisterAction(string name, GameHandler handler, string[] callTypeCheck) { if (string.IsNullOrEmpty(name)) { GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "RegisterAction name 参数未提供"); return(null); } if (handler == null) { GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "RegisterAction handler 参数未提供"); return(null); } if (IsActionRegistered(name)) { GameLogger.Warning(TAG, "操作 {0} 已注册", name); GameErrorManager.LastError = GameError.AlredayRegistered; return(null); } GameAction gameAction = new GameAction(name, handler, callTypeCheck); actions.Add(name, gameAction); return(gameAction); }
private void InitiazeChildElement(UIElement uIElement, Dictionary <string, GameHandler> handlers, string[] initialProps) { //初始化子元素的事件接收器 Dictionary <string, GameHandler> lateInitHandlers = new Dictionary <string, GameHandler>(); foreach (string key in handlers.Keys) { string[] sp = key.Split(':'); if (sp.Length >= 2 && sp[0] == uIElement.Name) { try { lateInitHandlers.Add(sp[1], handlers[key]); } catch (System.ArgumentException e) { GameLogger.Warning(TAG, "Add event for {0} -> {1} failed {2}", key, handlers[key].Name, e.Message); continue; } } } if (lateInitHandlers.Count > 0) { uIElement.InitHandlers(lateInitHandlers); } if (initialProps != null) { //初始化一些初始属性参数 foreach (string v in initialProps) { string[] sp = v.Split(':'); if (sp.Length >= 3 && sp[0] == uIElement.Name) { uIElement.SetProperty(sp[1], sp[2]); } } } }
public static void Init(ILRuntime.Runtime.Enviorment.AppDomain appdomain) { // 注册委托 appdomain.DelegateManager.RegisterMethodDelegate <float>(); appdomain.DelegateManager.RegisterMethodDelegate <bool>(); appdomain.DelegateManager.RegisterMethodDelegate <List <object> >(); appdomain.DelegateManager.RegisterMethodDelegate <ILTypeInstance>(); appdomain.DelegateManager.RegisterMethodDelegate <MotionFramework.Network.INetworkPackage>(); appdomain.DelegateManager.RegisterMethodDelegate <MotionFramework.Event.IEventMessage>(); appdomain.DelegateManager.RegisterMethodDelegate <MotionFramework.Resource.AssetOperationHandle>(); appdomain.DelegateManager.RegisterMethodDelegate <MotionFramework.Resource.SceneInstance>(); appdomain.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>(); appdomain.DelegateManager.RegisterMethodDelegate <Google.Protobuf.Adapter_IMessage.Adaptor>(); appdomain.DelegateManager.RegisterFunctionDelegate <Google.Protobuf.Adapter_IMessage.Adaptor>(); // 注册委托转换器 appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) => { return(new UnityEngine.Events.UnityAction(() => { ((Action)act)(); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <float> >((act) => { return(new UnityEngine.Events.UnityAction <float>((arg0) => { ((Action <float>)act)(arg0); })); }); appdomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction <bool> >((act) => { return(new UnityEngine.Events.UnityAction <bool>((arg0) => { ((Action <bool>)act)(arg0); })); }); // 注册值类型绑定器 appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Vector2), new Vector2Binder()); appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Vector3), new Vector3Binder()); appdomain.RegisterValueTypeBinder(typeof(UnityEngine.Quaternion), new QuaternionBinder()); // 执行CLR绑定 //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appDomain); Type classCLRBinding = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings"); if (classCLRBinding != null) { var method = classCLRBinding.GetMethod("Initialize"); method.Invoke(null, new object[] { appdomain }); } else { GameLogger.Warning("ILRuntime not generated binding scripts."); } // 注册适配器 Google.Protobuf.Adapter_IMessage adaptor = new Google.Protobuf.Adapter_IMessage(); appdomain.RegisterCrossBindingAdaptor(adaptor); // 注册LitJson LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); }
/// <summary> /// 通过包名加载模组包 /// </summary> /// <param name="packageName">模组包包名</param> /// <param name="initialize">是否立即初始化模组包</param> /// <returns>返回模组包UID</returns> public GameMod LoadGameModByPackageName(string packageName, bool initialize = true) { GameMod mod = FindGameMod(packageName); if (mod != null) { GameLogger.Warning(TAG, "Mod \"{0}\" already registered, skip", packageName); return(mod); } string pathInMods = GamePathManager.GetResRealPath("mod", packageName + ".ballance"); string pathInCore = GamePathManager.GetResRealPath("core", packageName + ".ballance"); string pathInEditorMods = GamePathManager.DEBUG_MOD_FOLDER + "/" + packageName; if (false) { } #if UNITY_EDITOR //编辑器直接加载模组 else if (DebugSettings.Instance.ModLoadInEditor && File.Exists(pathInEditorMods + "/ModDef.xml")) { mod = LoadModInEditor(pathInEditorMods, packageName); } #endif else if (File.Exists(pathInMods)) { mod = new GameMod(pathInMods, this, packageName); } else if (File.Exists(pathInCore)) { mod = new GameMod(pathInCore, this, packageName); } #if UNITY_EDITOR else if (DebugSettings.Instance.ModLoadInEditor == false && File.Exists(pathInEditorMods + "/ModDef.xml")) { mod = LoadModInEditor(pathInEditorMods, packageName); } #endif else { GameLogger.Warning(TAG, "无法通过包名加载模组包 {0} ,未找到文件", packageName); GameErrorManager.LastError = GameError.FileNotFound; return(null); } if (!mod.Init()) { return(null); } if (!gameMods.Contains(mod)) { gameMods.Add(mod); } GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_REGISTERED, "*", mod.PackageName, mod); GameLogger.Log(TAG, "Register mod \"{0}\" {1}", packageName, (mod.IsEditorPack ? "(Editor Pack)" : "")); if (initialize) { mod.Load(this); } return(mod); }