react-three-game 0.0.88 → 0.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useThree } from '@react-three/fiber';
|
|
3
4
|
import { SoundPicker } from '../../assetviewer/page';
|
|
4
5
|
import { useAssetRuntime, useEntityRuntime } from '../assetRuntime';
|
|
5
6
|
import { gameEvents } from '../GameEvents';
|
|
@@ -142,6 +143,7 @@ function SoundComponentEditor({ component, onUpdate, basePath = '' }) {
|
|
|
142
143
|
function SoundComponentView({ properties, children }) {
|
|
143
144
|
const { getSound } = useAssetRuntime();
|
|
144
145
|
const { editMode, nodeId } = useEntityRuntime();
|
|
146
|
+
const { camera } = useThree();
|
|
145
147
|
const { eventName, autoplay = false, positional = false, refDistance = 1, maxDistance = 24, rolloffFactor = 1, distanceModel = 'inverse' } = properties;
|
|
146
148
|
const sequenceIndexRef = useRef(0);
|
|
147
149
|
const listenerRef = useRef(null);
|
|
@@ -150,6 +152,22 @@ function SoundComponentView({ properties, children }) {
|
|
|
150
152
|
if (!listenerRef.current) {
|
|
151
153
|
listenerRef.current = getSharedAudioListener();
|
|
152
154
|
}
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
var _a;
|
|
157
|
+
const listener = listenerRef.current;
|
|
158
|
+
if (!listener) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (listener.parent !== camera) {
|
|
162
|
+
(_a = listener.parent) === null || _a === void 0 ? void 0 : _a.remove(listener);
|
|
163
|
+
camera.add(listener);
|
|
164
|
+
}
|
|
165
|
+
return () => {
|
|
166
|
+
if (listener.parent === camera) {
|
|
167
|
+
camera.remove(listener);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}, [camera]);
|
|
153
171
|
useEffect(() => {
|
|
154
172
|
const audio = positionalAudioRef.current;
|
|
155
173
|
if (!audio) {
|