public override void OnShow(object userData) { base.OnShow(userData); m_AircraftData = EntityData as AircraftData; if (m_AircraftData == null) { HotLog.Error("Aircraft data is invalid."); return; } RuntimeEntity.Name = Utility.Text.Format("Aircraft ({0})", RuntimeEntity.Id.ToString()); GameEntry.Entity.ShowThruster(m_AircraftData.ThrusterData); //显示推进器 //显示所有武器 List <WeaponData> weaponDatas = m_AircraftData.AllWeaponData; for (int i = 0; i < weaponDatas.Count; i++) { GameEntry.Entity.ShowWeapon(weaponDatas[i]); } //显示所有装甲 List <ArmorData> armorDatas = m_AircraftData.AllArmorData; for (int i = 0; i < armorDatas.Count; i++) { GameEntry.Entity.ShowArmor(armorDatas[i]); } }
public override void OnOpen(object userData) { //对话框数据 DialogParams dialogParams = (DialogParams)userData; if (dialogParams == null) { HotLog.Warning("DialogParams is invalid."); return; } DialogMode = dialogParams.Mode; RefreshDialogMode(); //信息 m_TitleText.text = dialogParams.Title; m_MessageText.text = dialogParams.Message; //暂停游戏 IsPauseGame = dialogParams.PauseGame; RefreshPauseGame(); UserData = dialogParams.UserData; //按钮文本和事件 RefreshConfirmText(dialogParams.ConfirmText); m_OnClickConfirm = dialogParams.OnClickConfirm; RefreshCancelText(dialogParams.CancelText); m_OnClickCancel = dialogParams.OnClickCancel; RefreshOtherText(dialogParams.OtherText); m_OnClickOther = dialogParams.OnClickOther; }
//更新 public virtual void Update(float elapseSeconds, float realElapseSeconds) { if (!IsGameOver && m_MyAircraft != null && m_MyAircraft.IsDead) { IsGameOver = true; HotLog.Debug("玩家死亡,游戏结束"); return; } }
public override void OnOpen(object userData) { m_ProcedureMenu = userData as ProcedureMenu; if (m_ProcedureMenu == null) { HotLog.Warning("ProcedureMenu is invalid when open MenuForm."); return; } }
public override void OnShow(object userData) { base.OnShow(userData); m_BulletData = EntityData as BulletData; if (m_BulletData == null) { HotLog.Error("Bullet data is invalid."); return; } }
/// <summary> /// 实体显示 /// </summary> /// <param name="userData">用户自定义数据</param> public override void OnShow(object userData) { base.OnShow(userData); m_TargetableObjectData = EntityData as TargetableObjectData; if (m_TargetableObjectData == null) { HotLog.Error("Targetable object data is invalid -> m_TargetableObjectData == null"); return; } }
/// <summary> /// 实体显示 /// </summary> /// <param name="userData">用户自定义数据</param> public virtual void OnShow(object userData) { EntityData = userData as EntityData; if (EntityData == null) { HotLog.Error("Entity data is invalid -> m_EntityData == null"); return; } RuntimeEntity.Position = EntityData.Position; RuntimeEntity.Rotation = EntityData.Rotation; }
//加载场景更新的回调 private void OnLoadSceneUpdate(object sender, GameEventArgs e) { LoadSceneUpdateEventArgs args = e as LoadSceneUpdateEventArgs; if (args.UserData != this) { return; } HotLog.Info("Load scene '{0}' update, progress '{1}'.", args.SceneAssetName, args.Progress.ToString("P2")); }
//加载场景时加载依赖资源的回调 private void OnLoadSceneDependencyAsset(object sender, GameEventArgs e) { LoadSceneDependencyAssetEventArgs ne = e as LoadSceneDependencyAssetEventArgs; if (ne.UserData != this) { return; } HotLog.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName, ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString()); }
//加载场景失败的回调 private void OnLoadSceneFailure(object sender, GameEventArgs e) { LoadSceneFailureEventArgs args = e as LoadSceneFailureEventArgs; if (args.UserData != this) { return; } HotLog.Error("Load scene '{0}' failure, error message '{1}'.", args.SceneAssetName, args.ErrorMessage); }
//点击退出按钮 public void OnQuitButtonClick() { HotLog.Info("On Click Quit Button"); //打开对话框 GameEntry.UI.OpenDialog(new DialogParams() { Mode = 2, Title = GameEntry.Localization.GetString("AskQuitGame.Title"), Message = GameEntry.Localization.GetString("AskQuitGame.Message"), OnClickConfirm = delegate(object userData) { UnityGameFrame.Runtime.GameEntry.Shutdown(ShutdownType.Quit); }, }); }
public override void OnShow(object userData) { base.OnShow(userData); m_AsteroidData = EntityData as AsteroidData; if (m_AsteroidData == null) { HotLog.Error("Asteroid data is invalid."); return; } m_RotateSphere = Random.insideUnitSphere; }
public static void Start(GameObject frameObj) { HotLog.Debug("热更新启动"); GlobalObj = frameObj; ObjectPool = new ObjectPoolManager(); HPBar = new HPBarComponent(); //注册回调函数 GameEntry.Hotfix.OnUpdate = Update; GameEntry.Hotfix.OnLateUpdate = LateUpdate; GameEntry.Hotfix.OnApplication = ApplicationQuit; }
private float m_ElapseSeconds = 0f; //记录时间 public override void OnShow(object userData) { base.OnShow(userData); m_EffectData = userData as EffectData; if (m_EffectData == null) { HotLog.Error("Effect data is invalid."); return; } m_ElapseSeconds = 0f; }
public static void ApplicationQuit() { try { ObjectPool.Shutdown(); ReferencePool.ClearAll(); HotLog.Debug("Hotfix ApplicationQuit..."); } catch (Exception) { throw; } }
public override void OnShow(object userData) { base.OnShow(userData); m_WeaponData = userData as WeaponData; if (m_WeaponData == null) { HotLog.Error("Weapon data is invalid."); return; } //挂载到拥有者实体上 GameEntry.Entity.AttachEntity(this, m_WeaponData.OwnerId, AttachPointName); }
public override void OnShow(object userData) { base.OnShow(userData); //装甲数据 m_ArmorData = userData as ArmorData; if (m_ArmorData == null) { HotLog.Error("Armor data is invalid."); return; } //绑定到拥有者实体上 GameEntry.Entity.AttachEntity(this, m_ArmorData.OwnerId, AttachPointName); }
//加载场景成功的回调 private void OnLoadSceneSuccess(object sender, GameEventArgs e) { LoadSceneSuccessEventArgs args = e as LoadSceneSuccessEventArgs; if (args.UserData != this) { return; } HotLog.Info("Load scene '{0}' OK.", args.SceneAssetName); if (m_BackgroundMusicId > 0) { GameEntry.Sound.PlayMusic(m_BackgroundMusicId); } m_IsChangeSceneComplete = true; //加载完成的标志位 }
//显示实体血条 public void ShowHPBar(Entity entity, float fromHPRatio, float toHPRatio) { if (entity == null) { HotLog.Warning("Entity is invalid."); return; } HPBarItem hpBarItem = GetActiveHPBarItem(entity); if (hpBarItem == null) { hpBarItem = CreateHPbarItem(); m_ListActiveHPBar.Add(hpBarItem); } hpBarItem.Init(entity, m_CachedCanvas, fromHPRatio, toHPRatio); }
private Canvas m_CachedCanvas = null; //画布 //这种方法后期可以抽象出去,例如使用接口、使用特性获取调用等 public HPBarComponent() { GameObject obj = new GameObject("HP Bar"); obj.transform.SetParent(HotfixEntry.GlobalObj.transform.Find("Customs")); (obj.AddComponent(typeof(ComponentView)) as ComponentView).Component = this; GameObject InstaceObj = new GameObject("HP Bar Instance"); InstaceObj.transform.SetParent(obj.transform); m_CachedCanvas = InstaceObj.AddComponent(typeof(Canvas)) as Canvas; m_CachedCanvas.renderMode = RenderMode.ScreenSpaceOverlay; CanvasScaler scaler = InstaceObj.AddComponent(typeof(CanvasScaler)) as CanvasScaler; scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.referenceResolution = new Vector2(1080, 1920); scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; scaler.matchWidthOrHeight = 0; m_HPBarInstanceRoot = InstaceObj.transform; if (m_HPBarInstanceRoot == null) { HotLog.Error("You must set HP bar instance root first."); return; } m_HPBarItemObjectPool = HotfixEntry.ObjectPool.CreateSingleSpawnObjectPool <HPBarItemObject>("HPBarItem", m_InstancePoolCapacity); m_ListActiveHPBar = new List <HPBarItem>(); GameEntry.Resource.LoadAsset(HotAssetUtility.GetUIItemsAsset("HPBarItem"), RuntimeConstant.AssetPriority.UIFormAsset, (assetName, asset, duration, userData) => { HotLog.Info("Load HPBarItem OK."); m_HPBarItemTemplate = asset as GameObject; }, //加载失败的回调 (assetName, status, errorMessage, userData) => { HotLog.Error("Can not load HPBarItem from '{0}' with error message '{1}'.", assetName, errorMessage); }); }
private int m_BackgroundMusicId = 0; //切换场景时的背景音乐 //流程进入回调 public override void OnEnter(IFsm <IProcedureManager> procedureOwner) { m_IsChangeSceneComplete = false; //订阅事件 GameEntry.Event.Subscribe(LoadSceneSuccessEventArgs.EventId, OnLoadSceneSuccess); GameEntry.Event.Subscribe(LoadSceneFailureEventArgs.EventId, OnLoadSceneFailure); GameEntry.Event.Subscribe(LoadSceneUpdateEventArgs.EventId, OnLoadSceneUpdate); GameEntry.Event.Subscribe(LoadSceneDependencyAssetEventArgs.EventId, OnLoadSceneDependencyAsset); //停止所有声音 GameEntry.Sound.StopAllLoadingSounds(); //停止正在加载所有声音 GameEntry.Sound.StopAllLoadedSounds(); //停止加载完成的声音 //隐藏所有实体 GameEntry.Entity.HideAllLoadingEntities(); //加载中的实体 GameEntry.Entity.HideAllLoadedEntities(); //加载完成的实体 //卸载所有场景 string[] loadedSceneAssetNames = GameEntry.Scene.GetLoadedSceneAssetNames(); for (int i = 0; i < loadedSceneAssetNames.Length; i++) { GameEntry.Scene.UnloadScene(loadedSceneAssetNames[i]); } //还原游戏进度 GameEntry.Base.ResetNormalGameSpeed(); //获取场景数据 int sceneId = procedureOwner.GetData <VarInt>(Constant.ProcedureData.NextSceneId).Value; m_ChangeToMenu = sceneId == MenuSceneId; //是否切换到菜单场景 IDataTable <DRScene> dtScene = GameEntry.DataTable.GetDataTable <DRScene>(); DRScene drScene = dtScene.GetDataRow(sceneId); if (drScene == null) { HotLog.Warning("Can not load scene '{0}' from data table.", sceneId.ToString()); return; } //加载场景 GameEntry.Scene.LoadScene(RuntimeAssetUtility.GetSceneAsset(drScene.AssetName), RuntimeConstant.AssetPriority.SceneAsset, this); m_BackgroundMusicId = drScene.BackgroundMusicId; }
private float m_InitPosition = 0f; //初始位置 public override void OnInit(object userData) { base.OnInit(userData); //画布大小 CanvasScaler canvasScaler = (CanvasScaler)RuntimeUIForm.GetComponentInParent(typeof(CanvasScaler)); if (canvasScaler == null) { HotLog.Warning("Can not find CanvasScaler component."); return; } //初始位置设置为高度的一半 m_InitPosition = -0.5f * canvasScaler.referenceResolution.x * Screen.height / Screen.width; ReferenceCollector collector = RuntimeUIForm.ReferenceCollector; m_RectTransform = (RectTransform)collector.Get("trans_Content", typeof(RectTransform)); (collector.Get("bt_Back", typeof(CommonButton)) as CommonButton).ComButtonAddClick(OnClickClose); }
/// <summary> /// 获取两个阵营之间的关系。 /// </summary> /// <param name="first">阵营一。</param> /// <param name="second">阵营二。</param> /// <returns>阵营间关系。</returns> public static RelationType GetRelation(CampType first, CampType second) { //第一阵营一定小于或等于第二阵营 if (first > second) { CampType temp = first; first = second; second = temp; } RelationType relationType; if (s_CampPairToRelation.TryGetValue(((int)first << 4) + (int)second, out relationType)) { return(relationType); } HotLog.Warning("Unknown relation between '{0}' and '{1}'.", first.ToString(), second.ToString()); return(RelationType.Unknown); }
private MyAircraft m_MyAircraft = null; //我的战机 //初始化 public virtual void Initialize() { //注册事件 GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess); GameEntry.Event.Subscribe(ShowEntityFailureEventArgs.EventId, OnShowEntityFailure); //滚动背景 SceneBackground = Object.FindObjectOfType <ScrollableBackground>(); if (SceneBackground == null) { HotLog.Warning("Can not find scene background."); return; } SceneBackground.VisibleBoundary.gameObject.GetOrAddComponent <HideByBoundary>(); //添加触发离开时隐藏实体 GameEntry.Entity.ShowMyAircraft(new MyAircraftData(GameEntry.Entity.GenerateSerialId(), 10000) { Name = "My Aircraft", Position = Vector3.zero }); IsGameOver = false; m_MyAircraft = null; }
public override void OnShow(object userData) { base.OnShow(userData); //缓存我的战机数据 m_MyAircraftData = userData as MyAircraftData; if (m_MyAircraftData == null) { HotLog.Error("My aircraft data is invalid."); return; } ScrollableBackground sceneBackground = (ScrollableBackground)Object.FindObjectOfType(typeof(ScrollableBackground)); if (sceneBackground == null) { HotLog.Warning("Can not find scene background."); return; } //创建移动区域 m_PlayerMoveBoundary = new Rect(sceneBackground.PlayerMoveBoundary.bounds.min.x, sceneBackground.PlayerMoveBoundary.bounds.min.z, sceneBackground.PlayerMoveBoundary.bounds.size.x, sceneBackground.PlayerMoveBoundary.bounds.size.z); }
private ProcedureMenu m_ProcedureMenu = null; //菜单流程管理 //点击开始游戏按钮 public void OnStartButtonClick() { HotLog.Info("On Click Start Button"); m_ProcedureMenu.StartGame(); }
//点击设置按钮 public void OnSettingButtonClick() { HotLog.Info("On Click Setting Button"); GameEntry.UI.OpenUIForm(UIFormID.SettingForm); }
//点击关于按钮 public void OnAboutButtonClick() { HotLog.Info("On Click About Button"); GameEntry.UI.OpenUIForm(UIFormID.AboutForm); }
protected virtual void OnShowEntityFailure(object sender, GameEventArgs e) { ShowEntityFailureEventArgs ne = e as ShowEntityFailureEventArgs; HotLog.Warning("Show entity failure with error message '{0}'.", ne.ErrorMessage); }