public override void OnGUI(Rect windowRect) { GUILayout.BeginArea(windowRect); Event evt = Event.current; bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter); m_NewName = GUILayout.TextField(m_NewName); if (GUILayout.Button("Save") || hitEnter) { if (string.IsNullOrEmpty(m_NewName)) { Debug.LogError("Path pair prefix cannot be empty."); } else if (m_NewName == m_ProfileGroupType.GroupTypePrefix) { editorWindow.Close(); } else if (VariableWithNewPrefixAlreadyExists()) { Debug.LogError("One or more build or load path variables with prefix '" + m_NewName + "' already exist. Please rename them or pick a different prefix."); } else if (m_NewName.Trim().Length == 0) // new name cannot only contain spaces { Debug.LogError("Path pair prefix cannot be only spaces"); } else { var loadPathVariableData = m_Settings.profileSettings.GetProfileDataByName(m_ProfileGroupType.GroupTypePrefix + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kLoadPath); var buildPathVariableData = m_Settings.profileSettings.GetProfileDataByName(m_ProfileGroupType.GroupTypePrefix + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kBuildPath); if (loadPathVariableData == default(AddressableAssetProfileSettings.ProfileIdData) || buildPathVariableData == default(AddressableAssetProfileSettings.ProfileIdData)) { Debug.LogError("Valid path pair to rename not found."); } else { Undo.RecordObject(m_Settings, "Path pair prefix Renamed"); m_ProfileGroupType.GroupTypePrefix = m_NewName; loadPathVariableData.SetName(m_ProfileGroupType.GroupTypePrefix + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kLoadPath, m_Settings.profileSettings); buildPathVariableData.SetName(m_ProfileGroupType.GroupTypePrefix + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kBuildPath, m_Settings.profileSettings); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings, true); editorWindow.Close(); } } } GUILayout.EndArea(); }
//Creates a new BuildProfile and reloads the ProfilesPane void NewProfile() { var uniqueProfileName = settings.profileSettings.GetUniqueProfileName("New Profile"); if (!string.IsNullOrEmpty(uniqueProfileName)) { Undo.RecordObject(settings, "New Profile Created"); //Either copy values from the selected profile, or if there is no selected profile, copy from the default string idToCopyFrom = GetSelectedProfile() != null ? GetSelectedProfile().id : settings.profileSettings.profiles[0].id; settings.profileSettings.AddProfile(uniqueProfileName, idToCopyFrom); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); m_ProfileTreeView.Reload(); } }
protected override void RenameEnded(RenameEndedArgs args) { var item = FindItemInVisibleRows(args.itemID); AddressableAssetProfileSettings.BuildProfile profile = GetProfile(item.id); Undo.RecordObject(m_Window.settings, "Profile renamed"); bool renameSuccessful = m_Window.settings.profileSettings.RenameProfile(profile, args.newName); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Window.settings, true); if (renameSuccessful) { Reload(); } }
public void OnGUIMultiple(Rect position, SerializedProperty property, GUIContent label, bool showMixed) { m_Property = property; if (m_SerializedFieldInfo == null) { m_SerializedFieldInfo = GetFieldInfo(property); } if (m_Types == null) { m_Types = GetTypes(m_SerializedFieldInfo); } List <GUIContent> typeContent = new List <GUIContent>(); typeContent.Add(new GUIContent("<none>", "Clear the type.")); foreach (var type in m_Types) { typeContent.Add(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), "")); } bool resetShowMixed = EditorGUI.showMixedValue; EditorGUI.BeginProperty(position, label, property); EditorGUI.showMixedValue = showMixed; var st = (SerializedType)m_SerializedFieldInfo.GetValue(property.serializedObject.targetObject); int index = GetIndexForType(st.Value); int selectedValue = EditorGUI.Popup(position, label, index, typeContent.ToArray()); if (selectedValue != index) { Undo.RecordObject(m_Property.serializedObject.targetObject, "Set Serialized Type"); m_SerializedFieldInfo.SetValue(m_Property.serializedObject.targetObject, new SerializedType { Value = selectedValue == 0 ? null : m_Types[selectedValue - 1], ValueChanged = true }); EditorUtility.SetDirty(m_Property.serializedObject.targetObject); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Property.serializedObject.targetObject); } EditorGUI.EndProperty(); EditorGUI.showMixedValue = resetShowMixed; }
void DeleteProfile(object context) { List <TreeViewItem> selectedNodes = context as List <TreeViewItem>; foreach (var item in selectedNodes) { var prof = m_TreeIndexToBuildProfileMap[item.id]; if (prof != default) { Undo.RecordObject(m_Window.settings, "Profile Deleted"); m_Window.settings.profileSettings.RemoveProfile(prof.id); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Window.settings); AssetDatabase.SaveAssets(); } } m_Window.ProfileIndex = -1; Reload(); }
public override void OnGUI(Rect windowRect) { GUILayout.Space(5); Event evt = Event.current; bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter); EditorGUIUtility.labelWidth = 120; m_Name = EditorGUILayout.TextField("Prefix Name", m_Name); m_BuildPath = EditorGUILayout.TextField("Build Path Value", m_BuildPath); m_LoadPath = EditorGUILayout.TextField("Load Path Value", m_LoadPath); UnityEngine.GUI.enabled = m_Name.Length != 0; if (GUILayout.Button("Save") || hitEnter) { string buildPathName = m_Name + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kBuildPath; string loadPathName = m_Name + ProfileGroupType.k_PrefixSeparator + AddressableAssetSettings.kLoadPath; if (string.IsNullOrEmpty(m_Name)) { Debug.LogError("Variable name cannot be empty."); } else if (buildPathName != m_Settings.profileSettings.GetUniqueProfileEntryName(buildPathName)) { Debug.LogError("Profile variable '" + buildPathName + "' already exists."); } else if (loadPathName != m_Settings.profileSettings.GetUniqueProfileEntryName(loadPathName)) { Debug.LogError("Profile variable '" + loadPathName + "' already exists."); } else { Undo.RecordObject(m_Settings, "Profile Path Pair Created"); m_Settings.profileSettings.CreateValue(buildPathName, m_BuildPath); m_Settings.profileSettings.CreateValue(loadPathName, m_LoadPath); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings); m_ProfileTreeView.Reload(); editorWindow.Close(); } } }
public override void OnGUI(Rect windowRect) { GUILayout.Space(5); Event evt = Event.current; bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter); UnityEngine.GUI.SetNextControlName("LabelName"); EditorGUIUtility.labelWidth = 80; name = EditorGUILayout.TextField("Label Name", name); if (needsFocus) { needsFocus = false; EditorGUI.FocusTextInControl("LabelName"); } UnityEngine.GUI.enabled = name.Length != 0; if (GUILayout.Button("Save") || hitEnter) { if (string.IsNullOrEmpty(name)) { Debug.LogError("Cannot add empty label to Addressables label list"); } else if (name != settings.labelTable.GetUniqueLabelName(name)) { Debug.LogError("Label name '" + name + "' is already in the labels list."); } else if (name.Contains("[") && name.Contains("]")) { Debug.LogErrorFormat("Label name '{0}' cannot contain '[ ]'.", name); } else { settings.AddLabel(name); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } editorWindow.Close(); } }
public override void OnGUI(Rect windowRect) { GUILayout.BeginArea(windowRect); Event evt = Event.current; bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter); m_NewName = GUILayout.TextField(m_NewName); if (GUILayout.Button("Save") || hitEnter) { if (string.IsNullOrEmpty(m_NewName)) { Debug.LogError("Variable name cannot be empty."); } else if (m_NewName == m_ProfileVariable.ProfileName) { editorWindow.Close(); } else if (m_NewName != m_Settings.profileSettings.GetUniqueProfileEntryName(m_NewName)) { Debug.LogError("Profile variable '" + m_NewName + "' already exists."); } else if (m_NewName.Trim().Length == 0) // new name cannot only contain spaces { Debug.LogError("Name cannot be only spaces"); } else { Undo.RecordObject(m_Settings, "Profile Variable Renamed"); m_ProfileVariable.SetName(m_NewName, m_Settings.profileSettings); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings, true); editorWindow.Close(); } } GUILayout.EndArea(); }
//Displays all variables for the currently selected profile and initializes each variable's context menu void VariablesPane(Rect variablesPaneRect) { DrawOutline(variablesPaneRect, 1); Event evt = Event.current; AddressableAssetProfileSettings.BuildProfile selectedProfile = GetSelectedProfile(); if (selectedProfile == null) { return; } if (evt.isMouse || evt.isKey) { m_ProfileTreeView.lastClickedProfile = ProfileIndex; } //ensures amount of visible text is not affected by label width float fieldWidth = variablesPaneRect.width - (2 * k_ItemRectPadding) + m_LabelWidth + m_FieldBufferWidth; float fieldX = variablesPaneRect.x + k_ItemRectPadding; float fieldHeight = k_ToolbarHeight; //Amount of text visible not affected by amount of text either, large enough for arbitrary # of variables float viewRectHeight = (fieldHeight + k_VariableItemPadding) * settings.profileSettings.profileEntryNames.Count + fieldHeight; float viewRectWidth = fieldWidth + (2 * k_ItemRectPadding); Rect viewRect = new Rect(variablesPaneRect.x, variablesPaneRect.y, viewRectWidth, viewRectHeight); if (!EditorGUIUtility.labelWidth.Equals(m_LabelWidth)) { EditorGUIUtility.labelWidth = m_LabelWidth; } int maxLabelLen = 0; int maxFieldLen = 0; m_VariablesPaneScrollPosition = UnityEngine.GUI.BeginScrollView(variablesPaneRect, m_VariablesPaneScrollPosition, viewRect); for (int i = 0; i < settings.profileSettings.profileEntryNames.Count; i++) { //Keep track of the maximum length label, field so we can ensure that variable names, values are always completely visible maxLabelLen = Math.Max(maxLabelLen, settings.profileSettings.profileEntryNames[i].ProfileName.Length); maxFieldLen = Math.Max(maxFieldLen, selectedProfile.values[i].value.Length); float fieldY = (variablesPaneRect.y + k_VariableItemPadding) * i + k_ItemRectPadding + k_ToolbarHeight; AddressableAssetProfileSettings.ProfileIdData curVariable = settings.profileSettings.profileEntryNames[i]; Rect fieldRect = new Rect(fieldX, fieldY, fieldWidth, fieldHeight); Rect labelRect = new Rect(fieldX, fieldY, m_LabelWidth, fieldHeight); string newName = EditorGUI.TextField(fieldRect, curVariable.ProfileName, selectedProfile.values[i].value); //Ensure changes get serialized if (selectedProfile.values[i].value != newName && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, settings.profileSettings.profileEntryNames[i].ProfileName, newName); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(labelRect, curVariable, i, evt); } } UnityEngine.GUI.EndScrollView(); //Update the label width to the maximum of the minimum acceptable label width and the amount of //space required to contain the longest variable name m_LabelWidth = Mathf.Max(maxLabelLen * k_ApproxCharWidth, k_MinLabelWidth); m_FieldBufferWidth = Mathf.Clamp((maxFieldLen * k_ApproxCharWidth) - fieldWidth, 0f, float.MaxValue); }
void DeleteVariable(AddressableAssetProfileSettings.ProfileIdData toBeDeleted) { Undo.RecordObject(settings, "Profile Variable Deleted"); settings.profileSettings.RemoveValue(toBeDeleted.Id); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); }
static void SetAaEntry(AddressableAssetSettings aaSettings, Object[] targets, bool create) { if (create && aaSettings.DefaultGroup.ReadOnly) { Debug.LogError("Current default group is ReadOnly. Cannot add addressable assets to it"); return; } Undo.RecordObject(aaSettings, "AddressableAssetSettings"); var targetInfos = new List <TargetInfo>(); foreach (var t in targets) { if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out var path, out var guid, out var mainAssetType)) { targetInfos.Add(new TargetInfo() { Guid = guid, Path = path, MainAssetType = mainAssetType }); } } if (!create) { targetInfos.ForEach(ti => { AddressableAssetGroup group = aaSettings.FindAssetEntry(ti.Guid).parentGroup; aaSettings.RemoveAssetEntry(ti.Guid); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(group); }); } else { var resourceTargets = targetInfos.Where(ti => AddressableAssetUtility.IsInResources(ti.Path)); if (resourceTargets.Any()) { var resourcePaths = resourceTargets.Select(t => t.Path).ToList(); var resourceGuids = resourceTargets.Select(t => t.Guid).ToList(); AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, aaSettings.DefaultGroup, resourcePaths, resourceGuids); } var entriesAdded = new List <AddressableAssetEntry>(); var modifiedGroups = new HashSet <AddressableAssetGroup>(); var otherTargetInfos = targetInfos.Except(resourceTargets); foreach (var info in otherTargetInfos) { var e = aaSettings.CreateOrMoveEntry(info.Guid, aaSettings.DefaultGroup, false, EnumLocalResourceMode.Disable, false); entriesAdded.Add(e); modifiedGroups.Add(e.parentGroup); } foreach (var g in modifiedGroups) { g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, false, true); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(g); } aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true, false); } }
void OnRemoveLabel(ReorderableList list) { m_Settings.RemoveLabel(m_Settings.labelTable.labelNames[list.index]); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings); }
static void SetAaEntry(AddressableAssetSettings aaSettings, List <TargetInfo> targetInfos, bool create) { /* * if (create && aaSettings.DefaultGroup.ReadOnly) * { * Debug.LogError("Current default group is ReadOnly. Cannot add addressable assets to it"); * return; * } */ Undo.RecordObject(aaSettings, "AddressableAssetSettings"); if (!create) { List <AddressableAssetEntry> removedEntries = new List <AddressableAssetEntry>(targetInfos.Count); for (int i = 0; i < targetInfos.Count; ++i) { AddressableAssetEntry e = aaSettings.FindAssetEntry(targetInfos[i].Guid); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(e.parentGroup); removedEntries.Add(e); aaSettings.RemoveAssetEntry(removedEntries[i], false); } if (removedEntries.Count > 0) { aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, removedEntries, true, false); } } else { AddressableAssetGroup parentGroup = aaSettings.DefaultGroup; var resourceTargets = targetInfos.Where(ti => AddressableAssetUtility.IsInResources(ti.Path)); if (resourceTargets.Any()) { var resourcePaths = resourceTargets.Select(t => t.Path).ToList(); var resourceGuids = resourceTargets.Select(t => t.Guid).ToList(); AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, parentGroup, resourcePaths, resourceGuids); } var entriesCreated = new List <AddressableAssetEntry>(); var entriesMoved = new List <AddressableAssetEntry>(); var otherTargetInfos = targetInfos.Except(resourceTargets); foreach (var info in otherTargetInfos) { var hook = aaSettings.hook; AddressableAssetGroup assetGroup = default; string customAddress = default; if (hook != null) { hook.BeforeSetEntryOnInspectorGUI(info.Path, out assetGroup, out customAddress); } if (assetGroup == null) { assetGroup = aaSettings.DefaultGroup; } string guid = info.Guid; if (string.IsNullOrEmpty(guid)) { continue; } AddressableAssetEntry e = aaSettings.FindAssetEntry(guid); if (e != null) //move entry to where it should go... { aaSettings.MoveEntry(e, assetGroup, false, false); } else //create entry { e = aaSettings.CreateAndAddEntryToGroup_Custom(guid, assetGroup, false, false); } if (string.IsNullOrEmpty(customAddress) == false) { e.SetAddress(customAddress, false); } entriesCreated.Add(e); entriesMoved.Add(e); } bool openedInVC = false; if (entriesMoved.Count > 0) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); openedInVC = true; aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesMoved, true, false); } if (entriesCreated.Count > 0) { if (!openedInVC) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); } aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, entriesCreated, true, false); } } }
//Displays all variables for the currently selected profile and initializes each variable's context menu void VariablesPane(Rect variablesPaneRect) { DrawOutline(variablesPaneRect, 1); Event evt = Event.current; AddressableAssetProfileSettings.BuildProfile selectedProfile = GetSelectedProfile(); if (selectedProfile == null) { return; } if (evt.isMouse || evt.isKey) { m_ProfileTreeView.lastClickedProfile = ProfileIndex; } //ensures amount of visible text is not affected by label width float fieldWidth = variablesPaneRect.width - (2 * k_ItemRectPadding) + m_LabelWidth + m_FieldBufferWidth; if (!EditorGUIUtility.labelWidth.Equals(m_LabelWidth)) { EditorGUIUtility.labelWidth = m_LabelWidth; } int maxLabelLen = 0; int maxFieldLen = 0; GUILayout.BeginArea(variablesPaneRect); EditorGUI.indentLevel++; List <ProfileGroupType> groupTypes = CreateGroupTypes(selectedProfile); HashSet <string> drawnGroupTypes = new HashSet <string>(); //Displaying Path Groups foreach (ProfileGroupType groupType in groupTypes) { bool?foldout; m_foldouts.TryGetValue(groupType.GroupTypePrefix, out foldout); GUILayout.Space(5); m_foldouts[groupType.GroupTypePrefix] = EditorGUILayout.Foldout(foldout != null ? foldout.Value : true, groupType.GroupTypePrefix, true); //Specific Grouped variables List <ProfileGroupType.GroupTypeVariable> pathVariables = new List <ProfileGroupType.GroupTypeVariable>(); pathVariables.Add(groupType.GetVariableBySuffix("BuildPath")); drawnGroupTypes.Add(groupType.GetName(groupType.GetVariableBySuffix("BuildPath"))); pathVariables.Add(groupType.GetVariableBySuffix("LoadPath")); drawnGroupTypes.Add(groupType.GetName(groupType.GetVariableBySuffix("LoadPath"))); if (m_foldouts[groupType.GroupTypePrefix].Value) { EditorGUI.indentLevel++; //Displaying Path Groups foreach (var variable in pathVariables) { Rect newPathRect = EditorGUILayout.BeginVertical(); string newPath = EditorGUILayout.TextField(groupType.GetName(variable), variable.Value); EditorGUILayout.EndVertical(); if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(variablesPaneRect, newPathRect, settings.profileSettings.GetProfileDataByName(groupType.GetName(variable)), evt); } if (newPath != variable.Value && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, groupType.GetName(variable), newPath); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } } EditorGUI.indentLevel--; } } //Display all other variables for (var i = 0; i < settings.profileSettings.profileEntryNames.Count; i++) { AddressableAssetProfileSettings.ProfileIdData curVariable = settings.profileSettings.profileEntryNames[i]; if (!drawnGroupTypes.Contains(curVariable.ProfileName)) { GUILayout.Space(5); Rect newValueRect = EditorGUILayout.BeginVertical(); string newValue = EditorGUILayout.TextField(curVariable.ProfileName, selectedProfile.values[i].value); EditorGUILayout.EndVertical(); if (newValue != selectedProfile.values[i].value && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, settings.profileSettings.profileEntryNames[i].ProfileName, newValue); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(variablesPaneRect, newValueRect, curVariable, evt); } } maxLabelLen = Math.Max(maxLabelLen, curVariable.ProfileName.Length); } EditorGUI.indentLevel--; GUILayout.EndArea(); //Update the label width to the maximum of the minimum acceptable label width and the amount of //space required to contain the longest variable name m_LabelWidth = Mathf.Max(maxLabelLen * k_ApproxCharWidth, k_MinLabelWidth); m_FieldBufferWidth = Mathf.Clamp((maxFieldLen * k_ApproxCharWidth) - fieldWidth, 0f, float.MaxValue); }
static void SetAaEntry(AddressableAssetSettings aaSettings, List <TargetInfo> targetInfos, bool create) { if (create && aaSettings.DefaultGroup.ReadOnly) { Debug.LogError("Current default group is ReadOnly. Cannot add addressable assets to it"); return; } Undo.RecordObject(aaSettings, "AddressableAssetSettings"); if (!create) { List <AddressableAssetEntry> removedEntries = new List <AddressableAssetEntry>(targetInfos.Count); for (int i = 0; i < targetInfos.Count; ++i) { AddressableAssetEntry e = aaSettings.FindAssetEntry(targetInfos[i].Guid); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(e.parentGroup); removedEntries.Add(e); aaSettings.RemoveAssetEntry(removedEntries[i], false); } if (removedEntries.Count > 0) { aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, removedEntries, true, false); } } else { AddressableAssetGroup parentGroup = aaSettings.DefaultGroup; var resourceTargets = targetInfos.Where(ti => AddressableAssetUtility.IsInResources(ti.Path)); if (resourceTargets.Any()) { var resourcePaths = resourceTargets.Select(t => t.Path).ToList(); var resourceGuids = resourceTargets.Select(t => t.Guid).ToList(); AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, parentGroup, resourcePaths, resourceGuids); } var otherTargetInfos = targetInfos.Except(resourceTargets); List <string> otherTargetGuids = new List <string>(targetInfos.Count); foreach (var info in otherTargetInfos) { otherTargetGuids.Add(info.Guid); } var entriesCreated = new List <AddressableAssetEntry>(); var entriesMoved = new List <AddressableAssetEntry>(); aaSettings.CreateOrMoveEntries(otherTargetGuids, parentGroup, entriesCreated, entriesMoved, false, false); bool openedInVC = false; if (entriesMoved.Count > 0) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); openedInVC = true; aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesMoved, true, false); } if (entriesCreated.Count > 0) { if (!openedInVC) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); } aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, entriesCreated, true, false); } } }
static void OnPostHeaderGUI(Editor editor) { var aaSettings = AddressableAssetSettingsDefaultObject.Settings; AddressableAssetEntry entry = null; if (editor.targets.Length > 0) { int addressableCount = 0; bool foundValidAsset = false; bool foundAssetGroup = false; var targetInfos = new List <TargetInfo>(); foreach (var t in editor.targets) { foundAssetGroup |= t is AddressableAssetGroup; foundAssetGroup |= t is AddressableAssetGroupSchema; if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out var path, out var guid, out var mainAssetType)) { // Is asset if (!BuildUtility.IsEditorAssembly(mainAssetType.Assembly)) { foundValidAsset = true; var info = new TargetInfo() { Guid = guid, Path = path, MainAssetType = mainAssetType }; if (aaSettings != null) { entry = aaSettings.FindAssetEntry(guid); if (entry != null && !entry.IsSubAsset) { addressableCount++; info.Entry = entry; } } targetInfos.Add(info); } } } if (foundAssetGroup) { GUILayout.BeginHorizontal(); GUILayout.Label("Profile: " + AddressableAssetSettingsDefaultObject.GetSettings(true).profileSettings. GetProfileName(AddressableAssetSettingsDefaultObject.GetSettings(true).activeProfileId)); GUILayout.FlexibleSpace(); if (GUILayout.Button("System Settings", "MiniButton")) { EditorGUIUtility.PingObject(AddressableAssetSettingsDefaultObject.Settings); Selection.activeObject = AddressableAssetSettingsDefaultObject.Settings; } GUILayout.EndHorizontal(); } if (!foundValidAsset) { return; } // Overrides a DisabledScope in the EditorElement.cs that disables GUI drawn in the header when the asset cannot be edited. bool prevEnabledState = UnityEngine.GUI.enabled; UnityEngine.GUI.enabled = true; if (addressableCount == 0) { if (GUILayout.Toggle(false, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), targetInfos, true); } } else if (addressableCount == editor.targets.Length) { GUILayout.BeginHorizontal(); if (!GUILayout.Toggle(true, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(aaSettings, targetInfos, false); UnityEngine.GUI.enabled = prevEnabledState; GUIUtility.ExitGUI(); } if (editor.targets.Length == 1 && entry != null) { string newAddress = EditorGUILayout.DelayedTextField(entry.address, GUILayout.ExpandWidth(true)); if (newAddress != entry.address) { if (newAddress.Contains("[") && newAddress.Contains("]")) { Debug.LogErrorFormat("Rename of address '{0}' cannot contain '[ ]'.", entry.address); } else { entry.address = newAddress; AddressableAssetUtility.OpenAssetIfUsingVCIntegration(entry.parentGroup, true); } } } else { EditorGUILayout.LabelField(addressableCount + " out of " + editor.targets.Length + " assets are addressable."); } if (GUILayout.Button("Select")) { SelectEntriesInGroupsWindow(targetInfos); } GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); if (s_ToggleMixed == null) { s_ToggleMixed = new GUIStyle("ToggleMixed"); } if (GUILayout.Toggle(false, s_AddressableAssetToggleText, s_ToggleMixed, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), targetInfos, true); } EditorGUILayout.LabelField(addressableCount + " out of " + editor.targets.Length + " assets are addressable."); if (GUILayout.Button("Select")) { SelectEntriesInGroupsWindow(targetInfos); } GUILayout.EndHorizontal(); } UnityEngine.GUI.enabled = prevEnabledState; } }
static void OnPostHeaderGUI(Editor editor) { var aaSettings = AddressableAssetSettingsDefaultObject.Settings; if (editor.targets.Length > 0) { foreach (var t in editor.targets) { if (t is AddressableAssetGroup || t is AddressableAssetGroupSchema) { GUILayout.BeginHorizontal(); GUILayout.Label("Profile: " + AddressableAssetSettingsDefaultObject.GetSettings(true).profileSettings. GetProfileName(AddressableAssetSettingsDefaultObject.GetSettings(true).activeProfileId)); GUILayout.FlexibleSpace(); if (GUILayout.Button("System Settings", "MiniButton")) { EditorGUIUtility.PingObject(AddressableAssetSettingsDefaultObject.Settings); Selection.activeObject = AddressableAssetSettingsDefaultObject.Settings; } GUILayout.EndHorizontal(); return; } } List <TargetInfo> targetInfos = GatherTargetInfos(editor.targets, aaSettings); if (targetInfos.Count == 0) { return; } bool targetHasAddressableSubObject = false; int mainAssetsAddressable = 0; int subAssetsAddressable = 0; foreach (TargetInfo info in targetInfos) { if (info.MainAssetEntry == null) { continue; } if (info.MainAssetEntry.IsSubAsset) { subAssetsAddressable++; } else { mainAssetsAddressable++; } if (!info.IsMainAsset) { targetHasAddressableSubObject = true; } } // Overrides a DisabledScope in the EditorElement.cs that disables GUI drawn in the header when the asset cannot be edited. bool prevEnabledState = UnityEngine.GUI.enabled; if (targetHasAddressableSubObject) { UnityEngine.GUI.enabled = false; } else { UnityEngine.GUI.enabled = true; foreach (var info in targetInfos) { if (!info.IsMainAsset) { UnityEngine.GUI.enabled = false; break; } } } int totalAddressableCount = mainAssetsAddressable + subAssetsAddressable; if (totalAddressableCount == 0) // nothing is addressable { if (GUILayout.Toggle(false, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), targetInfos, true); } } else if (totalAddressableCount == editor.targets.Length) // everything is addressable { var entryInfo = targetInfos[targetInfos.Count - 1]; if (entryInfo == null || entryInfo.MainAssetEntry == null) { throw new NullReferenceException("EntryInfo incorrect for Addressables content."); } GUILayout.BeginHorizontal(); if (mainAssetsAddressable > 0 && subAssetsAddressable > 0) { if (s_ToggleMixed == null) { s_ToggleMixed = new GUIStyle("ToggleMixed"); } if (GUILayout.Toggle(false, s_AddressableAssetToggleText, s_ToggleMixed, GUILayout.ExpandWidth(false))) { SetAaEntry(aaSettings, targetInfos, true); } } else if (mainAssetsAddressable > 0) { if (!GUILayout.Toggle(true, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(aaSettings, targetInfos, false); UnityEngine.GUI.enabled = prevEnabledState; GUIUtility.ExitGUI(); } } else if (GUILayout.Toggle(false, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(aaSettings, targetInfos, true); } if (editor.targets.Length == 1) { if (!entryInfo.IsMainAsset || entryInfo.MainAssetEntry.IsSubAsset) { bool preAddressPrevEnabledState = UnityEngine.GUI.enabled; UnityEngine.GUI.enabled = false; string address = entryInfo.Address + (entryInfo.IsMainAsset ? "" : $"[{entryInfo.TargetObject.name}]"); EditorGUILayout.DelayedTextField(address, GUILayout.ExpandWidth(true)); UnityEngine.GUI.enabled = preAddressPrevEnabledState; } else { string newAddress = EditorGUILayout.DelayedTextField(entryInfo.Address, GUILayout.ExpandWidth(true)); if (newAddress != entryInfo.Address) { if (newAddress.Contains("[") && newAddress.Contains("]")) { Debug.LogErrorFormat("Rename of address '{0}' cannot contain '[ ]'.", entryInfo.Address); } else { entryInfo.MainAssetEntry.address = newAddress; AddressableAssetUtility.OpenAssetIfUsingVCIntegration(entryInfo.MainAssetEntry.parentGroup, true); } } } } else { FindUniqueAssetGuids(targetInfos, out var uniqueAssetGuids, out var uniqueAddressableAssetGuids); EditorGUILayout.LabelField(uniqueAddressableAssetGuids.Count + " out of " + uniqueAssetGuids.Count + " assets are addressable."); } DrawSelectEntriesButton(targetInfos); GUILayout.EndHorizontal(); } else // mixed addressable selected { GUILayout.BeginHorizontal(); if (s_ToggleMixed == null) { s_ToggleMixed = new GUIStyle("ToggleMixed"); } if (GUILayout.Toggle(false, s_AddressableAssetToggleText, s_ToggleMixed, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), targetInfos, true); } FindUniqueAssetGuids(targetInfos, out var uniqueAssetGuids, out var uniqueAddressableAssetGuids); EditorGUILayout.LabelField(uniqueAddressableAssetGuids.Count + " out of " + uniqueAssetGuids.Count + " assets are addressable."); DrawSelectEntriesButton(targetInfos); GUILayout.EndHorizontal(); } UnityEngine.GUI.enabled = prevEnabledState; } }
static void OnPostHeaderGUI(Editor editor) { var aaSettings = AddressableAssetSettingsDefaultObject.Settings; AddressableAssetEntry entry = null; if (editor.targets.Length > 0) { int addressableCount = 0; bool foundValidAsset = false; bool foundAssetGroup = false; foreach (var t in editor.targets) { foundAssetGroup |= t is AddressableAssetGroup; foundAssetGroup |= t is AddressableAssetGroupSchema; if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out var path, out var guid, out var mainAssetType)) { // Is asset if (!BuildUtility.IsEditorAssembly(mainAssetType.Assembly)) { foundValidAsset = true; if (aaSettings != null) { entry = aaSettings.FindAssetEntry(guid); if (entry != null && !entry.IsSubAsset) { addressableCount++; } } } } } if (foundAssetGroup) { GUILayout.BeginHorizontal(); GUILayout.Label("Profile: " + AddressableAssetSettingsDefaultObject.GetSettings(true).profileSettings. GetProfileName(AddressableAssetSettingsDefaultObject.GetSettings(true).activeProfileId)); GUILayout.FlexibleSpace(); if (GUILayout.Button("System Settings", "MiniButton")) { EditorGUIUtility.PingObject(AddressableAssetSettingsDefaultObject.Settings); Selection.activeObject = AddressableAssetSettingsDefaultObject.Settings; } GUILayout.EndHorizontal(); } if (!foundValidAsset) { return; } if (addressableCount == 0) { if (GUILayout.Toggle(false, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), editor.targets, true); } } else if (addressableCount == editor.targets.Length) { GUILayout.BeginHorizontal(); if (!GUILayout.Toggle(true, s_AddressableAssetToggleText, GUILayout.ExpandWidth(false))) { SetAaEntry(aaSettings, editor.targets, false); GUIUtility.ExitGUI(); } if (editor.targets.Length == 1 && entry != null) { string newAddress = EditorGUILayout.DelayedTextField(entry.address, GUILayout.ExpandWidth(true)); if (newAddress != entry.address) { if (newAddress.Contains("[") && newAddress.Contains("]")) { Debug.LogErrorFormat("Rename of address '{0}' cannot contain '[ ]'.", entry.address); } else { entry.address = newAddress; AddressableAssetUtility.OpenAssetIfUsingVCIntegration(entry.parentGroup, true); } } } GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); if (s_ToggleMixed == null) { s_ToggleMixed = new GUIStyle("ToggleMixed"); } if (GUILayout.Toggle(false, s_AddressableAssetToggleText, s_ToggleMixed, GUILayout.ExpandWidth(false))) { SetAaEntry(AddressableAssetSettingsDefaultObject.GetSettings(true), editor.targets, true); } EditorGUILayout.LabelField(addressableCount + " out of " + editor.targets.Length + " assets are addressable."); GUILayout.EndHorizontal(); } if (entry != null) { GUILayout.BeginHorizontal(); GUILayout.Label(s_AddressableAllowLocalToggleText, GUILayout.ExpandWidth(false)); entry.allowLocalMode = (EnumLocalResourceMode)EditorGUILayout.EnumPopup(entry.allowLocalMode, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } } }
public override void OnGUI(Rect fullRect) { if (m_Entries.Count == 0) { return; } int count = -1; if (m_Labels == null) { m_Labels = GetLabelNamesOrderedSelectedFirst(); } var areaRect = new Rect(fullRect.xMin + 3, fullRect.yMin + 3, fullRect.width - 6, fullRect.height - 6); GUILayout.BeginArea(areaRect); GUILayoutUtility.GetRect(areaRect.width, 1); Rect barRect = EditorGUILayout.GetControlRect(); var marginDown = GUILayoutUtility.GetRect(areaRect.width, 1); Rect plusRect = barRect; plusRect.width = plusRect.height; plusRect.x = (barRect.width - plusRect.width) + 4; if (UnityEngine.GUI.Button(plusRect, m_ManageLabelsButtonContent, m_ToolbarButtonStyle)) { EditorWindow.GetWindow <LabelWindow>(true).Intialize(m_Settings); editorWindow.Close(); } Rect searchRect = barRect; float plusOffset = plusRect.width + 2; searchRect.width = searchRect.width - plusOffset; m_SearchValue = m_SearchField.OnGUI(searchRect, m_SearchValue, m_SearchStyles[0], m_SearchStyles[1], m_SearchStyles[2]); EditorGUI.BeginDisabledGroup(true); string labelText; int searchLabelIndex = m_Labels.IndexOf(m_SearchValue); if (searchLabelIndex >= 0) { if (m_LabelCount == null) { count = m_Entries[0].labels.Contains(m_SearchValue) ? m_Entries.Count : 0; } else { m_LabelCount.TryGetValue(m_SearchValue, out count); } labelText = string.Format(count == m_Entries.Count ? k_HintSearchFoundIsEnabled : k_HintSearchFoundIsDisabled, m_SearchValue); } else { labelText = !string.IsNullOrEmpty(m_SearchValue) ? string.Format(k_HintCreateNewLabel, m_SearchValue) : k_HintIdle; } Rect hintRect = EditorGUILayout.GetControlRect(true, m_HintLabelStyle.CalcHeight(new GUIContent(labelText), fullRect.width), m_HintLabelStyle); hintRect.x -= 3; hintRect.width += 6; hintRect.y -= 3; EditorGUI.LabelField(hintRect, new GUIContent(labelText), m_HintLabelStyle); EditorGUI.EndDisabledGroup(); if (Event.current.isKey && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) && m_SearchField.HasFocus()) { if (!string.IsNullOrEmpty(m_SearchValue)) { if (searchLabelIndex >= 0) { if (count != m_Entries.Count) { SetLabelForEntries(m_SearchValue, true); } else { SetLabelForEntries(m_SearchValue, false); } } else { m_Settings.AddLabel(m_SearchValue); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings); SetLabelForEntries(m_SearchValue, true); m_Labels.Insert(0, m_SearchValue); } m_ControlToFocus = m_SearchValue; UnityEngine.GUI.ScrollTo(new Rect(0, searchLabelIndex * 19, 0, 0)); m_SearchValue = ""; m_LastItemCount = -1; Event.current.Use(); GUIUtility.ExitGUI(); editorWindow.Repaint(); } } var scrollViewHeight = areaRect.height - (hintRect.y + hintRect.height + 2); m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, false, false); Vector2 yPositionDrawRange = new Vector2(m_ScrollPosition.y - 19, m_ScrollPosition.y + scrollViewHeight); for (int i = 0; i < m_Labels.Count; ++i) { var labelName = m_Labels[i]; if (!string.IsNullOrEmpty(m_SearchValue)) { if (labelName.IndexOf(m_SearchValue, StringComparison.OrdinalIgnoreCase) < 0) { continue; } } var toggleRect = EditorGUILayout.GetControlRect(GUILayout.Width(m_LabelToggleControlRectWidth), GUILayout.Height(m_LabelToggleControlRectHeight)); if (toggleRect.height > 1) { // only draw toggles if they are in view if (toggleRect.y < yPositionDrawRange.x || toggleRect.y > yPositionDrawRange.y) { continue; } } else { continue; } bool newState; if (m_LabelCount == null) { count = m_Entries[0].labels.Contains(labelName) ? m_Entries.Count : 0; } else { m_LabelCount.TryGetValue(labelName, out count); } bool oldState = count == m_Entries.Count; if (!(count == 0 || count == m_Entries.Count)) { EditorGUI.showMixedValue = true; } UnityEngine.GUI.SetNextControlName(labelName); newState = EditorGUI.ToggleLeft(toggleRect, new GUIContent(labelName), oldState); EditorGUI.showMixedValue = false; if (oldState != newState) { SetLabelForEntries(labelName, newState); } } EditorGUILayout.EndScrollView(); GUILayout.EndArea(); if (Event.current.type == EventType.Repaint && m_Labels != null && m_ControlToFocus != null) { UnityEngine.GUI.FocusControl(m_ControlToFocus); m_ControlToFocus = null; } }