Example #1
0
        /// <summary>Removes X (<paramref name="value"/>) points from this PointSystem's Current Points (always use positive values, the calculation is made within the function).</summary>
        /// <remarks>
        /// If, after the calculation, the amount
        /// of points is greater then 0, then it triggers OnPointsDecreased and OnPointsChanged events. However if, after the calculation, the amount
        /// of points is less or equal to 0 then it triggers OnPointsDecreased, OnPointsChanged and OnPointsZero events.
        ///</remarks>
        /// <param name="value">value to be subtracted from this PointSystem 's Current Points.</param>
        public void RemovePoints(int value)
        {
            if (value > 0)
            {
                int aux = currentPoints - value;

                if (aux > 0)
                {
                    currentPoints = aux;
                    OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
                        CurrentPointsEventArgs = currentPoints
                    };
                    OnPointsDecreased?.Invoke(this, EventArgsData);
                    OnPointsChanged?.Invoke(this, EventArgsData);
                }

                else
                {
                    currentPoints = 0;
                    OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
                        CurrentPointsEventArgs = currentPoints
                    };
                    OnPointsDecreased?.Invoke(this, EventArgsData);
                    OnPointsChanged?.Invoke(this, EventArgsData);
                    OnPointsZero?.Invoke(this, EventArgsData);
                }
            }
            else
            {
                Debug.LogError("value can't be negative nor zero!");
            }
        }
Example #2
0
        /// <summary>Adds X (<paramref name="value"/>) points to this PointSystem's Current Points.</summary>
        /// <remarks>
        /// If, after the calculation, the amount
        /// of points is less then MaxPoints, then it triggers OnPointsIncreased and OnPointsChanged events. However if, after the calculation, the amount
        /// of points is greater or equal to MaxPoints, then it triggers OnPointsIncreased, OnPointsChanged and OnPointsMax events.
        ///</remarks>
        /// <param name="value">value to be summed to this PointSystem's Current Points.</param>
        public void AddPoints(int value)
        {
            if (value > 0)
            {
                int aux = currentPoints + value;// Propriedade auxiliar para não precisar repetir função
                if (aux >= maxPoints)
                {
                    currentPoints = maxPoints;
                    OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
                        CurrentPointsEventArgs = currentPoints
                    };
                    OnPointsMax?.Invoke(this, EventArgsData);

                    OnPointsIncreased?.Invoke(this, EventArgsData);
                    OnPointsChanged?.Invoke(this, EventArgsData);
                }
                else
                {
                    currentPoints = aux;
                    OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
                        CurrentPointsEventArgs = currentPoints
                    };
                    OnPointsIncreased?.Invoke(this, EventArgsData);
                    OnPointsChanged?.Invoke(this, EventArgsData);
                }
            }
            else
            {
                Debug.LogError("value can't be negative nor zero!");
            }
        }
Example #3
0
        /// <summary>
        /// Set CurrentPoints variable to 0
        /// </summary>
        /// <remarks>Triggers the OnPointsChanged and OnPointsZero events</remarks>
        public void ResetPoints()
        {
            currentPoints = 0;

            OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
                CurrentPointsEventArgs = currentPoints
            };

            OnPointsChanged?.Invoke(this, EventArgsData);
            OnPointsZero?.Invoke(this, EventArgsData);
        }
Example #4
0
 /// <summary>
 /// Set currentPoints in the PointsSystem instance
 /// </summary>
 public void SetCurrentPoints(int currentpoints)
 {
     if (currentpoints > 0 && currentpoints <= maxPoints)
     {
         OnPointsDataEventArgs EventArgsData = new OnPointsDataEventArgs {
             CurrentPointsEventArgs = currentPoints
         };
         if (currentpoints == maxPoints)
         {
             OnPointsMax?.Invoke(this, EventArgsData);
         }
         currentPoints = currentpoints;
         OnPointsChanged?.Invoke(this, EventArgsData);
     }
     else
     {
         Debug.LogError("value can't be negative, zero nor greater then MaxPoints!");
     }
 }