· 6 years ago · Jan 28, 2020, 01:12 PM
1using UnityEngine;
2using System;
3using System.IO;
4#if UNITY_EDITOR
5using UnityEditor;
6#endif
7
8
9[Serializable]
10#if UNITY_EDITOR
11[InitializeOnLoad]
12#endif
13
14
15
16public class AskBluSettings : ScriptableObject
17{
18 const string AskBluSettingsAssetName = "AskBluSettings";
19
20 const string AskBluSettingsPath = "Resources";
21
22 const string AskBluSettingsAssetExtension = ".asset";
23 private static AskBluSettings instance;
24 public static AskBluSettings GetInstance
25 {
26 get
27 {
28 if (instance == null)
29 {
30 instance = Resources.Load(AskBluSettingsAssetName) as AskBluSettings;
31
32 if (instance == null)
33 {
34
35 instance = CreateInstance<AskBluSettings>();
36#if UNITY_EDITOR
37
38 CreateFolder(AskBluSettingsPath);
39
40 string fullPath = Path.Combine(Path.Combine("Assets", AskBluSettingsPath),
41 AskBluSettingsAssetName + AskBluSettingsAssetExtension
42 );
43
44 AssetDatabase.CreateAsset(instance, fullPath);
45#endif
46 }
47 }
48 return instance;
49 }
50 }
51
52 public string ApiKey = "Paste Api Key Here";
53 public static bool isNewPlayer()
54 {
55 //rewrite this function with your logic
56 return true;
57 }
58 public static askbluai_Mode getSDKMode()
59 {
60 return askbluai_Mode.RELEASE;
61 }
62
63#if UNITY_EDITOR
64 [MenuItem("Tools/AskBlu Settings")]
65 private static void OpenAskBluSettings()
66 {
67 Selection.activeObject = AskBluSettings.GetInstance;
68 }
69
70 public static bool IsFolderExists(string folderPath)
71 {
72 if (folderPath.Equals(string.Empty))
73 {
74 return false;
75 }
76
77 return Directory.Exists(GetFullPath(folderPath));
78 }
79
80 private static void CreateFolder(string folderPath)
81 {
82 if (!IsFolderExists(folderPath))
83 {
84 Directory.CreateDirectory(GetFullPath(folderPath));
85
86 AssetDatabase.Refresh();
87 }
88 }
89 private static bool IsFileExists(string fileName)
90 {
91 if (fileName.Equals(string.Empty))
92 {
93 return false;
94 }
95
96 return File.Exists(GetFullPath(fileName));
97 }
98
99 private static void CreateFile(string fileName)
100 {
101 if (!IsFileExists(fileName))
102 {
103 CreateFolder(fileName.Substring(0, fileName.LastIndexOf('/')));
104
105#if UNITY_4 || UNITY_5
106
107 FileStream stream = File.Create (GetFullPath (fileName));
108 stream.Close();
109
110#else
111 File.Create(GetFullPath(fileName));
112#endif
113 }
114
115 }
116 private static string GetFullPath(string srcName)
117 {
118 if (srcName.Equals(string.Empty))
119 {
120 return Application.dataPath;
121 }
122
123 if (srcName[0].Equals('/'))
124 {
125 srcName.Remove(0, 1);
126 }
127
128 return Application.dataPath + "/" + srcName;
129 }
130#endif
131
132}