private void OnEnable() { m_assetHistory = null; m_isLoadingHistory = false; m_isAssetValid = false; if (m_asset != null) { m_isAssetValid = Locker.IsAssetTypeValid(m_asset); if (m_isAssetValid) { Show(m_asset); } } }
private void OnGUI() { using (var scope = new EditorGUI.ChangeCheckScope()) { m_asset = EditorGUILayout.ObjectField(m_asset, typeof(Object), true); if (scope.changed) { m_assetHistory = null; m_isAssetValid = Locker.IsAssetTypeValid(m_asset); if (m_isAssetValid) { Show(m_asset); } } } var currentEvent = Event.current; if (m_assetHistory == null) { if (m_isLoadingHistory) { EditorGUILayout.LabelField("Loading..."); } else if (m_asset == null) { EditorGUILayout.LabelField("Select an asset to view history"); } else if (!m_isAssetValid) { EditorGUILayout.LabelField("Asset is not a valid lockable asset"); } return; } { var controlRect = EditorGUILayout.GetControlRect(false, 1); EditorGUI.DrawRect(controlRect, Color.gray); } using (var scroll = new EditorGUILayout.ScrollViewScope(m_scrollPosition)) { var repaint = false; DrawSimpleEntry(Container.GetLockSettings().LockIconLarge, DateHeader, LockerHeader, ""); var controlRect = EditorGUILayout.GetControlRect(false, 1); if (m_assetHistory.Length > 0) { var height = EditorGUIUtility.singleLineHeight * m_assetHistory.Length + EditorGUIUtility.standardVerticalSpacing * m_assetHistory.Length; GUI.Box(new Rect(controlRect.x, controlRect.y + EditorGUIUtility.standardVerticalSpacing, controlRect.width, height), "", GUI.skin.box); for (var i = 0; i < m_assetHistory.Length; i++) { var rect = EditorGUILayout.GetControlRect(); var history = m_assetHistory[i]; var hasUnlockSha = !string.IsNullOrEmpty(history.UnlockSha); var icon = history.Locked ? Container.GetLockSettings().LockIconLarge : (hasUnlockSha ? Container.GetLockSettings().LockedNowButUnlockedLaterIconLarge : Container.GetLockSettings().LockedByMeIconLarge); DrawSimpleEntry(rect, icon, history.Date.ToString(), history.LockerName, hasUnlockSha ? "Unlocked at commit " + history.UnlockSha + " (right click to copy)" : ""); if (hasUnlockSha && currentEvent.isMouse && currentEvent.button == 1 && currentEvent.type == EventType.MouseDown && rect.Contains(currentEvent.mousePosition)) { currentEvent.Use(); EditorGUIUtility.systemCopyBuffer = history.UnlockSha; } if (i != m_assetHistory.Length - 1) { EditorGUI.DrawRect(new Rect(rect.x + 1, rect.y + rect.height, rect.width - 2, 1), new Color(0.7f, 0.7f, 0.7f)); } } } m_scrollPosition = scroll.scrollPosition; if (repaint) { Repaint(); } } }