Exemplo n.º 1
0
        public bool CreateScriptObject(string className, IntPtr nativeObject, ref ScriptObjectInstanceInfo info)
        {
            var objType = FindScriptObjectTypeByName(className);

            if (objType != null)
            {
                var constructor = objType.GetConstructor(new Type[] { typeof(long), typeof(UObjectHandle) });
                if (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(nativeObject, false);
                    var obj          = (IScriptObject)constructor.Invoke(
                        new object[] { instanceID, objectHandle }
                        );
                    var objInfo = RegisterScriptObject(obj);
                    info.InstanceID = instanceID;
                    info.BeginPlay  = objInfo.BeginPlay;
                    info.Tick       = objInfo.Tick;
                    info.Destroy    = objInfo.Destroy;
                    return(true);
                }
            }
            // TODO: log an error
            return(false);
        }
Exemplo n.º 2
0
 public bool CreateScriptObject(string className, IntPtr nativeObject, ref ScriptObjectInstanceInfo info)
 {
     var objType = FindScriptObjectTypeByName(className);
     if (objType != null)
     {
         var constructor = objType.GetConstructor(new Type[] { typeof(long), typeof(UObjectHandle) });
         if (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(nativeObject, false);
             var obj = (IScriptObject)constructor.Invoke(
                 new object[] { instanceID, objectHandle }
             );
             var objInfo = RegisterScriptObject(obj);
             info.InstanceID = instanceID;
             info.BeginPlay = objInfo.BeginPlay;
             info.Tick = objInfo.Tick;
             info.Destroy = objInfo.Destroy;
             return true;
         }
     }
     // TODO: log an error
     return false;
 }