Created
April 2, 2018 13:09
-
-
Save shana/6fb3ae2f1d51230c95b4843047410efe to your computer and use it in GitHub Desktop.
FirstRun example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
[InitializeOnLoad] | |
[Location("our_cache.txt", LocationAttribute.Location.LibraryFolder)] | |
public class FirstRun : ScriptObjectSingleton<FirstRun> | |
{ | |
[SerializeField] private string lastTimeWeRan; | |
public string LastTimeWeRan | |
{ | |
get { return lastTimeWeRan; } | |
set | |
{ | |
lastTimeWeRan = value; | |
Save(true); | |
} | |
} | |
static FirstRun() | |
{ | |
EditorApplication.delayCall += EntryPoint; | |
} | |
static void EntryPoint() | |
{ | |
var isFirstRun = instance == null; | |
var theRealInstance = Instance; | |
if (isFirstRun) | |
{ | |
Debug.LogFormat("Running for the first time! The last time we ran was '{0}'", theRealInstance.LastTimeWeRan); | |
theRealInstance.LastTimeWeRan = DateTimeOffset.UtcNow.ToString("yyyyMMddHHmmss"); | |
} | |
else | |
Debug.LogFormat("I saw what you did there Unity! The last time we ran was '{0}'", theRealInstance.LastTimeWeRan); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment