浏览代码

POV are a bit more functional now

/main
Thomas ICHÉ 6 年前
当前提交
877ac6ac
共有 7 个文件被更改,包括 114 次插入21 次删除
  1. 2
      Editor/GameViewLink/LinkGameView.cs
  2. 76
      Editor/SceneViewPOV/SceneViewPOV.cs
  3. 2
      Editor/SceneViewToolbar.cs
  4. 8
      Runtime/SceneViewPOV.meta
  5. 36
      Runtime/SceneViewPOV/ScenePOVRoot.cs
  6. 11
      Runtime/SceneViewPOV/ScenePOVRoot.cs.meta

2
Editor/GameViewLink/LinkGameView.cs


camera.orthographic = sceneCamera.orthographic;
camera.fieldOfView = sceneCamera.fieldOfView;
camera.orthographicSize = sceneCamera.orthographicSize;
needRepaint = false;
}
}
}

76
Editor/SceneViewPOV/SceneViewPOV.cs


{
public class SceneViewPOV : PopupWindowContent
{
static GameObject POVRoot;
static GameObject[] ALlPOVRoots;
static ScenePOVRoot POVRoot;
const string kPOVRootTag = "SceneViewPOVRoot";
[InitializeOnLoadMethod]
static void Initialize()

public static void CheckPOVGameObjects()
{
var activePov = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault<GameObject>(o => o.name == kPOVObjectName && o.tag == kPOVRootTag);
var activeScene = SceneManager.GetActiveScene();
if (activePov == null)
ScenePOVRoot[] allRoots = GameObject.FindObjectsOfType<ScenePOVRoot>();
ScenePOVRoot activePOV = null;
foreach (var povRoot in allRoots)
activePov = CreatePOVRootObject();
if (povRoot.Scene == activeScene)
activePOV = povRoot;
POVRoot = activePov;
ALlPOVRoots = GameObject.FindGameObjectsWithTag(kPOVRootTag);
if (activePOV == null)
{
activePOV = CreatePOVRootObject();
}
POVRoot = activePOV;
static GameObject CreatePOVRootObject()
static ScenePOVRoot CreatePOVRootObject()
povRoot.tag = kPOVRootTag;
return povRoot;
return povRoot.AddComponent<ScenePOVRoot>();
}
static GameObject CreatePOV(GameObject povRoot, string name, Transform transform)

public override Vector2 GetWindowSize()
{
return new Vector2(256.0f, 480.0f);
CheckPOVGameObjects();
return new Vector2(256.0f, 80.0f + POVRoot.AllPOV.Length * 20);
string m_NewPOVName = "New POV";
public override void OnGUI(Rect rect)
{

if (POVRoot != null && SceneView.lastActiveSceneView != null)
if (m_SceneView != null)
var povs = GameObject.FindGameObjectsWithTag("POV");
Styles.Header("Add Point Of View");
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Name", GUILayout.Width(64));
m_NewPOVName = GUILayout.TextField(m_NewPOVName);
GUILayout.Label("Go to POVs", EditorStyles.boldLabel);
if (GUILayout.Button("+", GUILayout.Width(32)))
{
POVRoot.AddPOV(m_SceneView.camera.transform, m_NewPOVName);
}
}
GUILayout.Space(8);
var povs = POVRoot.AllPOV;
Styles.Header("Go to Point Of View");
if (GUILayout.Button(pov.name))
if (GUILayout.Button(pov.name, EditorStyles.foldout))
SceneView.lastActiveSceneView.AlignViewToObject(pov.transform);
m_SceneView.AlignViewToObject(pov.transform);
if (EditorUtility.DisplayDialog("Destroy POV?", "Do you want to destroy this POV: " + pov.name + " ?", "Yes", "No")) ;
//Destroy(pov);
if (EditorUtility.DisplayDialog("Destroy POV?", "Do you want to destroy this POV: " + pov.gameObject.name + " ?", "Yes", "No"))
GameObject.Destroy(pov.gameObject);
}
}
}

EditorGUILayout.HelpBox("No POV Root found (Create an Empty Game Object named 'POV_ROOT') or no SceneView currently active", MessageType.Warning);
EditorGUILayout.HelpBox("No POV Root found (Create an Empty Game Object named 'POV_ROOT') or no SceneView currently active", MessageType.Warning) ;
}
static class Styles
{
public static void Header(string name)
{
var content = new GUIContent(name);
var rect = GUILayoutUtility.GetRect(content, EditorStyles.boldLabel);
rect.xMin = 0;
rect.xMax = EditorGUIUtility.currentViewWidth;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.1f));
EditorGUI.LabelField(rect, content, EditorStyles.boldLabel);
}
}
}
}

2
Editor/SceneViewToolbar.cs


if(GUILayout.Button("POV", EditorStyles.toolbarDropDown))
{
Rect btnrect = GUILayoutUtility.GetLastRect();
btnrect.yMax += 16;
btnrect.yMax += 17;
SceneViewPOV.ShowPopup(btnrect, sceneView);
}

8
Runtime/SceneViewPOV.meta


fileFormatVersion: 2
guid: 23cde805c3888694799b0991bf8ef9aa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

36
Runtime/SceneViewPOV/ScenePOVRoot.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace GameplayIngredients
{
public class ScenePOVRoot : MonoBehaviour
{
public Scene Scene
{
get { return gameObject.scene; }
}
public Transform[] AllPOV
{
get
{
List<Transform> all = new List<Transform>();
for(int i = 0; i< gameObject.transform.childCount; i++)
all.Add(gameObject.transform.GetChild(i));
return all.ToArray();
}
}
public void AddPOV(Transform t, string Name)
{
var newPov = new GameObject(Name);
newPov.transform.position = t.position;
newPov.transform.rotation = t.rotation;
newPov.transform.parent = this.transform;
}
}
}

11
Runtime/SceneViewPOV/ScenePOVRoot.cs.meta


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