First commit for private source control. Older commits available on Github.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
public sealed class EditorUserSettings : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private bool _alwaysShowSearch = false;
|
||||
[SerializeField, Range(1, 10)]
|
||||
private int _pageCountForSearch = 1;
|
||||
[SerializeField, Min(1)]
|
||||
private int _elementsPerPage = 10;
|
||||
|
||||
public bool AlwaysShowSearch => _alwaysShowSearch;
|
||||
public int PageCountForSearch => _pageCountForSearch;
|
||||
public int ElementsPerPage => _elementsPerPage;
|
||||
|
||||
private static EditorUserSettings _instance;
|
||||
|
||||
private const string _filePath = "UserSettings/SerializedCollectionsEditorSettings.asset";
|
||||
|
||||
public static EditorUserSettings Get()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = CreateInstance<EditorUserSettings>();
|
||||
LoadInto(_instance);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private static void LoadInto(EditorUserSettings settings)
|
||||
{
|
||||
if (!File.Exists(_filePath)) return;
|
||||
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(_filePath);
|
||||
EditorJsonUtility.FromJsonOverwrite(json, settings);
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Save()
|
||||
{
|
||||
string contents = EditorJsonUtility.ToJson(Get());
|
||||
File.WriteAllText(_filePath, contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21353c5f0548cba4a98029e0c433a0dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Settings/EditorUserSettings.cs
|
||||
uploadId: 632226
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AnimatedValues;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
public class EditorUserSettingsProvider : SettingsProvider
|
||||
{
|
||||
public const string PreferencesPath = "Preferences/Serialized Collections";
|
||||
|
||||
private SerializedObject _serializedObject;
|
||||
private SerializedProperty _alwaysShowSearch;
|
||||
private SerializedProperty _pageCountForSearch;
|
||||
private SerializedProperty _elementsPerPage;
|
||||
private AnimBool _searchAnimBool;
|
||||
|
||||
class Styles
|
||||
{
|
||||
}
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateProvider()
|
||||
{
|
||||
var provider = new EditorUserSettingsProvider(PreferencesPath, SettingsScope.User);
|
||||
|
||||
provider.keywords = GetSearchKeywordsFromGUIContentProperties<Styles>();
|
||||
return provider;
|
||||
}
|
||||
|
||||
public EditorUserSettingsProvider(string path, SettingsScope scope = SettingsScope.User) : base(path, scope) { }
|
||||
|
||||
public static bool IsSettingsAvailable() => EditorUserSettings.Get() != null;
|
||||
|
||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
EnsureSerializedObjectExists();
|
||||
}
|
||||
|
||||
private void EnsureSerializedObjectExists()
|
||||
{
|
||||
if (_serializedObject == null)
|
||||
{
|
||||
_searchAnimBool = new AnimBool();
|
||||
_searchAnimBool.valueChanged.AddListener(new UnityAction(Repaint));
|
||||
_serializedObject = new SerializedObject(EditorUserSettings.Get());
|
||||
_alwaysShowSearch = _serializedObject.FindProperty("_alwaysShowSearch");
|
||||
_pageCountForSearch = _serializedObject.FindProperty("_pageCountForSearch");
|
||||
_elementsPerPage = _serializedObject.FindProperty("_elementsPerPage");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
EnsureSerializedObjectExists();
|
||||
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
_serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
EditorGUILayout.PropertyField(_alwaysShowSearch);
|
||||
_searchAnimBool.target = !_alwaysShowSearch.boolValue;
|
||||
using (var group = new EditorGUILayout.FadeGroupScope(_searchAnimBool.faded))
|
||||
{
|
||||
if (group.visible)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_pageCountForSearch);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.PropertyField(_elementsPerPage);
|
||||
|
||||
bool changed =_serializedObject.ApplyModifiedProperties();
|
||||
if (changed)
|
||||
{
|
||||
EditorUserSettings.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01b95baf6e99cff43a84c4ba42557db4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Settings/EditorUserSettingsProvider.cs
|
||||
uploadId: 632226
|
||||
Reference in New Issue
Block a user