예제 #1
0
        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());
        }
예제 #2
0
        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());
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
    void Update()
    {
        if (Time.time >= nextRotateAction)
        {
            bool   skipRotate = false;
            string action     = rotatePattern.GetNextAction();
            switch (action)
            {
            case "delay":
                break;

            case "sync":
                skipRotate = spawnPattern.GetCurrentStep() > 0;
                break;

            default:
                int degrees = int.Parse(action);
                transform.Rotate(new Vector3(0, degrees, 0));
                break;
            }

            if (!skipRotate)
            {
                if (rotatePattern.Next() != null)
                {
                    nextRotateAction = Time.time + (float)rotatePattern.GetNextExecution() / 1000;
                }
                else
                {
                    nextRotateAction = float.MaxValue;
                }
            }
        }

        if (Time.time >= nextSpawnAction)
        {
            string action = spawnPattern.GetNextAction();
            switch (action)
            {
            case "delay":
                break;

            default:
                if (_onlyPlayOnFire && _audioSource != null)
                {
                    _audioSource.pitch = Random.Range(0.9f, 1.1f);
                    _audioSource.Play();
                }
                Bullet obj = Instantiate <Bullet>(bullet, transform.position + transform.TransformVector(bulletSpawnOffset), transform.rotation);
                obj.IsFriendly = IsFriendlyFire;
                obj.Launch((transform.forward * speed) + relativeVelocity);
                break;
            }

            if (spawnPattern.Next() != null)
            {
                nextSpawnAction = Time.time + (float)spawnPattern.GetNextExecution() / 1000;
            }
            else
            {
                nextSpawnAction = float.MaxValue;
            }
        }
    }