-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from brunomikoski/feature/support-for-regular-…
…animation Feature/support for regular animation
- Loading branch information
Showing
9 changed files
with
172 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace BrunoMikoski.AnimationSequencer | ||
{ | ||
public sealed class AnimationSequencerSettings : ScriptableObjectForPreferences<AnimationSequencerSettings> | ||
{ | ||
[SerializeField] | ||
private bool autoHideStepsWhenPreviewing = true; | ||
public bool AutoHideStepsWhenPreviewing => autoHideStepsWhenPreviewing; | ||
|
||
[SettingsProvider] | ||
private static SettingsProvider SettingsProvider() | ||
{ | ||
return CreateSettingsProvider("Animation Sequencer", null); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace BrunoMikoski.AnimationSequencer | ||
{ | ||
//From https://github.com/baba-s/UniScriptableObjectForPreferences/blob/master/Editor/ScriptableObjectForPreferences.cs | ||
public abstract class ScriptableObjectForPreferences<T> : ScriptableObject | ||
where T : ScriptableObjectForPreferences<T> | ||
{ | ||
private static string ConfigName => typeof(T).Name; | ||
private static T instance; | ||
|
||
public static T GetInstance() | ||
{ | ||
if (instance != null) | ||
{ | ||
return instance; | ||
} | ||
|
||
instance = CreateInstance<T>(); | ||
string json = EditorUserSettings.GetConfigValue(ConfigName); | ||
EditorJsonUtility.FromJsonOverwrite(json, instance); | ||
if (instance == null) | ||
{ | ||
instance = CreateInstance<T>(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public static SettingsProvider CreateSettingsProvider( | ||
string settingsProviderPath = null, | ||
Action<SerializedObject> onGUI = null, | ||
Action<SerializedObject> onGUIExtra = null | ||
) | ||
{ | ||
if (settingsProviderPath == null) | ||
{ | ||
settingsProviderPath = $"{typeof(T).Name}"; | ||
} | ||
|
||
T foundInstance = GetInstance(); | ||
SerializedObject serializedObject = new SerializedObject(foundInstance); | ||
IEnumerable<string> keywords = SettingsProvider.GetSearchKeywordsFromSerializedObject(serializedObject); | ||
SettingsProvider provider = new SettingsProvider(settingsProviderPath, SettingsScope.User, keywords); | ||
provider.guiHandler += _ => OnGuiHandler(onGUI, onGUIExtra); | ||
return provider; | ||
} | ||
|
||
private static void OnGuiHandler(Action<SerializedObject> onGUI, | ||
Action<SerializedObject> onGUIExtra) | ||
{ | ||
T foundInstance = GetInstance(); | ||
Editor editor = Editor.CreateEditor(foundInstance); | ||
using (EditorGUI.ChangeCheckScope scope = new EditorGUI.ChangeCheckScope()) | ||
{ | ||
SerializedObject serializedObject = editor.serializedObject; | ||
serializedObject.Update(); | ||
if (onGUI != null) | ||
{ | ||
onGUI(serializedObject); | ||
} | ||
else | ||
{ | ||
editor.DrawDefaultInspector(); | ||
} | ||
|
||
onGUIExtra?.Invoke(serializedObject); | ||
if (!scope.changed) | ||
{ | ||
return; | ||
} | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
string json = EditorJsonUtility.ToJson(editor.target); | ||
EditorUserSettings.SetConfigValue(ConfigName, json); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Scripts/Editor/Utility/ScriptableObjectForPreferences.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters