NotifyForLockedFiles.cs 1.54 KB
Newer Older
1
2
3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
4
5
6
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;
7
8
using System.IO;

9
[InitializeOnLoad]
10
public class NotifyForLockedFiles : UnityEditor.AssetModificationProcessor
11
12
13
14
15
16
17
18
19
20
21
22
{
	static NotifyForLockedFiles()
	{
		EditorSceneManager.activeSceneChangedInEditMode += CheckActivatedScene;
		if (EditorSceneManager.GetActiveScene() != null)
		{
			CheckActivatedScene(EditorSceneManager.GetActiveScene(), EditorSceneManager.GetActiveScene());
		}
	}


    public static string[] OnWillSaveAssets(string[] paths)
23
    {
24
25
26
        List<string> pathsToSave = new List<string>();

        for (int i = 0; i < paths.Length; ++i)
27
        {
28
29
30
31
32
33
34
            FileInfo info = new FileInfo(paths[i]);
            if (info.IsReadOnly)
                UnityEditor.EditorUtility.DisplayDialog("Konnte nicht speichern",
                "Die Scene " + paths[i] + " ist Read-Only. Sie konnte nicht gespeichert werden. Sie kann aber unter anderem Namen gespeichert werden.",
                "Ok");
            else
                pathsToSave.Add(paths[i]);
35
        }
36
37
38
39
40
41
42
43
44
45
46

        return pathsToSave.ToArray();
    }

    public static void CheckActivatedScene(Scene oldScene, Scene newScene)
    {
    	FileInfo info = new FileInfo(newScene.path);
    	if (info.IsReadOnly)
    	{
    		UnityEditor.EditorUtility.DisplayDialog("Read-Only", "Die Scene " + newScene.path + " ist Read-Only. Sie wird nicht gespeichert werden können.", "Ok");
    	}
47
    }
48
}
49