/// <summary> /// Resolve a cross-scene reference if possible. /// </summary> /// <returns>The cross-scene referenced object if it's possible</returns> private Object RuntimeResolve() { var scene = this.scene.scene; if (!scene.IsValid()) { return(null); } // Try to find the Object with our custom method that checks only the subscene GameObject gameObject = GameObjectEx.FindBySceneAndPath(scene, fullPath); // If that fails, we can try using Unity's GameObject.Find in case the user has switched it on us, or // in the case that's it's in a DontDestroyOnLoad scene if (!gameObject) { gameObject = GameObject.Find(fullPath); // It's truly failed if (!gameObject) { return(null); } else { AmsDebug.LogWarning(gameObject, "UniqueObject '{0}' resolved unexpected to '{1}'{2}. Did you move it manually?", this, gameObject.scene.name, gameObject.GetFullName()); } } if (string.IsNullOrEmpty(componentName)) { return(gameObject); } // This is the old method where we didn't store the component index (deprecated) if (version < 1) { Component oldStyleComponent = gameObject.GetComponent(componentName); if (componentIndex < 0 || oldStyleComponent) { return(oldStyleComponent); } } // Get the component and index System.Type type = System.Type.GetType(componentName, false); if (type != null) { gameObject.GetComponents(type, _reusableComponentsList); if (componentIndex < _reusableComponentsList.Count) { return(_reusableComponentsList[componentIndex]); } } return(null); }
/// <summary> /// Resolve a cross-scene reference if possible. /// </summary> /// <returns>The cross-scene referenced object if it's possible</returns> private Object RuntimeResolve() { var scene = this.scene.scene; if (!scene.IsValid()) { return(null); } // Try to find the Object GameObject gameObject = GameObjectEx.FindBySceneAndPath(scene, fullPath); if (!gameObject) { return(null); } if (string.IsNullOrEmpty(componentName)) { return(gameObject); } // This is the old method where we didn't store the component index (deprecated) if (version < 1) { Component oldStyleComponent = gameObject.GetComponent(componentName); if (componentIndex < 0 || oldStyleComponent) { return(oldStyleComponent); } } // Get the component and index System.Type type = System.Type.GetType(componentName, false, true); if (type != null) { gameObject.GetComponents(type, _reusableComponentsList); if (componentIndex < _reusableComponentsList.Count) { return(_reusableComponentsList[componentIndex]); } } return(null); }