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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        public override string ToString()
        {
            string fromString = fromObject ? fromObject.ToString() : "(null)";
            string toString   = toInstance ? toInstance.ToString() : "(null)";

            var fromGameObject = GameObjectEx.EditorGetGameObjectFromComponent(fromObject);

            if (fromGameObject)
            {
                fromString = string.Format("{0} ({1})", fromGameObject.GetFullName(), fromObject.GetType());
            }

            var toGameObject = GameObjectEx.EditorGetGameObjectFromComponent(toInstance);

            if (toGameObject)
            {
                toString = string.Format("{0} ({1})", toGameObject.GetFullName(), toInstance.GetType());
            }

            return(string.Format("{0}.{1} => {2}", fromString, fromProperty.propertyPath, toString));
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Find the Scene of an object instance and use a cache to help look-ups.
		/// </summary>
		/// <param name="instance">The instance to look at</param>
		/// <param name="cache">The cache to populate</param>
		/// <returns>The scene instance belongs to</returns>
		private static Scene FindSceneCached( Object instance, Dictionary<Object, Scene> cache )
		{
			// Null SubScene
			if ( !instance )
				return new Scene();

			// Quick case, it's already cached...
			Scene scene = new Scene();
			if ( cache.TryGetValue(instance, out scene) )
				return scene;

			// Persistent objects are Assets
			if ( !EditorUtility.IsPersistent(instance) )
			{
                var gameObj = GameObjectEx.EditorGetGameObjectFromComponent( instance );
                if ( gameObj )
					scene = gameObj.scene;
			}

			cache.Add(instance, scene);
			return scene;
		}
        public UniqueObject(Object obj)
        {
#if USE_STRONG_EDITOR_REFS
            editorLocalId = 0;
#endif

            scene          = new AmsSceneReference();
            fullPath       = string.Empty;
            componentName  = string.Empty;
            version        = CurrentSerializedVersion;
            componentIndex = 0;

            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 USE_STRONG_EDITOR_REFS
            editorLocalId = GetEditorId(obj);
#endif
        }
        private Object  EditorResolveSlow()
        {
            var scene = this.scene.scene;

            if (!scene.IsValid())
            {
                return(null);
            }

            if (!scene.isLoaded)
            {
                return(null);
            }

            // Find the object (this is potentially very slow).
            Object[] allObjs = EditorUtility.CollectDeepHierarchy(scene.GetRootGameObjects());
            foreach (var obj in allObjs)
            {
                // Apparently this happens... bummer
                if (!obj)
                {
                    continue;
                }

                // If it's a prefab, it's a lot more difficult since Unity doesn't store IDs
                var prefabObj = PrefabUtility.GetPrefabObject(obj);
                if (prefabObj && editorLocalId == GetEditorId(prefabObj))
                {
                    GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj);
                    if (!gameObject)
                    {
                        Debug.LogWarningFormat(obj, "Could not SLOW resolve {0} (cross-scene reference is broken). Pointing it to {1}.", this, obj);
                        return(obj);
                    }

                    // Make sure we do this from the root
                    var prefabRoot = PrefabUtility.FindPrefabRoot(gameObject);
                    if (prefabRoot)
                    {
                        gameObject = prefabRoot;
                    }

                    // If we have a relative path, grab that GameObject
                    if (!string.IsNullOrEmpty(editorPrefabRelativePath))
                    {
                        Transform transform = gameObject.transform.Find(editorPrefabRelativePath);
                        if (transform)
                        {
                            gameObject = transform.gameObject;
                        }
                        else
                        {
                            Debug.LogWarningFormat(gameObject, "Tried to perform a slow resolve for {0} and found prefab {1}, but could not resolve the expected sub-path {2} which indicates the Prefab instance path was renamed.", this, gameObject, editorPrefabRelativePath);
                        }
                    }

                    Debug.LogWarningFormat(gameObject, "Performed a slow resolve on {0} due to a rename.  We found PREFAB with same ID named {1} (but we're not sure). Attempting a resolve with it.", this, gameObject);
                    fullPath = GameObjectEx.GetFullName(gameObject);
                    return(RuntimeResolve());
                }
                else if (editorLocalId == GetEditorId(obj))
                {
                    GameObject gameObject = GameObjectEx.EditorGetGameObjectFromComponent(obj);
                    Debug.LogWarningFormat(obj, "Performed a slow resolve on {0} and found {1} ({2}). Double-check this is correct.", this, gameObject ? gameObject.GetFullName() : "(Non-Existant GameObject)", obj.GetType());
                    return(obj);
                }
            }

            return(null);
        }