Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

65 行
2.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
public static class PlayFromHere
{
public delegate void PlayFromHereDelegate(Vector3 position, Vector3 forward);
public static event PlayFromHereDelegate OnPlayFromHere;
[InitializeOnLoadMethod]
public static void Initialize()
{
EditorApplication.playModeStateChanged += OnEnterPlayMode;
}
public static bool IsReady
{
get
{
return OnPlayFromHere != null && OnPlayFromHere.GetInvocationList().Length > 0;
}
}
public static void Play()
{
EditorPrefs.SetBool("playFromHereNext",true);
EditorApplication.isPlaying = true;
}
static void OnEnterPlayMode(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredPlayMode && EditorPrefs.GetBool("playFromHereNext"))
{
if (OnPlayFromHere != null)
{
Vector3 position = Vector3.zero;
Vector3 forward = Vector3.forward;
if (SceneView.lastActiveSceneView != null)
{
// Let's choose a point 1m in front of the point of view
var camera = SceneView.lastActiveSceneView.camera;
position = camera.transform.position;
forward = camera.transform.forward;
}
else
Debug.LogWarning("Play From Here : Could not find the position of the last sceneview camera, playing at world's origin.");
OnPlayFromHere.Invoke(position,forward);
}
else
{
Debug.LogWarning("Play From Here : No Actions to take. Please add events to PlayFromHere.OnPlayFromHere()");
}
EditorPrefs.SetBool("playFromHereNext", false);
}
}
}
}