浏览代码

Play From Here + Toolbar now Scriptable

/main
Thomas ICHÉ 6 年前
当前提交
9a47eea4
共有 5 个文件被更改,包括 102 次插入4 次删除
  1. 2
      Editor/GameViewLink/LinkGameView.cs
  2. 11
      Editor/MenuItems.cs
  3. 24
      Editor/SceneViewToolbar.cs
  4. 58
      Editor/PlayFromHere.cs
  5. 11
      Editor/PlayFromHere.cs.meta

2
Editor/GameViewLink/LinkGameView.cs


{
s_GameObject.transform.position = sceneCamera.transform.position;
s_GameObject.transform.rotation = sceneCamera.transform.rotation;
camera.orthographic = sceneCamera.orthographic;
camera.orthographicSize = sceneCamera.orthographicSize;
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
}

11
Editor/MenuItems.cs


Selection.activeObject = null;
}
[MenuItem("Edit/Play from SceneView Position #%&P", priority = 160)]
static void PlayHere()
{
EditorApplication.isPlaying = true;
}
[MenuItem("Edit/Play from SceneView Position #%&P", priority = 160)]
static bool PlayHereValidate()
{
return true;
}
static readonly string helperPreferenceName = "GameplayIngredients.toggleIngredientHelpers";
[MenuItem("Edit/Gameplay Ingredients/Toggle Helpers", priority = kMenuPriority)]

24
Editor/SceneViewToolbar.cs


{
static class SceneViewToolbar
{
public delegate void SceneViewToolbarDelegate(SceneView sceneView);
public static event SceneViewToolbarDelegate OnSceneViewToolbarGUI;
[InitializeOnLoadMethod]
static void Initialize()
{

{
using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
{
bool link = LinkGameView.Active;
link = GUILayout.Toggle(link, "Link Game View", EditorStyles.toolbarButton);
bool play = GUILayout.Toggle(EditorApplication.isPlaying, "Play from Here", EditorStyles.toolbarButton);
if (GUI.changed)
LinkGameView.Active = link;
if(GUI.changed)
{
if (play)
PlayFromHere.Play();
else
EditorApplication.isPlaying = false;
}
// Custom Code here
if (OnSceneViewToolbarGUI != null)
OnSceneViewToolbarGUI.Invoke(sceneView);
// Saving Space not to overlap view controls
GUILayout.Space(96);
}
}
}

58
Editor/PlayFromHere.cs


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 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);
}
}
}
}

11
Editor/PlayFromHere.cs.meta


fileFormatVersion: 2
guid: 0a474d3e13883394eae0cc77c0c8634e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存