Exemplo n.º 1
0
        /**
         * @brief Instantiates a new prefab in a deterministic way.
         *
         * @param prefab GameObject's prefab to instantiate.
         * @param position Position to place the new GameObject.
         * @param rotation Rotation to set in the new GameObject.
         **/
        public static GameObject SyncedInstantiate(GameObject prefab, TSVector position, TSQuaternion rotation)
        {
            if (instance != null && instance.lockstep != null)
            {
                GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;

                if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
                {
                    AddGameObjectOnSafeMap(go);
                }

                MonoBehaviour[] monoBehaviours = go.GetComponentsInChildren <MonoBehaviour>();
                for (int index = 0, length = monoBehaviours.Length; index < length; index++)
                {
                    MonoBehaviour bh = monoBehaviours[index];

                    if (bh is ITrueSyncBehaviour)
                    {
                        instance.queuedBehaviours.Add(instance.NewManagedBehavior((ITrueSyncBehaviour)bh));
                    }
                }

                InitializeGameObject(go, position, rotation);

                return(go);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///@brief Instantiates a new prefab in a deterministic way.
        ///
        ///@param prefab GameObject's prefab to instantiate.
        ///@param position Position to place the new GameObject.
        ///@param rotation Rotation to set in the new GameObject.
        /// </summary>
        public static GameObject SyncedInstantiate(GameObject prefab, TSVector position, TSQuaternion rotation)
        {
            if (instance != null && instance.lockstep != null)
            {
                //先实例化一个GameObject
                GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;

                if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
                {
                    //非录像模式将该对象添加到帧记录里。AddGameObjectOnSafeMap(go);
                    AddGameObjectOnSafeMap(go);
                }

                MonoBehaviour[] monoBehaviours = go.GetComponentsInChildren <MonoBehaviour>();
                for (int index = 0, length = monoBehaviours.Length; index < length; index++)
                {
                    MonoBehaviour bh = monoBehaviours[index];

                    if (bh is ITrueSyncBehaviour)
                    {
                        //将该对象的帧行为添加到queuedBehaviours,等待帧更新的时候分配拥有者和调度初始化方法
                        instance.queuedBehaviours.Add(instance.NewManagedBehavior((ITrueSyncBehaviour)bh));
                    }
                }

                //该对象上组件的初始化方法(ICollider注册到物理管理器里PhysicsManager, TSTransform, TSTransform2D)。
                InitializeGameObject(go, position, rotation);

                return(go);
            }

            return(null);
        }
Exemplo n.º 3
0
        /**
         * @brief Instantiates a new prefab in a deterministic way.
         *
         * @param prefab GameObject's prefab to instantiate.
         * @param position Position to place the new GameObject.
         * @param rotation Rotation to set in the new GameObject.
         **/
        public static GameObject SyncedInstantiate(GameObject prefab, TSVector position, TSQuaternion rotation)
        {
            if (instance != null && instance.lockstep != null && (prefab.GetComponentInChildren <TSTransform>() != null || prefab.GetComponentInChildren <TSTransform2D>() != null))
            {
                GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;

                foreach (MonoBehaviour bh in go.GetComponentsInChildren <MonoBehaviour>())
                {
                    if (bh is ITrueSyncBehaviour)
                    {
                        instance.queuedBehaviours.Add(instance.NewManagedBehavior((ITrueSyncBehaviour)bh));
                    }
                }

                InitializeGameObject(go, position, rotation);

                return(go);
            }

            return(null);
        }
        protected override Vector3 GetGizmosSize()
        {
            TSVector size3 = new TSVector(size.x, size.y, 1);

            return(size3.ToVector());
        }