/// <summary> /// 创建音乐盒子 /// </summary> /// <param name="aiUid"></param> private void CreateSoundBox(ulong aiUid) { if (aiUid <= 0 || m_AISoundBoxs.ContainsKey(aiUid)) { /// TODO. /// or play sound box begin music Debug.LogError("aiUid is 0 or Plot repeated trigger the Invaded2"); return; } SpacecraftEntity AI = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)aiUid); if (AI) { Npc npc = AI.GetNPCTemplateVO(); if (npc.Behavior > 0) { PlotBehavior plotBehavior = m_CfgEternityProxy.PlotBehaviorsByKey((uint)npc.Behavior); if (plotBehavior.FightBeginSound > 0) { GameObject soundBox = WwiseManager.CreatTAkAmbientSphereBox((int)plotBehavior.FightBeginSound, (int)plotBehavior.FightEndSound); soundBox.transform.position = AI.GetRootTransform().position; float scale = plotBehavior.SoundBoxSize; soundBox.transform.localScale = new Vector3(scale, scale, scale); m_AISoundBoxs.Add(aiUid, soundBox); } } } }
/// <summary> /// 根据死亡延时创建宝箱 /// </summary> public void CreateDropItemByDeath(ulong key, SpacecraftEntity spe) { Debug.Log("CreateDropItemByDeath key:" + key + " SpacecraftEntity:" + spe); m_SpacecraftEntityDic.Add(key, spe); Npc npcVO = spe.GetNPCTemplateVO(); CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; Model model = cfgEternityProxy.GetModel(npcVO.Model); int ruinTime = model.RuinTime; if (ruinTime > 0) { UIManager.Instance.StartCoroutine(DelayToCreateDropItemByDeath(key, spe, ruinTime / 1000.0f)); } else { CreateDropItem((uint)key, spe, 2); } /// TODO.宝藏特殊处理 /// 服务器创建后立马死亡,没有死亡特效 ///if (spe.GetHeroType() == KHeroType.htPreicous) ///{ /// CreateDropItem((uint)key, spe, 2); ///} ///else ///{ /// UIManager.Instance.StartCoroutine(DelayToCreateDropItemByDeath(key, spe)); ///} ///CreateDropItem((uint)key, spe, 2); }
/// <summary> /// 寻找大矿及其附属矿 /// </summary> /// <returns></returns> private ModelInfo[] FindSubsidiaryMine() { List <ModelInfo> target = new List <ModelInfo>(); ModelInfo mine = new ModelInfo(); mine.perfab = m_CfgEternityProxy.GetModel(m_NearestTarget.GetNPCTemplateVO().Model).AssetName; mine.position = Vector3.zero; mine.rotation = Vector3.zero; mine.scale = Vector3.one; target.Add(mine); m_TargetList.Add(m_NearestTarget.UId()); Transform mainShip = m_NearestTarget.GetSkinRootTransform(); foreach (SpacecraftEntity ship in m_GameplayProxy.GetEntities <SpacecraftEntity>(KHeroType.htMine)) { if (ship.GetHeroType() != KHeroType.htMine) { continue; } if (ship.GetCurrentState().GetMainState() == EnumMainState.Dead) { continue; } if (ship.GetAttribute(AttributeName.kHP) <= 0) { continue; } if (ship.m_EntityFatherOwnerID == m_NearestTarget.UId()) { m_TargetList.Add(ship.UId()); ModelInfo model = new ModelInfo(); model.perfab = m_CfgEternityProxy.GetModel(ship.GetNPCTemplateVO().Model).AssetName; Transform curr = ship.GetSkinRootTransform(); Vector3 localPoint = mainShip.InverseTransformPoint(curr.TransformPoint(Vector3.zero)); model.position = localPoint; model.rotation = curr.localEulerAngles; model.scale = Vector3.one; target.Add(model); } } return(target.ToArray()); }
/// <summary> /// 播放入侵2效果(专门给区域-精英战用的) /// </summary> private void PlayInvadedTwo(ulong aiUid) { if (aiUid <= 0) { return; } SpacecraftEntity AI = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)aiUid); if (AI) { Npc npc = AI.GetNPCTemplateVO(); if (npc.Behavior > 0) { PlotBehavior plotBehavior = m_CfgEternityProxy.PlotBehaviorsByKey((uint)npc.Behavior); /// 特效 string fightBeginFx = plotBehavior.FightBeginFx; if (!string.IsNullOrEmpty(fightBeginFx)) { SpacecraftEntity main = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID()); m_AIActionEffect = EffectManager.GetInstance().CreateEffect(fightBeginFx, EffectManager.GetEffectGroupNameInSpace(true)); m_AIActionEffect.transform.SetParent(main.GetSkinRootTransform(), false); m_AIActionEffect.SetCreateForMainPlayer(true); /// 特效声音 if (plotBehavior.FightBeginFxSound > 0) { WwiseUtil.PlaySound((int)plotBehavior.FightBeginFxSound, false, null); } } /// HUD if (Enum.TryParse(plotBehavior.FightBeginHud, out UIPanel panelName)) { MSG_WarningHUDInfo info = new MSG_WarningHUDInfo(); info.languageId = plotBehavior.FightBeginHudText; info.time = plotBehavior.FightBeginHudTime; UIManager.Instance.OpenPanel(panelName, info); } CreateSoundBox(aiUid); if (plotBehavior.FightBeginVideo > 0) { SendNotification((int)plotBehavior.FightBeginVideo); } } } }
/// <summary> /// 更新目标点 /// </summary> /// <param name="view">敌方点</param> /// <param name="distance">距离</param> /// <param name="main">主角</param> /// <param name="target">目标</param> private void UpdateTarget(RectTransform view, float distance, SpacecraftEntity main, SpacecraftEntity target) { if (!view.gameObject.activeSelf) { view.gameObject.SetActive(true); view.Find("Image_Enemy").gameObject.SetActive(true); } Vector3 position = target.transform.position - main.transform.position; Vector3 direction = new Vector3(position.x, 0, position.z).normalized *distance; view.anchoredPosition = new Vector2(direction.x, direction.z); Image img = view.Find("Image_Enemy").GetComponent <Image>(); KHeroType heroType = target.GetHeroType(); /// 玩家不再npc表 /// 先用指定ID if (heroType == KHeroType.htPlayer) { UIUtil.SetIconImage(img, TableUtil.GetIconBundle(PLAYER_MAP_ICON), TableUtil.GetIconAsset(PLAYER_MAP_ICON)); } else { Npc npc = target.GetNPCTemplateVO(); uint mapIcon = npc.MapIcon; if (mapIcon != 0) { /// TODO. /// 暂无考虑:同一NPC不同时刻改变阵营时,是否需要显示不同图标 UIUtil.SetIconImage(img, TableUtil.GetIconBundle(mapIcon), TableUtil.GetIconAsset(mapIcon)); } else { view.gameObject.SetActive(false); view.Find("Image_Enemy").gameObject.SetActive(false); } } }
/// <summary> /// 更新视图 /// </summary> protected override void Update() { if (!IsDead() && !IsWatchOrUIInputMode() && !IsLeaping()) { //GameplayProxy sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; //SpacecraftEntity main = sceneProxy.GetEntityById<SpacecraftEntity>(sceneProxy.GetMainPlayerUID()); if (m_MainEntity == null) { m_MainEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID()); } if (!m_MainEntity) { return; } List <SpacecraftEntity> entitys = m_GameplayProxy.GetEntities <SpacecraftEntity>(); //按距离排序 entitys.Sort((a, b) => { Vector3 distanceA = a.transform.position - m_MainEntity.transform.position; Vector3 distanceB = b.transform.position - m_MainEntity.transform.position; return((int)(distanceB.sqrMagnitude - distanceA.sqrMagnitude)); }); bool isInSpace = IsInSpace(); for (int i = 0; i < entitys.Count; i++) { SpacecraftEntity entity = entitys[i]; KHeroType heroType = entity.GetHeroType(); Vector3 titleOffset = Vector3.zero; float visibilityDistance = GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP; //忽略自已 // if (entity == main) // continue; //忽略不需要显示的NPC if (heroType != KHeroType.htPlayer) { Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID()); if (entityVO.Display == 0) { continue; } if (entityVO.HeroHeaderLength >= 3) { titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2)); } visibilityDistance = entityVO.MissionTargetHiddenDistance * (isInSpace ? GameConstant.METRE_PER_UNIT : 1); } //忽略死亡的( 除了矿石 ) if (heroType != KHeroType.htMine && heroType != KHeroType.htPreicous && (entity.GetAttribute(AttributeName.kHP) <= 0 || entity.GetCurrentState().GetMainState() == EnumMainState.Dead)) { continue; } if (entity.m_EntityFatherOwnerID > 0 && heroType == KHeroType.htMine) { continue; } //忽略不支持的 RectTransform template = GetTemplate(m_MainEntity, entity); if (!template) { continue; } //忽略过远的 float distance = (entity.transform.position - m_MainEntity.transform.position).magnitude; if (entity.GetHeroType() == KHeroType.htMine && distance > entity.GetNPCTemplateVO().TriggerRange) { continue; } distance = distance * GameConstant.METRE_PER_UNIT; if (distance >= visibilityDistance) { continue; } //忽略屏幕外的 Vector3 screenPosition = Camera.main.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset)); if (!(screenPosition.z > Camera.main.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= Camera.main.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight)) { continue; } Vector2 anchoredPosition; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Root, screenPosition, m_Camera, out anchoredPosition)) { Transform templatePool = m_TemplateToPool[template]; uint uid = entity.GetUId(); bool isNew = false; EntityView info; if (m_UIDToRectTranform1.ContainsKey(uid)) { info = m_UIDToRectTranform1[uid]; m_UIDToRectTranform1.Remove(uid); m_UIDToRectTranform2[uid] = info; } else { RectTransform view = templatePool.childCount > 0 ? templatePool.GetChild(0).GetComponent <RectTransform>() : Object.Instantiate(template, m_Root); view.SetParent(m_Root); view.transform.SetAsLastSibling(); view.gameObject.SetActive(true); info = new EntityView() { uid = uid, view = view, viewPool = templatePool }; m_UIDToRectTranform2[uid] = info; isNew = true; OnTargetCreate(entity, view); } OnTargetUpdate(m_MainEntity, entity, info.view, anchoredPosition, distance, visibilityDistance, m_MouseMoved, isNew); } } } m_MouseMoved = false; //回收无效的 foreach (EntityView info in m_UIDToRectTranform1.Values) { info.view.SetParent(info.viewPool); } m_UIDToRectTranform1.Clear(); Dictionary <uint, EntityView> tmp = m_UIDToRectTranform1; m_UIDToRectTranform1 = m_UIDToRectTranform2; m_UIDToRectTranform2 = tmp; }
/// <summary> /// 查找最近的矿物 /// </summary> /// <returns>找到的矿物</returns> private SpacecraftEntity FindNearestTarget() { m_NearestTargetList.Clear(); float distance = float.MaxValue; SpacecraftEntity target = null; foreach (SpacecraftEntity ship in m_GameplayProxy.GetEntities <SpacecraftEntity>(KHeroType.htMine)) { if (ship.GetHeroType() != KHeroType.htMine) { continue; } if (ship.GetCurrentState().GetMainState() == EnumMainState.Dead) { continue; } if (ship.GetAttribute(AttributeName.kHP) <= 0) { continue; } if (ship.m_EntityFatherOwnerID > 0) { continue; } float magnitude = (ship.transform.position - m_MainSpacecraftEntity.transform.position).sqrMagnitude; if ((ship.transform.position - m_MainSpacecraftEntity.transform.position).magnitude < ship.GetNPCTemplateVO().TriggerRange) { target = ship; m_NearestTargetList.Add(ship); } } if (m_NearestTargetList.Count > 1) //重叠区域 { if (m_CurrentTarget != null) { if (m_CurrentTarget.m_EntityFatherOwnerID > 0) { m_CurrentTarget = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_CurrentTarget.m_EntityFatherOwnerID); } if (m_NearestTargetList.Contains(m_CurrentTarget)) { target = m_CurrentTarget; } } else { if (m_NearestTargetLast == null) { for (int i = 0; i < m_NearestTargetList.Count; i++) { float magnitude = (m_NearestTargetList[i].transform.position - m_MainSpacecraftEntity.transform.position).sqrMagnitude; if (magnitude < distance) { distance = magnitude; target = m_NearestTargetList[i]; } } } else { target = m_NearestTargetLast; } } } else { if (target && (target.transform.position - m_MainSpacecraftEntity.transform.position).magnitude > target.GetNPCTemplateVO().TriggerRange) { target = null; } } return(target); }
/// <summary> ///保存玩家是否进入战斗状态(加入仇恨列表) /// </summary> public void SavePlayerInBattle(bool f) { m_PlayerInBattle = f; if (f) { PlayForeWarnVoice(true); if (!IsInAIArea()) { int soundId = 0; /// 在导演中 if (m_CurrentAIUid > 0) { SpacecraftEntity aiEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)m_CurrentAIUid); if (aiEntity) { Npc npc = aiEntity.GetNPCTemplateVO(); if (npc.SoundFightBegin > 0) { soundId = (int)npc.SoundFightBegin; } } } else if (CanPalyNormalBattle()) { soundId = (int)SoundID.CombatOpen; } if (soundId != 0) { WwiseUtil.PlaySound(soundId, false, null); } } else { WwiseUtil.PlaySound((int)SoundID.AIAreaCombat, false, null); if (m_AIBossState.ContainsKey(m_CurrentAIUid) && m_AIBossState[m_CurrentAIUid].m_AIPlotState == AIPlotState.CallingBossSuccess) { WwiseUtil.PlaySound((int)SoundID.AIAreaCallingBossSuccess, false, null); } } SetPlayerState(PlayerAIState.InBattleState); } else { if (!IsInAIArea()) { int soundId = 0; if (m_CurrentAIUid > 0) { SpacecraftEntity aiEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)m_CurrentAIUid); if (aiEntity) { Npc npc = aiEntity.GetNPCTemplateVO(); if (npc.SoundFightBegin > 0) { soundId = (int)npc.SoundFightEnd; } } } else if (CanPalyNormalBattle()) { soundId = (int)SoundID.CombatEnd; } if (soundId != 0) { WwiseUtil.PlaySound(soundId, false, null); } } } }
/// <summary> /// 更新 /// </summary> protected override void Update() { bool visibleOld = GetTransform().gameObject.activeSelf; bool visibleNew = !IsWatchOrUIInputMode() && !IsDead() && !IsLeaping(); if (visibleNew != visibleOld) { GetTransform().gameObject.SetActive(visibleNew); } if (!visibleNew) { return; } GameplayProxy proxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity main = proxy.GetEntityById <SpacecraftEntity>(proxy.GetMainPlayerUID()); if (main != null) { m_Arrow.localEulerAngles = new Vector3(0, 0, -main.transform.eulerAngles.y); m_Viewport.localEulerAngles = new Vector3(0, 0, -Camera.main.transform.eulerAngles.y); int index = 0; float maxDistance = m_RangeImage.rect.width / 2; List <SpacecraftEntity> entitys = proxy.GetEntities <SpacecraftEntity>(); for (int i = 0; i < entitys.Count; i++) { SpacecraftEntity entity = entitys[i]; /// 过滤掉主角 if (entity != main) { float distance = Vector3.Distance(entity.transform.position, main.transform.position) * GameConstant.METRE_PER_UNIT; /// 是否更新小地图 bool update = false; /// 玩家没有npc,不考虑贴边显示 if (entity.GetHeroType() == KHeroType.htPlayer) { update = distance < GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP; } else { Npc npc = entity.GetNPCTemplateVO(); bool overView = npc.OverView; if (overView) { distance = Mathf.Min(distance, GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP); update = true; } else if (distance < GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP) { update = true; } } if (update) { if (index >= m_ImageView.childCount) { Object.Instantiate(m_Enemy, m_ImageView); } m_ImageView.GetChild(index).localEulerAngles = new Vector3(0, 0, 0); UpdateTarget(m_ImageView.GetChild(index).GetComponent <RectTransform>(), maxDistance * (distance / GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP), main, entity); index++; } } } for (int i = index; i < m_ImageView.childCount; i++) { m_ImageView.GetChild(i).gameObject.SetActive(false); } } }
/// <summary> /// 更新所有任务标记 /// </summary> protected override void Update() { if (!IsDead() && !IsWatchOrUIInputMode() && !IsLeaping()) { float w = m_Flags.rect.width; float h = m_Flags.rect.height; m_ScaleBox.localScale = w > h ? new Vector3(1, h / w, 1) : new Vector3(w / h, 1, 1); GameplayProxy sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity main = sceneProxy.GetEntityById <SpacecraftEntity>(sceneProxy.GetMainPlayerUID()); if (!main) { return; } List <SpacecraftEntity> entitys = sceneProxy.GetEntities <SpacecraftEntity>(); for (int i = 0; i < entitys.Count; i++) { SpacecraftEntity entity = entitys[i]; KHeroType heroType = entity.GetHeroType(); Vector3 titleOffset = Vector3.zero; //忽略自已 if (entity == main) { continue; } //忽略不需要显示的NPC if (heroType != KHeroType.htPlayer) { Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID()); //if (entityVO.Display == 0) //continue; if (entityVO.HeroHeaderLength >= 3) { titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2)); } } //忽略死亡的( 除了矿石 ) if (heroType != KHeroType.htMine && heroType != KHeroType.htPreicous && (entity.GetAttribute(AttributeName.kHP) <= 0 || entity.GetCurrentState().GetMainState() == EnumMainState.Dead)) { continue; } //忽略不支持的 RectTransform template = GetTemplate(main, entity); if (!template) { continue; } //忽略过远的 float distance = (entity.transform.position - main.transform.position).magnitude; if (entity.GetHeroType() == KHeroType.htMine && distance > entity.GetNPCTemplateVO().TriggerRange) { continue; } distance = distance * GameConstant.METRE_PER_UNIT; if (distance >= GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP) { continue; } //忽略屏幕内的 Vector3 screenPosition = Camera.main.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset)); if (screenPosition.z > Camera.main.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= Camera.main.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight) { // is in screen } else { //忽略屏幕外的 Transform templatePool = m_TemplateToPool[template]; uint uid = entity.GetUId(); EntityView info; if (m_UIDToRectTranform1.ContainsKey(uid)) { info = m_UIDToRectTranform1[uid]; m_UIDToRectTranform1.Remove(uid); m_UIDToRectTranform2[uid] = info; } else { RectTransform view = templatePool.childCount > 0 ? templatePool.GetChild(0).GetComponent <RectTransform>() : Object.Instantiate(template, m_Flags); view.SetParent(m_Flags); view.transform.SetAsLastSibling(); view.gameObject.SetActive(true); info = new EntityView() { uid = uid, view = view, viewPool = templatePool }; m_UIDToRectTranform2[uid] = info; OnTargetCreate(view, entity); } OnTargetUpdate(info.view, entity.transform.position, distance); } } } //回收无效的 foreach (EntityView info in m_UIDToRectTranform1.Values) { info.view.SetParent(info.viewPool); } m_UIDToRectTranform1.Clear(); Dictionary <uint, EntityView> tmp = m_UIDToRectTranform1; m_UIDToRectTranform1 = m_UIDToRectTranform2; m_UIDToRectTranform2 = tmp; }