Class SceneReferenceResolver
The scene reference resolver.
Inheritance
Implements
Inherited Members
Namespace: Bayat.Core
Assembly: Bayat.Core.Runtime.dll
Syntax
[AddComponentMenu("Bayat/Core/Scene Reference Resolver")]
[DisallowMultipleComponent]
public class SceneReferenceResolver : MonoBehaviour, ISerializationCallbackReceiver
Fields
| Improve this Doc View Sourceguids
Declaration
[HideInInspector]
[SerializeField]
protected List<string> guids
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
guidToReference
Declaration
[SerializeField]
protected GuidToReferenceDictionary guidToReference
Field Value
Type | Description |
---|---|
GuidToReferenceDictionary |
invalidGameObjectTags
Declaration
[SerializeField]
protected string[] invalidGameObjectTags
Field Value
Type | Description |
---|---|
System.String[] |
referenceResolvers
Declaration
protected static Dictionary<Scene, SceneReferenceResolver> referenceResolvers
Field Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<UnityEngine.SceneManagement.Scene, SceneReferenceResolver> |
referenceToGuid
Declaration
protected ReferenceToGuidDictionary referenceToGuid
Field Value
Type | Description |
---|---|
Bayat.Core.Utilities.ReferenceToGuidDictionary |
sceneDependencies
Declaration
[HideInInspector]
[SerializeField]
protected List<Object> sceneDependencies
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Object> |
Properties
| Improve this Doc View SourceCurrent
Gets the current scene reference resolver.
Declaration
public static SceneReferenceResolver Current { get; }
Property Value
Type | Description |
---|---|
SceneReferenceResolver |
Guids
Gets the GUIDs list.
Declaration
[Obsolete("This property will be removed in future releases, use GuidToReference or ReferenceToGuid instead.", false)]
public virtual List<string> Guids { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
GuidToReference
Declaration
public virtual GuidToReferenceDictionary GuidToReference { get; set; }
Property Value
Type | Description |
---|---|
GuidToReferenceDictionary |
ReferenceResolvers
A dictionary of all the available Scene Reference Resolvers based on the Scene they are managing.
Declaration
public static Dictionary<Scene, SceneReferenceResolver> ReferenceResolvers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<UnityEngine.SceneManagement.Scene, SceneReferenceResolver> |
Remarks
Use GetReferenceResolver(Scene) to get the appropriate reference resolver for a scene, it works on both Editor and Play mode but this property does not.
ReferenceToGuid
Declaration
public virtual ReferenceToGuidDictionary ReferenceToGuid { get; set; }
Property Value
Type | Description |
---|---|
Bayat.Core.Utilities.ReferenceToGuidDictionary |
SceneDependencies
Gets the scene dependencies list.
Declaration
[Obsolete("This property will be removed in future releases, use GuidToReference or ReferenceToGuid instead.", false)]
public virtual List<Object> SceneDependencies { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Object> |
Methods
| Improve this Doc View SourceAdd(Object)
Adds the object to the database by generating a new GUID if it is not already in the database.
Declaration
public virtual string Add(Object obj)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | obj |
Returns
Type | Description |
---|---|
System.String |
Add(Object, String)
Adds the object to the database with the given GUID if it is not empty, otherwise generates a new GUID.
Declaration
public virtual void Add(Object obj, string guid)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | obj | |
System.String | guid |
ChangeGuid(String, String)
Changes the old GUID to the new GUID in the database.
Declaration
public virtual void ChangeGuid(string oldGuid, string newGuid)
Parameters
Type | Name | Description |
---|---|---|
System.String | oldGuid | |
System.String | newGuid |
Clear()
Clears the database.
Declaration
public virtual void Clear()
Contains(String)
Checks whether the database contains the given GUID or not.
Declaration
public virtual bool Contains(string referenceID)
Parameters
Type | Name | Description |
---|---|---|
System.String | referenceID |
Returns
Type | Description |
---|---|
System.Boolean |
Contains(Object)
Checks whether the database contains the given object or not.
Declaration
public virtual bool Contains(Object obj)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean |
CreateNewInstance()
Creates a new instance of SceneReferenceResolver in the current scene.
Declaration
public static GameObject CreateNewInstance()
Returns
Type | Description |
---|---|
UnityEngine.GameObject |
Get(String)
Gets the object associated with the given GUID.
Declaration
public virtual Object Get(string guid)
Parameters
Type | Name | Description |
---|---|---|
System.String | guid |
Returns
Type | Description |
---|---|
UnityEngine.Object |
Get(Object)
Gets the given object reference GUID.
Declaration
public virtual string Get(Object obj)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | obj |
Returns
Type | Description |
---|---|
System.String |
GetAllUnityObjects()
Gets all referenced Unity objects from all the currently available reference resolvers.
Declaration
public static List<Object> GetAllUnityObjects()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Object> | Returns a List of currently referenced Unity objecs from the available reference resolvers |
Remarks
It retrieves the referenced Unity objects from the currently open scenes that have a SceneReferenceResolver in them.
GetAnyGuidReference(Object)
Searches through all reference resolvers and gets the referenced unityObject
's GUID.
Declaration
public static string GetAnyGuidReference(Object unityObject)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | unityObject | The referenced Unity object |
Returns
Type | Description |
---|---|
System.String | Returns the referenced |
GetAnyUnityObjectReference(String)
Searches through all reference resolvers and gets the Unity object by the specified guid
.
Declaration
public static Object GetAnyUnityObjectReference(string guid)
Parameters
Type | Name | Description |
---|---|---|
System.String | guid | The referenced Unity object GUID |
Returns
Type | Description |
---|---|
UnityEngine.Object | Returns the referenced Unity object if available, otherwise null |
GetReferenceResolver(Scene)
Gets the reference resolver for the specified scene
.
Declaration
public static SceneReferenceResolver GetReferenceResolver(Scene scene)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.SceneManagement.Scene | scene | The scene to look for the reference resolver |
Returns
Type | Description |
---|---|
SceneReferenceResolver | Returns the reference resolver in the provided scene if available, otherwise null |
GetSceneGuidReference(Scene, Object)
Gets the referenced unityObject
GUID from the specified scene
's reference resolver if available.
Declaration
public static string GetSceneGuidReference(Scene scene, Object unityObject)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.SceneManagement.Scene | scene | The scene to look for the reference resolver |
UnityEngine.Object | unityObject | The referenced Unity object |
Returns
Type | Description |
---|---|
System.String | Returns the referenced |
GetSceneUnityObjectReference(Scene, String)
Gets the Unity object from the specified scene
's reference resolver if available.
Declaration
public static Object GetSceneUnityObjectReference(Scene scene, string guid)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.SceneManagement.Scene | scene | The scene to look for the reference resolver |
System.String | guid | The referenced Unity object GUID |
Returns
Type | Description |
---|---|
UnityEngine.Object | Returns the referenced Unity object if available, otherwise null |
GetUnityObjectScene(Object)
Gets the Unity object's scene.
Declaration
public static Scene? GetUnityObjectScene(Object unityObject)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | unityObject | The Unity object |
Returns
Type | Description |
---|---|
System.Nullable<UnityEngine.SceneManagement.Scene> | Returns the Unity object's scene if it is a GameObject or Component, otherwise null |
Remarks
First checks if the provided Unity object is a GameObject or Component, then uses the GameObject.scene property to retrieve the scene the Unity object is residing at.
HasNullValues()
Returns true if the database has null references, otherwise true.
Declaration
public virtual bool HasNullValues()
Returns
Type | Description |
---|---|
System.Boolean |
OnAfterDeserialize()
Declaration
public virtual void OnAfterDeserialize()
OnBeforeSerialize()
Declaration
public virtual void OnBeforeSerialize()
OnDisable()
Declaration
protected virtual void OnDisable()
OnEnable()
Declaration
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
protected virtual void OnEnable()
Remove(String)
Removes the GUID and the associated object from the database.
Declaration
public virtual void Remove(string referenceID)
Parameters
Type | Name | Description |
---|---|---|
System.String | referenceID |
Remove(Object)
Removes the object and its GUID from the database.
Declaration
public virtual void Remove(Object obj)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Object | obj |
RemoveDuplicateValues()
Removes the duplicate values.
Declaration
public virtual void RemoveDuplicateValues()
RemoveNullValues()
Removes null values and references from the database.
Declaration
public virtual void RemoveNullValues()
Reset()
Declaration
public virtual void Reset()