Esempio n. 1
0
        //初始化
        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();
            }
        }
Esempio n. 2
0
        //点击了技能,在单体目标技能情况下
        private void OnBattleUnitAndGridTouched_StateSkill_SingleBattleUnitTarget(GridUnit gridTouched, BattleUnit battleUnitTouched)
        {
            //没有点中战斗单位
            if (battleUnitTouched == null)
            {
                return;
            }

            //点中了可以被使用技能的单位
            if (usedManualReleaseAnalysisor.suitableUnits.Contains(battleUnitTouched))
            {
                ManualSkill(battleUnitTouched);
            }

            //点中了超出距离的
            else if (usedManualReleaseAnalysisor.distanceLimit.Contains(battleUnitTouched))
            {
                UtilityHelper.Log("目标超出攻击范围");
            }

            //同一个队伍
            else if (usedManualReleaseAnalysisor.teamLimit.Contains(battleUnitTouched))
            {
                UtilityHelper.Log("不能对同一个队伍的单位使用这个技能");
            }

            else
            {
                UtilityHelper.Log("无效的目标单位");
            }
        }
Esempio n. 3
0
 //界面初始化
 public void Init()
 {
     UtilityHelper.Log(string.Format("View Init : {0}, {1}", config.viewName, this.GetInstanceID()));
     InitCanvas();
     InitUIObjects();
     InitBG();
 }
Esempio n. 4
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");
        }
Esempio n. 5
0
        //被显示时
        public virtual void OnShow()
        {
            if (!gameObject.activeSelf)
            {
                gameObject.SetActive(true);
                UpdateLayer();
            }

            if (ViewState != UIViewState.Visible)
            {
                //将z坐标归0
                Vector3 pos = transform.localPosition;
                pos.z = 0;
                transform.localPosition = pos;

                ViewState = UIViewState.Visible;

                UtilityHelper.Log(string.Format("View On Show : {0}, {1}", config.viewName, this.GetInstanceID()));
            }

            if (dirty)
            {
                UpdateView();
            }
        }
Esempio n. 6
0
        //点击了地块、战斗单位
        public void OnBattleUnitAndGridTouched(GridUnit gridTouched, BattleUnit battleUnitTouched)
        {
            //对应当前地图的操作状态
            switch (manualOperationState)
            {
            case ManualOperationState.Waiting:
                //当前为等待中
                UtilityHelper.Log("当前为等待中...");
                break;

            case ManualOperationState.Select:
                //当前为允许操作待选择
                OnBattleUnitAndGridTouched_StateSelect(gridTouched, battleUnitTouched);
                break;

            case ManualOperationState.Move:
                //当前为选择移动目标
                OnBattleUnitAndGridTouched_StateMove(gridTouched, battleUnitTouched);
                break;

            case ManualOperationState.Skill:
                //当前为技能使用判断
                OnBattleUnitAndGridTouched_StateSkill(gridTouched, battleUnitTouched);
                break;

            default:
                break;
            }
        }
Esempio n. 7
0
        public void Init(params object[] args)
        {
            manualReleaseAnalysisor   = new BattleSkillManualReleaseAnalysisor();
            autoReleaseAnalysisor     = new BattleSkillAutoReleaseAnalysisor(10);
            battleSkillEffectAnalysis = new BattleSkillEffectAnalysis();

            UtilityHelper.Log("Battle calculator inited.");
        }
Esempio n. 8
0
        private void Start()
        {
            UtilityHelper.Log("Main start.");

            UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);

            //准备管理器
            PrepareManager();
        }
Esempio n. 9
0
        public void Test_RemoteRange(GridUnit gridUnit)
        {
            if (releaserGrid == null)
            {
                releaserGrid = gridUnit;
                releaserGrid.gridUnitRenderer.AppendGridRenderType(GridRenderType.Start);

                battleField.battleMap.GetCircularGrids(releaserGrid.row, releaserGrid.column,
                                                       motionRadius, 0, true, releaseRange);

                foreach (var item in releaseRange)
                {
                    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.SkillReleaseRange);
                }
            }
            else if (targetGrid == null)
            {
                UtilityHelper.TimerStart();

                targetGrid = gridUnit;
                targetGrid.gridUnitRenderer.AppendGridRenderType(GridRenderType.End);

                for (int i = 0; i < 1000; ++i)
                {
                    battleField.battleMap.GetCircularGrids(releaserGrid.row, releaserGrid.column,
                                                           motionRadius, 0, true, skillRange, delegate(GridUnit _gridUnit)
                    {
                        return(_gridUnit.Distance(targetGrid) <= effectRadius);
                    });
                }

                foreach (var item in skillRange)
                {
                    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.SkillEffectRange);
                }

                UtilityHelper.Log("Test_RemoteRange cost:" + UtilityHelper.TimerEnd());
            }
            else
            {
                releaserGrid.gridUnitRenderer.ResetGridRenderType();
                targetGrid.gridUnitRenderer.ResetGridRenderType();
                foreach (var item in releaseRange)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                foreach (var item in skillRange)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                releaserGrid = null;
                targetGrid   = null;
                releaseRange.Clear();
                skillRange.Clear();
            }
        }
Esempio n. 10
0
        //点击了技能,在单体带环绕的技能情况下
        private void OnBattleUnitAndGridTouched_StateSkill_SurroundBattleUnit(GridUnit gridTouched, BattleUnit battleUnitTouched)
        {
            //没有点中战斗单位
            if (battleUnitTouched == null)
            {
                return;
            }

            //是否是有效单位
            if (usedManualReleaseAnalysisor.suitableUnits.Contains(battleUnitTouched))
            {
                //重复点击同一个有效的战斗单位,则释放技能
                if (battleUnitTouched.battleUnitRenderer.Equals(selectedBattleUnitRenderer))
                {
                    ManualSkill(battleUnitTouched);
                    return;
                }
                else if (selectedBattleUnitRenderer != null)
                {
                    //取消选中
                    selectedBattleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
                }
                //显示新的范围
                selectedBattleUnitRenderer = battleUnitTouched.battleUnitRenderer;
                //范围内战斗单位设置为选中
                for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                {
                    if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius)
                    {
                        usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);
                    }
                }
                SetCircularRangeRenderStateActive(
                    true,
                    GridRenderType.SkillEffectRange,
                    gridTouched.row,
                    gridTouched.column,
                    usedManualReleaseAnalysisor.battleSkill.effectRadius);
            }
            //不是有效单位
            else if (usedManualReleaseAnalysisor.distanceLimit.Contains(battleUnitTouched))
            {
                UtilityHelper.Log("目标超出攻击范围");
            }

            //队伍不符合
            else if (usedManualReleaseAnalysisor.teamLimit.Contains(battleUnitTouched))
            {
                UtilityHelper.Log("不能对同一个队伍的单位使用这个技能");
            }

            else
            {
                UtilityHelper.Log("目标单位无效");
            }
        }
Esempio n. 11
0
 public void Init(params object[] args)
 {
     //初始化一定数量的导航数据
     navigationDataPool = new List <NavigationData>(EGameConstL.WorldMapMaxTryTimes);
     for (int i = 0; i < EGameConstL.WorldMapMaxTryTimes; ++i)
     {
         navigationDataPool.Add(new NavigationData());
     }
     UtilityHelper.Log("Map navigator inited.");
 }
Esempio n. 12
0
        //将被移除
        public virtual void OnExit()
        {
            //如果不是缓存池状态,则需要先弹出
            if (ViewState != UIViewState.Cache)
            {
                OnPopup();
            }

            UtilityHelper.Log(string.Format("View On Exit : {0}, {1}", config.viewName, this.GetInstanceID()));
        }
Esempio n. 13
0
        public void Init(params object[] args)
        {
            if (inited)
            {
                return;
            }


            inited = true;
            UtilityHelper.Log("Battle creator inited.");
        }
Esempio n. 14
0
        //点击了地块、战斗单位 -- 在当前是选择移动目标的情况下
        private void OnBattleUnitAndGridTouched_StateMove(GridUnit gridTouched, BattleUnit battleUnitTouched)
        {
            //点中了战斗单位
            if (battleUnitTouched != null)
            {
                //显示战斗单位的详情
                UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched);
            }
            //点中了地图
            else
            {
                //障碍物不能作为移动目标(暂时)
                if (gridTouched.GridType == GridType.Obstacle)
                {
                    UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched);
                }
                else
                {
                    //点击是否超出了范围
                    GridUnit fromGrid = manualOperatingBattleUnitRenderer.battleUnit.mapGrid;
                    if (fromGrid.Distance(gridTouched) > manualOperatingBattleUnitRenderer.battleUnit.battleUnitAttribute.mobility)
                    {
                        UtilityHelper.Log("超出了移动半径!");
                        UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched);
                    }
                    else
                    {
                        //判断移动是否可以到达
                        bool result = MapNavigator.Instance.Navigate(
                            fieldRenderer.battleField.battleMap,
                            fromGrid,
                            gridTouched,
                            UtilityObjs.gridUnits,
                            null,
                            manualOperatingBattleUnitRenderer.battleUnit.battleUnitAttribute.mobility
                            );

                        //判断是否可以到达(导航成功且可以可以到达)
                        if (result && UtilityObjs.gridUnits[UtilityObjs.gridUnits.Count - 1].Equals(gridTouched))
                        {
                            //可以到达
                            ManualMoveTo(gridTouched, UtilityObjs.gridUnits.ToArray());
                            UtilityObjs.gridUnits.Clear();
                        }
                        else
                        {
                            //不可以到达
                            UtilityHelper.Log("点击位置不可到达!");
                            UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched);
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        public void ConnectRenderer(BattleFieldRenderer renderer)
        {
            //当前已经在显示状态中了,整啥呢啊?
            if (battleFieldRenderer != null)
            {
                return;
            }

            battleFieldRenderer = renderer;
            battleFieldRenderer.OnConnect(this);
            UtilityHelper.Log(string.Format("{0} connect renderer.", this.ToString()));
        }
Esempio n. 16
0
        private void Start()
        {
            //先自保
            DontDestroyOnLoad(this);

            UtilityHelper.Log("Main start.");

            UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);

            //准备管理器
            PrepareBaseManager();
        }
Esempio n. 17
0
        private void OnBattleFieldReady()
        {
            battleFiledRendererIsReady = true;
            UtilityHelper.Log("Battle field renderer ready.");

            UIViewMain viewMain = UIViewManager.Instance.GetViewByName <UIViewMain>(UIViewName.Main);

            if (viewMain)
            {
                viewMain.BattleFieldReady();
            }
        }
Esempio n. 18
0
        protected override void InitManager()
        {
            if (effectUnitModel == null || poolNode == null)
            {
                UtilityHelper.LogError(" Init effect manager failed.");
                return;
            }

            base.InitManager();

            pool = new ELStack <EffectController>(2, CreateEffect);
            UtilityHelper.Log("Effect manager inited.");
        }
Esempio n. 19
0
        protected override void InitManager()
        {
            base.InitManager();

            //初始化战场数据创建器
            var battleCreater = BattleCreator.Instance;
            //战斗计算器
            var battleCalculator = BattleCalculator.Instance;

            //初始化战场显示器
            BattleFieldRenderer.Instance.Init(OnBattleFieldReady);

            UtilityHelper.Log("Battle manager inited.");
        }
Esempio n. 20
0
        //被隐藏
        public virtual void OnHide()
        {
            if (ViewState == UIViewState.Visible)
            {
                //从相机的视域体内推出
                Vector3 pos = transform.localPosition;
                pos.z = -EGameConstL.Infinity;
                transform.localPosition = pos;

                ViewState = UIViewState.Nonvisible;

                UtilityHelper.Log(string.Format("View On Hide : {0}, {1}", config.viewName, this.GetInstanceID()));
            }
        }
Esempio n. 21
0
        //播放战场动作
        public IEnumerator PlayBattleActions()
        {
            if (battleField == null ||
                battleField.msgAction.battleActions == null ||
                battleField.msgAction.battleActions.Count == 0)
            {
                UtilityHelper.LogError(string.Format("Play battle action failed. -> {0}", battleField.battleID));
                yield break;
            }

            UtilityHelper.Log("Play battle actions");

            yield return(StartCoroutine(PlayMsgAction(battleField.msgAction)));
        }
Esempio n. 22
0
        protected override void InitManager()
        {
            base.InitManager();

            //初始化与战斗有关的单例控制器
            var battleCreater      = BattleCreator.Instance;        //初始化战场数据创建器
            var battleCalculator   = BattleCalculator.Instance;     //战斗计算器
            var mapNavigator       = MapNavigator.Instance;         //导航器
            var battleSkillManager = BattleSkillManager.Instance;   //战斗技能管理器

            //初始化战场显示器
            BattleFieldRenderer.Instance.Init(OnBattleFieldReady);

            UtilityHelper.Log("Battle manager inited.");
        }
Esempio n. 23
0
        //被移出窗口栈
        public virtual void OnPopup()
        {
            if (ViewState == UIViewState.Cache)
            {
                return;
            }

            //如果不是隐藏状态,需要先隐藏
            if (ViewState == UIViewState.Visible)
            {
                OnHide();
            }

            UtilityHelper.Log(string.Format("View On Popup : {0}, {1}", config.viewName, this.GetInstanceID()));
            ViewState = UIViewState.Cache;
        }
Esempio n. 24
0
 //生成战斗结果
 private void GenerateBattleResult()
 {
     //TODO:生成战斗结果
     if (BattleEndState == 0)
     {
         UtilityHelper.Log("Team 0 win");
     }
     else if (BattleEndState == 1)
     {
         UtilityHelper.Log("Team 1 win");
     }
     else
     {
         UtilityHelper.LogError("Draw game.");
     }
 }
Esempio n. 25
0
        //播放战场动作
        private IEnumerator PlayBattleByCoroutine(System.Action callback)
        {
            if (battleField == null ||
                battleField.msgAction.battleActions == null ||
                battleField.msgAction.battleActions.Count == 0)
            {
                UtilityHelper.LogError(string.Format("Play battle action failed. -> {0}", battleField.battleID));
                yield break;
            }

            UtilityHelper.Log("Play battle actions");

            //遍历所有战斗动作
            var msgAction = battleField.msgAction;

            while (battleField.currentIndex < msgAction.battleActions.Count)
            {
                if (msgAction.battleActions[battleField.currentIndex] == null)
                {
                    UtilityHelper.LogError(string.Format("Play action error. Action is none or type is none, index = {0}", battleField.currentIndex));
                    continue;
                }

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

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

            UtilityHelper.Log("Play Msg Action fin");

            if (callback != null)
            {
                callback();
            }
        }
Esempio n. 26
0
        //初始化管理器
        protected override void InitManager()
        {
            base.InitManager();

            //获取根画布尺寸
            screenUICanvasRootSize = screenUIRT.sizeDelta;
            UtilityHelper.Log(string.Format("Screen ui canvas root size = {0}", screenUICanvasRootSize.ToString()));

            //初始化配置
            InitViewConfig();
            //初始化层级
            InitViewLayers();

            //默认打开主界面
            ShowView(UIViewName.Main);

            UtilityHelper.Log("UI manager inited.");
        }
Esempio n. 27
0
 //获取战场点击的情况
 private void UpdateBattleFieldTouched()
 {
     //如果点击了鼠标左键
     if (Input.GetMouseButtonDown(0))
     {
         if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
         {
             //点中了UI
             UtilityHelper.Log("点中了UI");
             return;
         }
         ClickedBattleField(Input.mousePosition);
     }
     else if (Input.GetMouseButtonDown(1))
     {
         //右键点击为取消
         manualOperationHelper.ClickedCancel();
     }
 }
Esempio n. 28
0
        //准备战斗
        private void Prepare()
        {
            //UtilityHelper.Log(string.Format("<color=#ff0000> {0} battle prepare. </color>", this.ToString()));

            //进入战场
            EnterBattleField(true);

            //到此生成了战斗入场数据
            battleState = BattleState.Ready;

            if (battleFieldRenderer != null)
            {
                UtilityHelper.Log("Play actions");
                battleFieldRenderer.PlayBattle(Fight);
            }
            else
            {
                Fight();
            }
        }
Esempio n. 29
0
        protected override void InitManager()
        {
            if (worldRoot == null)
            {
                UtilityHelper.LogError(" Init effect manager failed.");
                return;
            }

            base.InitManager();

            //TEMP
            string[] effectList = new string[2] {
                EGameConstL.Effect_HexFrame,
                EGameConstL.Effect_DamageLabel
            };

            //建立字典
            for (int i = 0; i < effectList.Length; i++)
            {
                effectDic.Add(effectList[i].ToLower(), new ELStack <EffectController>(2, effectList[i], CreateEffect));
            }
            UtilityHelper.Log("Effect manager inited.");
        }
Esempio n. 30
0
        //被压入到窗口栈中
        public virtual void OnPush()
        {
            UtilityHelper.Log(string.Format("View On Push : {0}, {1}", config.viewName, this.GetInstanceID()));
            ViewState = UIViewState.Nonvisible;

            if (!canvas.overrideSorting)
            {
                canvas.overrideSorting = true;
            }

            switch (config.viewLayer)
            {
            case UIViewLayer.Background:
                canvas.sortingLayerName = EGameConstL.SortingLayer_Background;
                break;

            case UIViewLayer.Base:
                canvas.sortingLayerName = EGameConstL.SortingLayer_Base;
                break;

            case UIViewLayer.Popup:
                canvas.sortingLayerName = EGameConstL.SortingLayer_Popup;
                break;

            case UIViewLayer.Top:
                canvas.sortingLayerName = EGameConstL.SortingLayer_Top;
                break;

            case UIViewLayer.Debug:
                canvas.sortingLayerName = EGameConstL.SortingLayer_Debug;
                break;

            default:
                UtilityHelper.LogError(string.Format("Set Layer And Order failed: Error layer -> {0}", config.viewLayer));
                break;
            }
        }