Level 3
Using Level 3 to do a big art pass and get a lot of systems set up and cleaned up. Add Phantom Camera addon with comprehensive 2D/3D camera system
This commit is contained in:
1 parent
5ce882b53d
commit
2c6a395938
1122 files changed
+42103
-40
No files matched your search
@@ -0,0 +1,36 @@
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace PhantomCamera.Manager;
|
||||
|
||||
public static class PhantomCameraManager
|
||||
{
|
||||
private static GodotObject? _instance;
|
||||
|
||||
public static GodotObject Instance => _instance ??= Engine.GetSingleton("PhantomCameraManager");
|
||||
|
||||
public static PhantomCamera2D[] PhantomCamera2Ds =>
|
||||
Instance.Call(MethodName.GetPhantomCamera2Ds).AsGodotArray<Node2D>()
|
||||
.Select(node => new PhantomCamera2D(node)).ToArray();
|
||||
|
||||
public static PhantomCamera3D[] PhantomCamera3Ds =>
|
||||
Instance.Call(MethodName.GetPhantomCamera3Ds).AsGodotArray<Node3D>()
|
||||
.Select(node => new PhantomCamera3D(node)).ToArray();
|
||||
|
||||
public static PhantomCameraHost[] PhantomCameraHosts =>
|
||||
Instance.Call(MethodName.GetPhantomCameraHosts).AsGodotArray<Node>()
|
||||
.Select(node => new PhantomCameraHost(node)).ToArray();
|
||||
|
||||
public static PhantomCamera2D[] GetPhantomCamera2Ds() => PhantomCamera2Ds;
|
||||
public static PhantomCamera3D[] GetPhantomCamera3Ds() => PhantomCamera3Ds;
|
||||
public static PhantomCameraHost[] GetPhantomCameraHosts() => PhantomCameraHosts;
|
||||
|
||||
public static class MethodName
|
||||
{
|
||||
public static readonly StringName GetPhantomCamera2Ds = new("get_phantom_camera_2ds");
|
||||
public static readonly StringName GetPhantomCamera3Ds = new("get_phantom_camera_3ds");
|
||||
public static readonly StringName GetPhantomCameraHosts = new("get_phantom_camera_hosts");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://vtj8iqx4bp43
|
||||
@@ -0,0 +1,190 @@
|
||||
@tool
|
||||
extends Node
|
||||
|
||||
const _CONSTANTS = preload("res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_constants.gd")
|
||||
|
||||
#region Signals
|
||||
|
||||
# Noise
|
||||
signal noise_2d_emitted(noise_output: Transform2D, emitter_layer: int)
|
||||
signal noise_3d_emitted(noise_output: Transform3D, emitter_layer: int)
|
||||
|
||||
# PCam Host
|
||||
signal pcam_host_added_to_scene(pcam_host: PhantomCameraHost)
|
||||
signal pcam_host_removed_from_scene(pcam_host: PhantomCameraHost)
|
||||
|
||||
# PCam
|
||||
signal pcam_added_to_scene(pcam: Node)
|
||||
signal pcam_removed_from_scene(pcam: Node)
|
||||
|
||||
# Priority
|
||||
signal pcam_priority_changed(pcam: Node)
|
||||
signal pcam_visibility_changed(pcam: Node)
|
||||
|
||||
signal pcam_teleport(pcam: Node)
|
||||
|
||||
# Limit (2D)
|
||||
signal limit_2d_changed(side: int, limit: int)
|
||||
signal draw_limit_2d(enabled: bool)
|
||||
|
||||
# Camera3DResource (3D)
|
||||
signal camera_3d_resource_changed(property: String, value: Variant)
|
||||
|
||||
# Viewfinder Signals
|
||||
signal viewfinder_pcam_host_switch(pcam_host: PhantomCameraHost)
|
||||
signal pcam_priority_override(pcam: Node, shouldOverride: bool)
|
||||
signal pcam_dead_zone_changed(pcam: Node)
|
||||
signal pcam_host_layer_changed(pcam: Node)
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
|
||||
var _phantom_camera_host_list: Array[PhantomCameraHost]
|
||||
var _phantom_camera_2d_list: Array[PhantomCamera2D]
|
||||
var _phantom_camera_3d_list: Array[Node] ## Note: To support disable_3d export templates for 2D projects, this is purposely not strongly typed.
|
||||
var _phantom_camera_tween_director_list: Array[PhantomCameraTweenDirector]
|
||||
|
||||
var _viewfinder: Control = null
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Variables
|
||||
|
||||
var phantom_camera_hosts: Array[PhantomCameraHost]:
|
||||
get:
|
||||
return _phantom_camera_host_list
|
||||
|
||||
var phantom_camera_2ds: Array[PhantomCamera2D]:
|
||||
get:
|
||||
return _phantom_camera_2d_list
|
||||
|
||||
var phantom_camera_3ds: Array[Node]: ## Note: To support disable_3d export templates for 2D projects, this is purposely not strongly typed.
|
||||
get:
|
||||
return _phantom_camera_3d_list
|
||||
|
||||
var phantom_camera_tween_directors: Array[PhantomCameraTweenDirector]:
|
||||
get:
|
||||
return _phantom_camera_tween_director_list
|
||||
|
||||
var screen_size: Vector2i = Vector2i.ONE
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Functions
|
||||
|
||||
func _enter_tree() -> void:
|
||||
if not Engine.has_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME):
|
||||
Engine.register_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME, self)
|
||||
Engine.physics_jitter_fix = 0
|
||||
|
||||
## TODO - When Godot 4.5 becomes min verison
|
||||
# get_tree().scene_changed.connect(_scene_changed)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
Engine.unregister_singleton(_CONSTANTS.PCAM_MANAGER_NODE_NAME)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Setting default screensize
|
||||
screen_size = Vector2i(
|
||||
ProjectSettings.get_setting("display/window/size/viewport_width"),
|
||||
ProjectSettings.get_setting("display/window/size/viewport_height")
|
||||
)
|
||||
|
||||
# For editor
|
||||
if Engine.is_editor_hint():
|
||||
ProjectSettings.settings_changed.connect(func():
|
||||
screen_size = Vector2i(
|
||||
ProjectSettings.get_setting("display/window/size/viewport_width"),
|
||||
ProjectSettings.get_setting("display/window/size/viewport_height")
|
||||
)
|
||||
)
|
||||
# For runtime
|
||||
else:
|
||||
get_tree().get_root().size_changed.connect(func():
|
||||
screen_size = get_viewport().get_visible_rect().size
|
||||
)
|
||||
|
||||
## TODO - When Godot 4.5 becomes min verison
|
||||
#func _scene_changed() -> void:
|
||||
# pass
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Functions
|
||||
|
||||
func pcam_host_added(caller: Node) -> void:
|
||||
if is_instance_of(caller, PhantomCameraHost):
|
||||
_phantom_camera_host_list.append(caller)
|
||||
pcam_host_added_to_scene.emit(caller)
|
||||
else:
|
||||
printerr("This method can only be called from a PhantomCameraHost node")
|
||||
|
||||
func pcam_host_removed(caller: Node) -> void:
|
||||
if is_instance_of(caller, PhantomCameraHost):
|
||||
_phantom_camera_host_list.erase(caller)
|
||||
pcam_host_removed_from_scene.emit(caller)
|
||||
else:
|
||||
printerr("This method can only be called from a PhantomCameraHost node")
|
||||
|
||||
|
||||
func pcam_added(caller) -> void:
|
||||
if is_instance_of(caller, PhantomCamera2D):
|
||||
_phantom_camera_2d_list.append(caller)
|
||||
pcam_added_to_scene.emit(caller)
|
||||
elif caller.is_class("PhantomCamera3D"): ## Note: To support disable_3d export templates for 2D projects, this is purposely not strongly typed.
|
||||
_phantom_camera_3d_list.append(caller)
|
||||
pcam_added_to_scene.emit(caller)
|
||||
else:
|
||||
printerr("This method can only be called from a PhantomCamera node")
|
||||
|
||||
func pcam_removed(caller) -> void:
|
||||
if is_instance_of(caller, PhantomCamera2D):
|
||||
_phantom_camera_2d_list.erase(caller)
|
||||
pcam_removed_from_scene.emit(caller)
|
||||
elif caller.is_class("PhantomCamera3D"): ## Note: To support disable_3d export templates for 2D projects, this is purposely not strongly typed.
|
||||
_phantom_camera_3d_list.erase(caller)
|
||||
pcam_removed_from_scene.emit(caller)
|
||||
else:
|
||||
printerr("This method can only be called from a PhantomCamera node")
|
||||
|
||||
|
||||
func pcam_tween_director_added(caller: Node) -> void:
|
||||
if is_instance_of(caller, PhantomCameraTweenDirector):
|
||||
_phantom_camera_tween_director_list.append(caller)
|
||||
else:
|
||||
printerr("This function can only be called from a PhantomCameraTweenDirector node")
|
||||
|
||||
func pcam_tween_director_removed(caller: Node) -> void:
|
||||
if is_instance_of(caller, PhantomCameraTweenDirector):
|
||||
_phantom_camera_tween_director_list.erase(caller)
|
||||
else:
|
||||
printerr("This function can only be called from a PhantomCameraTweenDirector node")
|
||||
|
||||
|
||||
func get_phantom_camera_hosts() -> Array[PhantomCameraHost]:
|
||||
return _phantom_camera_host_list
|
||||
|
||||
func get_phantom_camera_2ds() -> Array[PhantomCamera2D]:
|
||||
return _phantom_camera_2d_list
|
||||
|
||||
func get_phantom_camera_3ds() -> Array: ## Note: To support disable_3d export templates for 2D projects, this is purposely not strongly typed.
|
||||
return _phantom_camera_3d_list
|
||||
|
||||
func set_viewfinder(caller: Node, value: Control) -> void:
|
||||
if caller is PhantomCameraHost:
|
||||
_viewfinder = value
|
||||
else:
|
||||
printerr("Viewfinder can only be set internally by the addon")
|
||||
|
||||
func get_viewfinder() -> Control:
|
||||
return _viewfinder
|
||||
|
||||
func scene_changed() -> void:
|
||||
_phantom_camera_2d_list.clear()
|
||||
_phantom_camera_3d_list.clear()
|
||||
_phantom_camera_host_list.clear()
|
||||
_phantom_camera_tween_director_list.clear()
|
||||
|
||||
#endregion
|
||||
@@ -0,0 +1 @@
|
||||
uid://duq6jhf6unyis
|
||||
Reference in new issue
Block a user