浏览代码

Game View Link : Cinemachine Brain Preview (#14)

* Added Base Feature

* Updated Changelog

* UX in Toolbar (+ SceneView Messages)

* Fixed Enter Play Mode
/main
GitHub 5 年前
当前提交
13ad399f
共有 4 个文件被更改,包括 112 次插入9 次删除
  1. 1
      CHANGELOG.md
  2. 55
      Editor/GameViewLink/LinkGameView.cs
  3. 6
      Editor/GameplayIngredients-Editor.asmdef
  4. 59
      Editor/SceneViewToolbar.cs

1
CHANGELOG.md


* Added API to AdvancedHierarchyView to add other Icons from component types
* Help Menu links (github, documentation, openUPM)
* Added support for SceneAsset and EditorSceneSetup in Discover
* Added an option to change the Game View Link camera behavior to Cinemachine Brain preview.
#### Changed

55
Editor/GameViewLink/LinkGameView.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Cinemachine;
namespace GameplayIngredients.Editor
{

static readonly string kCinemachinePreferenceName = "GameplayIngredients.LinkGameViewCinemachine";
static readonly string kLinkCameraName = "___LINK__SCENE__VIEW__CAMERA___";
public static bool Active

}
}
public static bool CinemachineActive
{
get
{
// Get preference only when not playing
if (!Application.isPlaying)
m_CinemachineActive = EditorPrefs.GetBool(kCinemachinePreferenceName, false);
return m_CinemachineActive;
}
set
{
// Update preference only when not playing
if (!Application.isPlaying)
EditorPrefs.SetBool(kCinemachinePreferenceName, value);
UpdateCinemachinePreview(value);
m_CinemachineActive = value;
}
}
static bool m_CinemachineActive = false;
public static SceneView LockedSceneView

Active = true;
else
Active = false;
if (CinemachineActive)
CinemachineActive = true;
else
CinemachineActive = false;
}
else // Cleanup before switching state
{

}
static GameObject s_GameObject;
static void Update(SceneView sceneView)
{

}
}
if (Active)
if (Active && !CinemachineActive)
{
var sv = s_LockedSceneView == null ? SceneView.lastActiveSceneView : s_LockedSceneView;
var sceneCamera = sv.camera;

}
}
const string kDefaultPrefabName = "LinkGameViewCamera";
const string kDefaultLinkPrefabName = "LinkGameViewCamera";
string[] assets = AssetDatabase.FindAssets(kDefaultPrefabName);
string[] assets = AssetDatabase.FindAssets(kDefaultLinkPrefabName);
if(assets.Length > 0)
{
string path = AssetDatabase.GUIDToAssetPath(assets[0]);

camera.depth = int.MaxValue;
go.SetActive(Active);
return go;
}
static void UpdateCinemachinePreview(bool value)
{
if (s_GameObject == null)
return;
CinemachineBrain brain;
if (!s_GameObject.TryGetComponent<CinemachineBrain>(out brain))
{
brain = s_GameObject.AddComponent<CinemachineBrain>();
}
brain.enabled = value;
}
}

6
Editor/GameplayIngredients-Editor.asmdef


"NaughtyAttributes>Editor",
"GameplayIngredients",
"Unity.ugui",
"Unity.Timeline"
"Unity.Timeline",
"Cinemachine"
],
"includePlatforms": [
"Editor"

"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}

59
Editor/SceneViewToolbar.cs


if(isLinked && isLocked)
{
GUI.color = Color.green *2;
GUI.color = Styles.lockedLinkColor * 2;
}
else if (isLinked && LinkGameView.CinemachineActive)
{
GUI.color = Styles.cineColor * 2;
isLinked = GUILayout.Toggle(isLinked, Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));
isLinked = GUILayout.Toggle(isLinked, LinkGameView.CinemachineActive? Contents.linkGameViewCinemachine: Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));
LinkGameView.Active = isLinked;
if(Event.current.shift)
{
if (!LinkGameView.Active)
LinkGameView.Active = true;
LinkGameView.CinemachineActive = !LinkGameView.CinemachineActive;
}
else
{
LinkGameView.Active = isLinked;
LinkGameView.CinemachineActive = false;
}
}
isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);

if (isLocked)
{
LinkGameView.CinemachineActive = false;
LinkGameView.LockedSceneView = sceneView;
}
else

}
}
if (LinkGameView.CinemachineActive)
{
DisplayText("CINEMACHINE PREVIEW", Styles.cineColor);
}
else if (LinkGameView.Active)
{
if (LinkGameView.LockedSceneView == sceneView)
{
DisplayText("GAME VIEW LINKED (LOCKED)", Styles.lockedLinkColor);
}
else if(LinkGameView.LockedSceneView == null && SceneView.lastActiveSceneView == sceneView)
{
DisplayText("GAME VIEW LINKED", Color.white);
}
}
static void DisplayText(string text, Color color)
{
Rect r = new Rect(16, 24, 512, 32);
GUI.color = Color.black;
GUI.Label(r, text);
r.x--;
r.y--;
GUI.color = color;
GUI.Label(r, text);
GUI.color = Color.white;
}
public static GUIContent linkGameViewCinemachine;
static Contents()
{

linkGameViewCinemachine = new GUIContent(EditorGUIUtility.Load("Packages/net.peeweek.gameplay-ingredients/Icons/GUI/Camera16x16.png") as Texture);
linkGameViewCinemachine.text = " Cine";
playFromHere = new GUIContent(EditorGUIUtility.IconContent("Animation.Play"));
playFromHere.text = "Here";
}

{
public static GUIStyle toolbar;
public static Color lockedLinkColor = new Color(0.5f, 1.0f, 0.1f, 1.0f);
public static Color cineColor = new Color(1.0f, 0.5f, 0.1f, 1.0f);
static Styles()
{

正在加载...
取消
保存