Example #1
0
 private static void OnProjectChanged()
 {
     if (SalinSetting.Data == null)
     {
         SalinSetting.CreateDataSettings();
         if (SalinSetting.Data == null)
         {
             Debug.LogError("CreateSettings() failed to create SalinSetting.Data.");
             return;
         }
     }
 }
Example #2
0
        public static void CreateDataSettings()
        {
            AssetDatabase.Refresh();
            SalinSetting.Data = (SalinData)Resources.Load(SalinConstants.dataSettingsFileName, typeof(SalinData));
            if (SalinSetting.Data != null)
            {
                return;
            }

            // if the project does not have SalinData yet, enable "Development Build" to use the Dev Region.
            EditorUserBuildSettings.development = true;

            // find out if SalinData can be instantiated (existing script check)
            ScriptableObject dataSettingTest = ScriptableObject.CreateInstance("SalinData");

            if (dataSettingTest == null)
            {
                Debug.LogError("missing settings script");
                return;
            }
            UnityEngine.Object.DestroyImmediate(dataSettingTest);

            // if still not loaded, create one
            if (SalinSetting.Data == null)
            {
                string _resourcesPath = SalinSetting.FindSalinAssetFolder();

                _resourcesPath += "Resources/";

                string dataSettingsAssetPath = _resourcesPath + SalinConstants.dataSettingsFileName + ".asset";
                string settingsPath          = Path.GetDirectoryName(dataSettingsAssetPath);
                if (!Directory.Exists(settingsPath))
                {
                    Directory.CreateDirectory(settingsPath);
                    AssetDatabase.ImportAsset(settingsPath);
                }

                SalinSetting.data = (SalinData)ScriptableObject.CreateInstance("SalinData");
                if (SalinSetting.Data != null)
                {
                    AssetDatabase.CreateAsset(SalinSetting.Data, dataSettingsAssetPath);
                }
                else
                {
                    Debug.LogError("SalinSDK failed creating a settings file. ScriptableObject.CreateInstance(\"SalinData\") returned null. Will try again later.");
                }
            }
        }