Initial Commit
This commit is contained in:
52
CameraUtility/Editor/CameraUtility.cs
Normal file
52
CameraUtility/Editor/CameraUtility.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DreadScripts.CameraUtility
|
||||
{
|
||||
public class CameraUtility
|
||||
{
|
||||
private const float SCENE_PIVOT_OFFSET = 1;
|
||||
|
||||
[MenuItem("DreadTools/Utility/Camera/Snap Scene To Game")]
|
||||
public static void SnapSceneViewToGame()
|
||||
{
|
||||
if (!TryGetGameCamera(out Camera gc)) return;
|
||||
|
||||
SceneView view = SceneView.lastActiveSceneView;
|
||||
if (YellowLog(view == null, "No Scene View found")) return;
|
||||
|
||||
Undo.RecordObject(view, "Snap STG");
|
||||
view.LookAtDirect(gc.transform.position, gc.transform.rotation, SCENE_PIVOT_OFFSET/2);
|
||||
view.pivot = gc.transform.position + gc.transform.forward * SCENE_PIVOT_OFFSET;
|
||||
}
|
||||
|
||||
[MenuItem("DreadTools/Utility/Camera/Snap Game To Scene")]
|
||||
public static void SnapGameViewToScene()
|
||||
{
|
||||
if (!TryGetGameCamera(out Camera gc)) return;
|
||||
if (!TryGetSceneCamera(out Camera sc)) return;
|
||||
|
||||
Undo.RecordObject(gc.transform, "Snap GTS");
|
||||
gc.transform.SetPositionAndRotation(sc.transform.position, sc.transform.rotation);
|
||||
}
|
||||
|
||||
private static bool TryGetGameCamera(out Camera gameCamera)
|
||||
{
|
||||
gameCamera = Camera.main ?? Object.FindObjectOfType<Camera>();
|
||||
return !YellowLog(!gameCamera, "No Camera found in scene");
|
||||
}
|
||||
private static bool TryGetSceneCamera(out Camera sceneCamera)
|
||||
{
|
||||
sceneCamera = SceneView.lastActiveSceneView?.camera;
|
||||
return !YellowLog(!sceneCamera, "No Scene View found");
|
||||
}
|
||||
|
||||
private static bool YellowLog(bool condition, string msg)
|
||||
{
|
||||
if (condition) Debug.LogWarning($"<color=yellow>[CameraUtility] {msg}</color>");
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
}
|
11
CameraUtility/Editor/CameraUtility.cs.meta
Normal file
11
CameraUtility/Editor/CameraUtility.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e230c2bf340461c46939efc284f6bf22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "com.dreadscripts.camerautility.Editor",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acb80353a76f6c0488836f3e26ef1785
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user