public void Init(Stander player, Stander key, Stander gateKey, List <Stander> obstaclesList, List <Stander> propList) { m_Player = player; m_Key = key; m_GateWay = gateKey; m_ObstaclesList = obstaclesList; m_PropList = propList; }
public void RemoveRefreshStander(Stander stander) { if (StanderList == null) { StanderList = new List <Stander>(); } StanderList.Remove(stander); stander.OnDestoryAction -= OnStanderDestory; }
public void AddRefreshStander(Stander stander) { if (StanderList == null) { StanderList = new List <Stander>(); } StanderList.Add(stander); stander.OnDestoryAction += OnStanderDestory; }
public void RemoveRefreshStander(Stander stander) { if (StanderList == null) { StanderList = new List <Stander>(); } StanderList.Remove(stander); stander.OnDestoryAction -= OnStanderDestory; if (StanderList.Count == 0) { Node.IsObstacle = false; } }
private Cell GetCell(Cell cell, Direction dir) { Cell nextCell = null; switch (dir) { case Direction.Up: nextCell = cell.UpCell; break; case Direction.Down: nextCell = cell.DownCell; break; case Direction.Left: nextCell = cell.LeftCell; break; case Direction.Right: nextCell = cell.RightCell; break; } //null if (nextCell == null) { return(cell); } else { for (int i = 0; i < nextCell.StanderList.Count; i++) { //下一个方块上道具则返回下一个方块 Stander s = nextCell.StanderList[i]; if (s.StanderType == StanderType.Prop) { return(nextCell); } else if (s.StanderType == StanderType.Obstacles) { //方块上有障碍物 Obstacles obstacles = (Obstacles)s; if (obstacles.IsShow) { return(cell); } } } return(GetCell(nextCell, dir)); } }
/// <summary> /// 创建地图 /// </summary> private void CreateMap() { //地面 //行 for (int i = 0; i < m_MapData.Count; i++) { List <int> data = m_MapData[i]; List <Cell> cellList = new List <Cell>(); //列 for (int j = 0; j < data.Count; j++) { //Cell 构建方块 Vector2 pos = new Vector2(j * ColumnInterval + ColumnInterval / 2f, -(i * RowInterval + RowInterval / 2f)); GameObject go = null; go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Building/Ground", isCache: true); go.transform.position = pos; go.transform.rotation = Quaternion.identity; go.transform.localScale = new Vector3(1, 1, 1); Cell cell = go.GetComponent <Cell>(); cell.Row = i; cell.Column = j; cellList.Add(cell); //-------------生成站在方块上的物体--------------// Stander stander = null; //玩家 go = null; if (data[j] == 2) { go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Role, "Player", isCache: true); stander = go.GetComponent <Stander>(); m_Player = (RoleCtrl)stander; } //传送门 if (data[j] == 3) { go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Prop/GateWay", isCache: true); m_GateWay = go.GetComponent <Stander>(); } //障碍物 Obstacles obstacles = null; RevocableObstaclesType revocableObstaclesType = RevocableObstaclesType.Red; RevocableObstacles ro = null; switch (data[j]) { case 1: //墙 string walllName = ""; int r = Random.Range(0, 2); if (r == 0) { walllName = "Wall01"; } else { walllName = "Wall02"; } go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Building/" + walllName, isCache: true); break; case 5: //红色可被解除的障碍物 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/RedObstacles", isCache: true); revocableObstaclesType = RevocableObstaclesType.Red; break; case 6: //蓝色可被解除的障碍物 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/BlueObstacles", isCache: true); revocableObstaclesType = RevocableObstaclesType.Blue; break; case 11: //忽隐忽现 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/FlickeringObstacles", isCache: true); break; case 70: //随着玩家移动轮流隐藏出现的的障碍物 case 71: go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/StepObstacles", isCache: true); StepObstacles so = go.GetComponent <StepObstacles>(); if (data[j] == 70) { so.Init(false); } else { so.Init(true); } break; case 8: //数字障碍物 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/NumberObstacles", isCache: true); break; case 12: //数字锁障碍物 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Obstacles/NumberLockObstacles", isCache: true); break; } //道具 Prop p = null; PropType propType = PropType.Key; switch (data[j]) { case 4: //钥匙 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Prop/Key", isCache: true); propType = PropType.Key; m_Key = go.GetComponent <Stander>(); break; case 9: //红色道具 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Prop/RedRelieveProp", isCache: true); propType = PropType.RedRelieve; break; case 10: //蓝色道具 go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Prop/BlueRelieveProp", isCache: true); propType = PropType.BlueRelieve; break; } // if (go != null) { go.transform.position = new Vector3(cell.transform.position.x, cell.transform.position.y, -2); go.transform.rotation = Quaternion.identity; go.transform.localScale = new Vector3(1, 1, 1); p = go.GetComponent <Prop>(); obstacles = go.GetComponent <Obstacles>(); stander = go.GetComponent <Stander>(); ro = go.GetComponent <RevocableObstacles>(); } //障碍物 if (obstacles != null) { m_ObstaclesList.Add(obstacles); if (ro != null) { ro.Init(revocableObstaclesType); } } //道具 if (p != null) { m_PropList.Add(p); p.Init(propType); } //stander if (stander != null) { stander.RefreshCell(cell); cell.AddRefreshStander(stander); } } m_MapCell.Add(cellList); } //站立物 //行 for (int i = 0; i < m_MapCell.Count; i++) { List <Cell> cellList = m_MapCell[i]; //列 for (int j = 0; j < cellList.Count; j++) { Cell upCell = null; Cell downCell = null; Cell rightCell = null; Cell leftCell = null; Cell cell = cellList[j]; int row = i; int column = j; int nextRow = -1; int nextColumn = -1; //上 nextRow = row - 1; nextColumn = column; if (CheckRangge(nextRow, nextColumn)) { upCell = m_MapCell[nextRow][nextColumn]; } //下 nextRow = row + 1; nextColumn = column; if (CheckRangge(nextRow, nextColumn)) { downCell = m_MapCell[nextRow][nextColumn]; } //左 nextRow = row; nextColumn = column - 1; if (CheckRangge(nextRow, nextColumn)) { leftCell = m_MapCell[nextRow][nextColumn]; } //右 nextRow = row; nextColumn = column + 1; if (CheckRangge(nextRow, nextColumn)) { rightCell = m_MapCell[nextRow][nextColumn]; } cell.Init(leftCell, rightCell, upCell, downCell); } } //填充背景 //向上填充10行 向下填充10行 for (int i = -5; i < m_MapCell.Count + 5; i++) { Vector2 p1 = new Vector2(ColumnInterval / 2f, -(i * RowInterval + RowInterval / 2f)); GameObject g = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.Item, "Building/FillBG", isCache: true); g.transform.position = p1; g.transform.rotation = Quaternion.identity; g.transform.localScale = new Vector3(1, 1, 1); if (i >= 0 && i < m_MapCell.Count) { FillBG fillBg = g.GetComponent <FillBG>(); fillBg.ToBottom(); } } }
public void OnStanderDestory(Stander stander) { RemoveRefreshStander(stander); }
private void OnPlayerArriveTarget(Cell preCell, Cell targetCell, Stander player) { player.RefreshCell(targetCell); preCell.RemoveRefreshStander(player); targetCell.AddRefreshStander(player); //是否有钥匙 if (((RoleCtrl)player).HasKey) { for (int i = 0; i < targetCell.StanderList.Count; i++) { if (targetCell.StanderList[i].StanderType == StanderType.GateWay) { OnWin(); return; } } } //StepObstacles(随着玩家移动轮流隐藏出现的的障碍物) 改变状态 List <Stander> sos = m_ObstaclesList.FindAll(x => ((Obstacles)x).ObstaclesType == ObstaclesType.Step); if (sos.Count > 0) { LFrameWork.Sound.EazySoundManager.PlaySound(m_StepObstaclesSound); } for (int i = 0; i < sos.Count; i++) { ((StepObstacles)sos[i]).Change(); } if (!m_NumberLockOpen) { //判断前方是否是数字障碍物 Cell c = ((RoleCtrl)m_Player).GetForwardCell(); if (c != null && c.StanderList.Count > 0) { for (int i = 0; i < c.StanderList.Count; i++) { if (c.StanderList[i].StanderType == StanderType.Obstacles && ((Obstacles)c.StanderList[i]).ObstaclesType == ObstaclesType.Number) { if (m_TriggerNumberObstaclesList.Contains((NumberObstacles)c.StanderList[i])) { continue; } m_TriggerNumberObstaclesList.Add((NumberObstacles)c.StanderList[i]); if (m_TriggerNumberObstaclesList.Count >= 3) { //触发成功 if (m_NumberTotal == GetNumberTotal()) { for (int j = 0; j < m_TriggerNumberObstaclesList.Count; j++) { m_TriggerNumberObstaclesList[j].TriggerSucess(); m_NumberLockOpen = true; //找到所有的数字锁,让其消失 List <Stander> noos = m_ObstaclesList.FindAll(x => ((Obstacles)x).ObstaclesType == ObstaclesType.NumberLock); for (int t = 0; t < noos.Count; t++) { ((NumberLockObstacles)noos[t]).Hide(); } } } else//触发失败 { for (int j = 0; j < m_TriggerNumberObstaclesList.Count; j++) { m_TriggerNumberObstaclesList[j].TriggerFail(); } m_TriggerNumberObstaclesList.Clear(); } } else { ((NumberObstacles)c.StanderList[i]).Trigger(); } } } } } }
public void OnStanderDestory(Stander stander) { StanderList.Remove(stander); }