private void InitSpawnPattern(string pattern) { spawnPattern = new PatternParser(pattern, true); if (spawnPattern.GetNextExecution() != null) { nextSpawnAction = Time.time + (float)spawnPattern.GetNextExecution() / 1000f; } }
private void InitRotatePattern(string pattern) { rotatePattern = new PatternParser(pattern, true); if (rotatePattern.GetNextExecution() != null) { nextRotateAction = Time.time + (float)rotatePattern.GetNextExecution() / 1000f; } }
public void SimplePattern() { PatternParser p = new PatternParser("500 , x"); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("x", p.GetNextAction()); p.Next(); Assert.IsNull(p.GetNextExecution()); Assert.IsNull(p.GetNextAction()); }
public void EmptyPattern() { PatternParser p = new PatternParser(""); Assert.IsNull(p.GetNextExecution()); Assert.IsNull(p.GetNextAction()); p = new PatternParser(null); Assert.IsNull(p.GetNextExecution()); Assert.IsNull(p.GetNextAction()); }
public void GlobalLoopingPattern() { PatternParser p = new PatternParser("500,x", true); for (int i = 0; i < 100; i++) { Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("x", p.GetNextAction()); p.Next(); } }
public void ComplexPattern() { PatternParser p = new PatternParser("500,x,20,y,loop 1,2,50,z"); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("x", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("y", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("y", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("y", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("z", p.GetNextAction()); p.Next(); Assert.IsNull(p.GetNextExecution()); Assert.IsNull(p.GetNextAction()); }
public void InfinitePattern() { PatternParser p = new PatternParser("50,x,20,y,10,z,loop 3,*"); for (int i = 0; i < 100; i++) { Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("x", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("y", p.GetNextAction()); p.Next(); Assert.True(p.GetNextExecution() > 0); Assert.AreEqual("z", p.GetNextAction()); p.Next(); } }
private void Update() { if (Time.time < delayPassedTime) { return; } if (Time.time >= nextRotateAction) { bool skipRotate = false; string action = rotatePattern.GetNextAction(); // gather delay to next iteration to determine tween length float nextRotateDelay = 1f; if (!skipRotate) { if (rotatePattern.Next() != null) { nextRotateDelay = (float)rotatePattern.GetNextExecution() / 1000f; nextRotateAction = Time.time + nextRotateDelay; } else { nextRotateAction = float.MaxValue; } } switch (action) { case "delay": break; case "sync": skipRotate = spawnPattern.GetCurrentStep() > 0; break; default: int degrees = int.Parse(action); objectToRotate.DOLocalRotate(rotationAxis * degrees, nextRotateDelay, RotateMode.LocalAxisAdd); break; } } if (Time.time >= nextSpawnAction) { string action = spawnPattern.GetNextAction(); switch (action) { case "delay": break; case "audio": if (audioSource != null) { audioSource.Play(); } break; default: shooter?.Fire(); break; } if (spawnPattern.Next() != null) { nextSpawnAction = Time.time + (float)spawnPattern.GetNextExecution() / 1000f; } else { nextSpawnAction = float.MaxValue; } } }