private void EatInvalidChars() { if (this.isRenamingFilename) { Event current = Event.current; if (GUIUtility.keyboardControl == this.m_TextFieldControlID && current.GetTypeForControl(this.m_TextFieldControlID) == EventType.KeyDown) { string text = string.Empty; string invalidFilenameChars = EditorUtility.GetInvalidFilenameChars(); if (invalidFilenameChars.IndexOf(current.character) > -1) { text = "A file name can't contain any of the following characters:\t" + invalidFilenameChars; } if (text != string.Empty) { current.Use(); this.ShowMessage(text); } else { this.RemoveMessage(); } } if (current.type == EventType.Repaint) { Rect screenRect = this.GetScreenRect(); if (!Mathf.Approximately(this.m_LastScreenPosition.x, screenRect.x) || !Mathf.Approximately(this.m_LastScreenPosition.y, screenRect.y)) { this.RemoveMessage(); } this.m_LastScreenPosition = screenRect; } } }
void EatInvalidChars() { if (isRenamingFilename) { Event evt = Event.current; if (GUIUtility.keyboardControl == m_TextFieldControlID && evt.GetTypeForControl(m_TextFieldControlID) == EventType.KeyDown) { string errorMsg = ""; string invalidChars = EditorUtility.GetInvalidFilenameChars(); if (invalidChars.IndexOf(evt.character) > -1) { errorMsg = "A file name can't contain any of the following characters:\t" + invalidChars; } if (errorMsg != "") { evt.Use(); // Eat character: prevents the textfield from inputting this evt.character ShowMessage(errorMsg); } else { RemoveMessage(); } } // Remove tooltip if screenpos of overlay has changed (handles the case where the main window is being moved or docked window // is resized) if (evt.type == EventType.Repaint) { Rect screenPos = GetScreenRect(); if (!Mathf.Approximately(m_LastScreenPosition.x, screenPos.x) || !Mathf.Approximately(m_LastScreenPosition.y, screenPos.y)) { RemoveMessage(); } m_LastScreenPosition = screenPos; } } }
void BottomArea() { // Background GUILayout.BeginVertical(Styles.bottomBarBg); GUILayout.Space(8); GUILayout.BeginHorizontal(); GUILayout.Space(10); EditorGUI.BeginChangeCheck(); m_IncludeDependencies = GUILayout.Toggle(m_IncludeDependencies, Styles.includeDependenciesText); if (EditorGUI.EndChangeCheck()) { RefreshAssetList(); } GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorGUIUtility.TrTextContent("Export..."))) { string invalidChars = EditorUtility.GetInvalidFilenameChars(); var selectedItemWithInvalidChar = m_ExportPackageItems.FirstOrDefault(item => Path.GetFileNameWithoutExtension(item.assetPath).IndexOfAny(invalidChars.ToCharArray()) != -1 && item.enabledStatus > 0); if (selectedItemWithInvalidChar != null && !EditorUtility.DisplayDialog(L10n.Tr("Cross platform incompatibility"), L10n.Tr($"The asset “{Path.GetFileNameWithoutExtension(selectedItemWithInvalidChar.assetPath)}” contains one or more characters that are not compatible across platforms: {invalidChars}"), L10n.Tr("I understand"), L10n.Tr("Cancel"))) { GUIUtility.ExitGUI(); return; } Export(); GUIUtility.ExitGUI(); } GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.EndVertical(); }