예제 #1
0
    void Update()
    {
        if (!pInput.IsActive())
        {
            return;
        }

        if (!isLoading && pInput.IsActing())
        {
            isLoading = true;
        }

        if (isLoading)
        {
            if (!pInput.IsActing())
            {
                isLoading  = false;
                loadStatus = 0.0f;

                if (lastTerminal && (lastTerminal.CanUpdateTerminal(pInput.team) || amIInteracting))
                {
                    lastTerminal.StopLoading(pInput.team);
                    lastTerminal   = null;
                    amIInteracting = false;
                }
            }
            else
            {
                GameObject terminal = GetClosestTerminal(maxDistance);

                if (terminal)
                {
                    Terminal t = terminal.GetComponent <Terminal>();

                    if (t.CanAddPackage(pInput.team))
                    {
                        if (lastTerminal != t)
                        {
                            if (lastTerminal)
                            {
                                lastTerminal.StopLoading(pInput.team);
                                amIInteracting = false;
                            }

                            lastTerminal = t;

                            if (lastTerminal.CanUpdateTerminal(pInput.team))
                            {
                                lastTerminal.StartLoading(pInput.team);
                                amIInteracting = true;
                            }
                        }

                        if (amIInteracting)
                        {
                            loadStatus += Time.deltaTime;
                        }

                        if (lastTerminal.CanUpdateTerminal(pInput.team) || amIInteracting)
                        {
                            lastTerminal.UpdateProgress(pInput.team, loadStatus / loadTime);
                        }

                        if (loadStatus >= loadTime)
                        {
                            isLoading  = false;
                            loadStatus = 0.0f;

                            //Spawn packet
                            Package package = Instantiate(packet, beginCentre.position, Quaternion.identity).GetComponent <Package>();
                            package.hookedTo = beginCentre.GetComponentInChildren <Hook>().transform;
                            package.terminal = lastTerminal;

                            lastTerminal.AddPackage(pInput.team);

                            if (lastTerminal.CanUpdateTerminal(pInput.team) || amIInteracting)
                            {
                                lastTerminal.FinishLoading(pInput.team);
                                lastTerminal = null;
                            }
                        }
                    }
                }
                else if (lastTerminal && (lastTerminal.CanUpdateTerminal(pInput.team) || amIInteracting))
                {
                    lastTerminal.StopLoading(pInput.team);
                    lastTerminal   = null;
                    amIInteracting = false;
                }
            }
        }
    }