コード例 #1
0
        //点击了技能按钮
        private void OnClickedSkillItem()
        {
            //获取当前点击对象
            string btnName  = EventSystem.current.currentSelectedGameObject.name;
            int    skillIdx = -1;

            if (int.TryParse(btnName.Replace(EGameConstL.STR_SkillBtn, string.Empty), out skillIdx))
            {
                SO_BattleSkill skill = battleUnit.battleUnitAttribute.battleSkills[skillIdx];
                if (skill != null)
                {
                    if (battleUnit.battleUnitAttribute.energy >= skill.energyCost && BattleFieldRenderer.Instance != null)
                    {
                        BattleFieldRenderer.Instance.BattleUnitUseSkill(battleUnit, skill);
                    }
                    else
                    {
                        UtilityHelper.LogWarning(string.Format("能量不足:{0}/{1}", battleUnit.battleUnitAttribute.energy, skill.energyCost));
                    }
                }
                else
                {
                    UtilityHelper.LogError("Skill item error ->" + btnName);
                }
            }
            else
            {
                UtilityHelper.LogError("Skill item name error ->" + btnName);
            }
        }
コード例 #2
0
        protected override void InitUIObjects()
        {
            base.InitUIObjects();

            //设置按钮文字
            SetObjectText(btnMove.gameObject, "移动");
            SetObjectText(btnAttack.gameObject, "攻击");
            SetObjectText(btnStay.gameObject, "待命");

            //点击回调
            btnMove.onClick.AddListener(OnClickedMove);
            btnAttack.onClick.AddListener(OnClickedAttack);
            btnStay.onClick.AddListener(OnClickedStay);
            btnOptionLayoutTrigger.onClick.AddListener(OnClickedOptionLayoutTrigger);

            //获取技能按钮
            rtSkillLayout.GetComponentsInChildren <Button>(true, skillBtns);
            //动态获取,保证顺序
            if (skillBtns == null || skillBtns.Count == 0)
            {
                UtilityHelper.LogError("Init BattleFieldPlayerActOption failed.Not found skill btn item.");
                return;
            }
            //绑定技能按钮回调
            for (int i = 0; i < skillBtns.Count; ++i)
            {
                skillBtns[i].name = string.Format("{0}{1}", EGameConstL.STR_SkillBtn, i);
                skillBtns[i].onClick.AddListener(OnClickedSkillItem);
            }
        }
コード例 #3
0
        //创建一个特效
        public T CreateEffectByName <T>(string effectName, EffectPlayType playType)
            where T : EffectController
        {
            effectName = effectName.ToLower();
            if (!effectDic.ContainsKey(effectName))
            {
                UtilityHelper.LogError(string.Format("Create effect by name error! -> {0}", effectName));
                return(null);
            }
            EffectController effect = effectDic[effectName].Get();

            if (effect != null && effect is T)
            {
                if (effect is T)
                {
                    //成功创建了特效
                    effect.playType = playType;
#if UNITY_EDITOR
                    effect.name = effect.effectName;
#endif
                    return((T)effect);
                }
                else
                {
                    UtilityHelper.LogError(string.Format("Create effect by name error! Type error -> {0},{1}", effectName, effect.GetType().ToString()));
                    ReturnEffect(effect);
                }
            }
            return(null);
        }
コード例 #4
0
        //弹出一个指定窗口
        public void Popup(UIViewBase view)
        {
            if (view == null)
            {
                return;
            }

            bool err = true;

            for (int i = views.Count - 1; i >= 0; --i)
            {
                if (views[i].GetInstanceID() == view.GetInstanceID())
                {
                    views.RemoveAt(i);
                    PopupSingleView(view);
                    err = false;
                    break;
                }
            }

            if (err)
            {
                UtilityHelper.LogError(string.Format("Popup view failed. Can not find {0} in {1}", view.config.viewName, viewLayer));
                return;
            }

            //刷新最大order
            RefreshTopOrder();
        }
コード例 #5
0
        //更新层级和Order值
        private void UpdateLayer()
        {
            //界面在没有active的时候,重写是无效的
            if (!canvas.overrideSorting)
            {
                canvas.overrideSorting = true;
                switch (config.viewLayer)
                {
                case UIViewLayer.Background:
                    canvas.sortingLayerID = EGameConstL.SortingLayer_UI_Background;
                    break;

                case UIViewLayer.Base:
                    canvas.sortingLayerID = EGameConstL.SortingLayer_UI_Base;
                    break;

                case UIViewLayer.Popup:
                    canvas.sortingLayerID = EGameConstL.SortingLayer_UI_Popup;
                    break;

                case UIViewLayer.Top:
                    canvas.sortingLayerID = EGameConstL.SortingLayer_UI_Top;
                    break;

                case UIViewLayer.Debug:
                    canvas.sortingLayerID = EGameConstL.SortingLayer_UI_Debug;
                    break;

                default:
                    UtilityHelper.LogError(string.Format("Set Layer And Order failed: Error layer -> {0}", config.viewLayer));
                    break;
                }
            }
        }
コード例 #6
0
        //运行
        public void Run()
        {
            switch (battleState)
            {
            //当前正在准备阶段
            case BattleState.Prepare:
                Prepare();
                break;

            case BattleState.Ready:
                Fight();
                break;

            case BattleState.Fighting:
                Fight();
                break;

            case BattleState.WaitForPlayer:
                UtilityHelper.LogError("Run error, wait for player operation.");
                break;

            case BattleState.End:
                BattleEnd();
                break;

            case BattleState.Exception:
                break;

            default:
                break;
            }
        }
コード例 #7
0
        //将战斗单位放置入战场
        private void EnterBattleField(bool recordProcess)
        {
            BattleUnit          battleUnit = null;
            List <BattleAction> actions    = null;

            if (recordProcess)
            {
                actions = new List <BattleAction>();
            }

            for (int i = 0; i < teams.Count; ++i)
            {
                for (int j = 0; j < teams[i].battleUnits.Count; ++j)
                {
                    battleUnit = teams[i].battleUnits[j];
                    GridUnit bornUnit = battleMap.GetBornGrid(i, true);
                    if (bornUnit == null)
                    {
                        battleUnit.battleUnitAttribute.hp = 0;
                        UtilityHelper.LogError("Get born unit failed.");
                        continue;
                    }
                    battleUnit.EnterBattleField(this, bornUnit, actions);
                    //生成行动队列
                    actionQueue.Enqueue(battleUnit);
                }
            }

            if (recordProcess)
            {
                AppendBattleActions(actions);
            }
        }
コード例 #8
0
ファイル: BattleTeam.cs プロジェクト: yxpandjay/HalfSLG
        //进入战场
        public void EnterBattleField(BattleField battleField, GridUnit[] bornGrids)
        {
            if (battleField == null)
            {
                UtilityHelper.LogError("Enter battle field failed. None battle field.");
                return;
            }

            if (bornGrids == null || bornGrids.Length == 0)
            {
                UtilityHelper.LogError("Enter battle field failed. None born grids");
                return;
            }

            this.battleField = battleField;

            //打乱
            for (int i = 0; i < battleUnits.Count; i++)
            {
                if (i >= bornGrids.Length)
                {
                    UtilityHelper.LogError("Battle unit enter battle field failed. Born grid not enough.");
                    continue;
                }
                battleUnits[i].EnterBattleField(battleField, bornGrids[i]);
            }
        }
コード例 #9
0
        //刷新战斗单位
        private void RefreshBattleUnits()
        {
            if (battleField == null)
            {
                UtilityHelper.LogError("Prepare battle units failed. No battle data.");
                return;
            }

            for (int i = 0; i < battleField.teams.Count; ++i)
            {
                BattleTeam team = battleField.teams[i];
                if (team.battleUnits != null)
                {
                    foreach (var battleUnitData in team.battleUnits)
                    {
                        BattleUnitRenderer battleUnitRenderer = GetUnusedBattleUnitRenderer();
                        battleUnitRenderer.teamColor = i == 0 ? TeamColor.Blue : TeamColor.Red;
                        if (battleUnitRenderer != null)
                        {
                            battleUnitData.ConnectRenderer(battleUnitRenderer);
                        }
                    }
                }
            }
        }
コード例 #10
0
        private IEnumerator PlayMsgAction(MsgAction msgAction)
        {
            //遍历所有战斗动作
            for (int i = 0; i < msgAction.battleActions.Count; ++i)
            {
                if (msgAction.battleActions[i] == null)
                {
                    UtilityHelper.LogError(string.Format("Play action error. Action is none or type is none, index = {0}", i));
                    continue;
                }

                BattleHeroAction heroAction = null;
                //一个英雄动作
                if (msgAction.battleActions[i] is BattleHeroAction)
                {
                    heroAction = (BattleHeroAction)msgAction.battleActions[i];

                    //有对应的战斗单位,且这个战斗单位已经连接了战斗单位渲染器
                    if (heroAction.actionUnit != null && heroAction.actionUnit.battleUnitRenderer != null)
                    {
                        yield return(heroAction.actionUnit.battleUnitRenderer.RunHeroAction(heroAction));
                    }
                }
            }

            UtilityHelper.Log("Play Msg Action fin");
        }
コード例 #11
0
        //准备加载战场
        private void RefreshBattleMapGrids()
        {
            if (battleField == null)
            {
                UtilityHelper.LogError("Prepare battle map failed. No battle data.");
                return;
            }

            for (int r = 0; r < battleField.battleMap.mapHeight; ++r)
            {
                for (int c = 0; c < battleField.battleMap.mapWidth; ++c)
                {
                    GridUnit gridUnitData = battleField.battleMap.mapGrids[c, r];
                    if (gridUnitData != null)
                    {
                        //创建一个用于显示的格子对象
                        GridUnitRenderer gridUnitRenderer = GetUnusedGridUnitRenderer();
                        if (gridUnitRenderer != null)
                        {
                            gridUnitData.ConnectRenderer(gridUnitRenderer);
                        }
                    }
                }
            }
        }
コード例 #12
0
        //点击了技能按钮
        private void OnClickedSkillItem()
        {
            //获取当前点击对象
            string btnName  = EventSystem.current.currentSelectedGameObject.name;
            int    skillIdx = -1;

            if (int.TryParse(btnName.Replace(EGameConstL.STR_SkillBtn, string.Empty), out skillIdx))
            {
                SO_BattleSkill skill = battleUnit.battleUnitRenderer.battleSkills[skillIdx];
                if (skill != null)
                {
                    if (BattleFieldRenderer.Instance)
                    {
                        BattleFieldRenderer.Instance.BattleUnitUseSkill(battleUnit, skill);
                    }
                }
                else
                {
                    UtilityHelper.LogError("Skill item error ->" + btnName);
                }
            }
            else
            {
                UtilityHelper.LogError("Skill item name error ->" + btnName);
            }
        }
コード例 #13
0
        private BattleFieldManualOperationHelper manualOperationHelper;     //手动操作的Helper

        //初始化
        public void Init(System.Action initedCallback)
        {
            if (gridUnitModel == null ||
                gridUnitsRoot == null ||
                battleUnitModel == null ||
                battleUnitsRoot == null)
            {
                UtilityHelper.LogError("Init battle field renderer failed!");
                return;
            }

            //初始化Helper
            manualOperationHelper = new BattleFieldManualOperationHelper(this);

            UtilityHelper.Log("Init battle field renderer.");

            //创建一定数量的格子和战斗单位渲染器,留作后面使用
            InitGridUnitRenderer(100);
            InitBattleUnitRenderer(10);

            UtilityHelper.Log("Battle field renderer inited.");

            //战场显示器初始化完成,通知回调
            if (initedCallback != null)
            {
                initedCallback();
            }
        }
コード例 #14
0
ファイル: BattleTeam.cs プロジェクト: yxpandjay/HalfSLG
        //添加战斗单位
        public void AddBattleUnit(BattleUnit battleUnit)
        {
            if (battleUnit == null)
            {
                return;
            }

            if (battleUnit.battleTeam != null)
            {
                //重复加入
                if (battleUnit.battleTeam.Equals(this))
                {
                    return;
                }

                UtilityHelper.LogError("Add battle unit failed.Battle unit already joined a team.");
                return;
            }

            //重复添加
            if (battleUnits.Contains(battleUnit))
            {
                return;
            }

            //加入
            battleUnits.Add(battleUnit);
            battleUnitsDic.Add(battleUnit.battleUnitID, battleUnit);

            battleUnit.JoinBattleTeam(this);
        }
コード例 #15
0
        //弹出一个面板
        private void ShowManualActionList()
        {
            if (manualBattleUnitRenderer == null)
            {
                return;
            }

            BattleUnit battleUnit = manualBattleUnitRenderer.battleUnit;

            if (battleUnit == null)
            {
                UtilityHelper.LogError("Show manual asction list error : Battle unit is none.");
                return;
            }

            //判断可操作状态
            if (battleUnit.CheckManualState(ManualActionState.Move) || battleUnit.CheckManualState(ManualActionState.Skill))
            {
                activeManualList = true;
            }
            else
            {
                //这个可操作单位不能操作...
                activeManualList         = false;
                manualBattleUnitRenderer = null;
            }
        }
コード例 #16
0
        //使用技能
        private IEnumerator PlaySkillAction(BattleHeroSkillAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroSkillAction");
                yield break;
            }


            if (action.skillResult == null)
            {
                UtilityHelper.LogError("Error BattleHeroSkillAction: No skill result.");
                yield break;
            }

            AddBattleBeSelected(this, EGameConstL.Color_Cyan);

            for (int i = 0; i < action.skillResult.Length; ++i)
            {
                if (action.skillResult[i].battleUnit != null && action.skillResult[i].battleUnit.battleUnitRenderer != null)
                {
                    AddBattleBeSelected(action.skillResult[i].battleUnit.battleUnitRenderer, EGameConstL.Color_Yellow);
                    yield return(EGameConstL.WaitForHalfSecond);

                    action.skillResult[i].battleUnit.battleUnitRenderer.RefreshAttribute(action.skillResult[i].syncAttribute);
                }
            }

            // yield return EGameConstL.WaitForTouchedScreen;

            ClearAllSelectedBattleUnit();
        }
コード例 #17
0
ファイル: BattleField.cs プロジェクト: yxpandjay/HalfSLG
 //战斗结束
 private void BattleEnd()
 {
     if (battleState == BattleState.Exception)
     {
         UtilityHelper.LogError(string.Format("{0} battle error:", this.ToString()));
     }
     Debug.Log(string.Format("<color=#ff0000> {0} battle end, step {1}.</color>", this.ToString(), actionCount));
 }
コード例 #18
0
        //运行英雄动作
        public IEnumerator RunHeroAction(BattleHeroAction heroAction)
        {
            if (heroAction == null)
            {
                yield break;
            }

            switch (heroAction.actionType)
            {
            //进入战场
            case MsgBattleHeroActionType.EnterBattleField:
                yield return(PlayEnterBattleFieldAction(heroAction as BattleHeroEnterBattleFieldAction));

                break;

            //切换目标
            case MsgBattleHeroActionType.ChangeTarget:
                yield return(PlayChangeTargetAction(heroAction as BattleHeroChangeTargetAction));

                break;

            //移动
            case MsgBattleHeroActionType.MotionAction:
                yield return(PlayMotionAction(heroAction as BattleHeroMotionAction));

                break;

            //使用技能
            case MsgBattleHeroActionType.SkillAction:
                yield return(PlaySkillAction(heroAction as BattleHeroSkillAction));

                break;

            //角色被击败
            case MsgBattleHeroActionType.Defeated:
                yield return(PlayDefeatedAction(heroAction as BattleHerodDefeatedAction));

                break;

            //一个警告,用于调试,不应该出现这种问题
            case MsgBattleHeroActionType.Warning:
                Debug.LogWarning(heroAction.ToString());
                yield return(EGameConstL.WaitForTouchScreen);

                break;

            //等待玩家手动操作
            case MsgBattleHeroActionType.Manual:
                yield return(PlayManualAction(heroAction as BattleHeroManualAction));

                break;

            default:
                UtilityHelper.LogError("Error type of hero action:" + heroAction.actionType);
                break;
            }
            yield return(null);
        }
コード例 #19
0
 private SO_UIViewConfig GetConfig(UIViewName viewName)
 {
     if (uiViewConfig.ContainsKey(viewName) == false)
     {
         UtilityHelper.LogError(string.Format("Get view config error: {0}", viewName));
         return(null);
     }
     return(uiViewConfig[viewName]);
 }
コード例 #20
0
 //获取技能
 public SO_BattleSkill GetSkill(int skillID)
 {
     if (!dicBattleSkills.ContainsKey(skillID))
     {
         UtilityHelper.LogError(string.Format("Get skill by id failed -> {0}", skillID));
         return(null);
     }
     return(dicBattleSkills[skillID]);
 }
コード例 #21
0
 //获取技能
 public SO_PackageItem GetItem(int itemID)
 {
     if (!dicPackageItems.ContainsKey(itemID))
     {
         UtilityHelper.LogError(string.Format("Get item by id failed -> {0}", itemID));
         return(null);
     }
     return(dicPackageItems[itemID]);
 }
コード例 #22
0
 //排序
 public void Sort(IComparer <T> comparer)
 {
     if (comparer == null)
     {
         UtilityHelper.LogError("SingletonDyncRecyclableList sort failed. None comparer!");
         return;
     }
     //排序
     data.Sort(0, beUsed, comparer);
 }
コード例 #23
0
        //被打服了
        private IEnumerator PlayDefeatedAction(BattleHerodDefeatedAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHerodDefeatedAction");
                yield break;
            }

            transform.ShiftOut();
        }
コード例 #24
0
        //设置某个圆形区域的显示状态(每种类型只能显示一个)
        public void SetCircularRangeRenderStateActive(bool active, GridRenderType gridRenderType, int centerRow = -1, int centerColumn = -1, int radius = -1)
        {
            //确定是哪种范围
            List <GridUnit> rangeHighlightGridUnits = null;

            switch (gridRenderType)
            {
            case GridRenderType.MoveRange:
                rangeHighlightGridUnits = moveRangeGridUnits;
                break;

            case GridRenderType.SkillReleaseRange:
                rangeHighlightGridUnits = skillReleaseRangeGridUnits;
                break;

            case GridRenderType.SkillEffectRange:
                rangeHighlightGridUnits = skillEffectRangeGridUnits;
                break;

            default:
                UtilityHelper.LogError(string.Format("SetRangeHighlightActive error grid render type : {0}", gridRenderType));
                return;
            }

            //当前是取消激活
            if (!active)
            {
                for (int i = 0; i < rangeHighlightGridUnits.Count; ++i)
                {
                    if (rangeHighlightGridUnits[i].gridUnitRenderer != null)
                    {
                        rangeHighlightGridUnits[i].gridUnitRenderer.RemoveGridRenderType(gridRenderType);
                    }
                }
                rangeHighlightGridUnits.Clear();
            }
            else
            {
                //当前存在上一个激活,先隐藏
                if (rangeHighlightGridUnits.Count > 0)
                {
                    SetCircularRangeRenderStateActive(false, gridRenderType);
                }
                //获取格子
                fieldRenderer.battleField.battleMap.GetCircularGrids(centerRow, centerColumn, radius, 0, true, rangeHighlightGridUnits);
                //设置高亮状态
                for (int i = 0; i < rangeHighlightGridUnits.Count; ++i)
                {
                    if (rangeHighlightGridUnits[i].gridUnitRenderer != null)
                    {
                        rangeHighlightGridUnits[i].gridUnitRenderer.AppendGridRenderType(gridRenderType);
                    }
                }
            }
        }
コード例 #25
0
ファイル: BattleTeam.cs プロジェクト: yxpandjay/HalfSLG
        //移除战斗单位
        public void RemoveBattleUnit(BattleUnit battleUnit)
        {
            if (battleUnit.battleTeam == null || !battleUnit.battleTeam.Equals(this))
            {
                UtilityHelper.LogError("Remove battle unit failed.");
                return;
            }

            battleUnits.Remove(battleUnit);
            battleUnit.battleTeam = null;
        }
コード例 #26
0
 //某个战斗单位点击了待命
 public void BattleUnitStay(BattleUnit battleUnit)
 {
     if (battleUnit == null ||
         battleUnit.battleUnitRenderer == null ||
         !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer))
     {
         UtilityHelper.LogError("Battle unit stay failed.");
         return;
     }
     ManualOperationComplete();
 }
コード例 #27
0
        //移动
        private IEnumerator PlayMotionAction(BattleUnitMotionAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroMotionAction");
                yield break;
            }

            UpdateRenderState(BattleUnitRenderState.Action);
            //手动操作的移动可能没有攻击目标
            if (action.targetUnit != null)
            {
                action.targetUnit.battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);
            }

            //先显示区域
            BattleFieldRenderer.Instance.SetCircularRangeRenderStateActive(
                true,
                GridRenderType.MoveRange,
                action.fromGrid.row,
                action.fromGrid.column,
                action.moveRange);

            //显示路径
            BattleFieldRenderer.Instance.SetGridsRenderStateActive(true, action.gridPath);

            //yield return EGameConstL.WaitForTouchedScreen;

            //移动
            for (int i = 0; i < action.gridPath.Length; ++i)
            {
                UpdatePositionByGrid(action.gridPath[i]);
                yield return(EGameConstL.WaitForDotOneSecond);
            }

            //清空范围和路径
            BattleFieldRenderer.Instance.SetCircularRangeRenderStateActive(false, GridRenderType.MoveRange);

            //显示路径
            BattleFieldRenderer.Instance.SetGridsRenderStateActive(false, null);

            //手动操作的移动可能没有攻击目标
            if (action.targetUnit != null)
            {
                action.targetUnit.battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
            }

            //TEMP
            if (!battleUnit.battleUnitAttribute.manualOperation)
            {
                UpdateRenderState(BattleUnitRenderState.Normal);
            }
        }
コード例 #28
0
        //进入战场
        private IEnumerator PlayEnterBattleFieldAction(BattleUnitEnterBattleFieldAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroEnterBattleFieldAction");
                yield break;
            }

            //设置位置
            UpdatePositionByGrid(action.bornGrid);
            RefreshAttribute(action.attribute);
        }
コード例 #29
0
        //展示界面
        public void ShowView(UIViewName viewName, params object[] args)
        {
            //获取界面配置
            SO_UIViewConfig config = GetConfig(viewName);

            if (config == null)
            {
                return;
            }

            UIViewBase view = null;

            //如果这个窗口是唯一的
            if (config.unique)
            {
                //如果界面是唯一打开的,则判断下是否打开过这个界面
                for (int i = 0; i < viewList.Count; ++i)
                {
                    if (viewList[i].config.viewName == viewName)
                    {
                        //我靠居然打开着呢!
                        view = viewList[i];
                        break;
                    }
                }
                //当前这个界面被打开了
                if (view != null)
                {
                    if (view.layerController == null)
                    {
                        UtilityHelper.LogError(string.Format("Show view error: {0}, not layer", viewName));
                        return;
                    }
                    //设置参数,重新放入窗口层级控制器
                    view.SetArguments(args);
                    view.layerController.Push(view);
                }
                else
                {
                    //没有,打开个新的吧
                    ShowViewFromCacheOrCreateNew(config, args);
                }
            }
            else
            {
                //开!!什么开...
                ShowViewFromCacheOrCreateNew(config, args);
            }

            //刷新显示、隐藏状态
            UpdateViewHideState();
        }
コード例 #30
0
        //等待玩家的操作
        private IEnumerator PlayManualAction(BattleUnitManualAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroManualAction");
                yield break;
            }

            UpdateRenderState(BattleUnitRenderState.Action);

            //通知战场管理器
            BattleFieldRenderer.Instance.SetManualBattleUnit(this);
        }