Exemplo n.º 1
0
        private void CollisionDetected(RigidBody body1, RigidBody body2, Contact c, string callbackName)
        {
            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);

            TrueSyncManager.UpdateCoroutines();
        }
        void OnDestroy()
        {
            ResourcePool.CleanUpAll();

            // Release StateTracker.

            StateTracker.CleanUp();

            // Release physics world.

            PhysicsManager.Cleanup();

            // Release self-reference.

            m_Instance = null;
        }
        void Awake()
        {
            instance = this;
            var currentConfig = ActiveConfig;

            StateTracker.Init(currentConfig.rollbackWindow);
            TSRandom.Init();

            if (currentConfig.physics2DEnabled || currentConfig.physics3DEnabled)
            {
                PhysicsManager.New(currentConfig);
                PhysicsManager.instance.LockedTimeStep = currentConfig.lockedTimeStep;
                PhysicsManager.instance.Init();
            }

            StateTracker.AddTracking(this, "time");
        }
        private void CollisionDetected(Physics2D.Body body1, Physics2D.Body body2, TrueSync.Physics2D.Contact contact, 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, contact), SendMessageOptions.DontRequireReceiver);
            b2.SendMessage(callbackName, GetCollisionInfo(body2, body1, contact), SendMessageOptions.DontRequireReceiver);

            TrueSyncManager.UpdateCoroutines();
        }
Exemplo n.º 5
0
 /**
  * @brief Clean up references to be collected by gc.
  **/
 public static void CleanUp()
 {
     ResourcePool.CleanUpAll();
     StateTracker.CleanUp();
     instance = null;
 }
Exemplo n.º 6
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

            ICommunicator communicator = null;

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

            TrueSyncConfig activeConfig = ActiveConfig;

            lockstep = AbstractLockstep.NewInstance(
                lockedTimeStep,
                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 <TrueSyncStats>().Lockstep = lockstep;
            }

            scheduler = new CoroutineScheduler(lockstep);

            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                lockstep.AddPlayer(0, "Local_Player", true);
                //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);
                //    }
                //}
            }

            TrueSyncBehaviour[] behavioursArray = FindObjectsOfType <TrueSyncBehaviour>();
            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;
        }
Exemplo n.º 7
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

            ICommunicator communicator = null;
            //初始化通信
            //if (!PhotonNetwork.connected || !PhotonNetwork.inRoom) {
            //    Debug.LogWarning("You are not connected to Photon. TrueSync will start in offline mode.");
            //} else {
            //    communicator = new PhotonTrueSyncCommunicator(PhotonNetwork.networkingPeer);
            //}

            TrueSyncConfig activeConfig = ActiveConfig;

            //创建lockstep
            lockstep = AbstractLockstep.NewInstance(
                lockedTimeStep.AsFloat(),
                communicator,
                PhysicsManager.instance,
                activeConfig.syncWindow,
                activeConfig.panicWindow,
                activeConfig.rollbackWindow,
                OnGameStarted,
                OnGamePaused,
                OnGameUnPaused,
                OnGameEnded,
                OnPlayerDisconnection,
                OnStepUpdate,
                ProvideInputData
                );
            //==========================================================================
            mFrameData = new FrameData();
            mLockStep  = gameObject.AddComponent <LockStep>();
            gameObject.AddComponent <GameProcessManager_Dota>();
            gameObject.AddComponent <MyTimerDriver>();

            PB_MatchTeamFight_FMS2GS2C mMatchTeamFight = (PB_MatchTeamFight_FMS2GS2C)NetData.Instance.Query(MsgID.S2CMatch, (uint)MatchMsgID.Fms2Gs2CMatchFight);

            FRS2C_Host  = mMatchTeamFight.Frs2Chost;
            FRS2C_Port  = mMatchTeamFight.Frs2Cport;
            guanqia     = mMatchTeamFight.Guanqia;
            teamid      = mMatchTeamFight.Teamid;
            fightroomid = mMatchTeamFight.Fightroomid;
            randomseed  = mMatchTeamFight.Seed;
            fps         = mMatchTeamFight.Fps;
            foreach (PB_FightPlayerInfo mFightPlayerInfo in mMatchTeamFight.Playersdata)
            {
                GameObject actorobj;
                Actor      actor;
                if (mFightPlayerInfo.ChooseHero == 1)
                {
                    actorobj = _AssetManager.GetGameObject("prefab/hero/yase/yase_prefab");
                    actor    = actorobj.GetComponent <PlayerActor_yase>();
                }
                else
                {
                    actorobj = _AssetManager.GetGameObject("prefab/hero/houyi/houyi_prefab");
                    actor    = actorobj.GetComponent <PlayerActor_houyi>();
                }
                //actor.ownerIndex =(int) mFightPlayerInfo.Playeridx;
                if (mFightPlayerInfo.Pid == NetData.Instance.PlayerID)
                {
                    actor.IsETCControl = true;
                    playeridx          = mFightPlayerInfo.Playeridx;
                    hellokey           = mFightPlayerInfo.Hellokey;
                    //actor.localOwner = new TSPlayerInfo((byte)mFightPlayerInfo.Pid, mFightPlayerInfo.Name);
                }
                else
                {
                    actor.IsETCControl = false;
                    //actor.owner = new TSPlayerInfo((byte)mFightPlayerInfo.Pid, mFightPlayerInfo.Name);
                }
                if (mActorParent == null)
                {
                    mActorParent = GameObject.Find("ActorParent").transform;
                }
                actor.transform.parent = mActorParent;
                //actor.Position = new CustomVector3(0, 0, 0);
                actor.Speed            = (FP)0.1f;
                actor.mActorAttr.HpMax = (FP)100;
                actor.mActorAttr.Hp    = (FP)50;
                actor.mActorAttr.Name  = mFightPlayerInfo.Name;
                actor.RotateTSTransform.LookAt(TSVector.left);
                actor.AllTSTransform.LookAt(TSVector.left);
                actor.Angle   = new TSVector();
                actor.OwnerID = mFightPlayerInfo.Playeridx;
                if (actor.OwnerID % 2 == 0)                //临时的阵营分配规则
                {
                    actor.OwnerCamp = GameCamp.BLUE;
                }
                else
                {
                    actor.OwnerCamp = GameCamp.RED;
                }
                AddPlayerActor(actor.OwnerID, actor);
            }
            OnBattleStart();
            //==========================================================================
            //检测是否是录像模式, 如果是就加载录像
            //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;
            //    }
            //}

            //如果配置了显示TrueSyncStats,那就初始化
            if (activeConfig.showStats)
            {
                this.gameObject.AddComponent <TrueSyncStats>().Lockstep = lockstep;
            }

            //创建协程调度
            scheduler = new CoroutineScheduler(lockstep);

            //非录像模式下 初始化帧的玩家列表
            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                lockstep.AddPlayer(0, "Local_Player", true);
                //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);
                //    }
                //}
            }

            //初始化场景中现有的帧同步行为
            TrueSyncBehaviour[] behavioursArray = FindObjectsOfType <TrueSyncBehaviour>();
            for (int index = 0, length = behavioursArray.Length; index < length; index++)
            {
                generalBehaviours.Add(NewManagedBehavior(behavioursArray[index]));
            }

            //实例化玩家预设playerPrefabs和同步其行为的拥有者
            initBehaviors();
            //初始化行为拥有者,并分配给对于玩家。没有继承TrueSyncBehaviour的就继续放到普通行为列表
            initGeneralBehaviors(generalBehaviours, false);

            //添加物理对象移除监听
            PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody);

            //设置启动状态
            startState = StartState.BEHAVIOR_INITIALIZED;
        }
Exemplo n.º 8
0
 /// <summary>
 ///@brief Clean up references to be collected by gc.
 ///DV 清除GC所收集的引用
 /// </summary>
 public static void CleanUp()
 {
     ResourcePool.CleanUpAll(); // 清理对象池
     StateTracker.CleanUp();    // 清理状态跟踪
     instance = null;           // 去除实例变量引用
 }
Exemplo n.º 9
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

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

            ICommunicator communicator = null;

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

            TrueSyncConfig activeConfig = ActiveConfig;

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

            if (activeConfig.showStats)
            {
                this.gameObject.AddComponent <TrueSyncStats>().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);

                    foreach (PhotonPlayer p in players)
                    {
                        lockstep.AddPlayer((byte)p.ID, p.NickName, p.IsLocal);
                    }
                }
            }

            generalBehaviours = new List <TrueSyncManagedBehaviour>();
            foreach (TrueSyncBehaviour tsb in FindObjectsOfType <TrueSyncBehaviour>())
            {
                generalBehaviours.Add(NewManagedBehavior(tsb));
            }

            initBehaviors();
            initGeneralBehaviors(generalBehaviours, false);

            PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody);

            startState = StartState.BEHAVIOR_INITIALIZED;
        }
        // MonoBehaviour's interface

        void Awake()
        {
            m_Instance       = this;
            m_NullPlayerInfo = new TSPlayerInfo(0, "");
        }
Exemplo n.º 11
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;
            }

            TSCollision collision = null;
            HashList <TrueSyncBehaviour> b1Behaviours = behavioursMap[body1];

            collision = GetCollisionInfo(body1, body2, c);
            for (int i = 0, count = b1Behaviours.Count; i < count; i++)
            {
                if (String.Equals(callbackName, "OnSyncedCollisionEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionEnter(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionStay(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionExit(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerEnter(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerStay(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerExit(collision);
                }
            }

            HashList <TrueSyncBehaviour> b2Behaviours = behavioursMap[body2];

            collision = GetCollisionInfo(body2, body1, c);
            for (int i = 0, count = b2Behaviours.Count; i < count; i++)
            {
                if (String.Equals(callbackName, "OnSyncedCollisionEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionEnter(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionStay(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionExit(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerEnter(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerStay(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerExit(collision);
                }
            }

            TrueSyncManager.UpdateCoroutines();
        }
Exemplo n.º 12
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

            //离线状态 就AbstractLockstep的OnEventDataReceived接收网络数据不会执行
            //更换网络接口 可以从ICommunicator接口 入手
            ICommunicator communicator = null;

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

            TrueSyncConfig 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 <TrueSyncStats>().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); //更新players activePlayers
                    }
                }
            }

            //搜寻场景预先挂载的TrueSyncBehaviour脚本,为它生成TrueSyncManagedBehaviour脚本
            //可能这部分脚本有些属于玩家 有些属于公共部分,都根据OwnerIndex来区分
            TrueSyncBehaviour[] behavioursArray = FindObjectsOfType <TrueSyncBehaviour>();
            for (int index = 0, length = behavioursArray.Length; index < length; index++)
            {
                generalBehaviours.Add(NewManagedBehavior(behavioursArray[index]));//一个TrueSyncBehaviour对应TrueSyncManagedBehaviour
            }

            initBehaviors();                                //初始化玩家prefab和挂在prefab上的TrueSyncBehaviour
            initGeneralBehaviors(generalBehaviours, false); //公用和玩家的区分,公用分给generalBehaviours,玩家分给behaviorsByPlayer

            PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody);

            startState = StartState.BEHAVIOR_INITIALIZED;//初始化完毕状态
        }