public UniqueObject(Object obj)
        {
            scene                    = new AmsSceneReference();
            fullPath                 = string.Empty;
            componentName            = string.Empty;
            version                  = CurrentSerializedVersion;
            componentIndex           = 0;
            editorLocalId            = 0;
            editorPrefabRelativePath = string.Empty;

            if (!obj)
            {
                return;
            }

            GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj);

            if (gameObject)
            {
                scene    = new AmsSceneReference(gameObject.scene);
                fullPath = gameObject.GetFullName();

                Component comp = obj as Component;
                if (comp)
                {
                    componentName = obj.GetType().AssemblyQualifiedName;
                    gameObject.GetComponents(obj.GetType(), _reusableComponentsList);
                    componentIndex = _reusableComponentsList.IndexOf(comp);
                }
            }

#if UNITY_2018_3_OR_NEWER
            // Get the nearest root (which will have an editor id)
            var prefabObj = PrefabUtility.GetPrefabInstanceHandle(obj);
            if (prefabObj)
            {
                editorLocalId = GetEditorId(prefabObj);

                var prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(obj);
                editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform);
            }
#else
            // Get the prefab object
            var prefabObj = PrefabUtility.GetPrefabObject(obj);
            if (prefabObj)
            {
                GameObject prefabRoot = PrefabUtility.FindPrefabRoot(gameObject);
                editorLocalId            = prefabRoot ? GetEditorId(prefabRoot) : GetEditorId(obj);
                editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform);
            }
#endif

            if (editorLocalId == 0)
            {
                editorLocalId = GetEditorId(obj);
            }
        }
Пример #2
0
        public UniqueObject(Object obj)
        {
            scene                    = new AmsSceneReference();
            fullPath                 = string.Empty;
            componentName            = string.Empty;
            version                  = CurrentSerializedVersion;
            componentIndex           = 0;
            editorLocalId            = 0;
            editorPrefabRelativePath = string.Empty;

            if (!obj)
            {
                return;
            }

            GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj);

            if (gameObject)
            {
                scene    = new AmsSceneReference(gameObject.scene);
                fullPath = gameObject.GetFullName();

                Component comp = obj as Component;
                if (comp)
                {
                    componentName = obj.GetType().AssemblyQualifiedName;
                    gameObject.GetComponents(obj.GetType(), _reusableComponentsList);
                    componentIndex = _reusableComponentsList.IndexOf(comp);
                }
            }

            // Get the prefab object
            var prefabObj = PrefabUtility.GetPrefabObject(obj);

            if (prefabObj)
            {
                GameObject prefabRoot = PrefabUtility.FindPrefabRoot(gameObject);
                editorLocalId            = prefabObj ? GetEditorId(prefabObj) : GetEditorId(obj);
                editorPrefabRelativePath = TransformEx.GetPathRelativeTo(gameObject.transform, prefabRoot.transform);
            }
        }