Exemplo n.º 1
0
        private void RegisterScriptComponent(
            long instanceID, IDisposable scriptComponent, ScriptComponentProxy proxy
            )
        {
            ScriptComponentInfo componentInfo;

            componentInfo.Instance = scriptComponent;
            componentInfo.Proxy    = proxy;
            _scriptComponents.Add(instanceID, componentInfo);
        }
Exemplo n.º 2
0
        public bool CreateScriptComponent(
            string className, IntPtr nativeComponent, ref ScriptComponentProxy proxy
            )
        {
            ScriptComponentTypeInfo componentTypeInfo;

            if (FindScriptComponentTypeByName(className, out componentTypeInfo))
            {
                if (componentTypeInfo.Constructor != null)
                {
                    var instanceID = GenerateScriptObjectID();
                    // The handle created here is set not to release the native object when the
                    // handle is disposed because that object is actually the owner of the script
                    // object created here, and no additional references are created to owners at
                    // the moment so there is no reference to remove.
                    var objectHandle = new UObjectHandle(nativeComponent, false);
                    var component    = (IDisposable)componentTypeInfo.Constructor.Invoke(
                        new object[] { instanceID, objectHandle }
                        );
                    // initialize the script component proxy
                    proxy.InstanceID = instanceID;
                    foreach (var methodInfo in componentTypeInfo.Methods)
                    {
                        methodInfo.BindToProxy(
                            ref proxy,
                            Delegate.CreateDelegate(
                                methodInfo.DelegateType, component, methodInfo.Method
                                )
                            );
                    }
                    // keep anything that may be called from native code alive
                    RegisterScriptComponent(instanceID, component, proxy);
                    return(true);
                }
            }
            // TODO: log an error
            return(false);
        }
Exemplo n.º 3
0
 private void RegisterScriptComponent(
     long instanceID, IDisposable scriptComponent, ScriptComponentProxy proxy
 )
 {
     ScriptComponentInfo componentInfo;
     componentInfo.Instance = scriptComponent;
     componentInfo.Proxy = proxy;
     _scriptComponents.Add(instanceID, componentInfo);
 }
Exemplo n.º 4
0
 public bool CreateScriptComponent(
     string className, IntPtr nativeComponent, ref ScriptComponentProxy proxy
 )
 {
     ScriptComponentTypeInfo componentTypeInfo;
     if (FindScriptComponentTypeByName(className, out componentTypeInfo))
     {
         if (componentTypeInfo.Constructor != null)
         {
             var instanceID = GenerateScriptObjectID();
             // The handle created here is set not to release the native object when the
             // handle is disposed because that object is actually the owner of the script 
             // object created here, and no additional references are created to owners at
             // the moment so there is no reference to remove.
             var objectHandle = new UObjectHandle(nativeComponent, false);
             var component = (IDisposable)componentTypeInfo.Constructor.Invoke(
                 new object[] { instanceID, objectHandle }
             );
             // initialize the script component proxy
             proxy.InstanceID = instanceID;
             foreach (var methodInfo in componentTypeInfo.Methods)
             {
                 methodInfo.BindToProxy(
                     ref proxy,
                     Delegate.CreateDelegate(
                         methodInfo.DelegateType, component, methodInfo.Method
                     )
                 );
             }
             // keep anything that may be called from native code alive
             RegisterScriptComponent(instanceID, component, proxy);
             return true;
         }
     }
     // TODO: log an error
     return false;
 }