Fixed nullRef on first OnValidate call

This commit is contained in:
Albin Corén 2018-04-10 18:26:52 +02:00
parent 11c6890da2
commit ac31f46089
2 changed files with 10 additions and 2 deletions

View File

@ -36,13 +36,13 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Development|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Development|AnyCPU'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\MLAPI-Examples\Assets\</OutputPath> <OutputPath>..\..\MLAPI-Examples\Assets\MLAPI\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<RunCodeAnalysis>false</RunCodeAnalysis> <RunCodeAnalysis>false</RunCodeAnalysis>
<DocumentationFile> <DocumentationFile>
</DocumentationFile> </DocumentationFile>

View File

@ -153,15 +153,20 @@ namespace MLAPI.MonoBehaviours.Core
private void OnValidate() private void OnValidate()
{ {
if (NetworkConfig == null)
return; //May occur when the component is added
if(NetworkConfig.EnableSceneSwitching && !NetworkConfig.RegisteredScenes.Contains(SceneManager.GetActiveScene().name)) if(NetworkConfig.EnableSceneSwitching && !NetworkConfig.RegisteredScenes.Contains(SceneManager.GetActiveScene().name))
{ {
Debug.LogWarning("MLAPI: The active scene is not registered as a networked scene. The MLAPI has added it"); Debug.LogWarning("MLAPI: The active scene is not registered as a networked scene. The MLAPI has added it");
NetworkConfig.RegisteredScenes.Add(SceneManager.GetActiveScene().name); NetworkConfig.RegisteredScenes.Add(SceneManager.GetActiveScene().name);
} }
if(!NetworkConfig.EnableSceneSwitching && NetworkConfig.HandleObjectSpawning) if(!NetworkConfig.EnableSceneSwitching && NetworkConfig.HandleObjectSpawning)
{ {
Debug.LogWarning("MLAPI: Please be aware that Scene objects are NOT supported if SceneManagement is turned on, even if HandleObjectSpawning is turned on"); Debug.LogWarning("MLAPI: Please be aware that Scene objects are NOT supported if SceneManagement is turned on, even if HandleObjectSpawning is turned on");
} }
if(NetworkConfig.HandleObjectSpawning) if(NetworkConfig.HandleObjectSpawning)
{ {
for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++) for (int i = 0; i < NetworkConfig.NetworkedPrefabs.Count; i++)
@ -173,6 +178,7 @@ namespace MLAPI.MonoBehaviours.Core
} }
} }
} }
if (NetworkConfig.HandleObjectSpawning) if (NetworkConfig.HandleObjectSpawning)
{ {
if(!string.IsNullOrEmpty(NetworkConfig.PlayerPrefabName)) if(!string.IsNullOrEmpty(NetworkConfig.PlayerPrefabName))
@ -198,7 +204,9 @@ namespace MLAPI.MonoBehaviours.Core
} }
if (!NetworkConfig.EnableEncryption) if (!NetworkConfig.EnableEncryption)
{
RegenerateRSAKeys = false; RegenerateRSAKeys = false;
}
else else
{ {
if(RegenerateRSAKeys) if(RegenerateRSAKeys)