コード例 #1
0
        private static ReferenceFile GetSceneReference(string scenePath, PropertyFilter filter,
                                                       bool containsEmpty = false)
        {
            var scene            = UnityApi.MakeSureSceneOpened(scenePath);
            var referenceObjects = scene.GetRootGameObjects()
                                   .SelectMany(go => UnityApi.GetAllComponentsInChildren(go)
                                               .Select(t => t.component == null
                        ? containsEmpty
                            ? ReferenceObject.EmptyComponent(
                                                           UnityApi.GetTransformPath(t.gameObject))
                            : null
                        : GetReferenceObject(t.component, filter, true))
                                               .Append(go == null
                        ? containsEmpty
                            ? ReferenceObject.EmptyGameObject
                            : null
                        : GetReferenceObject(go, filter, true))
                                               )
                                   .Where(refObj => refObj != null)
                                   .ToArray();

            return(referenceObjects.Length > 0
                ? new ReferenceFile {
                ReferenceFilePath = scenePath,
                ReferenceObjects = referenceObjects,
            }
                : null);
        }
コード例 #2
0
        private static ReferenceFile GetResourceReference(string path,
                                                          PropertyFilter filter, bool containsEmpty = false)
        {
            // AssetDatabase.LoadAllAssetsAtPath(path) can not find parent object
            var obj = AssetDatabase.LoadAssetAtPath <Object>(path);

            ReferenceObject[] referenceObjects = null;
            if (obj == null)
            {
                if (containsEmpty)
                {
                    referenceObjects = new[] { ReferenceObject.Empty };
                }
            }
            else if (obj is GameObject go)
            {
                referenceObjects = UnityApi.GetAllComponentsInChildren(go)
                                   .Select(t => t.component == null
                        ? containsEmpty
                            ? ReferenceObject.EmptyComponent(
                                               UnityApi.GetTransformPath(t.gameObject))
                            : null
                        : GetReferenceObject(t.component, filter))
                                   .Where(refObj => refObj != null)
                                   .ToArray();
            }
            else
            {
                referenceObjects = AssetDatabase.LoadAllAssetsAtPath(path)
                                   .Select(t => t == null
                        ? containsEmpty ? ReferenceObject.Empty : null
                        : GetReferenceObject(t, filter))
                                   .Where(refObj => refObj != null)
                                   .ToArray();
            }
            return(referenceObjects?.Length > 0
                ? new ReferenceFile {
                ReferenceFilePath = path,
                ReferenceObjects = referenceObjects,
            }
                : null);
        }