private FoundPath pathToGoal; // path from associated tile to goal tile private void Start() { if (null == pathShower) { Debug.LogWarning("set path shower field"); pathShower = Resources.FindObjectsOfTypeAll <PathShower>()[0]; // BAD } Debug.Assert(null != pathShower); DefendState.Instance.openDefend += GetPath; pathShower.pathFound += OnPathToGoalFound; // stop coroutine on exit?? if (null == associatedTile) { associatedTile = GetComponent <MapTile>(); // ToDo: better system } spawnElapsedTime = 0; }
public override void OnEnter() { base.OnEnter(); openDefend?.Invoke(); // ToDo: currentLevel.Board.goalTile.CastleHealth = castleHealth; // StartCoroutine("StartDelay"); // wait until found path PathShower ps = FindObjectOfType <PathShower>(); ps.pathFound += (() => PauseState.Instance.OnExit()); // THIS IS BAD if (Debugger.Instance.StateChangeMessages) { Debug.Log("enter defend"); } if (pauseOnEnter) { PauseState.Instance.PauseGame(true); } }
void Start() { currentpath = this.transform.FindChild ("Path").GetComponent<Text> (); addgame = this.transform.FindChild ("Panel").FindChild ("AddGame").GetComponent<Button> (); shower = GameObject.FindObjectOfType<PathShower> (); }
void Start() { currentpath = this.transform.FindChild("Path").GetComponent <Text> (); addgame = this.transform.FindChild("Panel").FindChild("AddGame").GetComponent <Button> (); shower = GameObject.FindObjectOfType <PathShower> (); }
/// <summary> /// 定时器,实现小人和线条按路径移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { if (_showers.Count == 0) { timer1.Enabled = false; } var isPathEnd = false; //是否已经到达 var isArrive = false; //垂直向下移动 if (_currentShower.VerticalDirection == Direction.Vertical) { _currentShower.CurrentPoint = new Point(_currentShower.CurrentPoint.X, _currentShower.CurrentPoint.Y + MoveStep); //小人重新定位 pictureBoxPerson.Location = new Point(_currentShower.CurrentPoint.X - pictureBoxPerson.Width / 2, _currentShower.CurrentPoint.Y + MoveStep - pictureBoxPerson.Height / 2); //线条高度加1 _currentShower.LineY.Height += MoveStep; //已经移动到终点 if (_currentShower.CurrentPoint.Y >= _currentShower.EndPoint.Y) { isPathEnd = true; } //已经到达 if (_currentShower.CurrentPoint.Y == _currentShower.ArrivePoint.Y) { isArrive = true; } } else//水平移动 { //向左移动 if (_currentShower.LeftOfRight == Direction.Left) { _currentShower.CurrentPoint = new Point(_currentShower.CurrentPoint.X - MoveStep, _currentShower.CurrentPoint.Y); _currentShower.LineX.Location = _currentShower.CurrentPoint; //线条宽度加 _currentShower.LineX.Width += MoveStep; //已经移动到终点 if (_currentShower.CurrentPoint.X <= _currentShower.EndPoint.X) { isPathEnd = true; } } else//向右移动 { _currentShower.CurrentPoint = new Point(_currentShower.CurrentPoint.X + MoveStep, _currentShower.CurrentPoint.Y); //线条宽度加 _currentShower.LineX.Width += MoveStep; //已经移动到终点 if (_currentShower.CurrentPoint.X >= _currentShower.EndPoint.X) { isPathEnd = true; } } //小人重新定位 pictureBoxPerson.Location = new Point(_currentShower.CurrentPoint.X - pictureBoxPerson.Width / 2, _currentShower.CurrentPoint.Y + MoveStep - pictureBoxPerson.Height / 2);// _currentShower.CurrentPoint; } //已经到达 if (isArrive) { if (_currentShower.PathName != ' ') { if (PathParameters.ContainsKey(_currentShower.PathName)) { //记录走过路径的概率值 _walkPathValues[_currentShower.PathName] = PathParameters[_currentShower.PathName]; CalculatePath(); } } } //是否已经走到当前路径终点 if (isPathEnd) { //已经是最后一个展示则结束本次路径演示,否则取下一条路径,继续展示 if (_currentShower.Index + 1 >= _showers.Count) { timer1.Enabled = false; return; } _currentShower = _showers[_currentShower.Index + 1]; } }
/// <summary> /// 显示路径初始化 /// </summary> private void PathInit(List <char> routes) { PathClear(); //清除走过路径的值 _walkPathValues.Clear(); var index = 0; //加入起点 routes.Insert(0, 'x'); for (var i = 0; i < routes.Count; i++) { var controls = groupBox1.Controls.Find("panel" + routes[i].ToString(), false); if (controls.Length == 0) { throw new Exception("panel" + routes[i].ToString() + "的控件不存在!"); } var panel = controls[0] as Panel; if (panel == null) { throw new Exception("panel" + routes[i].ToString() + "的控件不存在!"); } //panel的中心坐标 var panelCenterPoint = new Point(panel.Left + panel.Width / 2, panel.Top + panel.Height / 2); //设置上一路径结束坐标 if (i > 0) { var previousShower = _showers[index - 1]; //x轴=当前节点的x轴 var endPoint = new Point(panel.Left + panel.Width / 2, previousShower.StartPoint.Y); if (endPoint.X > previousShower.StartPoint.X) { //向右移动 previousShower.LeftOfRight = Direction.Right; } else { //向左移动 previousShower.LeftOfRight = Direction.Left; } previousShower.EndPoint = endPoint; } //不是最后节点 if (i < routes.Count - 1) { //竖线 var lineY = new LineY { LineColor = Color.Red, LineWidth = 3, Width = 0, Height = 0 }; groupBox1.Controls.Add(lineY); lineY.BringToFront(); var shower = new PathShower { PathName = routes[i], Index = index++, LineY = lineY, VerticalDirection = Direction.Vertical, //到达位置 ArrivePoint = panelCenterPoint }; if (i == 0) { shower.StartPoint = panelCenterPoint; } else { shower.StartPoint = _showers[index - 2].EndPoint; } lineY.Location = shower.StartPoint; shower.CurrentPoint = shower.StartPoint; _showers.Add(shower); //寻找节点框图底部的panel Panel bottomPanel = null; foreach (var ct in groupBox1.Controls) { var pnl = ct as Panel; if (pnl != null && pnl.Name != "panel" + routes[i].ToString()) { var pName = pnl.Name; pName = pName.Replace("panel", ""); if (pName.Contains(routes[i])) { bottomPanel = pnl; } } } if (bottomPanel == null) { throw new Exception("未找到底部Panel!"); } var bottomMiddle = bottomPanel.Top + bottomPanel.Height / 2; //节点框图的结束坐标 shower.EndPoint = new Point(shower.StartPoint.X, bottomMiddle); //添加横线 var lineX = new LineX { LineColor = Color.Red, LineWidth = 3, Width = 0, Height = 3 }; groupBox1.Controls.Add(lineX); lineX.BringToFront(); var bottomShower = new PathShower { PathName = ' ', //路径名称为空字符 Index = index++, StartPoint = shower.EndPoint, //开始坐标等于上一路径的结束坐标 VerticalDirection = Direction.Horizontal, //水平方向移动 LineX = lineX }; lineX.Location = bottomShower.StartPoint; bottomShower.CurrentPoint = bottomShower.StartPoint; _showers.Add(bottomShower); } else//最后一个节点 { //竖线 var lineY = new LineY { LineColor = Color.Red, LineWidth = 3, Width = 0, Height = 0 }; groupBox1.Controls.Add(lineY); lineY.BringToFront(); var shower = new PathShower { PathName = routes[i], Index = index++, LineY = lineY, VerticalDirection = Direction.Vertical, StartPoint = _showers[index - 2].EndPoint, EndPoint = panelCenterPoint, //到达位置 ArrivePoint = panelCenterPoint }; shower.CurrentPoint = shower.StartPoint; lineY.Location = shower.StartPoint; _showers.Add(shower); } } _currentShower = _showers[0]; }