Ejemplo n.º 1
0
        internal void LoadOrCreateProjectSettingsAsset()
        {
            if (File.Exists(projectSettingsStoragePath))
            {
                // Try loading the existing asset file.
                var objects = InternalEditorUtility.LoadSerializedFileAndForget(projectSettingsStoragePath);

                if (objects.Length <= 0 || objects[0] == null)
                {
                    // The file exists, but it isn't a valid asset.
                    // Warn and leave the asset as is to prevent losing its serialized contents
                    // because we might be able to salvage them by deserializing later on.
                    // Return a new empty instance in the mean time.
                    Debug.LogWarning($"Loading visual scripting project settings failed!");
                    projectSettingsAsset = ScriptableObject.CreateInstance <DictionaryAsset>();
                    return;
                }

                projectSettingsAsset = (DictionaryAsset)objects[0];
            }
            else
            {
                // The file doesn't exist, so create a new asset
                projectSettingsAsset = ScriptableObject.CreateInstance <DictionaryAsset>();
            }

            projectSettingsAsset.OnDestroyActions += SerializeProjectSettingsAssetToDisk;
        }
Ejemplo n.º 2
0
        public static void TransferSettings(DictionaryAsset legacySettingsDict, List <ProjectSettingMetadata> settingList)
        {
            var skippedKeys = new HashSet <string>()
            {
                "savedVersion", "projectSetupCompleted"
            };

            foreach (var legacySetting in legacySettingsDict)
            {
                if (!skippedKeys.Contains(legacySetting.Key))
                {
                    foreach (var setting in settingList)
                    {
                        if (setting.key == legacySetting.Key)
                        {
#if VISUAL_SCRIPT_DEBUG_MIGRATION
                            try
                            {
                                setting.value = legacySetting.Value;
                            }
                            catch (Exception e)
                            {
                                Debug.LogError(e);
                                throw;
                            }
#else
                            setting.value = legacySetting.Value;
#endif
                            setting.Save();
                            break;
                        }
                    }
                }
            }
        }
 public void Merge(DictionaryAsset other, bool overwriteExisting = true)
 {
     foreach (var key in other.Keys)
     {
         if (overwriteExisting)
         {
             dictionary[key] = other[key];
         }
         else if (!dictionary.ContainsKey(key))
         {
             dictionary.Add(key, other[key]);
         }
     }
 }
        private void LoadProjectSettings()
        {
            AssetUtility.TryLoadIfExists(projectSettingsStoragePath, out DictionaryAsset _projectSettingsAsset);

            projectSettingsAsset = _projectSettingsAsset;

            projectSettings = new List <ProjectSettingMetadata>();

            var metadata = Metadata.Root();

            foreach (var memberInfo in GetType().GetMembers().Where(f => f.HasAttribute <ProjectSettingAttribute>()).OrderBy(m => m.MetadataToken))
            {
                projectSettings.Add(metadata.ProjectSetting(this, memberInfo));
            }
        }
 internal void CreateProjectSettingsAsset()
 {
     AssetUtility.TryLoad(projectSettingsStoragePath, out DictionaryAsset loadedProjectSettingsAsset);
     projectSettingsAsset = loadedProjectSettingsAsset;
 }