@reactunity/renderer 0.14.5 → 0.14.6
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/models/environment/interop.d.ts +3 -0
- package/dist/src/models/generated/editor.js +1 -1
- package/dist/src/models/generated/react.d.ts +275 -28
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/generated/system.js +1 -1
- package/dist/src/models/generated/tests.js +1 -1
- package/dist/src/models/generated/unity.js +1 -1
- package/dist/src/models/generated/yoga.js +1 -1
- package/dist/src/models/properties/common.d.ts +2 -0
- package/dist/src/models/properties/common.js +1 -0
- package/dist/src/models/properties/index.d.ts +1 -0
- package/dist/src/models/properties/index.js +1 -0
- package/dist/src/models/properties/styles-enums.d.ts +0 -1
- package/dist/src/models/properties/styles.d.ts +2 -1
- package/dist/src/models/ugui/components.d.ts +2 -1
- package/dist/src/models/uitoolkit/components.d.ts +3 -1
- package/dist/src/renderer/renderer.d.ts +4 -0
- package/dist/src/renderer/renderer.js +76 -69
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/webgl-compat/error-messages.d.ts +9 -0
- package/dist/src/webgl-compat/error-messages.js +10 -0
- package/dist/src/webgl-compat/index.d.ts +13 -0
- package/dist/src/webgl-compat/index.js +8 -0
- package/dist/src/webgl-compat/use-event-system.d.ts +8 -0
- package/dist/src/webgl-compat/use-event-system.js +64 -0
- package/dist/src/webgl-compat/use-unity-context.d.ts +4 -0
- package/dist/src/webgl-compat/use-unity-context.js +74 -0
- package/dist/webgl-compat.d.ts +1 -0
- package/dist/webgl-compat.js +1 -0
- package/package.json +8 -3
- package/webgl-compat.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Types in assemblies: UnityEngine.CoreModule, Unity.InputSystem, UnityEngine.AudioModule, UnityEngine.UIModule, UnityEngine.TextRenderingModule, UnityEngine.AnimationModule, UnityEngine.IMGUIModule, UnityEngine.UnityAnalyticsModule, UnityEngine.ParticleSystemModule, UnityEngine.PhysicsModule, UnityEngine.InputLegacyModule, UnityEngine.AIModule, UnityEngine.UI, UnityEngine.VideoModule, UnityEngine.TestRunner, UnityEngine.TextCoreFontEngineModule, UnityEngine.TextCoreTextEngineModule, UnityEngine.UIElementsModule, UnityEngine.XRModule
|
|
3
|
-
// Generated
|
|
3
|
+
// Generated 18/02/2023 03:04:15
|
|
4
4
|
//
|
|
5
5
|
/* eslint-disable */
|
|
6
6
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type SafeString = string & {};
|
|
2
1
|
export type CssKeyword = 'initial' | 'inherit' | 'auto' | 'none' | 'unset' | 'default' | 'revert';
|
|
3
2
|
export type FontWeight = 'thin' | 100 | 'extra-light' | 200 | 'light' | 300 | 'regular' | 400 | 'medium' | 500 | 'semi-bold' | 600 | 'bold' | 700 | 'heavy' | 800 | 'black' | 900;
|
|
4
3
|
export type FontStyles = 'normal' | 'bold' | 'italic' | 'underline' | 'lowercase' | 'uppercase' | 'smallcaps' | 'strikethrough' | 'superscript' | 'subscript' | 'highlight';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SafeString } from './common';
|
|
2
|
+
import { AnimationDirection, AnimationFillMode, AnimationPlayState, Appearance, BackgroundBlendMode, BackgroundRepeat, BackgroundSize, BorderImageRepeat, BorderStyle, CursorType, FontStyles, FontWeight, NavigationMode, ObjectFit, PointerEvents, TextAlign, TextOverflowModes, TextTransform, TimingFunctionType, VerticalAlign, Visibility, WhiteSpace } from './styles-enums';
|
|
2
3
|
import { Array2Aux, AssetReference, AssetReferenceOrHttp, ColorAux, NumberAux, Vector2Aux, Vector3Aux } from './values';
|
|
3
4
|
import { YogaValue2Aux, YogaValueAux } from './yoga';
|
|
4
5
|
export interface RenderStyle {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseCmpProps, ContentSrcProps } from '../base';
|
|
2
2
|
import { ReactUnity, UnityEngine } from '../generated';
|
|
3
|
+
import { AnchorTarget } from '../properties';
|
|
3
4
|
import { AssetReference, AssetReferenceOrHttp } from '../properties/values';
|
|
4
5
|
import { ActionCallback, Events } from './events';
|
|
5
6
|
export interface View<T = ReactUnity.UGUI.UGUIComponent> extends Events<T>, BaseCmpProps {
|
|
@@ -39,7 +40,7 @@ export interface Anchor extends View<ReactUnity.UGUI.AnchorComponent> {
|
|
|
39
40
|
url?: string;
|
|
40
41
|
disabled?: boolean;
|
|
41
42
|
/** Works in WebGL only */
|
|
42
|
-
|
|
43
|
+
target?: AnchorTarget;
|
|
43
44
|
}
|
|
44
45
|
export interface BaseImage<T = ReactUnity.UGUI.ImageComponent> extends View<T> {
|
|
45
46
|
src?: AssetReferenceOrHttp;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCmpProps, ContentSrcProps } from '../base';
|
|
2
2
|
import { ReactUnity, UnityEditor, UnityEngine } from '../generated';
|
|
3
|
-
import { Style } from '../properties';
|
|
3
|
+
import { AnchorTarget, Style } from '../properties';
|
|
4
4
|
import { AssetReference } from '../properties/values';
|
|
5
5
|
import { ActionCallback, Events } from './events';
|
|
6
6
|
import Cmp = ReactUnity.UIToolkit;
|
|
@@ -52,6 +52,8 @@ export interface Button<TSender = Cmp.ButtonComponent> extends View<TSender> {
|
|
|
52
52
|
}
|
|
53
53
|
export interface Anchor extends View {
|
|
54
54
|
url?: string;
|
|
55
|
+
/** Works in WebGL only */
|
|
56
|
+
target?: AnchorTarget;
|
|
55
57
|
}
|
|
56
58
|
export interface Image extends View<Cmp.ImageComponent> {
|
|
57
59
|
src?: AssetReference;
|
|
@@ -11,6 +11,10 @@ interface RenderOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
disableBatchRendering?: boolean;
|
|
13
13
|
}
|
|
14
|
+
export declare function render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<AsyncContainerInstance, import("./async/types").AsyncInstance, import("./async/types").AsyncInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Instead, import `render` directly from `@reactunity/renderer`
|
|
17
|
+
*/
|
|
14
18
|
export declare const Renderer: {
|
|
15
19
|
render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<AsyncContainerInstance, import("./async/types").AsyncInstance, import("./async/types").AsyncInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
|
|
16
20
|
};
|
|
@@ -8,78 +8,85 @@ import { isDevelopment } from './constants';
|
|
|
8
8
|
import { syncReconciler } from './sync/reconciler';
|
|
9
9
|
var containerMap = new Map();
|
|
10
10
|
var renderCount = 0;
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
findFiberByHostInstance = function (instance) { return !instance ? null : fiberCache_1.getObject(instance.refId); };
|
|
26
|
-
}
|
|
27
|
-
var scheduled_1 = false;
|
|
28
|
-
var commands_1 = [];
|
|
29
|
-
commands_1.push = function () {
|
|
30
|
-
var args = [];
|
|
31
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
32
|
-
args[_i] = arguments[_i];
|
|
33
|
-
}
|
|
34
|
-
if (!scheduled_1) {
|
|
35
|
-
scheduled_1 = true;
|
|
36
|
-
Promise.resolve().then(function () {
|
|
37
|
-
asyncJobCallback();
|
|
38
|
-
scheduled_1 = false;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return Array.prototype.push.apply(commands_1, args);
|
|
42
|
-
};
|
|
43
|
-
var hostContainerInstance_1 = {
|
|
44
|
-
type: 'native',
|
|
45
|
-
commands: commands_1,
|
|
46
|
-
component: hostContainer,
|
|
47
|
-
context: hostContainer.Context,
|
|
48
|
-
refId: hostContainer.RefId,
|
|
49
|
-
fiberCache: fiberCache_1,
|
|
50
|
-
};
|
|
51
|
-
asyncJobCallback = function () {
|
|
52
|
-
if (!commands_1.length)
|
|
53
|
-
return;
|
|
54
|
-
var serialized = JSON.stringify(commands_1);
|
|
55
|
-
commands_1.length = 0;
|
|
56
|
-
hostContainerInstance_1.context.FlushCommands(serialized);
|
|
57
|
-
};
|
|
58
|
-
hostRoot = asyncReconciler.createContainer(hostContainerInstance_1, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
|
|
11
|
+
export function render(element, options) {
|
|
12
|
+
if (options === void 0) { options = {}; }
|
|
13
|
+
renderCount++;
|
|
14
|
+
var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
|
|
15
|
+
var cacheKey = hostContainer.InstanceId >= 0 ? hostContainer.InstanceId : hostContainer;
|
|
16
|
+
var isAsync = !(options === null || options === void 0 ? void 0 : options.disableBatchRendering);
|
|
17
|
+
var _a = containerMap.get(cacheKey) || {}, hostRoot = _a.hostRoot, asyncJobCallback = _a.asyncJobCallback;
|
|
18
|
+
var findFiberByHostInstance = function () { return null; };
|
|
19
|
+
if (!hostRoot) {
|
|
20
|
+
var mode = (options === null || options === void 0 ? void 0 : options.mode) === 'legacy' ? LegacyRoot : ConcurrentRoot;
|
|
21
|
+
if (isAsync) {
|
|
22
|
+
var fiberCache_1 = isDevelopment ? new ObjectsRepo() : null;
|
|
23
|
+
if (isDevelopment) {
|
|
24
|
+
findFiberByHostInstance = function (instance) { return !instance ? null : fiberCache_1.getObject(instance.refId); };
|
|
59
25
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
26
|
+
var scheduled_1 = false;
|
|
27
|
+
var commands_1 = [];
|
|
28
|
+
commands_1.push = function () {
|
|
29
|
+
var args = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
args[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
if (!scheduled_1) {
|
|
34
|
+
scheduled_1 = true;
|
|
35
|
+
Promise.resolve().then(function () {
|
|
36
|
+
asyncJobCallback();
|
|
37
|
+
scheduled_1 = false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return Array.prototype.push.apply(commands_1, args);
|
|
41
|
+
};
|
|
42
|
+
var hostContainerInstance_1 = {
|
|
43
|
+
type: 'native',
|
|
44
|
+
commands: commands_1,
|
|
45
|
+
component: hostContainer,
|
|
46
|
+
context: hostContainer.Context,
|
|
47
|
+
refId: hostContainer.RefId,
|
|
48
|
+
fiberCache: fiberCache_1,
|
|
70
49
|
};
|
|
71
|
-
|
|
50
|
+
asyncJobCallback = function () {
|
|
51
|
+
if (!commands_1.length)
|
|
52
|
+
return;
|
|
53
|
+
var serialized = JSON.stringify(commands_1);
|
|
54
|
+
commands_1.length = 0;
|
|
55
|
+
hostContainerInstance_1.context.FlushCommands(serialized);
|
|
56
|
+
};
|
|
57
|
+
hostRoot = asyncReconciler.createContainer(hostContainerInstance_1, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
hostRoot = syncReconciler.createContainer(hostContainer, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
|
|
72
61
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
containerMap.set(cacheKey, { hostRoot: hostRoot, asyncJobCallback: asyncJobCallback });
|
|
63
|
+
}
|
|
64
|
+
var shouldWrapWithHelpers = !(options === null || options === void 0 ? void 0 : options.disableHelpers);
|
|
65
|
+
if (shouldWrapWithHelpers) {
|
|
66
|
+
var viewWrapperProps = {
|
|
67
|
+
withHelpers: !(options === null || options === void 0 ? void 0 : options.disableHelpers),
|
|
68
|
+
renderCount: renderCount,
|
|
69
|
+
};
|
|
70
|
+
element = createElement(DefaultView, viewWrapperProps, element);
|
|
71
|
+
}
|
|
72
|
+
var rc = isAsync ? asyncReconciler : syncReconciler;
|
|
73
|
+
rc.updateContainer(element, hostRoot, null);
|
|
74
|
+
rc.injectIntoDevTools({
|
|
75
|
+
bundleType: isDevelopment ? 1 : 0,
|
|
76
|
+
version: version,
|
|
77
|
+
rendererPackageName: '@reactunity/renderer',
|
|
78
|
+
rendererConfig: { isAsync: isAsync },
|
|
79
|
+
findFiberByHostInstance: findFiberByHostInstance,
|
|
80
|
+
});
|
|
81
|
+
return rc;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Instead, import `render` directly from `@reactunity/renderer`
|
|
85
|
+
*/
|
|
86
|
+
export var Renderer = {
|
|
87
|
+
render: function (element, options) {
|
|
88
|
+
if (options === void 0) { options = {}; }
|
|
89
|
+
return render(element, options);
|
|
83
90
|
},
|
|
84
91
|
};
|
|
85
92
|
export var batchedUpdates = asyncReconciler.batchedUpdates;
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.14.
|
|
1
|
+
export declare const version = "0.14.6";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '0.14.
|
|
1
|
+
export var version = '0.14.6';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const errorMessages: {
|
|
2
|
+
genericNoUnityInstance: string;
|
|
3
|
+
requestFullscreenNoUnityInstance: string;
|
|
4
|
+
requestPointerLockNoUnityInstanceOrCanvas: string;
|
|
5
|
+
sendMessageNoUnityInstance: string;
|
|
6
|
+
quitNoUnityInstance: string;
|
|
7
|
+
screenshotNoUnityInstanceOrCanvas: string;
|
|
8
|
+
noEventListener: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Original file: https://github.com/jeffreylanters/react-unity-webgl/blob/main/module/source/constants/error-messages.ts
|
|
2
|
+
export var errorMessages = {
|
|
3
|
+
genericNoUnityInstance: "No Unity Instance found.",
|
|
4
|
+
requestFullscreenNoUnityInstance: "Unable to Set Fullscreen while Unity is not Instantiated.",
|
|
5
|
+
requestPointerLockNoUnityInstanceOrCanvas: "Unable to Request Pointer Lock while Unity is not Instantiated or the Canvas is not found.",
|
|
6
|
+
sendMessageNoUnityInstance: "Unable to Send Message while Unity is not Instantiated.",
|
|
7
|
+
quitNoUnityInstance: "Unable to Quit Unity while Unity is not Instantiated.",
|
|
8
|
+
screenshotNoUnityInstanceOrCanvas: "Unable to Take Screenshot while Unity is not Instantiated or Canvas is not available.",
|
|
9
|
+
noEventListener: "Unable to find Event Listener in Event System for Event",
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UnityConfig, UnityProps, WebGLContextAttributes } from 'react-unity-webgl';
|
|
2
|
+
export { useUnityContext } from './use-unity-context';
|
|
3
|
+
export type { UnityProps, UnityConfig, WebGLContextAttributes };
|
|
4
|
+
export declare const Unity: import("react").ForwardRefExoticComponent<{
|
|
5
|
+
readonly devicePixelRatio?: number;
|
|
6
|
+
readonly matchWebGLToCanvasSize?: boolean;
|
|
7
|
+
readonly disabledCanvasEvents?: (string | number | symbol)[];
|
|
8
|
+
} & {
|
|
9
|
+
readonly unityProvider: import("react-unity-webgl/distribution/types/unity-provider").UnityProvider;
|
|
10
|
+
readonly className?: string;
|
|
11
|
+
readonly style?: import("react").CSSProperties;
|
|
12
|
+
readonly tabIndex?: number;
|
|
13
|
+
} & import("react").RefAttributes<{}>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// <reference types="react-unity-webgl" />
|
|
3
|
+
import { forwardRef, useImperativeHandle } from "react";
|
|
4
|
+
export { useUnityContext } from './use-unity-context';
|
|
5
|
+
export var Unity = forwardRef(function Unity(props, ref) {
|
|
6
|
+
useImperativeHandle(ref, function () { return ({}); });
|
|
7
|
+
return _jsx(_Fragment, {});
|
|
8
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ReactUnityEventParameter = string | number | undefined;
|
|
2
|
+
type Callback = (...parameters: ReactUnityEventParameter[]) => ReactUnityEventParameter;
|
|
3
|
+
type EventSystemHook = {
|
|
4
|
+
readonly addEventListener: (eventName: string, callback: Callback) => void;
|
|
5
|
+
readonly removeEventListener: (eventName: string, callback: Callback) => void;
|
|
6
|
+
};
|
|
7
|
+
declare const useEventSystem: () => EventSystemHook;
|
|
8
|
+
export { useEventSystem };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Original file: https://github.com/jeffreylanters/react-unity-webgl/blob/main/module/source/hooks/use-event-system.ts
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
12
|
+
import { errorMessages } from './error-messages';
|
|
13
|
+
var mountedEventDispatchers = [];
|
|
14
|
+
var dispatchReactUnityEvent = function (eventName) {
|
|
15
|
+
var parameters = [];
|
|
16
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
17
|
+
parameters[_i - 1] = arguments[_i];
|
|
18
|
+
}
|
|
19
|
+
var returnValue = undefined;
|
|
20
|
+
mountedEventDispatchers.forEach(function (dispatchEvent) {
|
|
21
|
+
returnValue = dispatchEvent.apply(void 0, __spreadArray([eventName], parameters, false));
|
|
22
|
+
});
|
|
23
|
+
return returnValue;
|
|
24
|
+
};
|
|
25
|
+
if (typeof globalThis !== "undefined" || typeof window !== "undefined") {
|
|
26
|
+
(globalThis || window).dispatchReactUnityEvent = dispatchReactUnityEvent;
|
|
27
|
+
}
|
|
28
|
+
var useEventSystem = function () {
|
|
29
|
+
var eventListeners = useRef([]);
|
|
30
|
+
var addEventListener = useCallback(function (eventName, callback) {
|
|
31
|
+
eventListeners.current = __spreadArray(__spreadArray([], eventListeners.current, true), [
|
|
32
|
+
{ eventName: eventName, callback: callback },
|
|
33
|
+
], false);
|
|
34
|
+
}, [eventListeners]);
|
|
35
|
+
var removeEventListener = useCallback(function (eventName, callback) {
|
|
36
|
+
eventListeners.current = eventListeners.current.filter(function (eventListener) {
|
|
37
|
+
return eventListener.eventName !== eventName &&
|
|
38
|
+
eventListener.callback !== callback;
|
|
39
|
+
});
|
|
40
|
+
}, [eventListeners]);
|
|
41
|
+
var dispatchEvent = useCallback(function (eventName) {
|
|
42
|
+
var parameters = [];
|
|
43
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
44
|
+
parameters[_i - 1] = arguments[_i];
|
|
45
|
+
}
|
|
46
|
+
var eventListener = eventListeners.current.find(function (eventListener) { return eventListener.eventName === eventName; });
|
|
47
|
+
if (typeof eventListener === "undefined") {
|
|
48
|
+
console.warn(errorMessages.noEventListener, { eventName: eventName });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return eventListener.callback.apply(eventListener, parameters);
|
|
52
|
+
}, [eventListeners]);
|
|
53
|
+
useEffect(function () {
|
|
54
|
+
mountedEventDispatchers.push(dispatchEvent);
|
|
55
|
+
return function () {
|
|
56
|
+
mountedEventDispatchers.splice(mountedEventDispatchers.indexOf(dispatchEvent), 1);
|
|
57
|
+
};
|
|
58
|
+
}, [dispatchEvent]);
|
|
59
|
+
return {
|
|
60
|
+
addEventListener: addEventListener,
|
|
61
|
+
removeEventListener: removeEventListener,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export { useEventSystem };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Original file: https://github.com/jeffreylanters/react-unity-webgl/blob/main/module/source/hooks/use-unity-context.ts
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { errorMessages } from './error-messages';
|
|
4
|
+
import { useEventSystem } from "./use-event-system";
|
|
5
|
+
var useUnityContext = function (unityConfig) {
|
|
6
|
+
var _a = useState(typeof ReactUnityWebGLCompat !== 'undefined' ? ReactUnityWebGLCompat : null), unityInstance = _a[0], setUnityInstance = _a[1];
|
|
7
|
+
var _b = useState(1), loadingProgression = _b[0], setLoadingProgression = _b[1];
|
|
8
|
+
var _c = useState(true), isLoaded = _c[0], setIsLoaded = _c[1];
|
|
9
|
+
var _d = useState(null), initialisationError = _d[0], setInitialisationError = _d[1];
|
|
10
|
+
var eventSystem = useEventSystem();
|
|
11
|
+
var unityProvider = useRef({
|
|
12
|
+
setLoadingProgression: setLoadingProgression,
|
|
13
|
+
setInitialisationError: setInitialisationError,
|
|
14
|
+
setUnityInstance: setUnityInstance,
|
|
15
|
+
setIsLoaded: setIsLoaded,
|
|
16
|
+
unityConfig: unityConfig,
|
|
17
|
+
});
|
|
18
|
+
var requestFullscreen = useCallback(function (enabled) {
|
|
19
|
+
if (unityInstance === null) {
|
|
20
|
+
console.warn(errorMessages.requestFullscreenNoUnityInstance);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
unityInstance.SetFullscreen(enabled === true ? 1 : 0);
|
|
24
|
+
}, [unityInstance]);
|
|
25
|
+
var requestPointerLock = useCallback(function () {
|
|
26
|
+
if (unityInstance === null ||
|
|
27
|
+
typeof unityInstance.Module.canvas === "undefined") {
|
|
28
|
+
console.warn(errorMessages.requestPointerLockNoUnityInstanceOrCanvas);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return unityInstance.Module.canvas.requestPointerLock();
|
|
32
|
+
}, [unityInstance]);
|
|
33
|
+
var sendMessage = useCallback(function (gameObjectName, methodName, parameter) {
|
|
34
|
+
if (unityInstance === null) {
|
|
35
|
+
console.warn(errorMessages.sendMessageNoUnityInstance);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
unityInstance.SendMessage(gameObjectName, methodName, parameter);
|
|
39
|
+
}, [unityInstance]);
|
|
40
|
+
var takeScreenshot = useCallback(function (dataType, quality) {
|
|
41
|
+
if (unityInstance === null ||
|
|
42
|
+
typeof unityInstance.Module.canvas === "undefined") {
|
|
43
|
+
console.warn(errorMessages.screenshotNoUnityInstanceOrCanvas);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return unityInstance.Module.canvas.toDataURL(dataType, quality);
|
|
47
|
+
}, [unityInstance]);
|
|
48
|
+
var unload = useCallback(function () {
|
|
49
|
+
if (unityInstance === null) {
|
|
50
|
+
console.warn(errorMessages.quitNoUnityInstance);
|
|
51
|
+
return Promise.reject();
|
|
52
|
+
}
|
|
53
|
+
return unityInstance.Quit();
|
|
54
|
+
}, [unityInstance]);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
setIsLoaded(loadingProgression === 1);
|
|
57
|
+
}, [loadingProgression]);
|
|
58
|
+
return {
|
|
59
|
+
unityProvider: unityProvider.current,
|
|
60
|
+
loadingProgression: loadingProgression,
|
|
61
|
+
initialisationError: initialisationError,
|
|
62
|
+
isLoaded: isLoaded,
|
|
63
|
+
UNSAFE__detachAndUnloadImmediate: function () { return Promise.resolve(); },
|
|
64
|
+
UNSAFE__unityInstance: unityInstance,
|
|
65
|
+
requestFullscreen: requestFullscreen,
|
|
66
|
+
requestPointerLock: requestPointerLock,
|
|
67
|
+
sendMessage: sendMessage,
|
|
68
|
+
unload: unload,
|
|
69
|
+
takeScreenshot: takeScreenshot,
|
|
70
|
+
addEventListener: eventSystem.addEventListener,
|
|
71
|
+
removeEventListener: eventSystem.removeEventListener,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export { useUnityContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/webgl-compat';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/webgl-compat';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactunity/renderer",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.6",
|
|
4
4
|
"description": "React renderer for Unity3D",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"./editor": "./dist/editor.js",
|
|
12
12
|
"./test": "./dist/test.js",
|
|
13
13
|
"./ugui": "./dist/ugui.js",
|
|
14
|
-
"./uitoolkit": "./dist/uitoolkit.js"
|
|
14
|
+
"./uitoolkit": "./dist/uitoolkit.js",
|
|
15
|
+
"./webgl-compat": "./dist/webgl-compat.js"
|
|
15
16
|
},
|
|
16
17
|
"typesVersions": {
|
|
17
18
|
"*": {
|
|
@@ -26,6 +27,9 @@
|
|
|
26
27
|
],
|
|
27
28
|
"uitoolkit": [
|
|
28
29
|
"./dist/uitoolkit.d.ts"
|
|
30
|
+
],
|
|
31
|
+
"webgl-compat": [
|
|
32
|
+
"./dist/webgl-compat.d.ts"
|
|
29
33
|
]
|
|
30
34
|
}
|
|
31
35
|
},
|
|
@@ -61,8 +65,9 @@
|
|
|
61
65
|
"react": "^18.0.0"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
|
-
"@reactunity/scripts": "^0.14.
|
|
68
|
+
"@reactunity/scripts": "^0.14.1",
|
|
65
69
|
"@types/react-reconciler": "^0.28.2",
|
|
70
|
+
"react-unity-webgl": "^9.4.0",
|
|
66
71
|
"rimraf": "^4.1.2",
|
|
67
72
|
"typescript": "^4.9.5"
|
|
68
73
|
}
|
package/webgl-compat.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/webgl-compat';
|