|
11 | 11 |
|
12 | 12 | #if UNITY_EDITOR |
13 | 13 | using UnityEditor; |
14 | | -#if UNITY_2021_2_OR_NEWER |
15 | 14 | using UnityEditor.SceneManagement; |
16 | | -#else |
17 | | -using UnityEditor.Experimental.SceneManagement; |
18 | | -#endif |
19 | 15 | #endif |
20 | 16 | using UnityEngine; |
21 | 17 | using UnityEngine.SceneManagement; |
@@ -2691,12 +2687,6 @@ internal void InvokeBehaviourNetworkPreSpawn() |
2691 | 2687 | { |
2692 | 2688 | childBehaviour.NetworkPreSpawn(ref networkManager, this); |
2693 | 2689 | } |
2694 | | - |
2695 | | -#if UNIFIED_NETCODE |
2696 | | - InitializeComponentMarkers(NetworkManager); |
2697 | | -#endif |
2698 | | - |
2699 | | - |
2700 | 2690 | } |
2701 | 2691 |
|
2702 | 2692 | internal void InvokeBehaviourNetworkSpawn() |
@@ -2827,34 +2817,13 @@ internal bool InitializeChildNetworkBehaviours() |
2827 | 2817 | networkTransform.IsNested = networkTransform.gameObject != gameObject; |
2828 | 2818 | NetworkTransforms.Add(networkTransform); |
2829 | 2819 | } |
2830 | | - |
2831 | | -#if UNIFIED_NETCODE |
2832 | | - // For now, we will just destroy these components during runtime since they will not |
2833 | | - // be supported in hybrid mode (don't add to the children). |
2834 | | - if (HasGhost) |
2835 | | - { |
2836 | | - continue; |
2837 | | - } |
2838 | | -#endif |
2839 | | - |
2840 | 2820 | #if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D |
2841 | | - |
2842 | 2821 | var rigidbodyBase = behaviour as NetworkRigidbodyBase; |
2843 | 2822 | if (rigidbodyBase != null) |
2844 | 2823 | { |
2845 | 2824 | NetworkRigidbodies.Add(behaviour as NetworkRigidbodyBase); |
2846 | 2825 | } |
2847 | | -#if UNIFIED_NETCODE |
2848 | | - // For now, we will just destroy these components during runtime since they will not |
2849 | | - // be supported in hybrid mode (don't add to the children). |
2850 | | - if (HasGhost) |
2851 | | - { |
2852 | | - continue; |
2853 | | - } |
2854 | 2826 | #endif |
2855 | | - |
2856 | | -#endif |
2857 | | - |
2858 | 2827 | } |
2859 | 2828 | #if UNIFIED_NETCODE |
2860 | 2829 | // For now, cycle through all known NetworkTransform and NetworkRigidbodyBase derived components |
@@ -2886,138 +2855,10 @@ internal bool InitializeChildNetworkBehaviours() |
2886 | 2855 | NetworkTransforms.Clear(); |
2887 | 2856 | } |
2888 | 2857 | } |
2889 | | -#endif |
| 2858 | +#endif |
2890 | 2859 | return true; |
2891 | 2860 | } |
2892 | 2861 |
|
2893 | | -#if UNIFIED_NETCODE |
2894 | | - private void InitializeComponentMarkers(NetworkManager networkManager) |
2895 | | - { |
2896 | | - // TODO: Determine if this would be useful |
2897 | | - //var networkBehaviours = GetComponentsInChildren<NetworkBehaviour>(true); |
2898 | | - //foreach(var networkBehaviour in networkBehaviours) |
2899 | | - //{ |
2900 | | - //} |
2901 | | - |
2902 | | - |
2903 | | - var networkPrefab = GetPrefab(networkManager); |
2904 | | - // Most likely an in-scene placed NetworkObject that is not a registered prefab |
2905 | | - if (networkPrefab == null) |
2906 | | - { |
2907 | | - return; |
2908 | | - } |
2909 | | - |
2910 | | - var rigidbodies = GetComponentsInChildren<Rigidbody>(); |
2911 | | - var prefabRigidbodies = networkPrefab.Prefab.GetComponentsInChildren<Rigidbody>(); |
2912 | | - |
2913 | | - if (rigidbodies.Length != prefabRigidbodies.Length) |
2914 | | - { |
2915 | | - Debug.LogError($"[InitializeComponentTable][{name}][{GlobalObjectIdHash}] Rigidbody mismatch between prefab and prefab instance ({rigidbodies.Length} vs {prefabRigidbodies.Length}!"); |
2916 | | - return; |
2917 | | - } |
2918 | | - |
2919 | | - var hasAuthority = !NetworkManager.DistributedAuthorityMode ? NetworkManager.IsServer : IsOwner; |
2920 | | - |
2921 | | - var networkTransforms = GetComponentsInChildren<NetworkTransform>(); |
2922 | | - |
2923 | | - if (!hasAuthority && !NetworkManager.DistributedAuthorityMode && networkTransforms != null && networkTransforms.Length > 0) |
2924 | | - { |
2925 | | - foreach (var networkTransform in networkTransforms) |
2926 | | - { |
2927 | | - var shouldHaveAuthority = networkTransform.AuthorityMode == NetworkTransform.AuthorityModes.Owner && NetworkManager.LocalClientId == OwnerClientId; |
2928 | | - if (hasAuthority != shouldHaveAuthority) |
2929 | | - { |
2930 | | - hasAuthority = shouldHaveAuthority; |
2931 | | - break; |
2932 | | - } |
2933 | | - } |
2934 | | - } |
2935 | | - |
2936 | | - if (hasAuthority) |
2937 | | - { |
2938 | | - return; |
2939 | | - } |
2940 | | - |
2941 | | - // Remove NetworkRigidbody components first. |
2942 | | - if (NetworkRigidbodies != null && !NetworkManager.DistributedAuthorityMode) |
2943 | | - { |
2944 | | - for (int i = NetworkRigidbodies.Count - 1; i >= 0; i--) |
2945 | | - { |
2946 | | - ChildNetworkBehaviours.Remove(NetworkRigidbodies[i].NetworkBehaviourId); |
2947 | | - Destroy(NetworkRigidbodies[i]); |
2948 | | - } |
2949 | | - NetworkRigidbodies.Clear(); |
2950 | | - // Unregister any registered NetworkRigidbody components |
2951 | | - if (NetworkTransforms != null) |
2952 | | - { |
2953 | | - foreach (var networkTransform in NetworkTransforms) |
2954 | | - { |
2955 | | - networkTransform.UnregisterRigidbody(); |
2956 | | - } |
2957 | | - } |
2958 | | - } |
2959 | | - |
2960 | | - /// Mark all rigid bodies with the component marker. |
2961 | | - /// This provides us with an automated way to remove or add rigid bodies |
2962 | | - /// while preserving their state via <see cref="ComponentHelpers"/>. |
2963 | | - for (int i = 0; i < rigidbodies.Length; i++) |
2964 | | - { |
2965 | | - var rigidbody = rigidbodies[i]; |
2966 | | - var prefabRigidbody = prefabRigidbodies[i]; |
2967 | | - |
2968 | | - var componentMarker = rigidbody.gameObject.AddComponent<ComponentMarker>(); |
2969 | | - componentMarker.Initialize(networkManager, rigidbody, prefabRigidbody); |
2970 | | - // If we are in client-server and not the server |
2971 | | - if (!hasAuthority) |
2972 | | - { |
2973 | | - // Remove the rigid body. |
2974 | | - componentMarker.Remove<Rigidbody>(); |
2975 | | - componentMarker.Remove<Rigidbody2D>(); |
2976 | | - } |
2977 | | - } |
2978 | | - } |
2979 | | - |
2980 | | - public void UpdateComponentStatus<T>(bool shouldAdd) where T : Component |
2981 | | - { |
2982 | | - if (!IsSpawned) |
2983 | | - { |
2984 | | - return; |
2985 | | - } |
2986 | | - |
2987 | | - var gameObjectsTable = ComponentMarker.RegisteredMarkers[NetworkManager]; |
2988 | | - foreach (var gameObjectTable in gameObjectsTable) |
2989 | | - { |
2990 | | - foreach (var componentMarker in gameObjectTable.Value) |
2991 | | - { |
2992 | | - if (shouldAdd) |
2993 | | - { |
2994 | | - componentMarker.Add<T>(); |
2995 | | - } |
2996 | | - else |
2997 | | - { |
2998 | | - componentMarker.Remove<T>(); |
2999 | | - } |
3000 | | - } |
3001 | | - } |
3002 | | - } |
3003 | | - |
3004 | | - /// <summary> |
3005 | | - /// POC Version of this. |
3006 | | - /// Currently does not take overrides into consideration. |
3007 | | - /// We could auto-register each instance's source prefab. |
3008 | | - /// </summary> |
3009 | | - /// <param name="networkManager"></param> |
3010 | | - /// <returns></returns> |
3011 | | - private NetworkPrefab GetPrefab(NetworkManager networkManager) |
3012 | | - { |
3013 | | - if (networkManager && networkManager.NetworkConfig.Prefabs.PrefabTable.ContainsKey(GlobalObjectIdHash)) |
3014 | | - { |
3015 | | - return networkManager.NetworkConfig.Prefabs.PrefabTable[GlobalObjectIdHash]; |
3016 | | - } |
3017 | | - return null; |
3018 | | - } |
3019 | | -#endif |
3020 | | - |
3021 | 2862 | /// <summary> |
3022 | 2863 | /// Used when changing ownership, this will mark any owner read permission base NetworkVariables as dirty |
3023 | 2864 | /// and will check if any owner write permission NetworkVariables are dirty (primarily for collections) so |
|
0 commit comments