extends Camera # Turns an ARVRCamera node on when Virtual Reality is active # # As of Godot 3.0.2, using an ARVRCamera without VR fills you error log with this # # Condition 'arvr_interface.is_null()' is true. returned: Vector() # # This silly component turns of the ARVRCamera on only when virtual reality is active # ------------------------------------------------------------------------------------------------- # Manager that controls initialization and shutdown of virtual reality var virtualRealityManager # ------------------------------------------------------------------------------------------------- # Initializes the script component when the node is added to the scene func _ready(): InitializeIfNotYetDone() if self.virtualRealityManager == null: onVirtualRealityToggled(false) else: onVirtualRealityToggled(self.virtualRealityManager.IsVirtualRealityActive()) # ------------------------------------------------------------------------------------------------- # Initializes virtual reality if this hasn't already happened # @remarks # With this method, other components can avoid having to depend on an initialization # order that needs to be set up behind the scenes (and that would have no documentation # in an obvious place to indicate that) func InitializeIfNotYetDone(): if self.virtualRealityManager == null: self.virtualRealityManager = get_node("/root/Systems/VirtualRealityManager") if self.virtualRealityManager != null: self.virtualRealityManager.InitializeIfNotYetDone() self.virtualRealityManager.connect( "VirtualRealityToggled", self, "onVirtualRealityToggled" ) # ------------------------------------------------------------------------------------------------- # Called when virtual reality is activated or shut down # @param state Whether virtual reality is now active or not func onVirtualRealityToggled(var state): if state: self.make_current() else: self.clear_current() self.visible = state