/// <summary>
        /// Creates a UI element for the given demand and adds it to the demand queue.
        /// </summary>
        /// <param name="demand">The demand to add a UI element for.</param>
        public void AddDemand(Demand demand)
        {
            if (!this.demandUIElements.ContainsKey(demand.ID))
            {
                GameObject       uiElement        = GameObject.Instantiate(this.demandedMatterUIPrefab, Vector3.zero, Quaternion.identity, this.queueElementsContainer.transform);
                DemandedMatterUI demandedMatterUI = uiElement.GetComponent <DemandedMatterUI>();

                if (demandedMatterUI != null)
                {
                    demandedMatterUI.SetDemand(demand);
                    this.demandUIElements.Add(demand.ID, demandedMatterUI);
                }
                else
                {
                    Debug.LogWarning("Demanded Matter UI prefab is missing!", this);
                }
            }
            else
            {
                Debug.LogWarning($"Can't add demand with ID {demand.ID} as it already exists inside the queue.");
            }
        }
Esempio n. 2
0
        public override void OnDeserialize(NetworkReader reader, bool initialState)
        {
            base.OnDeserialize(reader, initialState);

            if (initialState)
            {
                int    amountOfDemands = reader.ReadInt32();
                Demand demand;

                for (int i = 0; i < amountOfDemands; i++)
                {
                    demand = new Demand(reader.ReadInt32(), Matter.GetByID(reader.ReadString()), reader.ReadSingle());

                    if (demand.HasTimeLimit)
                    {
                        demand.SetTimeLeft(reader.ReadSingle());
                    }

                    this.AcceptDemand(demand);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Called when a demand is removed from the demand queue.
 /// Removes the demand from the demand queue UI.
 /// </summary>
 /// <param name="demand">The demand that was removed.</param>
 private void DemandQueue_OnDemandRemoved(Demand demand) => GameManager.UI.LevelUI.DemandQueue.RemoveDemand(demand);
Esempio n. 4
0
 /// <summary>
 /// Called when a new demand is added to the demand queue.
 /// Adds the demand to the demand queue UI.
 /// </summary>
 /// <param name="demand">The new demand that has been added.</param>
 private void DemandQueue_OnDemandAdded(Demand demand) => GameManager.UI.LevelUI.DemandQueue.AddDemand(demand);
Esempio n. 5
0
 /// <summary>
 /// Called when a demand expires.
 /// Fires <see cref="OnDemandExpired"/> and removes the demand from the queue.
 /// Only called on the server since this event is only registered on the server side.
 /// </summary>
 /// <param name="demandedMatterUI">The demand that has expired.</param>
 private void Demand_OnExpired_Server(Demand demand)
 {
     this.OnDemandExpired?.Invoke(demand);
     this.RemoveDemand(demand);
 }