Beispiel #1
0
        public static List <RemovedComponent> GetRemovedComponents(GameObject prefabInstance)
        {
            ThrowExceptionIfNullOrNotPartOfPrefabInstance(prefabInstance);

            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);

            // From root of asset traverse all children and detect any Components that are not present on the instance object (these must be deleted)
            TransformVisitor transformVisitor = new TransformVisitor();
            var removedComponents             = new List <RemovedComponent>();

            if (PrefabUtility.IsDisconnectedFromPrefabAsset(prefabInstance))
            {
                return(removedComponents);
            }

            transformVisitor.VisitAll(prefabInstanceRoot.transform, CheckForRemovedComponents, removedComponents);
            return(removedComponents);
        }
Beispiel #2
0
        public static List <AddedComponent> GetAddedComponents(GameObject prefabInstance)
        {
            ThrowExceptionIfNullOrNotPartOfPrefabInstance(prefabInstance);

            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);

            // From root of instance traverse all child go and detect any components that are not part of that source prefab objects component list (these must be added)
            TransformVisitor transformVisitor = new TransformVisitor();
            var addedComponents = new List <AddedComponent>();

            if (PrefabUtility.IsDisconnectedFromPrefabAsset(prefabInstance))
            {
                return(addedComponents);
            }

            transformVisitor.VisitAll(prefabInstanceRoot.transform, CheckForAddedComponents, addedComponents);
            return(addedComponents);
        }
        public static List <AddedGameObject> GetAddedGameObjects(GameObject prefabInstance)
        {
            ThrowExceptionIfNullOrNotPartOfPrefabInstance(prefabInstance);

            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);

            // From root instance traverse all children and detect any GameObjects that are not a prefab gameobject (these must be added)
            TransformVisitor transformVisitor = new TransformVisitor();
            var addedGameObjects = new List <AddedGameObject>();

            transformVisitor.VisitAndConditionallyEnterChildren(
                prefabInstanceRoot.transform,
                CheckForAddedGameObjectAndIfSoAddItAndReturnFalse,
                new AddedGameObjectUserData()
            {
                addedGameObjects = addedGameObjects, contextGameObject = prefabInstanceRoot
            });
            return(addedGameObjects);
        }
        static Scene LoadOrCreatePreviewScene(string environmentEditingScenePath)
        {
            Scene previewScene;

            if (!string.IsNullOrEmpty(environmentEditingScenePath))
            {
                previewScene = EditorSceneManager.OpenPreviewScene(environmentEditingScenePath);
                var roots   = previewScene.GetRootGameObjects();
                var visitor = new TransformVisitor();
                foreach (var root in roots)
                {
                    visitor.VisitAll(root.transform, AppendEnvironmentName, null);
                }
            }
            else
            {
                previewScene = CreateDefaultPreviewScene();
            }

            return(previewScene);
        }
        public static List <ObjectOverride> GetObjectOverrides(GameObject prefabInstance, bool includeDefaultOverrides = false)
        {
            var prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(prefabInstance);

            // From root of instance traverse all child go and detect any GameObjects or components
            // that are not part of that source prefab objects component list (these must be added)
            TransformVisitor transformVisitor = new TransformVisitor();
            var modifiedObjects = new List <ObjectOverride>();

            System.Action <Transform, object> checkMethod;
            if (includeDefaultOverrides)
            {
                checkMethod = CheckForModifiedObjectsIncludingDefaultOverrides;
            }
            else
            {
                checkMethod = CheckForModifiedObjectsExcludingDefaultOverrides;
            }
            transformVisitor.VisitAll(prefabInstanceRoot.transform, checkMethod, modifiedObjects);
            return(modifiedObjects);
        }
        internal static GameObject FindFirstGameObjectThatMatchesFileID(Transform searchRoot, UInt64 fileID, bool generate)
        {
            GameObject result           = null;
            var        transformVisitor = new TransformVisitor();

            transformVisitor.VisitAndAllowEarlyOut(searchRoot,
                                                   (transform, userdata) =>
            {
                UInt64 id = generate ?
                            Unsupported.GetOrGenerateFileIDHint(transform.gameObject) :
                            GetPrefabOrVariantFileID(transform.gameObject);
                if (id == fileID)
                {
                    result = transform.gameObject;
                    return(false); // stop searching
                }
                return(true);      // continue searching
            }
                                                   , null);

            return(result);
        }