/// <summary> /// Sets the asset on the AssetReference. Only valid in the editor, this sets both the editorAsset attribute, /// and the internal asset GUID, which drives the RuntimeKey attribute. /// <param name="value">Object to reference</param> /// </summary> public bool SetEditorAsset(Object value) { if (value == null) { m_CachedAsset = null; m_AssetGUID = string.Empty; return(true); } if (m_CachedAsset != value) { var path = AssetDatabase.GetAssetOrScenePath(value); if (string.IsNullOrEmpty(path)) { Addressables.LogWarningFormat("Invalid object for AssetReference {0}.", value); return(false); } if (!ValidateAsset(path)) { Addressables.LogWarningFormat("Invalid asset for AssetReference path = '{0}'.", path); return(false); } else { m_AssetGUID = AssetDatabase.AssetPathToGUID(path); m_CachedAsset = value; } } return(true); }
/// <summary> /// Sets the main asset on the AssetReference. Only valid in the editor, this sets both the editorAsset attribute, /// and the internal asset GUID, which drives the RuntimeKey attribute. If the reference uses a sub object, /// then it will load the editor asset during edit mode and load the sub object during runtime. For example, if /// the AssetReference is set to a sprite within a sprite atlas, the editorAsset is the atlas (loaded during edit mode) /// and the sub object is the sprite (loaded during runtime). If called by AssetReferenceT, will set the editorAsset /// to the requested object if the object is of type T, and null otherwise. /// <param name="value">Object to reference</param> /// </summary> public virtual bool SetEditorAsset(Object value) { if (value == null) { CachedAsset = null; m_AssetGUID = string.Empty; m_SubObjectName = null; m_EditorAssetChanged = true; return(true); } if (CachedAsset != value) { m_SubObjectName = null; var path = AssetDatabase.GetAssetOrScenePath(value); if (string.IsNullOrEmpty(path)) { Addressables.LogWarningFormat("Invalid object for AssetReference {0}.", value); return(false); } if (!ValidateAsset(path)) { Addressables.LogWarningFormat("Invalid asset for AssetReference path = '{0}'.", path); return(false); } else { m_AssetGUID = AssetDatabase.AssetPathToGUID(path); Object mainAsset; if (m_DerivedClassType != null) { mainAsset = LocateEditorAssetForTypedAssetReference(value, path); } else { mainAsset = AssetDatabase.LoadMainAssetAtPath(path); if (value != mainAsset) { SetEditorSubObject(value); } } CachedAsset = mainAsset; } } m_EditorAssetChanged = true; return(true); }