private void HandleDragAndDrop(SerializedProperty property, bool isDragging, bool isDropping, string guid) { var aaSettings = AddressableAssetSettingsDefaultObject.Settings; //During the drag, doing a light check on asset validity. The in-depth check happens during a drop, and should include a log if it fails. var rejectedDrag = false; if (isDragging) { if (aaSettings == null) { rejectedDrag = true; } else { var aaEntries = DragAndDrop.GetGenericData("AssetEntryTreeViewItem") as List <AssetEntryTreeViewItem>; rejectedDrag = AssetReferenceDrawerUtilities.ValidateDrag(m_AssetRefObject, Restrictions, aaEntries, DragAndDrop.objectReferences, DragAndDrop.paths); } DragAndDrop.visualMode = rejectedDrag ? DragAndDropVisualMode.Rejected : DragAndDropVisualMode.Copy; } if (!rejectedDrag && isDropping) { var aaEntries = DragAndDrop.GetGenericData("AssetEntryTreeViewItem") as List <AssetEntryTreeViewItem>; if (aaEntries != null) { if (aaEntries.Count == 1) { var item = aaEntries[0]; if (item.entry != null) { if (item.entry.IsInResources) { Addressables.LogWarning("Cannot use an AssetReference on an asset in Resources. Move asset out of Resources first."); } else { if (AssetReferenceDrawerUtilities.SetObject(ref m_AssetRefObject, ref m_ReferencesSame, property, item.entry.TargetAsset, fieldInfo, m_label.text, out guid)) { TriggerOnValidate(property); } } } } } else { if (DragAndDrop.paths != null && DragAndDrop.paths.Length == 1) { var path = DragAndDrop.paths[0]; DragAndDropNotFromAddressableGroupWindow(path, guid, property, aaSettings); } } } }
bool ApplySelectionChanges(SerializedProperty property, AddressableAssetSettings aaSettings, ref string guid) { var checkToForceAddressable = string.Empty; if (!string.IsNullOrEmpty(newGuid) && newGuidPropertyPath == property.propertyPath) { if (newGuid == noAssetString) { if (AssetReferenceDrawerUtilities.SetObject(ref m_AssetRefObject, ref m_ReferencesSame, property, null, fieldInfo, m_label.text, out guid)) { TriggerOnValidate(property); } newGuid = string.Empty; } else if (newGuid == forceAddressableString) { checkToForceAddressable = guid; newGuid = string.Empty; } else if (guid != newGuid) { if (AssetReferenceDrawerUtilities.SetObject(ref m_AssetRefObject, ref m_ReferencesSame, property, AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(newGuid)), fieldInfo, m_label.text, out guid)) { checkToForceAddressable = newGuid; TriggerOnValidate(property); } newGuid = string.Empty; } } bool isNotAddressable = false; m_AssetName = noAssetString; if (aaSettings != null && !string.IsNullOrEmpty(guid)) { isNotAddressable = AssetReferenceDrawerUtilities.CheckForNewEntry(ref m_AssetName, aaSettings, guid, checkToForceAddressable); } return(isNotAddressable); }
internal void DragAndDropNotFromAddressableGroupWindow(string path, string guid, SerializedProperty property, AddressableAssetSettings aaSettings) { if (AddressableAssetUtility.IsInResources(path)) { Addressables.LogWarning("Cannot use an AssetReference on an asset in Resources. Move asset out of Resources first. "); } else if (!AddressableAssetUtility.IsPathValidForEntry(path)) { Addressables.LogWarning("Dragged asset is not valid as an Asset Reference. " + path); } else { Object obj; if (DragAndDrop.objectReferences != null && DragAndDrop.objectReferences.Length == 1) { obj = DragAndDrop.objectReferences[0]; } else { obj = AssetDatabase.LoadAssetAtPath <Object>(path); } if (AssetReferenceDrawerUtilities.SetObject(ref m_AssetRefObject, ref m_ReferencesSame, property, obj, fieldInfo, m_label.text, out guid)) { TriggerOnValidate(property); aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(true); var entry = aaSettings.FindAssetEntry(guid); if (entry == null && !string.IsNullOrEmpty(guid)) { string assetName; if (!aaSettings.IsAssetPathInAddressableDirectory(path, out assetName)) { aaSettings.CreateOrMoveEntry(guid, aaSettings.DefaultGroup); newGuid = guid; } } } } }