com.wallstop-studios.unity-helpers 2.0.0-rc70 → 2.0.0-rc72
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 +94 -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,38 @@
|
|
|
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 (list.GetType() != typeof(Transform) && 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
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
foreach (object element in list)
|
|
585
|
+
{
|
|
586
|
+
if (element == null || (element is Object unityObj && !unityObj))
|
|
587
|
+
{
|
|
588
|
+
context.LogError(
|
|
589
|
+
$"Field '{field.Name}' ({field.FieldType.Name}) on component '{componentType.Name}' has a null or missing element at index {index}."
|
|
590
|
+
);
|
|
591
|
+
issueCount++;
|
|
592
|
+
}
|
|
593
|
+
index++;
|
|
591
594
|
}
|
|
592
595
|
}
|
|
593
596
|
return issueCount;
|
|
594
597
|
}
|
|
595
598
|
|
|
596
|
-
private int ValidateRequiredComponents(Component component, GameObject context)
|
|
599
|
+
private static int ValidateRequiredComponents(Component component, GameObject context)
|
|
597
600
|
{
|
|
598
601
|
int issueCount = 0;
|
|
599
602
|
Type componentType = component.GetType();
|
|
@@ -606,46 +609,48 @@
|
|
|
606
609
|
.ToList()
|
|
607
610
|
);
|
|
608
611
|
|
|
609
|
-
if (required.Count
|
|
612
|
+
if (required.Count <= 0)
|
|
613
|
+
{
|
|
614
|
+
return issueCount;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
foreach (RequireComponent requirement in required)
|
|
610
618
|
{
|
|
611
|
-
|
|
619
|
+
if (
|
|
620
|
+
requirement.m_Type0 != null
|
|
621
|
+
&& component.GetComponent(requirement.m_Type0) == null
|
|
622
|
+
)
|
|
612
623
|
{
|
|
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
|
-
}
|
|
624
|
+
context.LogError(
|
|
625
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type0.Name}', but it is missing."
|
|
626
|
+
);
|
|
627
|
+
issueCount++;
|
|
628
|
+
}
|
|
629
|
+
if (
|
|
630
|
+
requirement.m_Type1 != null
|
|
631
|
+
&& component.GetComponent(requirement.m_Type1) == null
|
|
632
|
+
)
|
|
633
|
+
{
|
|
634
|
+
context.LogError(
|
|
635
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type1.Name}', but it is missing."
|
|
636
|
+
);
|
|
637
|
+
issueCount++;
|
|
638
|
+
}
|
|
639
|
+
if (
|
|
640
|
+
requirement.m_Type2 != null
|
|
641
|
+
&& component.GetComponent(requirement.m_Type2) == null
|
|
642
|
+
)
|
|
643
|
+
{
|
|
644
|
+
context.LogError(
|
|
645
|
+
$"Component '{componentType.Name}' requires component '{requirement.m_Type2.Name}', but it is missing."
|
|
646
|
+
);
|
|
647
|
+
issueCount++;
|
|
643
648
|
}
|
|
644
649
|
}
|
|
645
650
|
return issueCount;
|
|
646
651
|
}
|
|
647
652
|
|
|
648
|
-
private int ValidateEmptyStrings(Object component, GameObject context)
|
|
653
|
+
private static int ValidateEmptyStrings(Object component, GameObject context)
|
|
649
654
|
{
|
|
650
655
|
int issueCount = 0;
|
|
651
656
|
Type componentType = component.GetType();
|