// Use this for initialization
        public void Init()
        {
            ChecksumExtractor.Init(this);

            Settings.ContinuousPhysics = SpeculativeContacts;

            world = new TrueSync.Physics2D.World(new TSVector2(Gravity.x, Gravity.y));
            ContactManager.physicsManager = this;

            world.BodyRemoved += OnRemovedRigidBody;
            world.ContactManager.BeginContact += CollisionEnter;
            world.ContactManager.StayContact  += CollisionStay;
            world.ContactManager.EndContact   += CollisionExit;

            gameObjectMap = new Dictionary <IBody, GameObject>();
            collisionInfo = new Dictionary <Physics2D.Body, Dictionary <Physics2D.Body, TSCollision2D> >();

            instance = this;
            AddRigidBodies();
        }
        // LOGIC

        public void Initialize(TrueSyncConfig i_Config = null)
        {
            TrueSyncConfig config = (i_Config != null) ? i_Config : (Resources.Load <TrueSyncConfig>(s_TrueSyncConfigResourcePath));

            // Load config.

            m_Config = config;

            if (config == null)
            {
                return;
            }

            m_LockedTimeStep = config.lockedTimeStep;

            // Init state tracker.

            StateTracker.Init(config.rollbackWindow);

            // Init time.

            m_TimeScaler = new TSTimeScaler();
            m_TimeScaler.Init();

            // Create physics world.

            IPhysicsManager worldManager = new Physics2DWorldManager();

            worldManager.Gravity             = new TSVector(config.gravity.x, config.gravity.y, 0);
            worldManager.SpeculativeContacts = config.speculativeContacts;
            worldManager.LockedTimeStep      = config.lockedTimeStep;

            worldManager.Init();

            // Create communicator.

            ICommunicator communicator = null;

            if (isOnline)
            {
                communicator = new PhotonTrueSyncCommunicator(PhotonNetwork.networkingPeer);
            }
            else
            {
                Debug.Log("You are not connected to Photon. TrueSync will start in offline mode.");
            }

            // Create lockstep.

            m_Lockstep = AbstractLockstep.NewInstance(m_LockedTimeStep, communicator, worldManager, m_Config.syncWindow, m_Config.panicWindow, m_Config.rollbackWindow, OnGameStarted, OnGamePaused, OnGameUnPaused, OnGameEnded, OnPlayerDisconnection, OnStepUpdate, GetLocalData);

            Debug.Log("Lockstep initialized (Sync: " + m_Config.syncWindow + ", Rollback: " + m_Config.rollbackWindow + ")");

            // Stats

            if (m_Config.showStats)
            {
                TrueSyncStats statsComponent = gameObject.AddComponent <TrueSyncStats>();
                statsComponent.Lockstep = m_Lockstep;
            }

            // Add player on lockestep.

            if (isOnline)
            {
                List <PhotonPlayer> photonPlayers = new List <PhotonPlayer>(PhotonNetwork.playerList);
                photonPlayers.Sort(UnityUtils.playerComparer);

                for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Count; ++photonPlayerIndex)
                {
                    PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex];
                    m_Lockstep.AddPlayer((byte)photonPlayer.ID, photonPlayer.NickName, photonPlayer.IsLocal);
                }
            }
            else
            {
                m_Lockstep.AddPlayer(0, "Local_Player", true);
            }

            // Fill behaviours per player dictionary.

            foreach (TSPlayer player in m_Lockstep.Players.Values)
            {
                List <TrueSyncManagedBehaviour> behaviours = new List <TrueSyncManagedBehaviour>();
                m_BehavioursPerPlayer.Add(player.ID, behaviours);
            }

            // Initialize Physics Manager.

            PhysicsManager.Initialize(worldManager);
            PhysicsManager.OnRemoveBody(OnRemovedRigidbody);
        }
        public static TSRaycastHit2D[] Raycast(TSVector2 i_Origin, TSVector2 i_Direction, FP i_Distance, int i_Mask)
        {
            Physics2DWorldManager physicsManager = (Physics2DWorldManager)PhysicsManager.Instance;

            return(physicsManager.Raycast(i_Origin, i_Direction, i_Distance, i_Mask));
        }