예제 #1
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue UtilityPrototype;
            JavaScriptValue UtilityConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.Networking.Utility),
                (args) => { throw new NotImplementedException(); },
                out UtilityPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .GetProperty("Networking")
            .SetProperty("Utility", UtilityConstructor);


            // Static Fields


            // Static Property Accessors


            // Static Methods

            UtilityConstructor.SetProperty(
                "GetSourceID",
                Bridge.CreateFunction(
                    "GetSourceID",
                    (args) => Bridge.CreateExternalWithPrototype(UnityEngine.Networking.Utility.GetSourceID())
                    )
                );


            UtilityConstructor.SetProperty(
                "SetAccessTokenForNetwork",
                Bridge.CreateFunction(
                    "SetAccessTokenForNetwork",
                    (args) => UnityEngine.Networking.Utility.SetAccessTokenForNetwork(Bridge.GetExternal <UnityEngine.Networking.Types.NetworkID>(args[1]), Bridge.GetExternal <UnityEngine.Networking.Types.NetworkAccessToken>(args[2]))
                    )
                );


            UtilityConstructor.SetProperty(
                "GetAccessTokenForNetwork",
                Bridge.CreateFunction(
                    "GetAccessTokenForNetwork",
                    (args) => Bridge.CreateExternalWithPrototype(UnityEngine.Networking.Utility.GetAccessTokenForNetwork(Bridge.GetExternal <UnityEngine.Networking.Types.NetworkID>(args[1])))
                    )
                );


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #2
0
        private void SetTimeoutFunctions(JavaScriptValue globalObject)
        {
            Native.JsCreateFunction(SetTimeout, IntPtr.Zero, out var setTimeoutFunction);
            globalObject.SetProperty(JavaScriptPropertyId.FromString("setTimeout"), setTimeoutFunction, true);

            Native.JsCreateFunction(ClearTimeout, IntPtr.Zero, out var clearTimeoutFunction);
            globalObject.SetProperty(JavaScriptPropertyId.FromString("clearTimeout"), clearTimeoutFunction, true);
        }
        public void Send(string body)
        {
            if (client == null || requestMessage == null)
            {
                return;
            }
            if (requestTask != null)
            {
                return;
            }

            requestTask = Task.Run(async() => {
                try {
                    var responseHeaders = await client.SendRequestAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);

                    ProjectRuntime.Inst.DispatchRuntimeCode(() => {
                        objRef.SetProperty(JavaScriptPropertyId.FromString("status"), JavaScriptValue.FromInt32((int)responseHeaders.StatusCode), true);
                        string statusText = $"{(int)responseHeaders.StatusCode} {responseHeaders.ReasonPhrase}";
                        objRef.SetProperty(JavaScriptPropertyId.FromString("statusText"), JavaScriptValue.FromString(statusText), true);
                    });
                    ReadyState = ReadyStates.Headers_Received;

                    // ReadyState = ReadyStates.Loading;  // ignore, we don't do partial responses
                    var content = await responseHeaders.Content.ReadAsStringAsync();
                    ProjectRuntime.Inst.DispatchRuntimeCode(() => {
                        objRef.SetProperty(JavaScriptPropertyId.FromString("responseType"), JavaScriptValue.FromString("text"), true);
                        objRef.SetProperty(JavaScriptPropertyId.FromString("response"), JavaScriptValue.FromString(content), true);
                        objRef.SetProperty(JavaScriptPropertyId.FromString("responseText"), JavaScriptValue.FromString(content), true);

                        var callback = objRef.Get("onload");
                        if (callback.ValueType == JavaScriptValueType.Function)
                        {
                            callback.CallFunction(callback);
                        }
                    });
                } catch (Exception e) {
                    ProjectRuntime.Inst.DispatchRuntimeCode(() => {
                        var callback = objRef.Get("onerror");
                        if (callback.ValueType == JavaScriptValueType.Function)
                        {
                            callback.CallFunction(callback);
                        }
                    });
                }
                ReadyState     = ReadyStates.Done;
                requestMessage = null;
                requestTask    = null;
            });

            /*
             * cancellationTokenSource = new CancellationTokenSource();
             * requestTask = Task.Run(async () => {
             *  var response = await request;//.AsTask(cancellationTokenSource.Token);
             *  //response.
             *  int dsa = 0;
             * });
             */
        }
예제 #4
0
파일: JsBinding.cs 프로젝트: enklu/orchid
        /// <summary>
        /// This method binds a function to a specific field on a JavaScript object.
        /// </summary>
        /// <param name="name">The name of the field.</param>
        /// <param name="jsFunction">The callback function to execute when the JavaScript function is invoked.</param>
        /// <param name="instanceData">Any instance data that should be passed when the function is executed.</param>
        public void AddInstanceFunction(string name, JavaScriptNativeFunction jsFunction, IntPtr instanceData)
        {
            _scope.Run(() =>
            {
                var jsValue = _binder.BindInstanceFunction(jsFunction, instanceData);

                _value.SetProperty(JavaScriptPropertyId.FromString(name), jsValue, true);
            });
        }
예제 #5
0
        public static void Register(JavaScriptContext context)
        {
#if UNITY_EDITOR
            JavaScriptValue ModelImporterMeshCompressionPrototype;
            JavaScriptValue ModelImporterMeshCompressionConstructor = Bridge.CreateConstructor(
                typeof(UnityEditor.ModelImporterMeshCompression),
                (args) => { throw new NotImplementedException(); },
                out ModelImporterMeshCompressionPrototype
                );
            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEditor")
            .SetProperty("ModelImporterMeshCompression", ModelImporterMeshCompressionConstructor);


            // Static Fields

            ModelImporterMeshCompressionConstructor.SetProperty(
                "Off",
                Bridge.CreateExternalWithPrototype(UnityEditor.ModelImporterMeshCompression.Off)
                );


            ModelImporterMeshCompressionConstructor.SetProperty(
                "Low",
                Bridge.CreateExternalWithPrototype(UnityEditor.ModelImporterMeshCompression.Low)
                );


            ModelImporterMeshCompressionConstructor.SetProperty(
                "Medium",
                Bridge.CreateExternalWithPrototype(UnityEditor.ModelImporterMeshCompression.Medium)
                );


            ModelImporterMeshCompressionConstructor.SetProperty(
                "High",
                Bridge.CreateExternalWithPrototype(UnityEditor.ModelImporterMeshCompression.High)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
#endif
        }
예제 #6
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue PhysicMaterialCombinePrototype;
            JavaScriptValue PhysicMaterialCombineConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.PhysicMaterialCombine),
                (args) => { throw new System.NotImplementedException(); },
                out PhysicMaterialCombinePrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("PhysicMaterialCombine", PhysicMaterialCombineConstructor);


            // Static Fields

            PhysicMaterialCombineConstructor.SetProperty(
                "Average",
                Bridge.CreateExternalWithPrototype(UnityEngine.PhysicMaterialCombine.Average)
                );


            PhysicMaterialCombineConstructor.SetProperty(
                "Minimum",
                Bridge.CreateExternalWithPrototype(UnityEngine.PhysicMaterialCombine.Minimum)
                );


            PhysicMaterialCombineConstructor.SetProperty(
                "Multiply",
                Bridge.CreateExternalWithPrototype(UnityEngine.PhysicMaterialCombine.Multiply)
                );


            PhysicMaterialCombineConstructor.SetProperty(
                "Maximum",
                Bridge.CreateExternalWithPrototype(UnityEngine.PhysicMaterialCombine.Maximum)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #7
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue ForceModePrototype;
            JavaScriptValue ForceModeConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.ForceMode),
                (args) => { throw new System.NotImplementedException(); },
                out ForceModePrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("ForceMode", ForceModeConstructor);


            // Static Fields

            ForceModeConstructor.SetProperty(
                "Force",
                Bridge.CreateExternalWithPrototype(UnityEngine.ForceMode.Force)
                );


            ForceModeConstructor.SetProperty(
                "Acceleration",
                Bridge.CreateExternalWithPrototype(UnityEngine.ForceMode.Acceleration)
                );


            ForceModeConstructor.SetProperty(
                "Impulse",
                Bridge.CreateExternalWithPrototype(UnityEngine.ForceMode.Impulse)
                );


            ForceModeConstructor.SetProperty(
                "VelocityChange",
                Bridge.CreateExternalWithPrototype(UnityEngine.ForceMode.VelocityChange)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #8
0
        public static void Register(JavaScriptContext context)
        {
            updateCallbacks.Clear();
            oneUpdateCallbacks.Clear();

            JavaScriptValue UpdateHelper = JavaScriptValue.CreateObject();

            JavaScriptValue.GlobalObject.SetProperty(
                "UpdateHelper",
                UpdateHelper
                );

            UpdateHelper.SetProperty(
                "addUpdateHook",
                Bridge.CreateFunction(
                    "addUpdateHook",
                    (args) => {
                return(JavaScriptValue.FromString(
                           addUpdateHook(args[1])
                           ));
            }
                    )
                );

            UpdateHelper.SetProperty(
                "removeUpdateHook",
                Bridge.CreateFunction(
                    "removeUpdateHook",
                    (args) => {
                removeUpdateHook(args[1].ToString());
            }
                    )
                );

            UpdateHelper.SetProperty(
                "removeAllUpdateHooks",
                Bridge.CreateFunction(
                    "removeAllUpdateHooks",
                    (args) => {
                updateCallbacks.Clear();
                oneUpdateCallbacks.Clear();
            }
                    )
                );

            UpdateHelper.SetProperty(
                "addOneUpdateHook",
                Bridge.CreateFunction(
                    "addOneUpdateHook",
                    (args) => {
                addOneUpdateHook(args[1]);
            }
                    )
                );
        }
예제 #9
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue CursorLockModePrototype;
            JavaScriptValue CursorLockModeConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.CursorLockMode),
                (args) => { throw new System.NotImplementedException(); },
                out CursorLockModePrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("CursorLockMode", CursorLockModeConstructor);


            // Static Fields

            CursorLockModeConstructor.SetProperty(
                "None",
                Bridge.CreateExternalWithPrototype(UnityEngine.CursorLockMode.None)
                );


            CursorLockModeConstructor.SetProperty(
                "Locked",
                Bridge.CreateExternalWithPrototype(UnityEngine.CursorLockMode.Locked)
                );


            CursorLockModeConstructor.SetProperty(
                "Confined",
                Bridge.CreateExternalWithPrototype(UnityEngine.CursorLockMode.Confined)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #10
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue QueryTriggerInteractionPrototype;
            JavaScriptValue QueryTriggerInteractionConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.QueryTriggerInteraction),
                (args) => { throw new System.NotImplementedException(); },
                out QueryTriggerInteractionPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("QueryTriggerInteraction", QueryTriggerInteractionConstructor);


            // Static Fields

            QueryTriggerInteractionConstructor.SetProperty(
                "UseGlobal",
                Bridge.CreateExternalWithPrototype(UnityEngine.QueryTriggerInteraction.UseGlobal)
                );


            QueryTriggerInteractionConstructor.SetProperty(
                "Ignore",
                Bridge.CreateExternalWithPrototype(UnityEngine.QueryTriggerInteraction.Ignore)
                );


            QueryTriggerInteractionConstructor.SetProperty(
                "Collide",
                Bridge.CreateExternalWithPrototype(UnityEngine.QueryTriggerInteraction.Collide)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #11
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue CollisionDetectionModePrototype;
            JavaScriptValue CollisionDetectionModeConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.CollisionDetectionMode),
                (args) => { throw new System.NotImplementedException(); },
                out CollisionDetectionModePrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("CollisionDetectionMode", CollisionDetectionModeConstructor);


            // Static Fields

            CollisionDetectionModeConstructor.SetProperty(
                "Discrete",
                Bridge.CreateExternalWithPrototype(UnityEngine.CollisionDetectionMode.Discrete)
                );


            CollisionDetectionModeConstructor.SetProperty(
                "Continuous",
                Bridge.CreateExternalWithPrototype(UnityEngine.CollisionDetectionMode.Continuous)
                );


            CollisionDetectionModeConstructor.SetProperty(
                "ContinuousDynamic",
                Bridge.CreateExternalWithPrototype(UnityEngine.CollisionDetectionMode.ContinuousDynamic)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #12
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue RigidbodyInterpolationPrototype;
            JavaScriptValue RigidbodyInterpolationConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.RigidbodyInterpolation),
                (args) => { throw new System.NotImplementedException(); },
                out RigidbodyInterpolationPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("RigidbodyInterpolation", RigidbodyInterpolationConstructor);


            // Static Fields

            RigidbodyInterpolationConstructor.SetProperty(
                "None",
                Bridge.CreateExternalWithPrototype(UnityEngine.RigidbodyInterpolation.None)
                );


            RigidbodyInterpolationConstructor.SetProperty(
                "Interpolate",
                Bridge.CreateExternalWithPrototype(UnityEngine.RigidbodyInterpolation.Interpolate)
                );


            RigidbodyInterpolationConstructor.SetProperty(
                "Extrapolate",
                Bridge.CreateExternalWithPrototype(UnityEngine.RigidbodyInterpolation.Extrapolate)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #13
0
        public void AddType(JavaScriptValue parent, string name, Type type)
        {
            // Create the function that will call the class constructor
            var constructor = JavaScriptValue.CreateFunction(new JavaScriptNativeFunction((callee, isConstructCall, arguments, argumentCount, callbackData) =>
            {
                return(ToJavaScriptValue(Activator.CreateInstance(type)));
            }));

            // Add static functions (e.g Console.WriteLine)
            if (type.IsClass && type != typeof(string))
            {
                // Get the properties and methods
                var methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static)
                              .Where(m => !m.IsSpecialName && m.IsPrivate == false).ToList();

                // Loop through all methods
                foreach (var method in methods)
                {
                    SetMethod(constructor, method, null);
                }
            }

            // Set the property
            var childPropertyId = JavaScriptPropertyId.FromString(name);

            parent.SetProperty(childPropertyId, constructor, true);
        }
예제 #14
0
        private static void DefineHostCallback(JavaScriptValue anObject, string callbackName, JavaScriptNativeFunction callback, IntPtr callbackData)
        {
            JavaScriptPropertyId propertyId = JavaScriptPropertyId.FromString(callbackName);
            JavaScriptValue      function   = JavaScriptValue.CreateFunction(callback, callbackData);

            anObject.SetProperty(propertyId, function, true);
        }
예제 #15
0
        private void SetConsoleLogObject(JavaScriptValue globalObject)
        {
            Native.JsCreateObject(out var consoleObject);
            Native.JsCreateFunction(ConsoleLog, IntPtr.Zero, out var functionValue);

            consoleObject.SetProperty(JavaScriptPropertyId.FromString("log"), functionValue, true);
            globalObject.SetProperty(JavaScriptPropertyId.FromString("console"), consoleObject, true);
        }
예제 #16
0
        public static void DefineGetterSetter(
            JavaScriptValue obj,
            string keyName,
            Func <JavaScriptValue[], JavaScriptValue> callbackGetter,
            Func <JavaScriptValue[], JavaScriptValue> callbackSetter
            )
        {
            JavaScriptValue descriptor = JavaScriptValue.CreateObject();

            descriptor.SetProperty("get", FunctionAllocation.CreateFunction(callbackGetter));
            descriptor.SetProperty("set", FunctionAllocation.CreateFunction(callbackSetter));

            obj.DefineProperty(
                keyName,
                descriptor
                );
        }
        private JavaScriptContext CreateHostWebsocketContext(JavaScriptRuntime runtime, string clientId, string text, Stream binaryStream, bool isStream)
        {
            // Create the context. Note that if we had wanted to start debugging from the very
            // beginning, we would have called JsStartDebugging right after context is created.
            JavaScriptContext context = runtime.CreateContext();

            // Now set the execution context as being the current one on this thread.
            using (new JavaScriptContext.Scope(context))
            {
                // Create the host object the script will use.
                JavaScriptValue hostObject = JavaScriptValue.CreateObject();

                // Get the global object
                JavaScriptValue globalObject = JavaScriptValue.GlobalObject;

                // Get the name of the property ("host") that we're going to set on the global object.
                JavaScriptPropertyId hostPropertyId = JavaScriptPropertyId.FromString("host");

                // Set the property.
                globalObject.SetProperty(hostPropertyId, hostObject, true);

                // Now create the host callbacks that we're going to expose to the script.
                DefineHostCallback(hostObject, "echo", echoDelegate, IntPtr.Zero);
                DefineHostCallback(hostObject, "runScript", runScriptDelegate, IntPtr.Zero);
                DefineHostCallback(hostObject, "readFile", readFileDelegate, IntPtr.Zero);
                DefineHostCallback(hostObject, "writeFile", writeFileDelegate, IntPtr.Zero);
                DefineHostCallback(hostObject, "websocketClients", getWebSocketClientIdDelegate, IntPtr.Zero);
                DefineHostCallback(hostObject, "websocketPush", pushWebSocketMessageDelegate, IntPtr.Zero);

                JavaScriptValue requestParams = JavaScriptValue.CreateObject();
                if (isStream)
                {
                    requestParams.SetProperty(JavaScriptPropertyId.FromString("blob"), JavaScriptValue.FromString(text), true);
                    // not implemented yet #todo
                }
                else
                {
                    requestParams.SetProperty(JavaScriptPropertyId.FromString("text"), JavaScriptValue.FromString(text), true);
                }
                requestParams.SetProperty(JavaScriptPropertyId.FromString("clientId"), JavaScriptValue.FromString(clientId), true);

                hostObject.SetProperty(JavaScriptPropertyId.FromString("request"), requestParams, true);
            }

            return(context);
        }
예제 #18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                runtime = JavaScriptRuntime.Create();
                context = runtime.CreateContext();
                JavaScriptContext.Current = context;

                JavaScriptValue      hostObject     = JavaScriptValue.CreateObject();
                JavaScriptValue      globalObject   = JavaScriptValue.GlobalObject;
                JavaScriptPropertyId hostPropertyId = JavaScriptPropertyId.FromString("host");
                globalObject.SetProperty(hostPropertyId, hostObject, true);

                JavaScriptValue      delegateObject     = JavaScriptValue.CreateObject();
                JavaScriptPropertyId delegatePropertyId = JavaScriptPropertyId.FromString("delegate");
                globalObject.SetProperty(delegatePropertyId, delegateObject, true);

                DefineHostCallback(delegateObject, "ballCountChanged", onBallCountChanged, IntPtr.Zero);
                DefineHostCallback(delegateObject, "displayListChanged", onDisplayListChanged, IntPtr.Zero);
                DefineHostCallback(delegateObject, "eventsPerSecond", onEventsPerSecond, IntPtr.Zero);
                DefineHostCallback(delegateObject, "phaseChanged", onPhaseChanged, IntPtr.Zero);
                DefineHostCallback(delegateObject, "measureText", onMeasureText, IntPtr.Zero);
                DefineHostCallback(delegateObject, "log", onLog, IntPtr.Zero);

                Uri uri = new Uri("/model.js", UriKind.Relative);
                StreamResourceInfo     info = Application.GetContentStream(uri);
                System.IO.StreamReader sr   = new System.IO.StreamReader(info.Stream);
                string          script      = sr.ReadToEnd();
                JavaScriptValue result      = JavaScriptContext.RunScript(script);

                script = "var controller = initApp(" + balls.ActualWidth + ", " + balls.ActualHeight + ", delegate);";
                result = JavaScriptContext.RunScript(script);
            }
            catch (JavaScriptScriptException ex)
            {
                PrintScriptException(ex.Error);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("chakrahost: failed to run script: {0}", ex.Message);
            }

            timer          = new Timer(1.0 / 30.0 * 1000.0);
            timer.Elapsed += new ElapsedEventHandler(TimerFired);
            timer.Enabled  = true;
        }
예제 #19
0
        static void _define(JavaScriptValue globalObject, string callbackName, JavaScriptNativeFunction callback)
        {
            JavaScriptPropertyId propertyId = JavaScriptPropertyId.FromString(callbackName);
            JavaScriptValue      function   = JavaScriptValue.CreateFunction(callback, IntPtr.Zero);

            globalObject.SetProperty(propertyId, function, true);
            m_apis.Add(callbackName);
        }
예제 #20
0
            private void DefineCallback
                (JavaScriptValue hostObject, string callbackName, JavaScriptNativeFunction callbackDelegate)
            {
                var propertyId = JavaScriptPropertyId.FromString(callbackName);

                var function = JavaScriptValue.CreateFunction(callbackDelegate);

                hostObject.SetProperty(propertyId, function, true);
            }
예제 #21
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue PlayerSpawnMethodPrototype;
            JavaScriptValue PlayerSpawnMethodConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.Networking.PlayerSpawnMethod),
                (args) => { throw new NotImplementedException(); },
                out PlayerSpawnMethodPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .GetProperty("Networking")
            .SetProperty("PlayerSpawnMethod", PlayerSpawnMethodConstructor);


            // Static Fields

            PlayerSpawnMethodConstructor.SetProperty(
                "Random",
                Bridge.CreateExternalWithPrototype(UnityEngine.Networking.PlayerSpawnMethod.Random)
                );


            PlayerSpawnMethodConstructor.SetProperty(
                "RoundRobin",
                Bridge.CreateExternalWithPrototype(UnityEngine.Networking.PlayerSpawnMethod.RoundRobin)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #22
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue ReactorModelPrototype;
            JavaScriptValue ReactorModelConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.Networking.ReactorModel),
                (args) => { throw new NotImplementedException(); },
                out ReactorModelPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .GetProperty("Networking")
            .SetProperty("ReactorModel", ReactorModelConstructor);


            // Static Fields

            ReactorModelConstructor.SetProperty(
                "SelectReactor",
                Bridge.CreateExternalWithPrototype(UnityEngine.Networking.ReactorModel.SelectReactor)
                );


            ReactorModelConstructor.SetProperty(
                "FixRateReactor",
                Bridge.CreateExternalWithPrototype(UnityEngine.Networking.ReactorModel.FixRateReactor)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
예제 #23
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue SendMessageOptionsPrototype;
            JavaScriptValue SendMessageOptionsConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.SendMessageOptions),
                (args) => { throw new System.NotImplementedException(); },
                out SendMessageOptionsPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("SendMessageOptions", SendMessageOptionsConstructor);


            // Static Fields

            SendMessageOptionsConstructor.SetProperty(
                "RequireReceiver",
                Bridge.CreateExternalWithPrototype(UnityEngine.SendMessageOptions.RequireReceiver)
                );


            SendMessageOptionsConstructor.SetProperty(
                "DontRequireReceiver",
                Bridge.CreateExternalWithPrototype(UnityEngine.SendMessageOptions.DontRequireReceiver)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
        private static void DefineHostCallback(
            JavaScriptValue obj,
            string callbackName,
            JavaScriptNativeFunction callback)
        {
            var propertyId = JavaScriptPropertyId.FromString(callbackName);
            var function   = JavaScriptValue.CreateFunction(callback);

            obj.SetProperty(propertyId, function, true);
        }
예제 #25
0
        private void InitContext()
        {
            //
            // Create the host object the script will use.
            //

            JavaScriptValue hostObject = JavaScriptValue.CreateObject();

            //
            // Get the global object
            //

            JavaScriptValue globalObject = JavaScriptValue.GlobalObject;

            //
            // Get the name of the property ("host") that we're going to set on the global object.
            //

            JavaScriptPropertyId hostPropertyId = JavaScriptPropertyId.FromString("host");

            //
            // Set the property.
            //

            globalObject.SetProperty(hostPropertyId, hostObject, true);

            //
            // Now create the host callbacks that we're going to expose to the script.
            //

            DefineHostCallback(hostObject, "echo", echoDelegate, IntPtr.Zero);
            DefineHostCallback(hostObject, "runScript", runScriptDelegate, IntPtr.Zero);

            globalObject.SetProperty(JavaScriptPropertyId.FromString("global"), globalObject, true);
            DefineHostCallback(globalObject, "log", logDelegate, IntPtr.Zero);
            DefineHostCallback(globalObject, "watch", logDelegate, IntPtr.Zero);

            JavaScriptValue applicationObject = JavaScriptValue.CreateObject();

            globalObject.SetProperty(JavaScriptPropertyId.FromString("application"), applicationObject, true);
            //applicationObject.SetProperty(JavaScriptPropertyId.FromString("start"), JavaScriptValue.CreateFunction(Application.runDelegate, IntPtr.Zero), true);
            DefineHostCallback(applicationObject, "start", Application.runDelegate, IntPtr.Zero);
        }
예제 #26
0
        public void AddObject(JavaScriptValue parent, string name, object value)
        {
            // Convert to a JS property
            var jsValue = ToJavaScriptValue(value);

            // Set the property
            var childPropertyId = JavaScriptPropertyId.FromString(name);

            parent.SetProperty(childPropertyId, jsValue, true);
        }
예제 #27
0
        private void SetNativesObject(JavaScriptValue globalObject)
        {
            Native.JsCreateObject(out var processObject);
            Native.JsCreateObject(out var nativesObject);
            Native.JsCreateFunction(Bridge, IntPtr.Zero, out var functionValue);

            nativesObject.SetProperty(JavaScriptPropertyId.FromString("bridge"), functionValue, true);
            processObject.SetProperty(JavaScriptPropertyId.FromString("natives"), nativesObject, true);
            globalObject.SetProperty(JavaScriptPropertyId.FromString("process"), processObject, true);
        }
예제 #28
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue SpacePrototype;
            JavaScriptValue SpaceConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.Space),
                (args) => { throw new System.NotImplementedException(); },
                out SpacePrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("Space", SpaceConstructor);


            // Static Fields

            SpaceConstructor.SetProperty(
                "World",
                Bridge.CreateExternalWithPrototype(UnityEngine.Space.World)
                );


            SpaceConstructor.SetProperty(
                "Self",
                Bridge.CreateExternalWithPrototype(UnityEngine.Space.Self)
                );


            // Static Property Accessors


            // Static Methods


            // Instance Fields


            // Instance Property Accessors


            // Instance Methods
        }
        private void DefineHostCallback(JavaScriptValue globalObject, string callbackName, JavaScriptNativeFunction callback, IntPtr callbackData)
        {
            // Get property ID.
            JavaScriptPropertyId propertyId = JavaScriptPropertyId.FromString(callbackName);

            // Create a function
            JavaScriptValue function = JavaScriptValue.CreateFunction(callback, callbackData);

            // Set the property
            globalObject.SetProperty(propertyId, function, true);
        }
예제 #30
0
        private void DefineHostCallback(
            JavaScriptValue globalObject,
            string callbackName,
            JavaScriptNativeFunction callback,
            IntPtr callbackData)
        {
            var propertyId = JavaScriptPropertyId.FromString(callbackName);

            this.handles.Add(callback);
            var function = JavaScriptValue.CreateFunction(callback, callbackData);

            globalObject.SetProperty(propertyId, function, true);
        }