示例#1
0
    void Awake()
    {
        if (sceneManagerExists)
        {
            Debug.Log("PhysX Scene Manager already exists");
            Destroy(gameObject);
            return;
        }

        IntPtr unalignedMem = Marshal.AllocHGlobal(scratchKilobytes * 1024 + 15);

        scratchMem = new IntPtr(16 * ((unalignedMem.ToInt64() + 15) / 16));

        sceneManagerExists = true;

        GetComponent <PhysicsToggle>().Setup();

        PhysXLib.SetupPhysX();
        PhysXLib.RegisterCollisionCallback(AddCollision);
        PhysXLib.RegisterTriggerCallback(AddTrigger);
        DontDestroyOnLoad(gameObject);
        SceneManager.sceneLoaded   += OnSceneLoaded;
        SceneManager.sceneUnloaded += OnSceneUnloaded;
        PhysXSceneSimulator.AddScene(this);
    }
示例#2
0
    private bool EditPhysics(ref PlayerLoopSystem loopSystem, bool doPhysics)
    {
        if (loopSystem.type == typeof(FixedUpdate.PhysicsFixedUpdate))
        {
            if (physicsFunction == IntPtr.Zero)
            {
                physicsFunction = loopSystem.updateFunction;
            }

            if (doPhysics)
            {
                loopSystem.updateFunction = physicsFunction;
                loopSystem.updateDelegate = null;
            }
            else
            {
                loopSystem.updateFunction = IntPtr.Zero;
                loopSystem.updateDelegate = () => {
                    PhysXSceneSimulator.Simulate();
                };
            }

            return(true);
        }
        else
        {
            if (loopSystem.subSystemList != null)
            {
                for (int i = 0; i < loopSystem.subSystemList.Length; i++)
                {
                    if (EditPhysics(ref loopSystem.subSystemList[i], doPhysics))
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }