com.wallstop-studios.unity-helpers 2.0.0-rc70 → 2.0.0-rc71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/PrefabChecker.cs +95 -89
- package/package.json +1 -1
package/Editor/PrefabChecker.cs
CHANGED
|
@@ -63,27 +63,28 @@
|
|
|
63
63
|
private void OnGUI()
|
|
64
64
|
{
|
|
65
65
|
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
|
|
66
|
-
|
|
67
|
-
DrawConfigurationOptions();
|
|
68
|
-
|
|
69
|
-
EditorGUILayout.Space();
|
|
70
|
-
EditorGUILayout.LabelField("Target Folders", EditorStyles.boldLabel);
|
|
71
|
-
|
|
72
|
-
DrawAssetPaths();
|
|
73
|
-
|
|
74
|
-
if (GUILayout.Button("Add Folder"))
|
|
66
|
+
try
|
|
75
67
|
{
|
|
76
|
-
|
|
77
|
-
}
|
|
68
|
+
DrawConfigurationOptions();
|
|
78
69
|
|
|
79
|
-
|
|
70
|
+
EditorGUILayout.Space();
|
|
71
|
+
EditorGUILayout.LabelField("Target Folders", EditorStyles.boldLabel);
|
|
72
|
+
DrawAssetPaths();
|
|
73
|
+
if (GUILayout.Button("Add Folder"))
|
|
74
|
+
{
|
|
75
|
+
AddFolder();
|
|
76
|
+
}
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
EditorGUILayout.Space();
|
|
79
|
+
if (GUILayout.Button("Run Checks", GUILayout.Height(30)))
|
|
80
|
+
{
|
|
81
|
+
RunChecks();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally
|
|
82
85
|
{
|
|
83
|
-
|
|
86
|
+
EditorGUILayout.EndScrollView();
|
|
84
87
|
}
|
|
85
|
-
|
|
86
|
-
EditorGUILayout.EndScrollView();
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
private void DrawConfigurationOptions()
|
|
@@ -484,7 +485,7 @@
|
|
|
484
485
|
}
|
|
485
486
|
}
|
|
486
487
|
|
|
487
|
-
private GameObject FindOwnerOfMissingScript(
|
|
488
|
+
private static GameObject FindOwnerOfMissingScript(
|
|
488
489
|
GameObject prefabRoot,
|
|
489
490
|
List<MonoBehaviour> buffer
|
|
490
491
|
)
|
|
@@ -495,35 +496,30 @@
|
|
|
495
496
|
MonoBehaviour[] components = transform.GetComponents<MonoBehaviour>();
|
|
496
497
|
if (
|
|
497
498
|
components.Length
|
|
498
|
-
|
|
499
|
+
== buffer.Count(c => c != null && c.gameObject == transform.gameObject)
|
|
499
500
|
)
|
|
500
501
|
{
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
{
|
|
504
|
-
if (buffer.Contains(comp))
|
|
505
|
-
{
|
|
506
|
-
foundInNonNullBuffer = true;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
510
504
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
505
|
+
bool foundInNonNullBuffer = components.Any(buffer.Contains);
|
|
506
|
+
if (foundInNonNullBuffer)
|
|
507
|
+
{
|
|
508
|
+
return transform.gameObject;
|
|
509
|
+
}
|
|
515
510
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
511
|
+
if (components.Length != 0 || !buffer.Exists(c => c == null))
|
|
512
|
+
{
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
HashSet<GameObject> gameObjectsWithComponentsInBuffer = buffer
|
|
517
|
+
.Where(c => c != null)
|
|
518
|
+
.Select(c => c.gameObject)
|
|
519
|
+
.ToHashSet();
|
|
520
|
+
if (!gameObjectsWithComponentsInBuffer.Contains(transform.gameObject))
|
|
521
|
+
{
|
|
522
|
+
return transform.gameObject;
|
|
527
523
|
}
|
|
528
524
|
}
|
|
529
525
|
|
|
@@ -549,7 +545,7 @@
|
|
|
549
545
|
);
|
|
550
546
|
}
|
|
551
547
|
|
|
552
|
-
private int ValidateNoNullsInLists(Object component, GameObject context)
|
|
548
|
+
private static int ValidateNoNullsInLists(Object component, GameObject context)
|
|
553
549
|
{
|
|
554
550
|
int issueCount = 0;
|
|
555
551
|
Type componentType = component.GetType();
|
|
@@ -569,31 +565,39 @@
|
|
|
569
565
|
{
|
|
570
566
|
object fieldValue = field.GetValue(component);
|
|
571
567
|
|
|
572
|
-
if (fieldValue
|
|
568
|
+
if (fieldValue is not IEnumerable list)
|
|
573
569
|
{
|
|
574
570
|
continue;
|
|
575
571
|
}
|
|
576
572
|
|
|
577
|
-
|
|
573
|
+
int index = 0;
|
|
574
|
+
if (list is Object unityObject)
|
|
578
575
|
{
|
|
579
|
-
|
|
580
|
-
foreach (object element in list)
|
|
576
|
+
if (unityObject == null)
|
|
581
577
|
{
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
$"Field '{field.Name}' ({field.FieldType.Name}) on component '{componentType.Name}' has a null or missing element at index {index}."
|
|
586
|
-
);
|
|
587
|
-
issueCount++;
|
|
588
|
-
}
|
|
589
|
-
index++;
|
|
578
|
+
unityObject.LogError(
|
|
579
|
+
$"Field '{field.Name}' ({field.FieldType.Name}) on component '{componentType.Name}' has a null enumerable."
|
|
580
|
+
);
|
|
590
581
|
}
|
|
582
|
+
// Ignore all enumerable unity objects, they're spooky
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
foreach (object element in list)
|
|
586
|
+
{
|
|
587
|
+
if (element == null || (element is Object unityObj && !unityObj))
|
|
588
|
+
{
|
|
589
|
+
context.LogError(
|
|
590
|
+
$"Field '{field.Name}' ({field.FieldType.Name}) on component '{componentType.Name}' has a null or missing element at index {index}."
|
|
591
|
+
);
|
|
592
|
+
issueCount++;
|
|
593
|
+
}
|
|
594
|
+
index++;
|
|
591
595
|
}
|
|
592
596
|
}
|
|
593
597
|
return issueCount;
|
|
594
598
|
}
|
|
595
599
|
|
|
596
|
-
private int ValidateRequiredComponents(Component component, GameObject context)
|
|
600
|
+
private static int ValidateRequiredComponents(Component component, GameObject context)
|
|
597
601
|
{
|
|
598
602
|
int issueCount = 0;
|
|
599
603
|
Type componentType = component.GetType();
|
|
@@ -606,46 +610,48 @@
|
|
|
606
610
|
.ToList()
|
|
607
611
|
);
|
|
608
612
|
|
|
609
|
-
if (required.Count
|
|
613
|
+
if (required.Count <= 0)
|
|
614
|
+
{
|
|
615
|
+
return issueCount;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
foreach (RequireComponent requirement in required)
|
|
610
619
|
{
|
|
611
|
-
|
|
620
|
+
if (
|
|
621
|
+
requirement.m_Type0 != null
|
|
622
|
+
&& component.GetComponent(requirement.m_Type0) == null
|
|
623
|
+
)
|
|
612
624
|
{
|
|
613
|
-
|
|
614
|
-
requirement.m_Type0
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
requirement.m_Type1
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
requirement.m_Type2
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
{
|
|
638
|
-
context.LogError(
|
|
639
|
-
$"Component '{componentType.Name}' requires component '{requirement.m_Type2.Name}', but it is missing."
|
|
640
|
-
);
|
|
641
|
-
issueCount++;
|
|
642
|
-
}
|
|
625
|
+
context.LogError(
|
|
626
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type0.Name}', but it is missing."
|
|
627
|
+
);
|
|
628
|
+
issueCount++;
|
|
629
|
+
}
|
|
630
|
+
if (
|
|
631
|
+
requirement.m_Type1 != null
|
|
632
|
+
&& component.GetComponent(requirement.m_Type1) == null
|
|
633
|
+
)
|
|
634
|
+
{
|
|
635
|
+
context.LogError(
|
|
636
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type1.Name}', but it is missing."
|
|
637
|
+
);
|
|
638
|
+
issueCount++;
|
|
639
|
+
}
|
|
640
|
+
if (
|
|
641
|
+
requirement.m_Type2 != null
|
|
642
|
+
&& component.GetComponent(requirement.m_Type2) == null
|
|
643
|
+
)
|
|
644
|
+
{
|
|
645
|
+
context.LogError(
|
|
646
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type2.Name}', but it is missing."
|
|
647
|
+
);
|
|
648
|
+
issueCount++;
|
|
643
649
|
}
|
|
644
650
|
}
|
|
645
651
|
return issueCount;
|
|
646
652
|
}
|
|
647
653
|
|
|
648
|
-
private int ValidateEmptyStrings(Object component, GameObject context)
|
|
654
|
+
private static int ValidateEmptyStrings(Object component, GameObject context)
|
|
649
655
|
{
|
|
650
656
|
int issueCount = 0;
|
|
651
657
|
Type componentType = component.GetType();
|