Skip to content

Instantly share code, notes, and snippets.

@becksebenius
Created March 17, 2014 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save becksebenius/9593857 to your computer and use it in GitHub Desktop.
Save becksebenius/9593857 to your computer and use it in GitHub Desktop.
A small utility which adds a Unity event for preprocessing scene saves.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
public class AssetSaveProcess : AssetModificationProcessor
{
public static event Action OnSaveCurrentScene;
public static string[] OnWillSaveAssets (string[] paths)
{
bool savingCurrentScene = false;
for(int i = 0; i < paths.Length; i++)
{
var path = paths[i];
if(path == EditorApplication.currentScene)
{
savingCurrentScene = true;
}
}
if(savingCurrentScene)
{
if(OnSaveCurrentScene != null)
{
OnSaveCurrentScene();
}
}
return paths;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment