Esempio n. 1
0
        private void CollisionDetected(RigidBody body1, RigidBody body2, Contact c, string callbackName)
        {
            if (!gameObjectMap.ContainsKey(body1) || !gameObjectMap.ContainsKey(body2))
            {
                return;
            }

            GameObject b1 = gameObjectMap[body1];
            GameObject b2 = gameObjectMap[body2];

            if (b1 == null || b2 == null)
            {
                return;
            }

            b1.SendMessage(callbackName, GetCollisionInfo(body1, body2, c), SendMessageOptions.DontRequireReceiver);
            b2.SendMessage(callbackName, GetCollisionInfo(body2, body1, c), SendMessageOptions.DontRequireReceiver);

            FrameSyncManager.UpdateCoroutines();
        }
Esempio n. 2
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

            ICommunicator communicator = null;

//            if (!PhotonNetwork.connected || !PhotonNetwork.inRoom) {
//                Debug.LogWarning("You are not connected to Photon. FrameSync will start in offline mode.");
//            } else {
//                communicator = new PhotonFrameSyncCommunicator(PhotonNetwork.networkingPeer);
//            }


//             if (NetMgr.Instance.srvConn.status == Connection.Status.None)
//             {
//                 Debug.LogWarning("You are not connected to Server. FrameSync will start in offline mode.");
//             }
//             else
//             {
//                 communicator = new RealSyncCommunicator();
//             }

            FrameSyncConfig activeConfig = ActiveConfig;

            lockstep = AbstractLockstep.NewInstance(
                lockedTimeStep.AsFloat(),
                communicator,
                PhysicsManager.instance,
                activeConfig.syncWindow,
                activeConfig.panicWindow,
                activeConfig.rollbackWindow,
                OnGameStarted,
                OnGamePaused,
                OnGameUnPaused,
                OnGameEnded,
                OnPlayerDisconnection,
                OnStepUpdate,
                GetLocalData,
                ProvideInputData
                );

            if (ReplayRecord.replayMode == ReplayMode.LOAD_REPLAY)
            {
                //               ReplayPicker.replayToLoad.Load();

                ReplayRecord replayRecord = ReplayRecord.replayToLoad;
                if (replayRecord == null)
                {
                    Debug.LogError("Replay Record can't be loaded");
                    gameObject.SetActive(false);
                    return;
                }
                else
                {
                    lockstep.ReplayRecord = replayRecord;
                }
            }

            if (activeConfig.showStats)
            {
                this.gameObject.AddComponent <FrameSyncStats>().Lockstep = lockstep;
            }

            scheduler = new CoroutineScheduler(lockstep);

            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                if (communicator == null)
                {
                    lockstep.AddPlayer(0, "Local_Player", true);
                }
                else
                {
                    //                    List<PhotonPlayer> players = new List<PhotonPlayer>(PhotonNetwork.playerList);
                    //                    players.Sort(UnityUtils.playerComparer);
                    //
                    //                    for (int index = 0, length = players.Count; index < length; index++) {
                    //                        PhotonPlayer p = players[index];
                    //                        lockstep.AddPlayer((byte) p.ID, p.NickName, p.IsLocal);
                    //                    }

//                     for (int i = 0; i < GameData.Instance.RoomPlayers.Count; i++)
//                     {
//                         KBEngine.Avatar player = GameData.Instance.RoomPlayers[i];
//                         lockstep.AddPlayer((byte)(i + 1), player.id.ToString(), player.isPlayer());
//                     }
                }
            }

            FrameSyncBehaviour[] behavioursArray = FindObjectsOfType <FrameSyncBehaviour>();
            for (int index = 0, length = behavioursArray.Length; index < length; index++)
            {
                generalBehaviours.Add(NewManagedBehavior(behavioursArray[index]));
            }

            initBehaviors();
            initGeneralBehaviors(generalBehaviours, false);

            PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody);

            startState = StartState.BEHAVIOR_INITIALIZED;
        }
Esempio n. 3
0
 /**
  * @brief Clean up references to be collected by gc.
  **/
 public static void CleanUp()
 {
     ResourcePool.CleanUpAll();
     StateTracker.CleanUp();
     instance = null;
 }