/// <summary>
    /// Get addressable asset entry of an object.
    /// </summary>
    /// <param name="o">>object to recive addressable asset entry</param>
    /// <returns>addressable asset entry</returns>
    public static UnityEditor.AddressableAssets.Settings.AddressableAssetEntry GetAddressableAssetEntry(Object o)
    {
        UnityEditor.AddressableAssets.Settings.AddressableAssetSettings aaSettings = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings;

        UnityEditor.AddressableAssets.Settings.AddressableAssetEntry entry = null;
        string guid    = string.Empty;
        long   localID = 0;
        string path;

        bool foundAsset = AssetDatabase.TryGetGUIDAndLocalFileIdentifier(o, out guid, out localID);

        path = AssetDatabase.GUIDToAssetPath(guid);

        if (foundAsset && (path.ToLower().Contains("assets")))
        {
            if (aaSettings != null)
            {
                entry = aaSettings.FindAssetEntry(guid);
            }
        }

        if (entry != null)
        {
            return(entry);
        }

        return(null);
    }
Exemplo n.º 2
0
    private void CreateMissionSceneInternal(MissionEnum missionEnum)
    {
        string folderName = MissionSceneManager.Instance.GenerateFolderName(missionEnum);
        string sceneName  = MissionSceneManager.Instance.GenerateSceneName(missionEnum);
        bool   isConfirm  = EditorUtility.DisplayDialog("Create New Scene", "New scene file will be create.\nScene Name: " + sceneName + "\nLocation: data/graphics/World/" + folderName, "Ok, create it", "Cancel");

        if (isConfirm)
        {
            CreateMissionFolder(folderName);

            bool isExistMissionScene = MissionSceneManager.Instance.IsFileMissionSceneExistInAssets(folderName, sceneName);
            if (!isExistMissionScene)
            {
                Scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
                newScene.name = sceneName;
                string fullScenePath = MissionSceneManager.Instance.GenerateFullScenePath(folderName, sceneName);

                bool saveOK = EditorSceneManager.SaveScene(newScene, fullScenePath);
                UnityEditor.AddressableAssets.Settings.AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(false);

                //Make a gameobject an addressable
                AddressableAssetGroup missionSceneGroup = settings.FindGroup("MissionScene");
                string guid = AssetDatabase.AssetPathToGUID(fullScenePath);

                //This is the function that actually makes the object addressable
                var entry = settings.CreateOrMoveEntry(guid, missionSceneGroup ? missionSceneGroup : settings.DefaultGroup);
                entry.address = sceneName;

                //You'll need these to run to save the changes!
                settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
                AssetDatabase.SaveAssets();

                if (!saveOK)
                {
                    Debug.LogError("Save is faild. Scene:" + sceneName);
                }
                else
                {
                    SetCurrentScene(newScene);
                    EdtorSceneAutomaticOperatioin.UpdateSceneBuildSetting();
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Scene Conflict", "Scene file Already Exist, Please load this scene.\nScene Name: " + sceneName + "\nLocation: data/graphics/World" + folderName, "Ok");
            }
        }
    }
Exemplo n.º 3
0
        internal void GatherAllAssetReferenceDrawableEntries(List <IReferenceEntryData> refEntries, AddressableAssetSettings settings)
        {
            var path = AssetPath;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (guid == EditorSceneListName)
            {
                //We don't add Built in scenes to the list of assignable AssetReferences so no need to check this.
                return;
            }
            if (guid == ResourcesName)
            {
                //We don't add Resources assets to the list of assignable AssetReferences so no need to check this.
                return;
            }
            if (AssetDatabase.IsValidFolder(path))
            {
                foreach (var fi in AddressablesFileEnumeration.EnumerateAddressableFolder(path, settings, true))
                {
                    string relativeAddress = address + GetRelativePath(fi, path);
                    var    reference       = new ImplicitAssetEntry()
                    {
                        address       = relativeAddress,
                        AssetPath     = fi,
                        IsInResources = IsInResources
                    };

                    refEntries.Add(reference);
                }
            }
            else if (MainAssetType == typeof(AddressableAssetEntryCollection))
            {
                var col = AssetDatabase.LoadAssetAtPath <AddressableAssetEntryCollection>(AssetPath);
                if (col != null)
                {
                    foreach (var e in col.Entries)
                    {
                        refEntries.Add(e);
                    }
                }
            }
            else
            {
                refEntries.Add(this);
            }
        }
 internal AddressablesFileEnumerationCache(AddressableAssetSettings settings, bool prepopulateAssetsFolder, IBuildLogger logger)
 {
     BeginPrecomputedEnumerationSession(settings, prepopulateAssetsFolder, logger);
 }
 internal void Validate(AddressableAssetSettings addressableAssetSettings)
 {
 }
 internal void OnAfterDeserialize(AddressableAssetSettings settings)
 {
     m_Settings = settings;
 }
 public FastModeInitializationOperation(AddressablesImpl addressables, AddressableAssetSettings settings)
 {
     m_addressables = addressables;
     m_settings     = settings;
     m_addressables.ResourceManager.RegisterForCallbacks();
 }
 internal void Validate(AddressableAssetSettings addressableAssetSettings)
 {
     CreateDefaultProfile();
 }
        internal static bool ConvertEntryCollectionToEntries(AddressableAssetEntryCollection collection, AddressableAssetSettings settings)
        {
            if (settings == null)
            {
                settings = AddressableAssetSettingsDefaultObject.Settings;
            }
            if (settings == null || !AssetDatabase.TryGetGUIDAndLocalFileIdentifier(collection, out var collectionGuid, out long localId))
            {
                return(false);
            }

            var collectionEntry = settings.FindAssetEntry(collectionGuid, true);

            var group = collectionEntry == null ? settings.DefaultGroup : collectionEntry.parentGroup;
            List <AddressableAssetEntry> entries = new List <AddressableAssetEntry>();

            foreach (AddressableAssetEntry assetEntry in collection.Entries)
            {
                if (assetEntry == null)
                {
                    continue;
                }
                var entry = settings.FindAssetEntry(assetEntry.guid);
                if (entry != null)
                {
                    continue;
                }
                entries.Add(assetEntry);
            }

            HashSet <string> collectionLabels = new HashSet <string>();

            if (collectionEntry != null)
            {
                collectionLabels = collectionEntry.labels;
                if (!settings.RemoveAssetEntry(collectionEntry))
                {
                    return(false);
                }
            }

            foreach (AddressableAssetEntry entry in entries)
            {
                var newEntry = settings.CreateOrMoveEntry(entry.guid, group);
                newEntry.SetAddress(entry.address);
                foreach (string label in collectionLabels)
                {
                    newEntry.SetLabel(label, true);
                }
                foreach (string label in entry.labels)
                {
                    newEntry.SetLabel(label, true);
                }
            }

            return(true);
        }