void CreateUnit(Move move) { UnitFrame unit = new UnitFrame(); unit.HexGrid = this; unit.NextMove = move; unit.playerId = move.PlayerId; unit.MoveUpdateStats = move.Stats; unit.UnitId = move.UnitId; if (move.Stats.EngineLevel == 0) { // Cannot move to targetpos unit.currentPos = move.Positions[move.Positions.Count - 1]; } else { // Move to targetpos unit.currentPos = move.Positions[0]; } unit.Assemble(); Units.Add(move.UnitId, unit); /* * Text label = Instantiate<Text>(cellLabelPrefab); * label.rectTransform.SetParent(gridCanvas.transform, false); * label.rectTransform.anchoredPosition = new Vector2(unitPos3.x, unitPos3.z); * label.text = "\r\n" + move.UnitId;*/ }
// Update is called once per frame void Update() { UnitFrame?.Move(this); if (UnitFrame?.NextMove?.MoveType == MoveType.Upgrade) { if (UnitFrame.NextMove?.MoveType == MoveType.Upgrade && UnitFrame.NextMove?.Stats != null) { UnitFrame.MoveUpdateStats = UnitFrame.NextMove.Stats; UnitFrame.Assemble(); } if (particleSource == null) { Position from = UnitFrame.NextMove.Positions[0]; HexCell sourceCell = UnitFrame.HexGrid.GroundCells[from]; particleSource = UnitFrame.HexGrid.MakeParticleSource("ExtractSource"); particleSource.transform.SetParent(sourceCell.Cell.transform, false); } Position to = UnitFrame.NextMove.Positions[UnitFrame.NextMove.Positions.Count - 1]; HexCell targetCell = UnitFrame.HexGrid.GroundCells[to]; ParticleSystemForceField particleTarget = UnitFrame.HexGrid.MakeParticleTarget(); particleTarget.transform.SetParent(targetCell.Cell.transform, false); Vector3 unitPos3 = particleTarget.transform.position; unitPos3.y += 0.1f; particleTarget.transform.position = unitPos3; particleSource.externalForces.SetInfluence(0, particleTarget); HexGrid.Destroy(particleTarget, 2.5f); particleSource.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); var main = particleSource.main; main.duration = particleSource.main.duration * UnitFrame.HexGrid.GameSpeed; //particleSource.main.duration = particleSource.main.duration * UnitFrame.HexGrid.GameSpeed; particleSource.Play(); ParticleSystem particleDust = UnitFrame.HexGrid.MakeParticleSource("Build"); particleDust.transform.SetParent(targetCell.Cell.transform, false); particleDust.transform.position = particleTarget.transform.position; particleDust.Play(); HexGrid.Destroy(particleDust, 2.5f); UnitFrame.NextMove = null; } }