Exemplo n.º 1
0
        //添加战斗单位
        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.ID, battleUnit);

            battleUnit.JoinBattleTeam(this);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        //进入战场
        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]);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 尝试使用道具
        /// </summary>
        /// <param name="itemID"></param>
        /// <param name="useCount"></param>
        /// <returns>使用数量</returns>
        public int TryUseItem(int itemID, int useCount, ref int finalCount)
        {
            if (items == null || items.Count == 0)
            {
                UtilityHelper.LogError(string.Format("Use item failed. Do not have this item -> {0}", itemID));
                return(0);
            }
            for (int i = items.Count - 1; i >= 0; --i)
            {
                if (items[i].item.itemID == itemID)
                {
                    //使用道具
                    if (items[i].count < useCount)
                    {
                        UtilityHelper.LogWarning(string.Format("Use item warning. {0}/{1}", useCount, items[i].count));
                        useCount = items[i].count;
                    }

                    //使用道具
                    items[i].count -= useCount;

                    //判断是否还有剩余
                    if (items[i].count <= 0)
                    {
                        items[i].Reset();
                    }

                    finalCount = items[i].count;

                    return(useCount);
                }
            }
            UtilityHelper.LogError(string.Format("Use item failed. Do not have this item -> {0}", itemID));
            return(0);
        }
Exemplo n.º 5
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]);
 }
Exemplo n.º 6
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]);
 }
Exemplo n.º 7
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]);
 }
Exemplo n.º 8
0
 //排序
 public void Sort(IComparer <T> comparer)
 {
     if (comparer == null)
     {
         UtilityHelper.LogError("SingletonDyncRecyclableList sort failed. None comparer!");
         return;
     }
     //排序
     data.Sort(0, beUsed, comparer);
 }
Exemplo n.º 9
0
 //某个战斗单位点击了待命
 public void BattleUnitStay(BattleUnit battleUnit)
 {
     if (battleUnit == null ||
         battleUnit.battleUnitRenderer == null ||
         !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer))
     {
         UtilityHelper.LogError("Battle unit stay failed.");
         return;
     }
     ManualOperationComplete();
 }
Exemplo n.º 10
0
        //进入战场
        private IEnumerator PlayEnterBattleFieldAction(BattleUnitEnterBattleFieldAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroEnterBattleFieldAction");
                yield break;
            }

            //设置位置
            UpdatePositionByGrid(action.bornGrid);
            RefreshAttribute(action.attribute);
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
0
        //等待玩家的操作
        private IEnumerator PlayManualAction(BattleUnitManualAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroManualAction");
                yield break;
            }

            UpdateRenderState(BattleUnitRenderState.Action);

            //通知战场管理器
            BattleFieldRenderer.Instance.SetManualBattleUnit(this);
        }
Exemplo n.º 13
0
 public void BattleUnitUseItem(BattleUnit battleUnit, SO_PackageItem item, int count)
 {
     if (battleUnit == null ||
         battleUnit.battleUnitRenderer == null ||
         !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer))
     {
         UtilityHelper.LogError("Battle unit use item failed.");
         HideManualActionList();
         return;
     }
     battleUnit.UseItem(item.itemID, count);
     ManualOperationComplete();
 }
Exemplo n.º 14
0
        //移除战斗单位
        public void RemoveBattleUnit(BattleUnit battleUnit)
        {
            if (battleUnit.battleTeam == null || !battleUnit.battleTeam.Equals(this))
            {
                UtilityHelper.LogError("Remove battle unit failed.");
                return;
            }

            //移出
            battleUnits.Remove(battleUnit);
            battleUnitsDic.Remove(battleUnit.ID);

            battleUnit.QuitBattleTeam();
        }
Exemplo n.º 15
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(
                false,
                GridRenderType.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);
            }
        }
Exemplo n.º 16
0
        //拷贝文件夹
        public static void CopyFolder(string _from, string _to)
        {
            // UtilityHelper.Log(string.Format("拷贝文件:从{0}到{1}", _from, _to));
            if (Directory.Exists(_from) == false)
            {
                UtilityHelper.LogError("拷贝文件失败:文件不存在(" + _from + ")");
                return;
            }

            if (Directory.Exists(_to) == false)
            {
                // UtilityHelper.Log(_to + "文件不存在,新建");
                Directory.CreateDirectory(_to);
            }

            //TODO:先这么写吧,能用就行,有机会再完善
            //拷贝.txt, .lua, .json
            string[] paths = Directory.GetFiles(_from, "*.*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < paths.Length; ++i)
            {
                paths[i] = paths[i].Replace('\\', '/');
                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
                File.Copy(paths[i], _to + "/" + fileName, true);
            }
            //            paths = Directory.GetFiles(_from, "*.json", SearchOption.TopDirectoryOnly);
            //            for(int i = 0; i < paths.Length; ++i)
            //            {
            //                paths[i] = paths[i].Replace('\\','/');
            //                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
            //                File.Copy(paths[i], _to + "/" + fileName, true);
            //            }
            //            paths = Directory.GetFiles(_from, "*.txt", SearchOption.TopDirectoryOnly);
            //            for(int i = 0; i < paths.Length; ++i)
            //            {
            //                paths[i] = paths[i].Replace('\\','/');
            //                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
            //                File.Copy(paths[i], _to + "/" + fileName, true);
            //            }

            //拷贝文件夹
            string[] folderPaths = Directory.GetDirectories(_from, "*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < folderPaths.Length; ++i)
            {
                folderPaths[i] = folderPaths[i].Replace('\\', '/');
                string folderName = folderPaths[i].Remove(0, folderPaths[i].LastIndexOf("/") + 1);
                //递归拷贝
                CopyFolder(folderPaths[i], _to + "/" + folderName);
            }
        }
Exemplo n.º 17
0
        //读入界面
        private UIViewBase CreateUIView(SO_UIViewConfig config)
        {
            string     viewBundleName = TranslateViewBundleName(config.assetName);
            GameObject obj            = ClonePrefab(viewBundleName, config.assetName);

            if (obj)
            {
                obj.transform.CleanName();
                var viewBase = obj.GetComponent <UIViewBase>();
                return(viewBase);
            }

            UtilityHelper.LogError(string.Format("Load view error: no view : {0}", config.assetName));
            return(null);
        }
Exemplo n.º 18
0
        public void ConnectRenderer(GridUnitRenderer renderer)
        {
            if (renderer == null)
            {
                UtilityHelper.LogError("Grid unit connect renderer failed. RD is null");
                return;
            }

            if (gridUnitRenderer != null)
            {
                DisconnectRenderer();
            }

            gridUnitRenderer = renderer;
            gridUnitRenderer.OnConnect(this);
        }
Exemplo n.º 19
0
        //切换目标
        private IEnumerator PlayChangeTargetAction(BattleUnitChangeTargetAction action)
        {
            if (action == null)
            {
                UtilityHelper.LogError("Error BattleHeroChangeTargetAction");
                yield break;
            }

            UpdateRenderState(BattleUnitRenderState.Action);
            action.newTargetUnit.battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);

            yield return(EGameConstL.WaitForHalfSecond);

            UpdateRenderState(BattleUnitRenderState.Normal);
            action.newTargetUnit.battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
        }
Exemplo n.º 20
0
        //获取文件名字
        public static string GetFileName(string _path, bool hideBack = true)
        {
            int start = _path.LastIndexOf('/');

            if (start >= 0)
            {
                string _temp = _path.Remove(0, start + 1);
                int    end   = _temp.IndexOf('.');
                if (end >= 0 && hideBack)
                {
                    return(_temp.Remove(end));
                }
            }
            UtilityHelper.LogError("获取文件名称失败");
            return("");
        }
Exemplo n.º 21
0
        //连接渲染器
        public void ConnectRenderer(BattleUnitRenderer renderer)
        {
            if (renderer == null)
            {
                UtilityHelper.LogError("Battle unit connect renderer failed. RD is null");
                return;
            }

            if (battleUnitRenderer != null)
            {
                DisconnectRenderer();
            }

            battleUnitRenderer = renderer;
            battleUnitRenderer.OnConnect(this);
        }
Exemplo n.º 22
0
        //使用道具
        public bool UseItem(int itemID, int itemCount)
        {
            if (package != null)
            {
                var item = PackageItemManager.Instance.GetItem(itemID);
                if (item == null)
                {
                    return(false);
                }

                int finalCount = 0;
                int usedCount  = package.TryUseItem(itemID, itemCount, ref finalCount);
                if (usedCount > 0)
                {
                    BattleUnitUseItemAction action = BattleUnitActionEvent.CreateEvent <BattleUnitUseItemAction>(BattleUnitActionType.UseItem, this);
                    action.itemID      = itemID;
                    action.useCount    = usedCount;
                    action.remainCount = finalCount;
                    switch (item.itemType)
                    {
                    case PackageItemType.Recover:
                        action.attributeUpdate               = new BattleUnitSyncAttribute();
                        action.attributeUpdate.hpChanged     = Mathf.Min(battleUnitAttribute.maxHp - battleUnitAttribute.hp, item.hpRecovery);
                        action.attributeUpdate.energyChanged = Mathf.Min(battleUnitAttribute.maxEnergy - battleUnitAttribute.energy, item.energyRecovery);
                        action.attributeUpdate.currentHP     = battleUnitAttribute.hp + action.attributeUpdate.hpChanged;
                        action.attributeUpdate.currentEnergy = battleUnitAttribute.energy + action.attributeUpdate.energyChanged;

                        //自身属性更新
                        battleUnitAttribute.hp     = action.attributeUpdate.currentHP;
                        battleUnitAttribute.energy = action.attributeUpdate.currentEnergy;

                        break;

                    default:
                        break;
                    }
                    battleField.AppendBattleAction(action);
                }

                return(usedCount > 0);
            }
            else
            {
                UtilityHelper.LogError(string.Format("Use item failed, no package : {0} -> {1}", battleUnitAttribute.battleUnitName, itemID));
                return(false);
            }
        }
Exemplo n.º 23
0
        //添加特效
        public void AddEffect(EffectController effect)
        {
            if (effectNode == null)
            {
                UtilityHelper.LogError("Add effect failed. Node is null.");
                return;
            }

            if (effect != null)
            {
                effect.transform.SetParent(effectNode);
                effect.transform.Normalize();
                effect.gameObject.SetActive(true);
                effect.effectHolder = this;
                effectList.Add(effect);
            }
        }
Exemplo n.º 24
0
        //播放战场动作
        private IEnumerator PlayBattleByCoroutine(System.Action callback)
        {
            if (battleField == null ||
                battleField.battleFieldEvents == null ||
                battleField.battleFieldEvents.Count == 0)
            {
                UtilityHelper.LogError(string.Format("Play battle action failed. -> {0}", battleField.ID));
                yield break;
            }

            //遍历所有战斗动作
            while (currentActionIndex < battleField.battleFieldEvents.Count)
            {
                //一个英雄行动事件
                if (battleField.battleFieldEvents[currentActionIndex] is BattleUnitActionEvent)
                {
                    BattleUnitActionEvent actionEvent = (BattleUnitActionEvent)battleField.battleFieldEvents[currentActionIndex];
                    if (actionEvent.battleUnitActionType != BattleUnitActionType.EnterBattleField)
                    {
                        hotPointGridUnit   = actionEvent.actionUnit.mapGrid;
                        hotPointBattleUnit = actionEvent.actionUnit;
                    }

                    //有对应的战斗单位,且这个战斗单位已经连接了战斗单位渲染器
                    if (actionEvent.actionUnit != null && actionEvent.actionUnit.battleUnitRenderer != null)
                    {
                        yield return(actionEvent.actionUnit.battleUnitRenderer.RunHeroAction(actionEvent));
                    }
                }
                //一个格子事件
                else if (battleField.battleFieldEvents[currentActionIndex] is GridUnitEvent)
                {
                    GridUnitEvent gridUnitEvent = (GridUnitEvent)battleField.battleFieldEvents[currentActionIndex];
                    if (gridUnitEvent.grid != null && gridUnitEvent.grid.gridUnitRenderer != null)
                    {
                        yield return(gridUnitEvent.grid.gridUnitRenderer.RunGridEvent(gridUnitEvent));
                    }
                }
                ++currentActionIndex;
            }

            if (callback != null)
            {
                callback();
            }
        }
Exemplo n.º 25
0
 //关闭一层所有界面
 public void HideViews(UIViewLayer layer)
 {
     if (!viewDic.ContainsKey(layer))
     {
         UtilityHelper.LogError(string.Format("Hide views error: {0}", layer));
         return;
     }
     UIViewBase[] views = viewDic[layer].PopupAll();
     if (views != null)
     {
         for (int i = 0; i < views.Length; ++i)
         {
             viewList.Remove(views[i]);
             SchemeViewCache(views[i]);
         }
         UpdateViewHideState();
     }
 }
Exemplo n.º 26
0
        //显示手动操作面板
        private void ShowManualActionList()
        {
            if (manualOperatingBattleUnitRenderer == null)
            {
                return;
            }

            BattleUnit battleUnit = manualOperatingBattleUnitRenderer.battleUnit;

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

            //弹出面板
            UIViewManager.Instance.ShowView(UIViewName.BattleFieldPlayerActOption, battleUnit);
        }
Exemplo n.º 27
0
        private bool touch_0_valid = false;                             //第一次触碰是否有效

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

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

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

            BattleManager.Instance.MgrLog("Battle field renderer inited.");

            //战场显示器初始化完成,通知回调
            EventManager.Instance.Run(EGameConstL.EVENT_BATTLE_FIELD_RENDERER_READY, null);
        }
Exemplo n.º 28
0
        //先尝试从缓存中打开,如果失败则打开一个新的
        private void ShowViewFromCacheOrCreateNew(SO_UIViewConfig config, params object[] args)
        {
            //先尝试从缓存区中读取
            UIViewBase view = GetViewFromCache(config);

            //缓存区内没有,打开新的
            if (view == null)
            {
                view = ShowNewView(config);
            }

            if (view != null)
            {
                PushViewToLayer(view, args);
            }
            else
            {
                UtilityHelper.LogError(string.Format("Show view failed -> {0}", config.viewName));
            }
        }
Exemplo n.º 29
0
        //根据指定界面
        public void HideView(UIViewBase view)
        {
            if (view == null)
            {
                return;
            }

            //在窗口栈中的界面都可以关闭
            if (view.layerController != null)
            {
                viewList.Remove(view);
                view.layerController.Popup(view);
                SchemeViewCache(view);
                UpdateViewHideState();
            }
            else
            {
                UtilityHelper.LogError(string.Format("Attamp to hide a error view {0}, not in controller.", view.config.viewName));
            }
        }
Exemplo n.º 30
0
        //完全打开一个新的
        private UIViewBase ShowNewView(SO_UIViewConfig config)
        {
            if (!viewDic.ContainsKey(config.viewLayer))
            {
                UtilityHelper.LogError("Show new view failed. Layer error.");
                return(null);
            }

            //加载
            UIViewBase view = CreateUIView(config);

            if (view)
            {
                //创建完毕,初始化
                view.Init();
                view.transform.SetParent(viewDic[config.viewLayer].transform);
                view.GetComponent <RectTransform>().Normalize();
            }
            return(view);
        }