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.
@@ -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
- AddFolder();
77
- }
68
+ DrawConfigurationOptions();
78
69
 
79
- EditorGUILayout.Space();
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
- if (GUILayout.Button("Run Checks", GUILayout.Height(30)))
78
+ EditorGUILayout.Space();
79
+ if (GUILayout.Button("Run Checks", GUILayout.Height(30)))
80
+ {
81
+ RunChecks();
82
+ }
83
+ }
84
+ finally
82
85
  {
83
- RunChecks();
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
- != buffer.Count(c => c != null && c.gameObject == transform.gameObject)
499
+ == buffer.Count(c => c != null && c.gameObject == transform.gameObject)
499
500
  )
500
501
  {
501
- bool foundInNonNullBuffer = false;
502
- foreach (MonoBehaviour comp in components)
503
- {
504
- if (buffer.Contains(comp))
505
- {
506
- foundInNonNullBuffer = true;
507
- break;
508
- }
509
- }
502
+ continue;
503
+ }
510
504
 
511
- if (foundInNonNullBuffer)
512
- {
513
- return transform.gameObject;
514
- }
505
+ bool foundInNonNullBuffer = components.Any(buffer.Contains);
506
+ if (foundInNonNullBuffer)
507
+ {
508
+ return transform.gameObject;
509
+ }
515
510
 
516
- if (components.Length == 0 && buffer.Any(c => c == null))
517
- {
518
- IEnumerable<GameObject> gameObjectsWithComponentsInBufer = buffer
519
- .Where(c => c != null)
520
- .Select(c => c.gameObject)
521
- .Distinct();
522
- if (!gameObjectsWithComponentsInBufer.Contains(transform.gameObject))
523
- {
524
- return transform.gameObject;
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 == null)
568
+ if (fieldValue is not IEnumerable list)
573
569
  {
574
570
  continue;
575
571
  }
576
572
 
577
- if (fieldValue is IEnumerable list)
573
+ int index = 0;
574
+ if (list is Object unityObject)
578
575
  {
579
- int index = 0;
580
- foreach (object element in list)
576
+ if (list.GetType() != typeof(Transform) && unityObject == null)
581
577
  {
582
- if (element == null || (element is Object unityObj && !unityObj))
583
- {
584
- context.LogError(
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 > 0)
612
+ if (required.Count <= 0)
613
+ {
614
+ return issueCount;
615
+ }
616
+
617
+ foreach (RequireComponent requirement in required)
610
618
  {
611
- foreach (RequireComponent requirement in required)
619
+ if (
620
+ requirement.m_Type0 != null
621
+ && component.GetComponent(requirement.m_Type0) == null
622
+ )
612
623
  {
613
- if (
614
- requirement.m_Type0 != null
615
- && component.GetComponent(requirement.m_Type0) == null
616
- )
617
- {
618
- context.LogError(
619
- $"Component '{componentType.Name}' requires component '{requirement.m_Type0.Name}', but it is missing."
620
- );
621
- issueCount++;
622
- }
623
- if (
624
- requirement.m_Type1 != null
625
- && component.GetComponent(requirement.m_Type1) == null
626
- )
627
- {
628
- context.LogError(
629
- $"Component '{componentType.Name}' requires component '{requirement.m_Type1.Name}', but it is missing."
630
- );
631
- issueCount++;
632
- }
633
- if (
634
- requirement.m_Type2 != null
635
- && component.GetComponent(requirement.m_Type2) == null
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc70",
3
+ "version": "2.0.0-rc72",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},