mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:27:40 +02:00
Autoplay began
This commit is contained in:
64
Assets/Scripts/Util/SwapEditorShortcutsOnPlayerFocus.cs
Normal file
64
Assets/Scripts/Util/SwapEditorShortcutsOnPlayerFocus.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.ShortcutManagement;
|
||||
#endif
|
||||
using System.Linq;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoad]
|
||||
public class SwitchShortcutsProfileOnPlay
|
||||
{
|
||||
private const string PlayingProfileId = "Playing";
|
||||
private static string _activeProfileId;
|
||||
private static bool _switched;
|
||||
|
||||
static SwitchShortcutsProfileOnPlay()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += DetectPlayModeState;
|
||||
}
|
||||
|
||||
private static void SetActiveProfile(string profileId)
|
||||
{
|
||||
Debug.Log($"Activating Shortcut profile \"{profileId}\"");
|
||||
ShortcutManager.instance.activeProfileId = profileId;
|
||||
}
|
||||
|
||||
private static void DetectPlayModeState(PlayModeStateChange state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case PlayModeStateChange.EnteredPlayMode:
|
||||
OnEnteredPlayMode();
|
||||
break;
|
||||
case PlayModeStateChange.ExitingPlayMode:
|
||||
OnExitingPlayMode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnExitingPlayMode()
|
||||
{
|
||||
if (!_switched)
|
||||
return;
|
||||
|
||||
_switched = false;
|
||||
SetActiveProfile("Default");
|
||||
}
|
||||
|
||||
private static void OnEnteredPlayMode()
|
||||
{
|
||||
_activeProfileId = ShortcutManager.instance.activeProfileId;
|
||||
if (_activeProfileId.Equals(PlayingProfileId))
|
||||
return; // Same as active
|
||||
|
||||
var allProfiles = ShortcutManager.instance.GetAvailableProfileIds().ToList();
|
||||
|
||||
if (!allProfiles.Contains(PlayingProfileId))
|
||||
return; // Couldn't find PlayingProfileId
|
||||
|
||||
_switched = true;
|
||||
SetActiveProfile("Playing");
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/Scripts/Util/SwapEditorShortcutsOnPlayerFocus.cs.meta
Normal file
11
Assets/Scripts/Util/SwapEditorShortcutsOnPlayerFocus.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f7f429e0ad42a74eae2a6a88474bd0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user