Esempio n. 1
0
    public void StartListenerFirebase(object sender, ValueChangedEventArgs args)
    {
        if (args.DatabaseError != null)
        {
            Debug.LogError(args.DatabaseError.Message);
            return;
        }

        // When game has all units, build queue list and advance turn
        if (args.Snapshot.ChildrenCount == 6)
        {
            gameBoard.gameDatabaseReference.Child("units").ValueChanged -= StartListenerFirebase;

            queueList = new List <QueueUnit>();

            foreach (DataSnapshot child in args.Snapshot.Children)
            {
                QueueUnit addQueueUnit = JsonUtility.FromJson <QueueUnit>(child.GetRawJsonValue());
                queueList.Add(addQueueUnit);
            }

            StartCoroutine(AdvanceTurn());

            GAME_STARTED = true;
        }
    }
        // This coroutine will be running as long as the provider instance exists
        private IEnumerator ConstantWorkingCoroutine()
        {
            while (true)
            {
                // if no request, just wait until it does
                while (m_displayRequestQueue.Count == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }

                bool isDisplayNewlyCreated = false;
                // if a displaying prefab is not there for us th edit the text, create one
                if (m_currentDisplayingText == null)
                {
                    m_currentDisplayingText = Instantiate(textDisplayPrefab, targetCanvas.transform);
                    isDisplayNewlyCreated   = true;
                }

                // retrieve resolving unit and set data to text accordingly
                QueueUnit currentUnit = m_displayRequestQueue.First.Value;
                m_displayRequestQueue.RemoveFirst();
                m_currentDisplayingText.GetComponentInChildren <Text>().text = currentUnit.content;

                // if we just created the displaying prefab, we need to fade it in
                if (isDisplayNewlyCreated)
                {
                    yield return(StartCoroutine(FadingCoroutine(true)));
                }

                // just let the text hang in there
                // might add a InterruptAction so player can click to skip a text
                yield return(new WaitForSeconds(currentUnit.durationTime));

                //// Also, if you need to read the input from a coroutine, make sure to skip a frame
                //// to refresh the input states
                //yield return new WaitUntil(() =>
                //{
                //    return Input.GetMouseButtonDown(0);
                //});
                //// refresh input states
                //yield return new WaitForEndOfFrame();

                if (currentUnit.onDisplayEnded != null)
                {
                    currentUnit.onDisplayEnded.Invoke();
                }

                if (m_displayRequestQueue.Count == 0)
                {
                    yield return(StartCoroutine(FadingCoroutine(false)));

                    // !! IMPORTANT !! : Unity only destroy GameObejcts at the end of the frame,
                    // so we need to wait an additional frame to actually destroy the
                    // m_currentDisplayingText. Otherwise it might lead to judgemental bug when
                    // deciding whether m_currentDisplayingText is null in next loop.
                    Destroy(m_currentDisplayingText);
                    yield return(new WaitForEndOfFrame());
                }
            }
        }
Esempio n. 3
0
    public void Push(Action action, PopPriority priority, PopCondition condition)
    {
        QueueUnit queueUnit = new QueueUnit
        {
            action    = action,
            priority  = (uint)priority,
            condition = condition
        };

        this.m_actionlist.Add(queueUnit);
        this.m_actionlist = Enumerable.ToList <QueueUnit>(Enumerable.OrderByDescending <QueueUnit, uint>(this.m_actionlist, (QueueUnit t) => t.priority));
    }
Esempio n. 4
0
    void StartGame()
    {
        queueList = new List <QueueUnit>();

        foreach (UnitClass unit in gameBoard.unitList)
        {
            QueueUnit addQueueUnit = new QueueUnit(unit.entityID, unit.playerTeam, unit.playerName, unit.entityName, unit.unitCooldownMax, unit.unitCooldown);
            queueList.Add(addQueueUnit);
        }

        StartCoroutine(AdvanceTurn());
    }
Esempio n. 5
0
 public bool CheckQueue(PopCondition condition)
 {
     if (!this.Islocked)
     {
         for (int i = 0; i < this.m_actionlist.get_Count(); i++)
         {
             if (this.m_actionlist.get_Item(i).condition == condition)
             {
                 QueueUnit queueUnit = this.m_actionlist.get_Item(i);
                 this.m_actionlist.RemoveAt(i);
                 queueUnit.JustCall();
                 this.Islocked = true;
                 return(true);
             }
         }
     }
     return(false);
 }