少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using UnityEngine;
using UnityEditor;
 
namespace Beebyte.Obfuscator
{
    public class OptionsManager
    {
        public const string ImportAssetName = "ObfuscatorOptionsImport";
        public const string OptionsAssetName = "ObfuscatorOptions";
 
        public const string DefaultImportPath = @"Assets/Editor/Beebyte/Obfuscator/ObfuscatorOptionsImport.asset";
        public const string DefaultOptionsPath = @"Assets/Editor/Beebyte/Obfuscator/ObfuscatorOptions.asset";
 
        public static Options LoadOptions()
        {
            if (HasInstallFiles()) Install();
 
            Options o = LoadAsset(OptionsAssetName);
 
            if (o != null) return o;
            
            Debug.LogError("Failed to load " + OptionsAssetName + " asset at " + DefaultOptionsPath);
            return null;
        }
 
        private static bool HasInstallFiles()
        {
            return LoadAsset(ImportAssetName) != null;
        }
 
        private static Options LoadAsset(string name)
        {
            string path = GetAssetPath(name);
 
            return LoadAssetAtPath(path);
        }
 
        private static void Install()
        {
            Options importOptions = LoadAsset(ImportAssetName);
            if (importOptions == null)
            {
                Debug.LogError("Could not find " + ImportAssetName + ".asset - aborting installation.");
                return;
            }
 
            string importPath = GetAssetPath(ImportAssetName);
            string newOptionsPath = GetInstallPathFromImport(importPath);
 
            Options o = LoadAssetAtPath(newOptionsPath);
 
            if (o != null)
            {
                bool overwrite = EditorUtility.DisplayDialog("Obfuscator Installation", "ObfuscatorOptions already exists, would you like to replace it with new default options?", "Use new defaults", "Keep existing settings");
                if (overwrite) AssetDatabase.MoveAssetToTrash(newOptionsPath);
                else
                {
                    AssetDatabase.MoveAssetToTrash(importPath);
                    return;
                }
            }
 
            //Copy & Delete instead of Move, otherwise future installs think that ObfuscatorOptions is actually ObfuscatorOptionsImport
            AssetDatabase.CopyAsset(importPath, newOptionsPath);
            AssetDatabase.DeleteAsset(importPath);
            AssetDatabase.Refresh();
        }
 
        private static string GetDefaultPath(string assetName)
        {
            if (ImportAssetName.Equals(assetName)) return DefaultImportPath;
            if (OptionsAssetName.Equals(assetName)) return DefaultOptionsPath;
            return null;
        }
 
#if UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_5_0 || UNITY_5_1
        private static string GetAssetPath(string name)
        {
            return GetDefaultPath(name);
        }
 
        private static Options LoadAssetAtPath(string path)
        {
            return (Options)Resources.LoadAssetAtPath(path, typeof(Options));
        }
#else
        private static string GetAssetPath(string name)
        {
            string guid = SearchForAssetGuid(name);
 
            return guid != null ? AssetDatabase.GUIDToAssetPath(guid) : null;
        }
 
        private static Options LoadAssetAtPath(string path)
        {
            return AssetDatabase.LoadAssetAtPath<Options>(path);
        }
 
        private static string SearchForAssetGuid(string assetName)
        {
            string[] optionPaths = AssetDatabase.FindAssets(assetName);
 
            if (optionPaths.Length == 0) return null;
            if (optionPaths.Length == 1) return optionPaths[0];
            
            Debug.LogError("Multiple " + assetName + " assets found! Aborting");
            return null;
        }
#endif
 
        private static string GetInstallPathFromImport(string importPath)
        {
            return importPath.Replace(ImportAssetName + ".asset", OptionsAssetName + ".asset");
        }
    }
}