Exemplo 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);
        }
Exemplo 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);
        }