Skip to content

Commit

Permalink
Revert "Update CompositionEditor.cs"
Browse files Browse the repository at this point in the history
This reverts commit 5921a5c.
  • Loading branch information
mrbusysky committed Jun 13, 2024
1 parent 5921a5c commit a12a7a6
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions package/Editor/CompositionEditor/CompositionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class CompositionEditor : EditorWindow

private int widthSliderValue = 512;
private int heightSliderValue = 512;
private float distanceOffset = 0.1f;
private float distanceOffset = 1f;
private GameObject compositionCamera = null;
internal RenderTexture renderTexture;
private Texture2D screenshot;

[MenuItem("Window/Scenario/Editors/Composition Editor", false, 0)]
[MenuItem("Window/Scenario/Editors/Composition Editor", false,0)]
public static void ShowWindow()
{
var window = GetWindow<CompositionEditor>("Composition Editor");
Expand All @@ -43,7 +43,7 @@ private void DrawBackground()
private void DrawScreenshotIfAvailable()
{
if (screenshot == null) return;

Rect textureRect = GUILayoutUtility.GetRect(screenshot.width, screenshot.height, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUI.DrawTexture(textureRect, screenshot, ScaleMode.ScaleToFit);
}
Expand Down Expand Up @@ -71,15 +71,16 @@ private void DrawControls()
private int DrawDimensionControl(string label, int currentValue, int[] allowedValues)
{
int index = 0;

EditorGUILayout.BeginVertical();
{
EditorGUILayout.LabelField(label, EditorStyles.label, GUILayout.Width(55), GUILayout.Height(20));
index = NearestValueIndex(currentValue, allowedValues);
index = GUILayout.SelectionGrid(index, Array.ConvertAll(allowedValues, x => x.ToString()), allowedValues.Length);
index = GUILayout.SelectionGrid(index, Array.ConvertAll(allowedValues, x => x.ToString()),
allowedValues.Length);
}
EditorGUILayout.EndVertical();

return allowedValues[index];
}

Expand Down Expand Up @@ -119,39 +120,21 @@ private void DrawUseImageButton()

private void PlaceCamera()
{
if (compositionCamera != null)
{
Debug.LogWarning("A composition camera already exists. Remove the existing one before placing a new one.");
return;
}

compositionCamera = new GameObject("CompositionCamera");
Camera camera = compositionCamera.AddComponent<Camera>();
SceneView sceneView = SceneView.lastActiveSceneView;

if (sceneView == null)
{
Debug.LogError("No active SceneView found. Cannot place the camera.");
return;
}

if (Mathf.Approximately(distanceOffset, 0.1f))
{
compositionCamera.transform.position = sceneView.camera.transform.position;
compositionCamera.transform.rotation = sceneView.camera.transform.rotation;
}
else
{
Vector3 cameraPosition = sceneView.camera.transform.position + sceneView.camera.transform.forward * distanceOffset;
compositionCamera.transform.position = cameraPosition;
compositionCamera.transform.rotation = sceneView.camera.transform.rotation;
}
if (sceneView == null) return;

Vector3 cameraPosition = sceneView.pivot + sceneView.rotation * Vector3.forward * distanceOffset;
compositionCamera.transform.position = cameraPosition;
compositionCamera.transform.rotation = sceneView.rotation;
}

private void RemoveCamera()
{
if (compositionCamera == null) return;

DestroyImmediate(compositionCamera);
compositionCamera = null;
}
Expand Down

0 comments on commit a12a7a6

Please sign in to comment.