Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix: fixed spam for broken unique name references
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonTheSourcerer committed Dec 15, 2020
1 parent 5c510d5 commit 7e709a2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Editor/UI/Drawers/UniqueNameReferenceDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Innoactive.Creator.Core.Configuration;
using Innoactive.Creator.Core.SceneObjects;
Expand All @@ -20,6 +21,8 @@ internal class UniqueNameReferenceDrawer : AbstractDrawer
private bool isUndoOperation;
private const string undoGroupName = "brotcat";

private readonly HashSet<string> missingUniqueNames = new HashSet<string>();

/// <inheritdoc />
public override Rect Draw(Rect rect, object currentValue, Action<object> changeValueCallback, GUIContent label)
{
Expand All @@ -37,6 +40,12 @@ public override Rect Draw(Rect rect, object currentValue, Action<object> changeV
string oldUniqueName = uniqueNameReference.UniqueName;
GameObject selectedSceneObject = GetGameObjectFromID(oldUniqueName, valueType);

if (selectedSceneObject == null && string.IsNullOrEmpty(oldUniqueName) == false && missingUniqueNames.Contains(oldUniqueName) == false)
{
missingUniqueNames.Add(oldUniqueName);
Debug.LogError($"The Training Scene Object with the unique name '{oldUniqueName}' cannot be found!");
}

CheckForMisconfigurationIssues(selectedSceneObject, valueType, ref rect, ref guiLineRect);
selectedSceneObject = EditorGUI.ObjectField(guiLineRect, label, selectedSceneObject, typeof(GameObject), true) as GameObject;

Expand Down Expand Up @@ -80,14 +89,7 @@ private GameObject GetGameObjectFromID(string objectUniqueName, Type valueType)
if (RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(objectUniqueName) == false)
{
// If the saved unique name is not registered in the scene, perhaps is actually a GameObject's InstanceID
GameObject gameObject = GetGameObjectFromInstanceID(objectUniqueName);

if (gameObject == null)
{
Debug.LogError($"{valueType.Name} with Unique Name \"{objectUniqueName}\" could not be found.");
}

return gameObject;
return GetGameObjectFromInstanceID(objectUniqueName);
}

ISceneObject sceneObject = RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByName(objectUniqueName);
Expand Down

0 comments on commit 7e709a2

Please sign in to comment.