Ejemplo n.º 1
0
        public static long GetUniqueObjectId(Object unityObject, bool recursiveCall = false)
        {
            var id        = -1L;
            var siblingId = 0;

            if (unityObject == null)
            {
                return(id);
            }

            var go = unityObject as GameObject;

            if (go != null)
            {
                siblingId = go.transform.GetSiblingIndex();
                //unityObject = go.transform;
            }

            if (CSPrefabTools.IsInstance(unityObject))
            {
                var prefabAssetSource = CSPrefabTools.GetAssetSource(unityObject);
                if (prefabAssetSource != null)
                {
                    if (!recursiveCall)
                    {
                        id = GetUniqueObjectId(prefabAssetSource, true);
                        return(id + siblingId);
                    }

                    Debug.LogError(Maintainer.ConstructError("Couldn't reach asset source: " + unityObject.name), unityObject);
                }
            }

            if (AssetDatabase.Contains(unityObject))
            {
                id = GetUniqueObjectIdFromAssetObject(unityObject);
            }
            else
            {
                id = GetLocalIdentifierInFile(unityObject);
                if (id <= 0)
                {
                    id = unityObject.GetInstanceID();
                }
            }

            if (id <= 0)
            {
                id = siblingId;
            }

            if (id <= 0)
            {
                id = unityObject.name.GetHashCode();
            }

            return(id);
        }
Ejemplo n.º 2
0
        public static long GetUniqueObjectId(Object unityObject)
        {
            var id        = -1L;
            var siblingId = 0;

            if (unityObject == null)
            {
                return(id);
            }

            var go = unityObject as GameObject;

            if (go != null)
            {
                siblingId = go.transform.GetSiblingIndex();
                //unityObject = go.transform;
            }

            if (CSPrefabTools.IsInstance(unityObject))
            {
                var prefabAssetSource = CSPrefabTools.GetAssetSource(unityObject);
                if (prefabAssetSource != null)
                {
                    id = GetUniqueObjectId(prefabAssetSource);
                    return(id + siblingId);
                }
            }

            if (AssetDatabase.Contains(unityObject))
            {
                id = GetUniqueObjectIdFromAssetObject(unityObject);
            }
            else
            {
                id = GetLocalIdentifierInFile(unityObject);
                if (id <= 0)
                {
                    id = unityObject.GetInstanceID();
                }
            }

            if (id <= 0)
            {
                id = siblingId;
            }

            if (id <= 0)
            {
                id = unityObject.name.GetHashCode();
            }

            return(id);
        }
Ejemplo n.º 3
0
        public static void TraverseGameObjectComponents(ObjectTraverseInfo traverseInfo, ComponentTraverseCallback callback)
        {
            var components = traverseInfo.current.GetComponents <Component>();
            var checkingPrefabInstanceObject  = false;
            var checkingAddedToInstanceObject = false;

            if (traverseInfo.SkipCleanPrefabInstances)
            {
#if UNITY_2018_3_OR_NEWER
                checkingPrefabInstanceObject = traverseInfo.inPrefabInstance && !traverseInfo.inMissingPrefabInstance;
                if (checkingPrefabInstanceObject)
                {
                    checkingAddedToInstanceObject = PrefabUtility.IsAddedGameObjectOverride(traverseInfo.current);
                }
#else
                checkingPrefabInstanceObject = CSPrefabTools.IsInstance(traverseInfo.current);
#endif
            }

            var hasDirtyComponents = traverseInfo.dirtyComponents != null;

            var visibleIndex = -1;
            for (var i = 0; i < components.Length; i++)
            {
                var component = components[i];
                if (component == null || component.hideFlags == HideFlags.None || component.hideFlags == HideFlags.HideInHierarchy)
                {
                    visibleIndex++;
                }

                if (component == null)
                {
                    // to register missing script
                    callback(traverseInfo, null, visibleIndex);
                    continue;
                }

                // transforms are checked at the GameObject level
                if (component is Transform)
                {
                    continue;
                }

                if (!checkingPrefabInstanceObject)
                {
                    Stats.componentsTraversed++;
                    callback(traverseInfo, component, visibleIndex);
                }
                else
                {
                    var hasOverridenProperties = checkingAddedToInstanceObject;
                    if (!hasOverridenProperties && hasDirtyComponents)
                    {
                        if (Array.IndexOf(traverseInfo.dirtyComponents, component.GetInstanceID()) != -1)
                        {
                            hasOverridenProperties = true;
                        }
                    }

                    if (hasOverridenProperties)
                    {
                        Stats.componentsTraversed++;
                        callback(traverseInfo, component, visibleIndex);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static bool TraverseGameObjectTree(ObjectTraverseInfo traverseInfo, GameObjectTraverseCallback callback)
        {
            Stats.gameObjectsTraversed++;

            var prefabInstanceRoot = false;

            if (!traverseInfo.inPrefabInstance)
            {
                //Debug.Log("IsPartOfPrefabInstance " + PrefabUtility.IsPartOfPrefabInstance(componentOrGameObject));
                //Debug.Log(traverseInfo.current.name);
                traverseInfo.inPrefabInstance = CSPrefabTools.IsInstance(traverseInfo.current);
                if (traverseInfo.inPrefabInstance)
                {
                    if (!CSPrefabTools.IsMissingPrefabInstance(traverseInfo.current))
                    {
                        if (traverseInfo.SkipCleanPrefabInstances)
                        {
                            if (CSPrefabTools.IsWholeInstanceHasAnyOverrides(traverseInfo.current))
                            {
                                CSPrefabTools.GetOverridenObjectsFromWholePrefabInstance(traverseInfo.current, out traverseInfo.dirtyComponents);
                            }
                        }
                    }
                    else
                    {
                        traverseInfo.inMissingPrefabInstance = true;
                    }

                    prefabInstanceRoot = true;
                }
            }

            if (!callback.Invoke(traverseInfo))
            {
                return(false);
            }

            if (traverseInfo.skipCurrentTree)
            {
                if (prefabInstanceRoot)
                {
                    traverseInfo.dirtyComponents         = null;
                    traverseInfo.inPrefabInstance        = false;
                    traverseInfo.inMissingPrefabInstance = false;
                    traverseInfo.skipCurrentTree         = false;
                }

                return(true);
            }

            var transform     = traverseInfo.current.transform;
            var childrenCount = transform.childCount;

            for (var i = 0; i < childrenCount; i++)
            {
                var child = transform.GetChild(i);
                traverseInfo.current = child.gameObject;
                if (!TraverseGameObjectTree(traverseInfo, callback))
                {
                    return(false);
                }
            }

            if (prefabInstanceRoot)
            {
                traverseInfo.dirtyComponents         = null;
                traverseInfo.inPrefabInstance        = false;
                traverseInfo.inMissingPrefabInstance = false;
                traverseInfo.skipCurrentTree         = false;
            }

            return(true);
        }