示例#1
0
        public virtual bool TryGetValue(UObject worldContextObject, out T value)
        {
            IntPtr world = Native_UObject.GetWorld(worldContextObject.Address);

            if (worldTypeFlags == 0)
            {
                if (values.TryGetValue(world, out value))
                {
                    return(true);
                }
            }
            else if (world != IntPtr.Zero)
            {
                int worldType = (1 << (int)Native_UWorld.Get_WorldType(world));
                if ((worldTypeFlags & worldType) == worldType)
                {
                    if (values.TryGetValue(world, out value))
                    {
                        return(true);
                    }
                }
            }
            value = default(T);
            return(false);
        }
示例#2
0
        public static Coroutine StartCoroutine(object obj, IEnumerator coroutine,
                                               CoroutineGroup group, string tag = null, bool pool = Coroutine.PoolByDefault)
        {
            Coroutine result = null;

            UObject ownerObj = obj as UObject;

            if (ownerObj != null)
            {
                IntPtr world = Native_UObject.GetWorld(ownerObj.Address);
                Debug.Assert(world != IntPtr.Zero, "UObject coroutines must be objects with a UWorld reference (e.g. AActor) - " +
                             "this is so that the coroutine can be stopped when the world is destroyed.");
            }

            // Let the caller do this check

            /*if (!FThreading.IsInGameThread())
             * {
             *  FThreading.RunOnGameThread(delegate () { result = StartCoroutine(obj, coroutine, group, tag, pool); });
             *  return result;
             * }*/

            if (pool)
            {
                result = CoroutinePool.New(coroutine);
            }
            else
            {
                result = new Coroutine(coroutine);
            }
            result.Owner = obj;
            result.Group = group;
            result.mainCollectionIndex = coroutines.Count;
            result.Tag = tag;
            coroutines.Add(result);

            if (ownerObj != null)
            {
                List <Coroutine> collection;
                if (!coroutinesByObject.TryGetValue(ownerObj, out collection))
                {
                    coroutinesByObject.Add(ownerObj, collection = new List <Coroutine>());
                }
                result.objectsCollectionIndex = collection.Count;
                collection.Add(result);
            }

            if (!string.IsNullOrEmpty(tag))
            {
                List <Coroutine> collection;
                if (!coroutinesByTag.TryGetValue(tag, out collection))
                {
                    coroutinesByTag.Add(tag, collection = new List <Coroutine>());
                }
                result.tagsCollectionIndex = collection.Count;
                collection.Add(result);
            }

            return(result);
        }
示例#3
0
        private static Invoker StartInvoker(object obj, InvokerHandlerType handlerType, Delegate handler, InvokerType type,
                                            ulong value, ulong repeatValue, CoroutineGroup group = CoroutineGroup.Tick, bool pool = PoolByDefault)
        {
            IntPtr  world    = IntPtr.Zero;
            UObject ownerObj = obj as UObject;

            if (ownerObj != null)
            {
                world = Native_UObject.GetWorld(ownerObj.Address);
                Debug.Assert(world != IntPtr.Zero, "UObject invokers must be objects with a UWorld reference (e.g. AActor) - " +
                             "this is so that the invoker can be stopped when the world is destroyed.");
            }

            Invoker invoker = pool ? InvokerPool.GetObject() : new Invoker();

            invoker.OwnerWorld = world;
            invoker.Owner      = obj;
            invoker.SetHandler(handlerType, handler);
            switch (type)
            {
            case InvokerType.Delay:
                TimeSpan time       = TimeSpan.FromTicks((long)value);
                TimeSpan repeatTime = TimeSpan.FromTicks((long)repeatValue);
                if (repeatTime != default(TimeSpan))
                {
                    invoker.SetTime(time, repeatTime);
                }
                else
                {
                    invoker.SetTime(time);
                }
                break;

            case InvokerType.Ticks:
                if (repeatValue != default(ulong))
                {
                    invoker.SetTicks(value, repeatValue);
                }
                else
                {
                    invoker.SetTicks(value);
                }
                break;

            case InvokerType.Frames:
                if (repeatValue != default(ulong))
                {
                    invoker.SetFrames(value, repeatValue);
                }
                else
                {
                    invoker.SetFrames(value);
                }
                break;
            }
            invoker.SetGroup(group);
            invoker.Start();
            return(invoker);
        }
示例#4
0
        private IntPtr GetDefaultWorld()
        {
#if WITH_EDITORONLY_DATA
            FWorldContext worldContext = new FWorldContext(Native_UEditorEngine.GetPIEWorldContext(FGlobals.GEditor));
            return(worldContext.IsNull ? IntPtr.Zero : worldContext.CurrentWorld);
#else
            return(Native_UObject.GetWorld(FGlobals.GEngine));
#endif
        }
示例#5
0
        public override void OnBegin()
        {
            UObject ownerObj = Owner.Owner as UObject;

            if (ownerObj != null && ownerObj.Address != IntPtr.Zero)
            {
                worldAddress = Native_UObject.GetWorld(ownerObj.Address);
            }

            startTimeSeconds = WorldTimeHelper.GetTimeSecondsChecked(worldAddress);
            endTimeSeconds   = (float)(startTimeSeconds + Time.TotalSeconds);
        }
示例#6
0
 private static void OnPostWorldCleanup(IntPtr world, bool sessionEnded, bool cleanupResources)
 {
     foreach (KeyValuePair <UObject, List <Coroutine> > obj in coroutinesByObject)
     {
         if (obj.Key.Address != IntPtr.Zero)
         {
             IntPtr objWorld = Native_UObject.GetWorld(obj.Key.Address);
             if (objWorld == world)
             {
                 StopAllCoroutines(obj.Key);
             }
         }
         else
         {
             StopAllCoroutines(obj.Key);
         }
     }
 }
示例#7
0
        public virtual bool HasValue(UObject worldContextObject)
        {
            IntPtr world = Native_UObject.GetWorld(worldContextObject.Address);

            if (worldTypeFlags == 0)
            {
                return(values.ContainsKey(world));
            }
            else if (world != IntPtr.Zero)
            {
                int worldType = (1 << (int)Native_UWorld.Get_WorldType(world));
                if ((worldTypeFlags & worldType) == worldType)
                {
                    return(values.ContainsKey(world));
                }
            }
            return(false);
        }
示例#8
0
        public virtual bool Set(UObject worldContextObject, T value)
        {
            IntPtr world = Native_UObject.GetWorld(worldContextObject.Address);

            if (worldTypeFlags == 0)
            {
                values[world] = value;
                return(true);
            }
            else if (world != IntPtr.Zero)
            {
                int worldType = (1 << (int)Native_UWorld.Get_WorldType(world));
                if ((worldTypeFlags & worldType) == worldType)
                {
                    values[world] = value;
                    return(true);
                }
            }
            return(false);
        }
示例#9
0
        private static void OnPostWorldCleanup(IntPtr world, bool sessionEnded, bool cleanupResources)
        {
            List <UObject> objectsToRemove = new List <UObject>();

            foreach (KeyValuePair <UObject, List <Invoker> > obj in invokersByUObject)
            {
                if (obj.Key.Address != IntPtr.Zero)
                {
                    IntPtr objWorld = Native_UObject.GetWorld(obj.Key.Address);
                    if (objWorld == world)
                    {
                        objectsToRemove.Add(obj.Key);
                    }
                }
                else
                {
                    objectsToRemove.Add(obj.Key);
                }
            }
            foreach (UObject obj in objectsToRemove)
            {
                StopAllInvokers(obj, true);
            }
        }