示例#1
0
    public void SetEditMode(bool on)
    {
        if (on && !CanEdit())
        {
            AddDebugMessage("Play mode only");
            return;
        }

        SetMouseoverTooltipText("");


        if (on)
        {
            navigationControls.TryReleaseCursor();
        }

        editMode = on;

        if (editMode)
        {
        }
        else
        {
        }

        consoleAnchor.anchoredPosition = editMode ? CONSOLE_ANCHOR_POSITION_EDIT : CONSOLE_ANCHOR_POSITION_PLAY;

        userBody.SetInPlayMode(!editMode);

        AvatarMain lastAvatar = currentAvatar;

        currentAvatar = on ? editMain : playMain;

        navigationControls.SetMode(editMode ? NavigationControls.Mode.Fly : NavigationControls.Mode.Grounded);

        // Only do the teleport if:
        // 1. Going from play to edit mode for the first time
        // 2. Going from edit to play mode if there is no player actor, then DO teleport to prevent
        // us from returning to a meaningless play-mode position.
        // if (lastAvatar != null && lastAvatar != currentAvatar && ((on && firstTimeInEditMode) || GetPlayerActor() == null))
        // {
        //   currentAvatar.Teleport(lastAvatar.GetAvatarPosition(), lastAvatar.GetAim());
        // }

        bool shouldTeleport = on || Util.IsControlOrCommandHeld();

        if (lastAvatar != null && lastAvatar != currentAvatar && (shouldTeleport || GetPlayerActor() == null))
        {
            currentAvatar.Teleport(lastAvatar.GetAvatarPosition(), lastAvatar.GetAim());
        }

        //this is a hack for the conditional above to only teleport from play->edit the first time
        // if (on && firstTimeInEditMode) firstTimeInEditMode = false;

        //making user body have no parent to prevent momentary setactive(false) (which messes w/ animation)
        userBody.transform.SetParent(null);

        AddDebugMessage(editMode ? "Switching to EDIT mode" : "Switching to PLAY mode");

        playMain.Activate(!editMode);
        editMain.Activate(editMode);

        voosEngine.NotifyEditModeToggled(on);

        //putting user body on its new home
        userBody.transform.SetParent(currentAvatar.bodyParent);
        userBody.transform.localPosition = Vector3.zero;
        userBody.transform.localRotation = Quaternion.identity;

        navigationControls.ToggleEditCullingMask(on);

        if (!editMode)
        {
            navigationControls.TryCaptureCursor();
        }

        if (editMode)
        {
            hudTransitionControl.SetEditMode();
        }
        else
        {
            hudTransitionControl.SetPlayMode();
        }

        if (playerOptions.autoPause)
        {
            if (editMode)
            {
                voosEngine.SetIsRunning(false);
            }
            else
            {
                voosEngine.SetIsRunning(true);
            }
        }
    }