Skip to content

Instantly share code, notes, and snippets.

@shana
Created April 2, 2018 13:09
Show Gist options
  • Save shana/6fb3ae2f1d51230c95b4843047410efe to your computer and use it in GitHub Desktop.
Save shana/6fb3ae2f1d51230c95b4843047410efe to your computer and use it in GitHub Desktop.
FirstRun example
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