コード例 #1
0
ファイル: FTimerManager.cs プロジェクト: yimengfan/USharp
        public static FTimerManager GetManager(IntPtr address)
        {
            if (address == IntPtr.Zero)
            {
                return(null);
            }

            TimerManagerInfo timerManagerInfo;

            if (timerManagers.TryGetValue(address, out timerManagerInfo))
            {
                return(timerManagerInfo.TimeManager);
            }

            UpdateOwnerClasses();

            IntPtr owner = IntPtr.Zero;

            if (owner == IntPtr.Zero && worldClass != IntPtr.Zero)
            {
                foreach (IntPtr world in new NativeReflection.NativeObjectIterator(worldClass))
                {
                    IntPtr timerManager = Native_UWorld.GetTimerManager(world);
                    if (timerManager == address)
                    {
                        IntPtr gameInstance = Native_UWorld.GetGameInstance(world);
                        if (gameInstance != IntPtr.Zero && Native_UGameInstance.GetTimerManager(gameInstance) == address)
                        {
                            owner = gameInstance;
                            break;
                        }
                        else
                        {
                            owner = world;
                            break;
                        }
                    }
                }
            }

            if (owner == IntPtr.Zero && gameInstanceClass != IntPtr.Zero)
            {
                foreach (IntPtr gameInstance in new NativeReflection.NativeObjectIterator(gameInstanceClass))
                {
                    if (Native_UGameInstance.GetTimerManager(gameInstance) == address)
                    {
                        owner = gameInstance;
                        break;
                    }
                }
            }

            if (owner == IntPtr.Zero && editorEngineClass != IntPtr.Zero)
            {
                foreach (IntPtr editorEngine in new NativeReflection.NativeObjectIterator(editorEngineClass))
                {
                    if (Native_UEditorEngine.GetTimerManager(editorEngine) == address)
                    {
                        owner = editorEngine;
                        break;
                    }
                }
            }

            if (owner != IntPtr.Zero)
            {
                FWeakObjectPtr ownerWeakObjPtr = new FWeakObjectPtr();
                ownerWeakObjPtr.Set(owner);
                timerManagerInfo             = new TimerManagerInfo();
                timerManagerInfo.Owner       = ownerWeakObjPtr;
                timerManagerInfo.TimeManager = new FTimerManager(address);

                timerManagers.Add(address, timerManagerInfo);
                timerManagerOwners[ownerWeakObjPtr] = address;

                return(timerManagerInfo.TimeManager);
            }
            else
            {
                return(new FTimerManager(address));
            }
        }