Answered Switching from Edit Mode (E) to Play Mode (P) with a Button or Trigger

You realize that you can switch by hotkeys P and E on your keyboard, right?

Then there is my EditMode plugin (part of Essentials) that you can setup as Session plugin, so VaM goes to Edit mode whenever you load a scene.

If you really want triggers, it should be easy to make yourself a little plugin that exposes the function as trigger, which you then can use from a UIButton or whatever in your scene:
C#:
using UnityEngine;

namespace MacGruber
{
    public class PlayEditModeTrigger : MVRScript
    { 
        public override void Init()
        {
            SetupAction("PlayMode", OnPlayMode);
            SetupAction("EditMode", OnEditMode);
        }
              
        private void OnPlayMode()
        {
            SuperController.singleton.gameMode = SuperController.GameMode.Play;
        }
      
        private void OnEditMode()
        {
            SuperController.singleton.gameMode = SuperController.GameMode.Edit;
        }
      
        public void SetupAction(string name, JSONStorableAction.ActionCallback callback)
        {
            JSONStorableAction action = new JSONStorableAction(name, callback);
            RegisterAction(action);
        }
    }
}
 
Upvote 0
Amazing. Thanks! Plus, this would be a good dipping of the toe into plugin creation for me.

History:
In my scene I'm using the TriggerUI plugin to open the appearance menu to select custom looks and of course when this happens it automatically switches to Edit Mode. My thought was that it would be good to automatically switch back to Play mode when exiting the "Select Look" portion of the scene and returning to the main scene. It's probably not ideal to switch a user unexpectedly from Edit to Play so maybe if I make my own plugin I'll capture the state before triggering Appearance menu restore that upon exit.

Again, thanks for the code snippet.
 
Upvote 0
Back
Top Bottom