Energy Suite

by mlnv

Simple real-time energy based system for your Unity3d game

( Crawled 4 months ago )
+

EnergySuite

This is a simple real-time energy based system for your Unity3d game. It depends on real-time, so even when the phone is not in the game. It works without an internet connection and is not depends on the time of the device (if you change time - nothing will change), iOS / Android.

Follow me on Twitter

Installation

  • Apply last available unitypackage to your project
  • Place EnergySuiteBehaviour prefab on your first scene (it's DontDestroyOnLoad script)
  • Edit Password and PasswordSalt fields in EnergySuiteConfig.cs
  • Add your time values to TimeValue enum
  • Place you time values to StoredInfo field in EnergySuiteConfig.cs
  • PROFIT

Example Code

Don't forget to add this at the top of the script:

using EnergySuite;

Get current time value amount:

EnergySuiteManager.GetAmount(timeValueType)

Get max time value amount:

EnergySuiteManager.GetMaxAmount(timeValueType)

Manually add amount of time value:

EnergySuiteManager.Add(timeValueType, amount);

Manually use amount of time value:

(returns false if currentAmount < amountToUse)

EnergySuiteManager.Use(timeValueType, amount);

Subscribe on time value amount changed action:

EnergySuiteManager.OnAmountChanged += OnAmountChanged;

void OnAmountChanged(int amount, TimeBasedValue timeBasedValue) {
    string text = amount + "/" + timeBasedValue.MaxAmount;

    switch (timeBasedValue.Type) {
        case TimeValue.Life:
            CurrentLifeAmountText.text = text;
            break;
        case TimeValue.Key:
            CurrentKeyAmountText.text = text;
            break;
        default:
            break;
    }
}

Subscribe on time left tick action :

(updated every sec if not full)

EnergySuiteManager.OnTimeLeftChanged += OnTimeLeftChanged;

void OnTimeLeftChanged(TimeSpan timeLeft, TimeBasedValue timeBasedValue) {

    string formatString = string.Format("{0:00}:{1:00}", timeLeft.Minutes, timeLeft.Seconds);

      switch (timeBasedValue.Type) {
        case TimeValue.Life:
            LifeTimeLeftText.text = formatString;
            break;
        case TimeValue.Key:
            KeyTimeLeftText.text = formatString;
            break;
        default:
            break;
    }
}

Convert time left value to slider value:

TimeLeftSlider.value = EnergySuiteManager.ConvertToSliderValue(timeLeft, timeBasedValue);

All examples you can find at Example folder.

TODO

  • [x] Encrypted PlayerPrefs
  • [x] Native iOS/Android time check
  • [x] Make system handle many simultaneous timers
  • [ ] Add Custom Editor
  • [ ] Simple handler solution for web server
  • [ ] Native iOS/Android notification system

Contribution

Yes, please

Dependencies

This asset use Secured PlayerPrefs and StateKit, so if you already have one of this asset in your project - just delete one copy of it.

Developed By

Maksym Yemelianov

Follow me on Twitter

License

Attribution-NonCommercial-ShareAlike 3.0 Unported with simple explanation with the attribution clause waived. You are free to use EnergySuite in any and all games that you make. You cannot sell EnergySuite directly or as part of a larger game asset.