Ejemplo n.º 1
0
        private void ReportMissingObjectRefs(
            GameObject rootObj,
            TestSession session)
        {
            rootObj = rootObj.transform.root.gameObject;
            _monoBehaviours.Clear();
            rootObj.GetComponentsInChildren(true, _monoBehaviours);

            _monoBehaviours.RemoveAll(ShouldIgnoreComponent);
            var rootObjScene = rootObj.scene;

            foreach (var monoBehaviour in _monoBehaviours)
            {
                _fieldsWithMissingValues.Clear();
                GetFieldsWithMissingValuesRecursive(monoBehaviour, "");
                var cmpPath = monoBehaviour.GetPath();
                foreach (var field in _fieldsWithMissingValues)
                {
                    session.ReportErr(
                        rootObjScene.IsValid()
                            ? $"Missing ObjRef:\n\tScene: {rootObjScene.path}\n\tGameObject: {cmpPath}\n\tComponent: {monoBehaviour.GetType()}\n\tField: {field.Path}"
                            : $"Missing ObjRef:\n\tGameObject: {cmpPath}\n\tComponent: {monoBehaviour.GetType()}\n\tField: {field.Path}",
                        monoBehaviour,
                        false);
                }
            }
        }
Ejemplo n.º 2
0
        public IEnumerator NoMissingObjectReferences_ScriptableObjects()
        {
            using (var session = new TestSession())
            {
                var paths = AssetDatabase.FindAssets("t:ScriptableObject")
                            .Select(AssetDatabase.GUIDToAssetPath);
                foreach (var path in paths)
                {
                    var obj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(path);
                    _fieldsWithMissingValues.Clear();
                    GetFieldsWithMissingValuesRecursive(obj, "");
                    foreach (var field in _fieldsWithMissingValues)
                    {
                        session.ReportErr(
                            $"Missing ObjRef:\n\tAsset: {path}\n\tField: {field.Path}",
                            obj,
                            false);
                    }

                    yield return(null);
                }

                yield return(Resources.UnloadUnusedAssets());
            }
        }
        public IEnumerator NoMissingScripts_Prefabs()
        {
            using (var session = new TestSession())
            {
                var paths = AssetDatabase.FindAssets("t:Prefab")
                            .Select(AssetDatabase.GUIDToAssetPath);
                foreach (var path in paths)
                {
                    var obj       = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    var hierarchy = obj.GetComponentsInChildren <Transform>(true).Select(t => t.gameObject).Distinct();
                    foreach (var gameObject in hierarchy)
                    {
                        var missingCount = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
                        if (missingCount > 0)
                        {
                            var assetPath = Path.GetDirectoryName(path).Replace('\\', '/');
                            var fullPath  = $"{assetPath}/{gameObject.transform.GetPath()}";
                            session.ReportErr($"Prefab: {fullPath}\nMissing: {missingCount}", obj, false);
                        }
                    }

                    yield return(null);
                }

                yield return(Resources.UnloadUnusedAssets());
            }
        }
        public IEnumerator NoMissingScripts_Scenes()
        {
            using (var session = new TestSession())
            {
                var paths = AssetDatabase.FindAssets("t:Scene")
                            .Select(AssetDatabase.GUIDToAssetPath);
                var rootGameObjects = new List <GameObject>();
                foreach (var path in paths)
                {
                    Debug.Log($"Loading scene: {path}");
                    EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
                    var scene = SceneManager.GetSceneByPath(path);
                    rootGameObjects.Clear();
                    scene.GetRootGameObjects(rootGameObjects);
                    foreach (var root in rootGameObjects)
                    {
                        var hierarchy = root.GetComponentsInChildren <Transform>(true)
                                        .Select(t => t.gameObject)
                                        .Distinct();
                        foreach (var gameObject in hierarchy)
                        {
                            var missingCount = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
                            if (missingCount > 0)
                            {
                                session.ReportErr(
                                    $"Scene: {scene.path}\nObject: {gameObject.transform.GetPath()}\nCount: {missingCount}");
                            }
                        }
                    }

                    EditorSceneManager.CloseScene(scene, true);
                    yield return(null);
                }

                yield return(Resources.UnloadUnusedAssets());
            }
        }