Esempio n. 1
0
        private void OnEnable()
        {
            if (!PublicDisplayerSettings.GetSettings(out settings))
            {
                bool createSettingsFile = EditorUtility.DisplayDialog("Create Settings File?",
                                                                      "A PublicDisplayerSettings file could not be found. Would you like to create one?" +
                                                                      " If you do not create one, your settings can't be saved.",
                                                                      "Yes",
                                                                      "No");

                if (!createSettingsFile)
                {
                    settings = null;
                    return;
                }

                var    script       = MonoScript.FromScriptableObject(this);
                string path         = AssetDatabase.GetAssetPath(script);
                string folderPath   = path.Remove(path.LastIndexOf('/'));
                string settingsPath = folderPath + "/Settings.asset";

                AssetDatabase.CreateAsset(settings, settingsPath);
            }

            EditorUtility.SetDirty(settings);
        }
Esempio n. 2
0
        public static bool GetSettings(out PublicDisplayerSettings settings)
        {
            // Get settings from the cached path.
            settings = AssetDatabase.LoadAssetAtPath <PublicDisplayerSettings>(currentPath);
            if (settings)
            {
                return(true);
            }

            // If the cached path is incorrect, the file has been moved and we need to search for it again.
            string[] guids = AssetDatabase.FindAssets($"t:{typeof(PublicDisplayerSettings).Name}");

            // If we can't find any file, return a generic instance instead...
            if (guids.Length <= 0)
            {
                settings = CreateInstance <PublicDisplayerSettings>();
                return(false);
            }
            // ...or log a warning saying we found too many files.
            else if (guids.Length > 1)
            {
                Debug.LogWarning("More than 1 PublicDisplayerSetting assets were found. " +
                                 "Only the first one will be used. " +
                                 "We recommend deleting all surplus assets.");
            }

            // Get the settings from the filepath.
            string settingsPath = AssetDatabase.GUIDToAssetPath(guids[0]);

            settings    = AssetDatabase.LoadAssetAtPath <PublicDisplayerSettings>(settingsPath);
            currentPath = settingsPath;

            return(true);
        }