private void generateSkillsUI() { List <int> skill = GameEntityMgr.GetSelectedEntity()?.GetNowSkillSockets(); if (skill == null) { return; } int cnt = skill.Count; skillUI = new SkillUI[cnt]; for (int i = 0; i < cnt; i++) { GameObject skillUIGo = //poolRemote.CreatePrefab(SkillPrefabObj); PoolingSystem.Instance.GetOneClone_NotActive(prefab); Transform skillUIT = skillUIGo.transform; skillUIT.SetParent(this.transform); skillUIT.localScale = Vector3.one; skillUIT.localPosition = Vector3.zero; skillUIT.SetSiblingIndex(i); skillUI[i] = skillUIGo.GetComponent <SkillUI>(); //var data = xxxx int data = skill[i]; skillUI[i].SetModel(data); skillUIGo.SetActive(true); } GetComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.MinSize; }
IEnumerator playerUpdate() { while (!entityVisual.modelLoaded) { yield return(null); } while (BeAlive()) { pathSensor.TakeSample(this); if (pathSensor.IsDirty && pathSensor.Value) { currentPath?.Clear(); AcceptPathChange(); } if (currentPath == null || currentPath.Count == 0) { if (currentPath?.Count == 0) { currentPath = null; onReachDst(); entityVisual.SetAniStatus(EntityAnimStatus.Idle); if (GameEntityMgr.GetSelectedEntity() == this) { ShowEyeSight(); } } //yield return new WaitForSeconds(0.5f); yield return(new WaitForEndOfFrame()); } if (currentPath != null && currentPath.Count > 0) { if (controllRemote.PTiliMove(1)) { if (currentPath.Count == 1) { //yield return movefromApoint2Bpoint(currentPath[0], currentPath[0]); currentPath.RemoveAt(0); } else { ICell start = currentPath[0]; ICell next = currentPath[1]; yield return(movefromApoint2Bpoint(start, next)); currentPath.RemoveAt(0); } } else { currentPath.Clear(); } } } }
internal void UpdateUI() { Skill sk = GameCore.GetRegistServices <BattleService>().GetSkillByID(skillID); if (sk != null) { text.text = "技能 " + GameCore.GetRegistServices <BattleService>().GetSkillByID(skillID).desc; } selectBg.SetActive(GameEntityMgr.GetSelectedEntity().GetControllRemote().SelectedSkillID == skillID && sk != null); }
void Start() { GameEntityMgr.Instance.onSelectedEntityValueChange += (eventType) => { if (eventType == ValueChangeType.AutoSkillChange) { foreach (SkillUI ui in skillUI) { ui.selectBg?.SetActive(GameEntityMgr.GetSelectedEntity().GetControllRemote().SelectedSkillID == ui.GetData()); } } }; }
void Start() { if (text == null) { text = transform.Find("Text").GetComponent <Text>(); } btnSelectSkill?.onClick.AddListener(() => { if (valid) { GameEntityMgr.GetSelectedEntity().SelectSkill(skillID); } }); }
private void Start() { button2itemid.Add(s_item1.GetInstanceID(), 0); button2itemid.Add(s_item2.GetInstanceID(), 0); st_Daiji.onClick.AddListener(() => { doStrategy(GSNPCStrategy.Daiji); }); st_Jingjie.onClick.AddListener(() => { doStrategy(GSNPCStrategy.Jingjie); }); st_Autofight.onClick.AddListener(() => { doStrategy(GSNPCStrategy.AutoFight); }); st_BackToManual.onClick.AddListener(() => { GameEntityMgr.GetSelectedEntity()?.Back2Manual(); }); s_item1.onClick.AddListener(() => { startUseItem(button2itemid[s_item1.GetInstanceID()]); }); s_item2.onClick.AddListener(() => { startUseItem(button2itemid[s_item2.GetInstanceID()]); }); s_switchSkillList.onClick.AddListener(() => { GameEntity entity = GameEntityMgr.GetSelectedEntity(); if (entity == null) { return; } List <int> newSkills = entity.GetdifferentSkills(entity.GetNowSkillSockets()); entity.ChangeNowSkillSockets(newSkills); ScrollViewRemote remote = s_scroll.GetComponent <ScrollViewRemote>(); remote.UpdateUI(); }); }
internal void UpdateInfo() { if (GameEntityMgr.Instance == null || this.gameObject.activeInHierarchy == false) { return; } GameEntity selected = GameEntityMgr.GetSelectedEntity(); if (selected != null) { nonePlayer.SetActive(false); ScrollViewRemote remote = s_scroll.GetComponent <ScrollViewRemote>(); remote.UpdateUI(); entityname.text = selected.GetEntityName(); hpSlider.value = selected.GetControllRemote().GetHPPer(); magicSlider.value = selected.GetControllRemote().GetMagicPer(); } else { nonePlayer.SetActive(true); } }
private void doStrategy(GSNPCStrategy strategy) { GameEntityMgr.GetSelectedEntity()?.ChangeAutoPlayStrategy(strategy); }
void initUniRxPrograming() { RX_LastMoveFrom = new Vector2ReactiveProperty(CurrentPoint); RX_LastMoveTo = new Vector2ReactiveProperty(CurrentPoint); RX_currentPoint = new Vector2ReactiveProperty(CurrentPoint); RX_LastClickCell.Subscribe(_ => { RX_targetEntity.Value = null; }); //如何过滤过快的点击切换路径? //假若RX_LastClickCell的输入频率是 0.3s 内来了 10个数据(玩家0.3s内点击了10个可以移动的地方) //则以最后一个数据为准作为通知 RX_LastClickCell.Throttle(TimeSpan.FromSeconds(0.2f)).Subscribe(_ => { RX_PathChanged.Value = true; }); RX_currentPoint.Subscribe(point => { mapController.SetStartPoint(Vector2Int.CeilToInt(point)); }); RX_LastMoveTo.Subscribe((to) => { m_Transform.LookAt(HexCoords.GetHexVisualCoords(Vector2Int.CeilToInt(to))); RX_moveFromA2BPer.Value = 0; RX_moveSpeed.Value = 1; }); RX_LastMoveTo.Buffer(RX_LastMoveTo.Where(point => point == RX_currentPoint.Value).Throttle(TimeSpan.FromSeconds(C_TimeToReachOnePoint))).Subscribe(_ => { RX_moveSpeed.Value = 0; }); #region 控制移动 RX_moveFromA2BPer.Skip(1).Subscribe(per => { entityVisual.Run2(); Vector3 fromVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveFrom.Value)); Vector3 toVisualPos = Coords.PointToVisualPosition(Vector2Int.CeilToInt(RX_LastMoveTo.Value)); Vector3 v = Vector3.Lerp(fromVisualPos, toVisualPos, RX_moveFromA2BPer.Value); m_Transform.position = v; //float near_start_or_near_dst = -0.5f + per; if (per >= 0.5f) { RX_currentPoint.Value = RX_LastMoveTo.Value; } else { RX_currentPoint.Value = RX_LastMoveFrom.Value; } }); var idle = RX_moveSpeed.Where(speed => speed == 0); var confused = idle.Where(_ => { return(false); }); idle.Subscribe(_ => { entityVisual.Idle2(); }); #endregion //0 0.5 0.9 1 1 1 0 0.6 1 -> 0 0.5 0.9 1 0 0.6 1 RX_reachFragment = RX_moveFromA2BPer.DistinctUntilChanged(); RX_reachFragment.Subscribe(_ => { //Debug.Log(_); }); RX_reachFragment.Where(per => per == 1).Subscribe(_ => { RXEnterCellPoint(Vector2Int.CeilToInt(RX_currentPoint.Value)); } ); RX_moveFromA2BPer.Buffer(RX_moveFromA2BPer.Where(per => per == 1).Throttle(TimeSpan.FromSeconds(0.3f))) .Where(buffer => GameCore.GetGameStatus() == GameStatus.Run && buffer.Count >= 2).Subscribe(_ => { if (GameEntityMgr.GetSelectedEntity() == this) { ShowEyeSight(); } }); RX_PathChanged.Where(changed => changed).Subscribe(_ => { //allowMove = false; RX_PathChanged.Value = false; Disposable_movementTimeLine?.Dispose(); IList <ICell> path = mapController.CalculatePath(); //Disposable_movementTimeLine = Observable.FromCoroutine(MoveM).Subscribe(unit => Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path, tellmeHowToMove(UseForClickCellMove)); //Disposable_movementTimeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => //{ // return per; //}).Where(per => per >= 1).Where(per => //{ // if (!controllRemote.PTiliMove(1)) // { // Disposable_movementTimeLine.Dispose(); // return false; // } // return true; //}).StartWith(1).Subscribe(h => //{ // Debug.Log("reach and show next fragment"); // if (path.Count > 1) // { // RX_LastMoveFrom.Value = path[0].Point; // RX_LastMoveTo.Value = path[1].Point; // path.RemoveAt(0); // } // else // { // Disposable_movementTimeLine.Dispose(); // } //}); //if (path.Count > 0) //{ // //转变为 (1-2)-(2-3)-(3-4)-(4-5)队列 // var rawPath = path.ToObservable<ICell>(); // var skipheader = rawPath.Skip(1); // var from_to_pathset = rawPath.Zip(skipheader, (raw, skip) => // { // return new FromAndTo(raw.Point, skip.Point); // }); // //要求路线按每隔 XXs 发出1个,其中第一段希望立即发出 这个时间没有基于gamecore状态 // var timeLine = Observable.EveryUpdate().CombineLatest(RX_reachFragment, (frame, per) => // { // return per; // }).Where(per => per == 1); // Disposable_movementTimeLine = timeLine.Subscribe(async (__) => // { // var s = await from_to_pathset.ToYieldInstruction(); // Debug.Log(__ + s.from.ToString() + " " + s.to); // RX_LastMoveFrom.Value = s.from; // RX_LastMoveTo.Value = s.to; // }); // Disposable_movementTimeLine = timeLine.StartWith(1).Zip(from_to_pathset, (time, from_to) => // { // return new { from_to = from_to, per = time }; // }).Where(zip => zip.per == 1).Do(zip => // { // Debug.Log("change next "); // var from_to = zip.from_to; // RX_LastMoveFrom.Value = from_to.from; // RX_LastMoveTo.Value = from_to.to; // }, // () => // { // }).Subscribe(); //} }); RX_alive.Value = BeAlive(); var onDeath = RX_alive.Where(alive => !alive); onDeath.Subscribe(_ => { Disposable_moveFromA2BPer.Dispose(); }, () => { }); //检测当前选中的玩家和第一个被点击的非玩家对象 var getFrameStream = Observable.EveryUpdate(); var selectEntityStream = getFrameStream.Select(_ => GameEntityMgr.GetSelectedEntity()); // 1 0 2 0 1 var onSelectEntityChangedStream = selectEntityStream.DistinctUntilChanged().Where(newEntity => newEntity != null); // 1 0 2 0 1 => 1 2 1 var selectEntityChooseNPCStream = RX_targetEntity.DistinctUntilChanged(); //1 0 2 onSelectEntityChangedStream.Subscribe(_ => { //Debug.Log(_.entityID); }); selectEntityChooseNPCStream.Subscribe(_ => { }); //选中玩家后,第一次选中不同的npc var rx_selectPlayer_then_npc = onSelectEntityChangedStream.CombineLatest(selectEntityChooseNPCStream, (frameDuringSelected, choosenpc) => { //int error = -1; //if (choosenpc == null) // return error; //if (choosenpc.BeAlive()) //{ // return choosenpc.entityID; //} //return error; return(choosenpc); }) /*.DistinctUntilChanged()*/.Where(combineResults => /*combineResults != -1*/ combineResults != null); rx_selectPlayer_then_npc.Subscribe(npc => { Debug.Log(npc.entityID); //move to entity then attack IList <ICell> path2reachEntity = mapController.GetPathFinder().FindPathOnMap(mapController.GetMap().GetCell(CurrentPoint), mapController.GetMap().GetCell(npc.CurrentPoint), mapController.GetMap()); ForgetMovement(); Disposable_movementTimeLine = Observable.FromCoroutine((tok) => MoveMS(path2reachEntity)).SelectMany(aftermove).Subscribe(); //RX_moveAlongPath(path2reachEntity, tellmeHowToMove(UseForBattleMove)); //Observable.FromCoroutine(playerAction2Entity).Subscribe(); }); var rx_selectPlayer_then_mapcell = getFrameStream.CombineLatest(RX_LastClickCell.DistinctUntilChanged(), (frameDuringSelected, selectPoint) => { return(selectPoint); }).DistinctUntilChanged(); rx_selectPlayer_then_mapcell.Subscribe(Cell => { //Debug.Log(Cell); }); }