コード例 #1
0
        float _counterIncrease; // needed for int counters as we won't necessarily update every frame.

        /// <summary>
        /// Awake - if you override then call through to the base class
        /// </summary>
        protected override void Awake()
        {
            base.Awake();
            _oldGameItemNumber = GameItem.GiId;
            _counterReference  = GameItem.GetCounter(Counter);
            Assert.IsNotNull(_counterReference, string.Format("The specified Counter '{0}' was not found. Check that is exists in the game configuration.", Counter));
        }
コード例 #2
0
        /// <summary>
        /// Evaluate the current condition
        /// </summary>
        /// <returns></returns>
        public override bool EvaluateCondition(MonoBehaviour monoBehaviour)
        {
            var gameItem = GameItem;

            if (gameItem)
            {
                var counterReference = GameItem.GetCounter(Counter);
                Assert.IsNotNull(counterReference, string.Format("The specified Counter '{0}' was not found. Check that is exists in the game configuration.", Counter));
                if (counterReference.Configuration.CounterType == ObjectModel.CounterConfiguration.CounterTypeEnum.Int)
                {
                    return(GameConditionHelper.CompareNumbers(counterReference.IntAmount, Comparison, IntAmount));
                }
                else
                {
                    return(GameConditionHelper.CompareNumbers(counterReference.FloatAmount, Comparison, FloatAmount));
                }
            }
            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Update method to update the counter.
        /// </summary>
        /// We need to use Update to get accurate timing incase the level is paused.
        public void Update()
        {
            if (OnlyWhenLevelRunning)
            {
                Assert.IsTrue(LevelManager.IsActive, string.Format("Ensure you have a LevelManager added to your scene to use ChangeCounterOverTime (GameObject: {0})", gameObject.name));
            }

            if (!OnlyWhenLevelRunning || LevelManager.Instance.IsLevelRunning)
            {
                // update counter reference if gameitem has changed (e.g. if selected mode).
                if (_oldGameItemNumber != GameItem.GiId)
                {
                    _counterReference = GameItem.GetCounter(Counter);
                }

                // int counter we can't update each frame as it is an int, so wait until > 1 before increasing
                if (_counterReference.Configuration.CounterType == CounterConfiguration.CounterTypeEnum.Int)
                {
                    _counterIncrease += (float)IntAmount * Time.deltaTime;
                    if (_counterIncrease > 1)
                    {
                        _counterReference.Increase(1);
                        _counterIncrease = _counterIncrease - 1;
                    }
                    else if (_counterIncrease < -1)
                    {
                        _counterReference.Decrease(1);
                        _counterIncrease = _counterIncrease + 1;
                    }
                }
                else
                {
                    _counterReference.Increase(FloatAmount * Time.deltaTime);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Evaluate the current condition
 /// </summary>
 /// <returns></returns>
 public override bool EvaluateCondition(GameItem gameItem)
 {
     return(EvaluateNumber(gameItem.GetCounter(Counter).IntAmount, Comparison, IntValue));
 }
コード例 #5
0
 // show counters - int then float to keep the interface nice due to different buttons.
 static void ShowCounters(List <CounterConfiguration> counterConfigurationList, GameItem gameItem)
 {
     foreach (var counterConfiguration in counterConfigurationList)
     {
         GUILayout.BeginHorizontal();
         var counter = gameItem.GetCounter(counterConfiguration.Name);
         if (counter.Configuration.CounterType == CounterConfiguration.CounterTypeEnum.Int)
         {
             GUILayout.Label(string.Format("{0} ({1}, {2})", counterConfiguration.Name, counter.IntAmount, counter.IntAmountBest), GUILayout.Width(100));
             if (GUILayout.Button("-100", GUILayout.Width(50)))
             {
                 counter.Decrease(100);
             }
             if (GUILayout.Button("-10", GUILayout.Width(50)))
             {
                 counter.Decrease(10);
             }
             if (GUILayout.Button("-1", GUILayout.Width(50)))
             {
                 counter.Decrease(1);
             }
             if (GUILayout.Button("0", GUILayout.Width(50)))
             {
                 counter.Set(0);
             }
             if (GUILayout.Button("+1", GUILayout.Width(50)))
             {
                 counter.Increase(1);
             }
             if (GUILayout.Button("+10", GUILayout.Width(50)))
             {
                 counter.Increase(10);
             }
             if (GUILayout.Button("+100", GUILayout.Width(50)))
             {
                 counter.Increase(100);
             }
         }
         GUILayout.EndHorizontal();
     }
     foreach (var counterConfiguration in counterConfigurationList)
     {
         GUILayout.BeginHorizontal();
         var counter = gameItem.GetCounter(counterConfiguration.Name);
         if (counter.Configuration.CounterType == CounterConfiguration.CounterTypeEnum.Float)
         {
             GUILayout.Label(string.Format("{0} ({1}, {2})", counterConfiguration.Name, counter.FloatAmount, counter.FloatAmountBest), GUILayout.Width(100));
             if (GUILayout.Button("-100", GUILayout.Width(50)))
             {
                 counter.Decrease(100f);
             }
             if (GUILayout.Button("-10", GUILayout.Width(50)))
             {
                 counter.Decrease(10f);
             }
             if (GUILayout.Button("-1", GUILayout.Width(50)))
             {
                 counter.Decrease(1f);
             }
             if (GUILayout.Button("-0.1", GUILayout.Width(50)))
             {
                 counter.Decrease(0.1f);
             }
             if (GUILayout.Button("0", GUILayout.Width(50)))
             {
                 counter.Set(0f);
             }
             if (GUILayout.Button("+0.1", GUILayout.Width(50)))
             {
                 counter.Increase(0.1f);
             }
             if (GUILayout.Button("+1", GUILayout.Width(50)))
             {
                 counter.Increase(1f);
             }
             if (GUILayout.Button("+10", GUILayout.Width(50)))
             {
                 counter.Increase(10f);
             }
             if (GUILayout.Button("+100", GUILayout.Width(50)))
             {
                 counter.Increase(100f);
             }
         }
         GUILayout.EndHorizontal();
     }
 }
 /// <summary>
 /// Initialisation - call base.Initialise in sub classes.
 /// </summary>
 /// <returns></returns>
 protected override void Initialise()
 {
     base.Initialise();
     CounterReference = GameItem.GetCounter(Counter);
     Assert.IsNotNull(CounterReference, string.Format("The specified Counter '{0}' was not found. Check that is exists in the game configuration.", Counter));
 }