Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AVVR-Unity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GDP Project 4
AVVR-Unity
Commits
11a89986
Commit
11a89986
authored
5 months ago
by
mhby1g21
Browse files
Options
Downloads
Patches
Plain Diff
window size is now adjustable
parent
2d1a34ee
No related branches found
No related tags found
1 merge request
!16
v2.2 merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AVVR/Assets/_Scripts/SpectatorWindow.cs
+77
-7
77 additions, 7 deletions
AVVR/Assets/_Scripts/SpectatorWindow.cs
with
77 additions
and
7 deletions
AVVR/Assets/_Scripts/SpectatorWindow.cs
+
77
−
7
View file @
11a89986
...
...
@@ -7,9 +7,18 @@ public class SpectatorWindow : MonoBehaviour
private
RenderTexture
renderTexture
;
private
bool
showWindow
=
true
;
private
Rect
windowRect
=
new
Rect
(
100
,
100
,
800
,
450
);
[
Header
(
"Window Settings"
)]
[
SerializeField
]
private
bool
enableWindowDrag
=
true
;
[
SerializeField
]
private
Vector2Int
renderResolution
=
new
Vector2Int
(
1920
,
1080
);
[
SerializeField
]
private
Vector2
minWindowSize
=
new
Vector2
(
400
,
225
);
[
SerializeField
]
private
Vector2
maxWindowSize
=
new
Vector2
(
1920
,
1080
);
private
bool
isResizing
=
false
;
private
Rect
resizeHandleRect
;
private
Vector2
resizeStartMouse
;
private
Vector2
resizeStartSize
;
private
readonly
float
resizeHandleSize
=
20f
;
private
void
Awake
()
{
...
...
@@ -55,6 +64,9 @@ public class SpectatorWindow : MonoBehaviour
// Draw the window with solid background
GUI
.
backgroundColor
=
Color
.
black
;
windowRect
=
GUI
.
Window
(
0
,
windowRect
,
DrawWindowContents
,
"Spectator View"
,
backgroundStyle
);
// Handle resizing outside of the window function
HandleResizing
();
}
private
void
DrawWindowContents
(
int
windowID
)
...
...
@@ -71,10 +83,68 @@ public class SpectatorWindow : MonoBehaviour
showWindow
=
false
;
}
// Window dragging
if
(
enableWindowDrag
)
// Draw resize handle (visual indicator)
resizeHandleRect
=
new
Rect
(
windowRect
.
width
-
resizeHandleSize
,
windowRect
.
height
-
resizeHandleSize
,
resizeHandleSize
,
resizeHandleSize
);
GUI
.
Box
(
resizeHandleRect
,
"↘"
);
// Window dragging (only if not resizing)
if
(
enableWindowDrag
&&
!
isResizing
)
{
GUI
.
DragWindow
(
new
Rect
(
0
,
0
,
windowRect
.
width
-
resizeHandleSize
,
20
));
}
}
private
void
HandleResizing
()
{
// Convert resize handle to screen coordinates
Rect
screenResizeRect
=
new
Rect
(
windowRect
.
x
+
windowRect
.
width
-
resizeHandleSize
,
windowRect
.
y
+
windowRect
.
height
-
resizeHandleSize
,
resizeHandleSize
,
resizeHandleSize
);
Event
e
=
Event
.
current
;
if
(
e
.
type
==
EventType
.
MouseDown
&&
e
.
button
==
0
&&
screenResizeRect
.
Contains
(
e
.
mousePosition
))
{
isResizing
=
true
;
resizeStartMouse
=
e
.
mousePosition
;
resizeStartSize
=
new
Vector2
(
windowRect
.
width
,
windowRect
.
height
);
e
.
Use
();
}
else
if
(
e
.
type
==
EventType
.
MouseUp
&&
e
.
button
==
0
)
{
GUI
.
DragWindow
();
isResizing
=
false
;
}
else
if
(
isResizing
&&
e
.
type
==
EventType
.
MouseDrag
)
{
// Calculate new size
float
newWidth
=
Mathf
.
Clamp
(
resizeStartSize
.
x
+
(
e
.
mousePosition
.
x
-
resizeStartMouse
.
x
),
minWindowSize
.
x
,
maxWindowSize
.
x
);
float
newHeight
=
Mathf
.
Clamp
(
resizeStartSize
.
y
+
(
e
.
mousePosition
.
y
-
resizeStartMouse
.
y
),
minWindowSize
.
y
,
maxWindowSize
.
y
);
// Maintain aspect ratio (16:9)
float
targetAspect
=
16f
/
9f
;
float
currentAspect
=
newWidth
/
newHeight
;
if
(
currentAspect
>
targetAspect
)
{
newWidth
=
newHeight
*
targetAspect
;
}
else
{
newHeight
=
newWidth
/
targetAspect
;
}
// Apply new size
windowRect
.
width
=
newWidth
;
windowRect
.
height
=
newHeight
;
e
.
Use
();
}
}
...
...
@@ -87,14 +157,14 @@ public class SpectatorWindow : MonoBehaviour
}
}
// Public methods
to control the window
// Public methods
public
void
ShowWindow
()
=>
showWindow
=
true
;
public
void
HideWindow
()
=>
showWindow
=
false
;
public
void
ToggleWindow
()
=>
showWindow
=
!
showWindow
;
public
void
SetWindowSize
(
float
width
,
float
height
)
{
windowRect
.
width
=
width
;
windowRect
.
height
=
height
;
windowRect
.
width
=
Mathf
.
Clamp
(
width
,
minWindowSize
.
x
,
maxWindowSize
.
x
)
;
windowRect
.
height
=
Mathf
.
Clamp
(
height
,
minWindowSize
.
y
,
maxWindowSize
.
y
)
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment