Beispiel #1
0
    void UpdateInsertion()
    {
        // Move chain and Add bullet to chain
        int dequeSize = 0;

        foreach (MovementRegistrationEntry entry in insertionQueue)
        {
            if (Time.frameCount > entry.registerFrame)
            {
                // move all the leading balls
                foreach (GameObject ball in balls)
                {
                    float deltaTime = Time.deltaTime;
                    if (entry.proceedTime + deltaTime > insetionSmoothTime)
                    {
                        deltaTime = insetionSmoothTime - entry.proceedTime;
                    }
                    ball.GetComponent <BallChainMovement>()
                    .PushFoward(diameterPercentPerSecond * deltaTime);
                    if (ball == entry.chainBall)
                    {
                        break;
                    }
                }

                entry.proceedTime += Time.deltaTime;

                // TODO: Fix the bug of position mismatch when multiple bullets
                // hit same chainBall
                if (entry.proceedTime > insetionSmoothTime)
                {
                    dequeSize++;
                    int idx = balls.IndexOf(entry.chainBall);
                    if (entry.repeatChainBall > 1)
                    {
                        Debug.Log("Same Time");
                    }
                    if (idx + entry.repeatChainBall >= balls.Count)
                    {
                        Debug.LogWarning("Insertion idx Larger than chain size");
                    }
                    balls.Insert(idx + entry.repeatChainBall, entry.bulletBall);
                    // Synchronizing the remove
                    CheckColorTableEntry setEntry = new CheckColorTableEntry();
                    setEntry.indexReference = idx + entry.repeatChainBall;
                    setEntry.covered        = false;
                    if (!checkColorTable.ContainsKey(entry.bulletBall))
                    {
                        checkColorTable.Add(entry.bulletBall, setEntry);
                    }
                    else
                    {
                        Debug.LogError("Same bulletBall registered twice " + entry.bulletBall);
                    }
                    combo = 0;
                    checkColorRegisterTime = Time.time;
                    //Debug.Log (entry.bulletBall.name + " " + entry.chainBall.name + " " + (idx));
                    entry.bulletBall.GetComponent <Rigidbody> ().isKinematic = false;
                    entry.bulletBall.transform.parent = ballsObject.transform;
                    BallChainMovement ballScript = entry.bulletBall
                                                   .AddComponent <BallChainMovement>();
                    ballScript.currPathPercent = entry.chainBall.GetComponent <BallChainMovement> ().currPathPercent
                                                 - (entry.repeatChainBall) * diameterPercent;
                    spawn.SetPPSForBallScript(ballScript);
                }
            }
            else
            {
                // as it is enqued in time order
                break;
            }
        }

        DequeHeadElements(dequeSize);

        // Move bullet
    }