com.unity.netcode.gameobjects@1.3.1
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.3.1] - 2023-03-27 ### Added - Added detection and graceful handling of corrupt packets for additional safety. (#2419) ### Changed - The UTP component UI has been updated to be more user-friendly for new users by adding a simple toggle to switch between local-only (127.0.0.1) and remote (0.0.0.0) binding modes, using the toggle "Allow Remote Connections" (#2408) - Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.3. (#2450) - `NetworkShow()` of `NetworkObject`s are delayed until the end of the frame to ensure consistency of delta-driven variables like `NetworkList`. - Dirty `NetworkObject` are reset at end-of-frame and not at serialization time. - `NetworkHide()` of an object that was just `NetworkShow()`n produces a warning, as remote clients will _not_ get a spawn/despawn pair. - Renamed the NetworkTransform.SetState parameter `shouldGhostsInterpolate` to `teleportDisabled` for better clarity of what that parameter does. (#2228) - Network prefabs are now stored in a ScriptableObject that can be shared between NetworkManagers, and have been exposed for public access. By default, a Default Prefabs List is created that contains all NetworkObject prefabs in the project, and new NetworkManagers will default to using that unless that option is turned off in the Netcode for GameObjects settings. Existing NetworkManagers will maintain their existing lists, which can be migrated to the new format via a button in their inspector. (#2322) ### Fixed - Fixed issue where changes to a layer's weight would not synchronize unless a state transition was occurring.(#2399) - Fixed issue where `NetworkManager.LocalClientId` was returning the `NetworkTransport.ServerClientId` as opposed to the `NetworkManager.m_LocalClientId`. (#2398) - Fixed issue where a dynamically spawned `NetworkObject` parented under an in-scene placed `NetworkObject` would have its `InScenePlaced` value changed to `true`. This would result in a soft synchronization error for late joining clients. (#2396) - Fixed a UTP test that was failing when you install Unity Transport package 2.0.0 or newer. (#2347) - Fixed issue where `NetcodeSettingsProvider` would throw an exception in Unity 2020.3.x versions. (#2345) - Fixed server side issue where, depending upon component ordering, some NetworkBehaviour components might not have their OnNetworkDespawn method invoked if the client side disconnected. (#2323) - Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput. (#2332) - Fixed an issue in `UnityTransport` where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321) - Fixed `NetworkAnimator` issue where it was not checking for `AnimatorStateTtansition.destinationStateMachine` and any possible sub-states defined within it. (#2309) - Fixed `NetworkAnimator` issue where the host client was receiving the ClientRpc animation updates when the host was the owner.(#2309) - Fixed `NetworkAnimator` issue with using pooled objects and when specific properties are cleaned during despawn and destroy.(#2309) - Fixed issue where `NetworkAnimator` was checking for animation changes when the associated `NetworkObject` was not spawned.(#2309) - Corrected an issue with the documentation for BufferSerializer (#2401)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
internal class NetcodeForGameObjectsSettings
|
||||
internal class NetcodeForGameObjectsEditorSettings
|
||||
{
|
||||
internal const string AutoAddNetworkObjectIfNoneExists = "AutoAdd-NetworkObject-When-None-Exist";
|
||||
internal const string InstallMultiplayerToolsTipDismissedPlayerPrefKey = "Netcode_Tip_InstallMPTools_Dismissed";
|
||||
@@ -14,6 +15,7 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
return EditorPrefs.GetInt(InstallMultiplayerToolsTipDismissedPlayerPrefKey);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,6 +30,7 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
return EditorPrefs.GetBool(AutoAddNetworkObjectIfNoneExists);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,4 +39,15 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
EditorPrefs.SetBool(AutoAddNetworkObjectIfNoneExists, autoAddSetting);
|
||||
}
|
||||
}
|
||||
|
||||
[FilePath("ProjectSettings/NetcodeForGameObjects.settings", FilePathAttribute.Location.ProjectFolder)]
|
||||
internal class NetcodeForGameObjectsProjectSettings : ScriptableSingleton<NetcodeForGameObjectsProjectSettings>
|
||||
{
|
||||
[SerializeField] public bool GenerateDefaultNetworkPrefabs = true;
|
||||
|
||||
internal void SaveSettings()
|
||||
{
|
||||
Save(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
internal static class NetcodeSettingsProvider
|
||||
{
|
||||
private const float k_MaxLabelWidth = 450f;
|
||||
private static float s_MaxLabelWidth;
|
||||
private static bool s_ShowEditorSettingFields = true;
|
||||
private static bool s_ShowProjectSettingFields = true;
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateNetcodeSettingsProvider()
|
||||
{
|
||||
@@ -20,25 +25,105 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
return provider;
|
||||
}
|
||||
|
||||
internal static NetcodeSettingsLabel NetworkObjectsSectionLabel = new NetcodeSettingsLabel("NetworkObject Helper Settings", 20);
|
||||
internal static NetcodeSettingsToggle AutoAddNetworkObjectToggle = new NetcodeSettingsToggle("Auto-Add NetworkObjects", "When enabled, NetworkObjects are automatically added to GameObjects when NetworkBehaviours are added first.", 20);
|
||||
internal static NetcodeSettingsLabel MultiplayerToolsLabel = new NetcodeSettingsLabel("Multiplayer Tools", 20);
|
||||
internal static NetcodeSettingsToggle MultiplayerToolTipStatusToggle = new NetcodeSettingsToggle("Multiplayer Tools Install Reminder", "When enabled, the NetworkManager will display " +
|
||||
"the notification to install the multiplayer tools package.", 20);
|
||||
|
||||
internal static NetcodeSettingsLabel NetworkObjectsSectionLabel;
|
||||
internal static NetcodeSettingsToggle AutoAddNetworkObjectToggle;
|
||||
internal static NetcodeSettingsLabel MultiplayerToolsLabel;
|
||||
internal static NetcodeSettingsToggle MultiplayerToolTipStatusToggle;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the settings UI Elements if they don't already exist.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We have to construct any NetcodeGUISettings derived classes here because in
|
||||
/// version 2020.x.x EditorStyles.label does not exist yet (higher versions it does)
|
||||
/// </remarks>
|
||||
private static void CheckForInitialize()
|
||||
{
|
||||
if (NetworkObjectsSectionLabel == null)
|
||||
{
|
||||
NetworkObjectsSectionLabel = new NetcodeSettingsLabel("NetworkObject Helper Settings", 20);
|
||||
}
|
||||
|
||||
if (AutoAddNetworkObjectToggle == null)
|
||||
{
|
||||
AutoAddNetworkObjectToggle = new NetcodeSettingsToggle("Auto-Add NetworkObject Component", "When enabled, NetworkObject components are automatically added to GameObjects when NetworkBehaviour components are added first.", 20);
|
||||
}
|
||||
|
||||
if (MultiplayerToolsLabel == null)
|
||||
{
|
||||
MultiplayerToolsLabel = new NetcodeSettingsLabel("Multiplayer Tools", 20);
|
||||
}
|
||||
|
||||
if (MultiplayerToolTipStatusToggle == null)
|
||||
{
|
||||
MultiplayerToolTipStatusToggle = new NetcodeSettingsToggle("Multiplayer Tools Install Reminder", "When enabled, the NetworkManager will display the notification to install the multiplayer tools package.", 20);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnGuiHandler(string obj)
|
||||
{
|
||||
var autoAddNetworkObjectSetting = NetcodeForGameObjectsSettings.GetAutoAddNetworkObjectSetting();
|
||||
var multiplayerToolsTipStatus = NetcodeForGameObjectsSettings.GetNetcodeInstallMultiplayerToolTips() == 0;
|
||||
// Make sure all NetcodeGUISettings derived classes are instantiated first
|
||||
CheckForInitialize();
|
||||
|
||||
var autoAddNetworkObjectSetting = NetcodeForGameObjectsEditorSettings.GetAutoAddNetworkObjectSetting();
|
||||
var multiplayerToolsTipStatus = NetcodeForGameObjectsEditorSettings.GetNetcodeInstallMultiplayerToolTips() == 0;
|
||||
var settings = NetcodeForGameObjectsProjectSettings.instance;
|
||||
var generateDefaultPrefabs = settings.GenerateDefaultNetworkPrefabs;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
NetworkObjectsSectionLabel.DrawLabel();
|
||||
autoAddNetworkObjectSetting = AutoAddNetworkObjectToggle.DrawToggle(autoAddNetworkObjectSetting);
|
||||
MultiplayerToolsLabel.DrawLabel();
|
||||
multiplayerToolsTipStatus = MultiplayerToolTipStatusToggle.DrawToggle(multiplayerToolsTipStatus);
|
||||
|
||||
GUILayout.BeginVertical("Box");
|
||||
s_ShowEditorSettingFields = EditorGUILayout.BeginFoldoutHeaderGroup(s_ShowEditorSettingFields, "Editor Settings");
|
||||
|
||||
if (s_ShowEditorSettingFields)
|
||||
{
|
||||
GUILayout.BeginVertical("Box");
|
||||
NetworkObjectsSectionLabel.DrawLabel();
|
||||
autoAddNetworkObjectSetting = AutoAddNetworkObjectToggle.DrawToggle(autoAddNetworkObjectSetting);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical("Box");
|
||||
MultiplayerToolsLabel.DrawLabel();
|
||||
multiplayerToolsTipStatus = MultiplayerToolTipStatusToggle.DrawToggle(multiplayerToolsTipStatus);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical("Box");
|
||||
s_ShowProjectSettingFields = EditorGUILayout.BeginFoldoutHeaderGroup(s_ShowProjectSettingFields, "Project Settings");
|
||||
if (s_ShowProjectSettingFields)
|
||||
{
|
||||
GUILayout.BeginVertical("Box");
|
||||
const string generateNetworkPrefabsString = "Generate Default Network Prefabs List";
|
||||
|
||||
if (s_MaxLabelWidth == 0)
|
||||
{
|
||||
s_MaxLabelWidth = EditorStyles.label.CalcSize(new GUIContent(generateNetworkPrefabsString)).x;
|
||||
s_MaxLabelWidth = Mathf.Min(k_MaxLabelWidth, s_MaxLabelWidth);
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = s_MaxLabelWidth;
|
||||
|
||||
GUILayout.Label("Network Prefabs", EditorStyles.boldLabel);
|
||||
generateDefaultPrefabs = EditorGUILayout.Toggle(
|
||||
new GUIContent(
|
||||
generateNetworkPrefabsString,
|
||||
"When enabled, a default NetworkPrefabsList object will be added to your project and kept up " +
|
||||
"to date with all NetworkObject prefabs."),
|
||||
generateDefaultPrefabs,
|
||||
GUILayout.Width(s_MaxLabelWidth + 20));
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
GUILayout.EndVertical();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
NetcodeForGameObjectsSettings.SetAutoAddNetworkObjectSetting(autoAddNetworkObjectSetting);
|
||||
NetcodeForGameObjectsSettings.SetNetcodeInstallMultiplayerToolTips(multiplayerToolsTipStatus ? 0 : 1);
|
||||
NetcodeForGameObjectsEditorSettings.SetAutoAddNetworkObjectSetting(autoAddNetworkObjectSetting);
|
||||
NetcodeForGameObjectsEditorSettings.SetNetcodeInstallMultiplayerToolTips(multiplayerToolsTipStatus ? 0 : 1);
|
||||
settings.GenerateDefaultNetworkPrefabs = generateDefaultPrefabs;
|
||||
settings.SaveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +141,7 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
public NetcodeSettingsLabel(string labelText, float layoutOffset = 0.0f)
|
||||
{
|
||||
m_LabelContent = labelText;
|
||||
AdjustLableSize(labelText, layoutOffset);
|
||||
AdjustLabelSize(labelText, layoutOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +157,7 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
|
||||
public NetcodeSettingsToggle(string labelText, string toolTip, float layoutOffset)
|
||||
{
|
||||
AdjustLableSize(labelText, layoutOffset);
|
||||
AdjustLabelSize(labelText, layoutOffset);
|
||||
m_ToggleContent = new GUIContent(labelText, toolTip);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +169,7 @@ namespace Unity.Netcode.Editor.Configuration
|
||||
|
||||
protected GUILayoutOption m_LayoutWidth { get; private set; }
|
||||
|
||||
protected void AdjustLableSize(string labelText, float offset = 0.0f)
|
||||
protected void AdjustLabelSize(string labelText, float offset = 0.0f)
|
||||
{
|
||||
m_LabelSize = Mathf.Min(k_MaxLabelWidth, EditorStyles.label.CalcSize(new GUIContent(labelText)).x);
|
||||
m_LayoutWidth = GUILayout.Width(m_LabelSize + offset);
|
||||
|
||||
187
Editor/Configuration/NetworkPrefabProcessor.cs
Normal file
187
Editor/Configuration/NetworkPrefabProcessor.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the default <see cref="NetworkPrefabsList"/> instance when prefabs are updated (created, moved, deleted) in the project.
|
||||
/// </summary>
|
||||
public class NetworkPrefabProcessor : AssetPostprocessor
|
||||
{
|
||||
private static string s_DefaultNetworkPrefabsPath = "Assets/DefaultNetworkPrefabs.asset";
|
||||
public static string DefaultNetworkPrefabsPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return s_DefaultNetworkPrefabsPath;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
s_DefaultNetworkPrefabsPath = value;
|
||||
// Force a recache of the prefab list
|
||||
s_PrefabsList = null;
|
||||
}
|
||||
}
|
||||
private static NetworkPrefabsList s_PrefabsList;
|
||||
private static Dictionary<string, NetworkPrefab> s_PrefabsListPath = new Dictionary<string, NetworkPrefab>();
|
||||
|
||||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
{
|
||||
var settings = NetcodeForGameObjectsProjectSettings.instance;
|
||||
if (!settings.GenerateDefaultNetworkPrefabs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool ProcessImportedAssets(string[] importedAssets1)
|
||||
{
|
||||
var dirty = false;
|
||||
foreach (var assetPath in importedAssets1)
|
||||
{
|
||||
// We only care about GameObjects, skip everything else. Can't use the more targeted
|
||||
// OnPostProcessPrefabs since that's not called for moves or deletes
|
||||
if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(GameObject))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
if (go.TryGetComponent<NetworkObject>(out _))
|
||||
{
|
||||
// Make sure we are not duplicating an already existing entry
|
||||
if (s_PrefabsListPath.ContainsKey(assetPath))
|
||||
{
|
||||
// Is the imported asset different from the one we already have in the list?
|
||||
if (s_PrefabsListPath[assetPath].Prefab.GetHashCode() != go.GetHashCode())
|
||||
{
|
||||
// If so remove the one in the list and continue on to add the imported one
|
||||
s_PrefabsList.List.Remove(s_PrefabsListPath[assetPath]);
|
||||
}
|
||||
else // If they are identical, then just ignore the import
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
s_PrefabsList.List.Add(new NetworkPrefab { Prefab = go });
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
bool ProcessDeletedAssets(string[] strings)
|
||||
{
|
||||
var dirty = false;
|
||||
var deleted = new List<string>(strings);
|
||||
for (int i = s_PrefabsList.List.Count - 1; i >= 0 && deleted.Count > 0; --i)
|
||||
{
|
||||
GameObject prefab;
|
||||
try
|
||||
{
|
||||
prefab = s_PrefabsList.List[i].Prefab;
|
||||
}
|
||||
catch (MissingReferenceException)
|
||||
{
|
||||
s_PrefabsList.List.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
if (prefab == null)
|
||||
{
|
||||
s_PrefabsList.List.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
string noPath = AssetDatabase.GetAssetPath(prefab);
|
||||
for (int j = strings.Length - 1; j >= 0; --j)
|
||||
{
|
||||
if (noPath == strings[j])
|
||||
{
|
||||
s_PrefabsList.List.RemoveAt(i);
|
||||
deleted.RemoveAt(j);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
if (s_PrefabsList == null)
|
||||
{
|
||||
s_PrefabsList = GetOrCreateNetworkPrefabs(DefaultNetworkPrefabsPath, out var newList, true);
|
||||
// A new list already processed all existing assets, no need to double-process imports & deletes
|
||||
if (newList)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Clear our asset path to prefab table each time
|
||||
s_PrefabsListPath.Clear();
|
||||
|
||||
// Create our asst path to prefab table
|
||||
foreach (var prefabEntry in s_PrefabsList.List)
|
||||
{
|
||||
if (!s_PrefabsListPath.ContainsKey(AssetDatabase.GetAssetPath(prefabEntry.Prefab)))
|
||||
{
|
||||
s_PrefabsListPath.Add(AssetDatabase.GetAssetPath(prefabEntry.Prefab), prefabEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Process the imported and deleted assets
|
||||
var markDirty = ProcessImportedAssets(importedAssets);
|
||||
markDirty &= ProcessDeletedAssets(deletedAssets);
|
||||
|
||||
if (markDirty)
|
||||
{
|
||||
EditorUtility.SetDirty(s_PrefabsList);
|
||||
}
|
||||
}
|
||||
|
||||
internal static NetworkPrefabsList GetOrCreateNetworkPrefabs(string path, out bool isNew, bool addAll)
|
||||
{
|
||||
var defaultPrefabs = AssetDatabase.LoadAssetAtPath<NetworkPrefabsList>(path);
|
||||
if (defaultPrefabs == null)
|
||||
{
|
||||
isNew = true;
|
||||
defaultPrefabs = ScriptableObject.CreateInstance<NetworkPrefabsList>();
|
||||
defaultPrefabs.IsDefault = true;
|
||||
AssetDatabase.CreateAsset(defaultPrefabs, path);
|
||||
|
||||
if (addAll)
|
||||
{
|
||||
// This could be very expensive in large projects... maybe make it manually triggered via a menu?
|
||||
defaultPrefabs.List = FindAll();
|
||||
}
|
||||
EditorUtility.SetDirty(defaultPrefabs);
|
||||
AssetDatabase.SaveAssetIfDirty(defaultPrefabs);
|
||||
return defaultPrefabs;
|
||||
}
|
||||
|
||||
isNew = false;
|
||||
return defaultPrefabs;
|
||||
}
|
||||
|
||||
private static List<NetworkPrefab> FindAll()
|
||||
{
|
||||
var list = new List<NetworkPrefab>();
|
||||
|
||||
string[] guids = AssetDatabase.FindAssets("t:GameObject");
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||||
|
||||
if (go.TryGetComponent(out NetworkObject _))
|
||||
{
|
||||
list.Add(new NetworkPrefab { Prefab = go });
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Configuration/NetworkPrefabProcessor.cs.meta
Normal file
11
Editor/Configuration/NetworkPrefabProcessor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8b62a05d80cc444f9c74731c01b8e39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
Editor/Configuration/NetworkPrefabsEditor.cs
Normal file
97
Editor/Configuration/NetworkPrefabsEditor.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.Editor
|
||||
{
|
||||
[CustomEditor(typeof(NetworkPrefabsList), true)]
|
||||
[CanEditMultipleObjects]
|
||||
public class NetworkPrefabsEditor : UnityEditor.Editor
|
||||
{
|
||||
private ReorderableList m_NetworkPrefabsList;
|
||||
private SerializedProperty m_IsDefaultBool;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_IsDefaultBool = serializedObject.FindProperty(nameof(NetworkPrefabsList.IsDefault));
|
||||
m_NetworkPrefabsList = new ReorderableList(serializedObject, serializedObject.FindProperty("List"), true, true, true, true);
|
||||
m_NetworkPrefabsList.elementHeightCallback = index =>
|
||||
{
|
||||
var networkOverrideInt = 0;
|
||||
if (m_NetworkPrefabsList.count > 0)
|
||||
{
|
||||
var networkPrefab = m_NetworkPrefabsList.serializedProperty.GetArrayElementAtIndex(index);
|
||||
var networkOverrideProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.Override));
|
||||
networkOverrideInt = networkOverrideProp.enumValueIndex;
|
||||
}
|
||||
|
||||
return 8 + (networkOverrideInt == 0 ? EditorGUIUtility.singleLineHeight : (EditorGUIUtility.singleLineHeight * 2) + 5);
|
||||
};
|
||||
m_NetworkPrefabsList.drawElementCallback = (rect, index, isActive, isFocused) =>
|
||||
{
|
||||
rect.y += 5;
|
||||
|
||||
var networkPrefab = m_NetworkPrefabsList.serializedProperty.GetArrayElementAtIndex(index);
|
||||
var networkPrefabProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.Prefab));
|
||||
var networkSourceHashProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.SourceHashToOverride));
|
||||
var networkSourcePrefabProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.SourcePrefabToOverride));
|
||||
var networkTargetPrefabProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.OverridingTargetPrefab));
|
||||
var networkOverrideProp = networkPrefab.FindPropertyRelative(nameof(NetworkPrefab.Override));
|
||||
var networkOverrideInt = networkOverrideProp.enumValueIndex;
|
||||
var networkOverrideEnum = (NetworkPrefabOverride)networkOverrideInt;
|
||||
EditorGUI.LabelField(new Rect(rect.x + rect.width - 70, rect.y, 60, EditorGUIUtility.singleLineHeight), "Override");
|
||||
if (networkOverrideEnum == NetworkPrefabOverride.None)
|
||||
{
|
||||
if (EditorGUI.Toggle(new Rect(rect.x + rect.width - 15, rect.y, 10, EditorGUIUtility.singleLineHeight), false))
|
||||
{
|
||||
networkOverrideProp.enumValueIndex = (int)NetworkPrefabOverride.Prefab;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!EditorGUI.Toggle(new Rect(rect.x + rect.width - 15, rect.y, 10, EditorGUIUtility.singleLineHeight), true))
|
||||
{
|
||||
networkOverrideProp.enumValueIndex = 0;
|
||||
networkOverrideEnum = NetworkPrefabOverride.None;
|
||||
}
|
||||
}
|
||||
|
||||
if (networkOverrideEnum == NetworkPrefabOverride.None)
|
||||
{
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 80, EditorGUIUtility.singleLineHeight), networkPrefabProp, GUIContent.none);
|
||||
}
|
||||
else
|
||||
{
|
||||
networkOverrideProp.enumValueIndex = GUI.Toolbar(new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight), networkOverrideInt - 1, new[] { "Prefab", "Hash" }) + 1;
|
||||
|
||||
if (networkOverrideEnum == NetworkPrefabOverride.Prefab)
|
||||
{
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 110, rect.y, rect.width - 190, EditorGUIUtility.singleLineHeight), networkSourcePrefabProp, GUIContent.none);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 110, rect.y, rect.width - 190, EditorGUIUtility.singleLineHeight), networkSourceHashProp, GUIContent.none);
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight + 5;
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight), "Overriding Prefab");
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 110, rect.y, rect.width - 110, EditorGUIUtility.singleLineHeight), networkTargetPrefabProp, GUIContent.none);
|
||||
}
|
||||
};
|
||||
m_NetworkPrefabsList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "NetworkPrefabs");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
using (new EditorGUI.DisabledScope(true))
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_IsDefaultBool);
|
||||
}
|
||||
|
||||
m_NetworkPrefabsList.DoLayoutList();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Configuration/NetworkPrefabsEditor.cs.meta
Normal file
11
Editor/Configuration/NetworkPrefabsEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d6d0919fa8ff41c9b1d1241256f7364
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user