How can I tell the user has deleted something in a scene given the way moving from edit mode to play mode and back in the editor trigger object destruction and recreation?

Some of my objects make dynamically created materials specifically for them when they have been created in the editor. I want to manage these resources and have them be removed along with the game object that necessitated them if the user decides to delete that game object.

However, I do NOT want the materials removed just because the user entered Play mode in the editor and then returned to edit mode. In this case the game object is essentially destroyed and reconstructed and it seems there is nothing that will let me know that it is the system destroying the object and not a user, and that the materials are still needed.

Write your destroy code for the materials in the OnDestroy() function of their parent objects, but test with an if statement, if the player/application is quitting:

privat var isQuitting : boolean = false;

function OnApplicationQuit() {
    isQuitting = true;
}

function OnDestroy() {
    if(!isQuitting) {
        DestroyMaterials();
    }
}

ApplicationQuit is called before Destroy.