update Nam' low tech tool
This commit is contained in:
@@ -26,6 +26,13 @@ namespace PerfectWorld.Scripts
|
||||
/// </summary>
|
||||
public class AnimScenePlayerBootstrap : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
public const string EditorPrefsSwitchProfessionKey =
|
||||
"PerfectWorld.AnimScenePlayerBootstrapEditor.SwitchProfession";
|
||||
public const string EditorPrefsSwitchGenderKey =
|
||||
"PerfectWorld.AnimScenePlayerBootstrapEditor.SwitchGender";
|
||||
#endif
|
||||
|
||||
[Header("Player Reference")]
|
||||
[Tooltip("Scene host player. Do not put this bootstrap component on the same GameObject as the host if you enable Replace host on role switch.")]
|
||||
[SerializeField]
|
||||
@@ -101,8 +108,27 @@ namespace PerfectWorld.Scripts
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
ApplyPersistedEditorSwitchRole();
|
||||
#endif
|
||||
await BootstrapAsync((byte)profession, (byte)gender, fromInitialStart: true);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Editor Play Mode: use profession/gender from the custom inspector dropdown (EditorPrefs), not stale Initial Role.
|
||||
/// 编辑器运行模式:使用自定义检视器下拉框(EditorPrefs)的职业/性别,而非过期的 Initial Role。
|
||||
/// </summary>
|
||||
public void ApplyPersistedEditorSwitchRole()
|
||||
{
|
||||
profession = (Profession)UnityEditor.EditorPrefs.GetInt(
|
||||
EditorPrefsSwitchProfessionKey,
|
||||
(int)Profession.PROF_MAGE);
|
||||
gender = (Gender)UnityEditor.EditorPrefs.GetInt(
|
||||
EditorPrefsSwitchGenderKey,
|
||||
(int)Gender.GENDER_FEMALE);
|
||||
}
|
||||
#endif
|
||||
public void ChangeCameraPos(int i)
|
||||
{
|
||||
if(i<0)
|
||||
|
||||
@@ -14,6 +14,54 @@ namespace PerfectWorld.Scripts
|
||||
private int _playActionIndex;
|
||||
private bool _playActionRestart = true;
|
||||
|
||||
static AnimScenePlayerBootstrapEditor()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
private static void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state != PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var boots = Object.FindObjectsByType<AnimScenePlayerBootstrap>(
|
||||
FindObjectsInactive.Include,
|
||||
FindObjectsSortMode.None);
|
||||
foreach (AnimScenePlayerBootstrap boot in boots)
|
||||
{
|
||||
boot.ApplyPersistedEditorSwitchRole();
|
||||
EditorUtility.SetDirty(boot);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_editorSwitchProfession = (Profession)EditorPrefs.GetInt(
|
||||
AnimScenePlayerBootstrap.EditorPrefsSwitchProfessionKey,
|
||||
(int)Profession.PROF_MAGE);
|
||||
_editorSwitchGender = (Gender)EditorPrefs.GetInt(
|
||||
AnimScenePlayerBootstrap.EditorPrefsSwitchGenderKey,
|
||||
(int)Gender.GENDER_FEMALE);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SaveSwitchModelEditorPrefs();
|
||||
}
|
||||
|
||||
private static void SaveSwitchModelEditorPrefs(Profession profession, Gender gender)
|
||||
{
|
||||
EditorPrefs.SetInt(AnimScenePlayerBootstrap.EditorPrefsSwitchProfessionKey, (int)profession);
|
||||
EditorPrefs.SetInt(AnimScenePlayerBootstrap.EditorPrefsSwitchGenderKey, (int)gender);
|
||||
}
|
||||
|
||||
private void SaveSwitchModelEditorPrefs()
|
||||
{
|
||||
SaveSwitchModelEditorPrefs(_editorSwitchProfession, _editorSwitchGender);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
@@ -21,16 +69,27 @@ namespace PerfectWorld.Scripts
|
||||
EditorGUILayout.Space(8f);
|
||||
EditorGUILayout.LabelField("Play Mode — switch model", EditorStyles.boldLabel);
|
||||
EditorGUILayout.HelpBox(
|
||||
"Enter Play Mode, pick profession / gender below, then click Switch model. " +
|
||||
"This calls SwitchRole on this component (same as code).",
|
||||
"On Play Mode enter, the model loads from the profession / gender below (saved in EditorPrefs). " +
|
||||
"Use Switch model to change role while playing.",
|
||||
MessageType.Info);
|
||||
|
||||
using (new EditorGUI.DisabledScope(!Application.isPlaying))
|
||||
{
|
||||
_editorSwitchProfession =
|
||||
(Profession)EditorGUILayout.EnumPopup("Switch to profession", _editorSwitchProfession);
|
||||
_editorSwitchGender =
|
||||
(Gender)EditorGUILayout.EnumPopup("Switch to gender", _editorSwitchGender);
|
||||
Profession profession = (Profession)EditorGUILayout.EnumPopup(
|
||||
"Switch to profession",
|
||||
_editorSwitchProfession);
|
||||
if (profession != _editorSwitchProfession)
|
||||
{
|
||||
_editorSwitchProfession = profession;
|
||||
SaveSwitchModelEditorPrefs();
|
||||
}
|
||||
|
||||
Gender gender = (Gender)EditorGUILayout.EnumPopup("Switch to gender", _editorSwitchGender);
|
||||
if (gender != _editorSwitchGender)
|
||||
{
|
||||
_editorSwitchGender = gender;
|
||||
SaveSwitchModelEditorPrefs();
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUI.DisabledScope(!Application.isPlaying))
|
||||
|
||||
+268
-29
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user