14 changes: 7 additions & 7 deletions Editor/Mono/Inspector/GenericInspector.cs
Expand Up @@ -64,9 +64,9 @@ internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out fl
while (property.NextVisible(childrenAreExpanded))
{
var handler = ScriptAttributeUtility.GetHandler(property);
height += handler.GetHeight(property, null, false) + EditorGUI.kControlVerticalSpacing;

childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
var hasPropertyDrawer = handler.propertyDrawer != null;
height += handler.GetHeight(property, null, hasPropertyDrawer) + EditorGUI.kControlVerticalSpacing;
childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);
}

m_LastHeight = height;
Expand Down Expand Up @@ -99,16 +99,16 @@ internal override bool OnOptimizedInspectorGUI(Rect contentRect)
while (property.NextVisible(childrenAreExpanded))
{
var handler = ScriptAttributeUtility.GetHandler(property);
contentRect.height = handler.GetHeight(property, null, false);
var hasPropertyDrawer = handler.propertyDrawer != null;
childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property);
contentRect.height = handler.GetHeight(property, null, hasPropertyDrawer);

if (contentRect.Overlaps(visibleRect))
{
EditorGUI.indentLevel = property.depth;
using (new EditorGUI.DisabledScope(isInspectorModeNormal && "m_Script" == property.propertyPath))
childrenAreExpanded = handler.OnGUI(contentRect, property, null, false, visibleRect) && property.isExpanded;
childrenAreExpanded &= handler.OnGUI(contentRect, property, null, false, visibleRect);
}
else
childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing;
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/Mono/Inspector/InspectorWindow.cs
Expand Up @@ -1454,7 +1454,7 @@ public static VersionControlBarButtonPresence Calculate(Editor assetEditor, Asse

res.revert = Provider.RevertIsValid(assetList, RevertMode.Normal);
res.revertUnchanged = Provider.RevertIsValid(assetList, RevertMode.Unchanged);
res.checkout = !Editor.IsAppropriateFileOpenForEdit(assetEditor.target);
res.checkout = isFolder || Provider.CheckoutIsValid(assetList, CheckoutMode.Both);
res.add = !isFolder && Provider.AddIsValid(assetList);
res.submit = Provider.SubmitIsValid(null, assetList);
res.@lock = !isFolder && Provider.LockIsValid(assetList);
Expand Down
68 changes: 68 additions & 0 deletions Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs
Expand Up @@ -64,6 +64,15 @@ internal class GeneralProperties
public static readonly GUIContent enableAlphaNumericSorting = EditorGUIUtility.TrTextContent("Enable Alphanumeric Sorting");
public static readonly GUIContent asyncShaderCompilation = EditorGUIUtility.TrTextContent("Asynchronous Shader Compilation");
public static readonly GUIContent codeCoverageEnabled = EditorGUIUtility.TrTextContent("Enable Code Coverage", "Check this to enable Code Coverage. Code Coverage lets you see how much of your code is executed when it is run. Note that Code Coverage lowers Editor performance.");
public static readonly GUIContent applicationFrameThrottling = EditorGUIUtility.TrTextContent("Frame throttling (milliseconds)", "Number of milliseconds to wait between each editor frames.");
public static readonly GUIContent interactionMode = EditorGUIUtility.TrTextContent("Interaction Mode", "Define how the editor application gets updated and throttled.");
public static readonly GUIContent[] interactionModes =
{
EditorGUIUtility.TrTextContent("Default", "The editor application will be throttled up to 4 ms per frame."),
EditorGUIUtility.TrTextContent("No throttling", "The editor application will not be throttled and run as fast as possible."),
EditorGUIUtility.TrTextContent("Monitor Refresh Rate", "The editor will wait up to the monitor refresh rate in milliseconds (i.e. ~16 ms)."),
EditorGUIUtility.TrTextContent("Custom", "Specify how many milliseconds at most the application will be idle per frame."),
};
}

internal class ExternalProperties
Expand Down Expand Up @@ -599,6 +608,65 @@ private void ShowGeneral(string searchContext)
{
ProjectBrowser.ShowAssetStoreHitsWhileSearchingLocalAssetsChanged();
}

DrawInteractionModeOptions();
}

enum InteractionMode
{
Default, // 4 ms
NoThrottling, // 0 ms (will never idle)
MonitorRefreshRate, // ~16 ms
Custom // Between 1 ms and 33 ms
}

private void DrawInteractionModeOptions()
{
const int defaultIdleTimeMs = 4;
int monitorRefreshDelayMs = (int)(1f / Math.Max(Screen.currentResolution.refreshRate, 1) * 1000f);
const string idleTimePrefKeyName = "ApplicationIdleTime";
const string interactionModePrefKeyName = "InteractionMode";
var idleTimeMs = EditorPrefs.GetInt(idleTimePrefKeyName, defaultIdleTimeMs);
var interactionModeOption = (InteractionMode)EditorPrefs.GetInt(interactionModePrefKeyName, (int)InteractionMode.Default);

if (Event.current.type == EventType.MouseDown)
GeneralProperties.interactionModes[(int)InteractionMode.MonitorRefreshRate].text = $"Monitor Refresh Rate ({monitorRefreshDelayMs} ms)";

EditorGUI.BeginChangeCheck();
interactionModeOption = (InteractionMode)EditorGUILayout.Popup(GeneralProperties.interactionMode, (int)interactionModeOption, GeneralProperties.interactionModes);
if (interactionModeOption == InteractionMode.Default)
{
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.DeleteKey(idleTimePrefKeyName);
EditorPrefs.DeleteKey(interactionModePrefKeyName);
}
}
else if (interactionModeOption == InteractionMode.NoThrottling)
{
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetInt(idleTimePrefKeyName, 0);
EditorPrefs.SetInt(interactionModePrefKeyName, (int)interactionModeOption);
}
}
else if (interactionModeOption == InteractionMode.MonitorRefreshRate)
{
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetInt(idleTimePrefKeyName, monitorRefreshDelayMs);
EditorPrefs.SetInt(interactionModePrefKeyName, (int)interactionModeOption);
}
}
else
{
idleTimeMs = EditorGUILayout.IntSlider(GeneralProperties.applicationFrameThrottling, idleTimeMs, 0, 33);
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetInt(idleTimePrefKeyName, idleTimeMs);
EditorPrefs.SetInt(interactionModePrefKeyName, (int)interactionModeOption);
}
}
}

public void ApplyChangesToPrefs(bool force = false)
Expand Down
4 changes: 2 additions & 2 deletions Editor/Mono/SceneHierarchy.cs
Expand Up @@ -854,9 +854,9 @@ public void GameObjectCreateDropdownButton()
GUIUtility.hotControl = 0;

GenericMenu menu = new GenericMenu();
var context = m_CustomParentForNewGameObjects != null ? new[] { m_CustomParentForNewGameObjects.gameObject } : null;
var targetSceneHandle = m_CustomParentForNewGameObjects != null ? m_CustomParentForNewGameObjects.gameObject.scene.handle : kInvalidSceneHandle;
AddCreateGameObjectItemsToMenu(menu, context, true, false, targetSceneHandle);
// The context should be null, just like it is in the main menu. Case 1185434.
AddCreateGameObjectItemsToMenu(menu, null, true, false, targetSceneHandle);
menu.DropDown(rect);

Event.current.Use();
Expand Down
2 changes: 2 additions & 0 deletions Editor/Mono/SceneView/SceneView.cs
Expand Up @@ -2331,6 +2331,8 @@ protected virtual void OnGUI()
Tools.InvalidateHandlePosition(); // Some cases that should invalidate the cached position are not handled correctly yet so we refresh it once per frame
}

sceneViewGrids.UpdateGridColor();

Color origColor = GUI.color;
Rect origCameraRect = m_Camera.rect;
Rect windowSpaceCameraRect = cameraRect;
Expand Down
7 changes: 6 additions & 1 deletion Editor/Mono/SceneView/SceneViewGrid.cs
Expand Up @@ -202,9 +202,14 @@ internal Grid activeGrid
}
}

internal void OnEnable(SceneView view)
internal void UpdateGridColor()
{
xGrid.color = yGrid.color = zGrid.color = kViewGridColor;
}

internal void OnEnable(SceneView view)
{
UpdateGridColor();

GridSettings.sizeChanged += GridSizeChanged;

Expand Down
33 changes: 18 additions & 15 deletions Editor/Mono/SceneVisibilityHierarchyGUI.cs
Expand Up @@ -101,6 +101,9 @@ public static void DrawBackground(Rect rect)

public static void DoItemGUI(Rect rect, GameObjectTreeViewItem goItem, bool isSelected, bool isHovered, bool isFocused, bool isDragging)
{
if (Event.current.isKey || Event.current.type == EventType.Layout)
return;

Rect iconRect = rect;
iconRect.xMin += k_VisibilityIconPadding;
iconRect.width = k_IconWidth;
Expand Down Expand Up @@ -147,25 +150,25 @@ public static void DoItemGUI(Rect rect, GameObjectTreeViewItem goItem, bool isSe

private static void DrawItemBackground(Rect rect, bool isScene, bool isSelected, bool isHovered, bool isFocused)
{
if (Event.current.type == EventType.Repaint)
{
rect.width = utilityBarWidth;
if (Event.current.type != EventType.Repaint)
return;

if (isScene)
rect.width = utilityBarWidth;

if (isScene)
{
if (isSelected)
{
if (isSelected)
{
TreeViewGUI.Styles.selectionStyle.Draw(rect, false, false, true, isFocused);
}
TreeViewGUI.Styles.selectionStyle.Draw(rect, false, false, true, isFocused);
}
else
}
else
{
using (new GUI.BackgroundColorScope(Styles.GetItemBackgroundColor(isHovered, isSelected, isFocused))
)
{
using (new GUI.BackgroundColorScope(Styles.GetItemBackgroundColor(isHovered, isSelected, isFocused))
)
{
GUI.Label(rect, GUIContent.none,
GameObjectTreeViewGUI.GameObjectStyles.hoveredItemBackgroundStyle);
}
GUI.Label(rect, GUIContent.none,
GameObjectTreeViewGUI.GameObjectStyles.hoveredItemBackgroundStyle);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Modules/IMGUI/DrawStates.cs
Expand Up @@ -22,10 +22,8 @@ public DrawStates(int controlId, bool isHover, bool isActive, bool on, bool hasK

hasTextInput = false;
drawSelectionAsComposition = false;
cursorFirst = -1;
cursorLast = -1;
cursorColor = Color.red;
selectionColor = Color.red;
cursorFirst = cursorLast = -1;
selectionColor = cursorColor = Color.red;
}

public DrawStates(int controlId, bool isHover, bool isActive, bool on, bool hasKeyboardFocus,
Expand Down
675 changes: 608 additions & 67 deletions Modules/StyleSheetsEditor/StyleCatalog.cs

Large diffs are not rendered by default.

236 changes: 151 additions & 85 deletions Modules/StyleSheetsEditor/StylePainter.cs

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Modules/Tilemap/Managed/Tilemap.cs
Expand Up @@ -10,7 +10,7 @@ namespace UnityEngine.Tilemaps
{
public partial class Tilemap
{
internal static event Action<Tilemap, SyncTile[]> tilemapTileChanged;
public static event Action<Tilemap, SyncTile[]> tilemapTileChanged;

private Dictionary<Vector3Int, SyncTile> m_SyncTileBuffer;
private Dictionary<Vector3Int, SyncTile> syncTileBuffer
Expand Down Expand Up @@ -51,7 +51,15 @@ private void HandleSyncTileCallback(SyncTile[] syncTiles)

private void SendTilemapTileChangedCallback(SyncTile[] syncTiles)
{
Tilemap.tilemapTileChanged(this, syncTiles);
try
{
Tilemap.tilemapTileChanged(this, syncTiles);
}
catch (Exception e)
{
// Case 1215834: Log user exception/s and ensure engine code continues to run
Debug.LogException(e, this);
}
}

internal static void SetSyncTileCallback(Action<Tilemap, SyncTile[]> callback)
Expand Down
23 changes: 19 additions & 4 deletions Modules/Tilemap/ScriptBindings/Tilemap.bindings.cs
Expand Up @@ -266,11 +266,26 @@ public void EditorPreviewBoxFill(Vector3Int position, Object tile, int startX, i
public extern void ClearAllEditorPreviewTiles();

[RequiredByNativeCode]
internal struct SyncTile
public struct SyncTile
{
public Vector3Int m_Position;
public TileBase m_Tile;
public TileData m_TileData;
internal Vector3Int m_Position;
internal TileBase m_Tile;
internal TileData m_TileData;

public Vector3Int position
{
get { return m_Position; }
}

public TileBase tile
{
get { return m_Tile; }
}

public TileData tileData
{
get { return m_TileData; }
}
}

[RequiredByNativeCode]
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
## Unity 2019.3.7f1 C# reference source code
## Unity 2019.3.8f1 C# reference source code

The C# part of the Unity engine and editor source code.
May be used for reference purposes only.
Expand Down
9 changes: 6 additions & 3 deletions Runtime/Export/Scripting/UnitySynchronizationContext.cs
Expand Up @@ -79,10 +79,13 @@ private void Exec()
m_AsyncWorkQueue.Clear();
}

foreach (var work in m_CurrentFrameWork)
// When you invoke work, remove it from the list to stop it being triggered again (case 1213602)
while (m_CurrentFrameWork.Count > 0)
{
WorkRequest work = m_CurrentFrameWork[0];
m_CurrentFrameWork.Remove(work);
work.Invoke();

m_CurrentFrameWork.Clear();
}
}

private bool HasPendingTasks()
Expand Down
83 changes: 79 additions & 4 deletions Runtime/Export/Shaders/Shader.bindings.cs
Expand Up @@ -136,10 +136,85 @@ public partial class Material : Object

extern public Shader shader { get; set; }

public Color color { get { return GetColor("_Color"); } set { SetColor("_Color", value); } }
public Texture mainTexture { get { return GetTexture("_MainTex"); } set { SetTexture("_MainTex", value); } }
public Vector2 mainTextureOffset { get { return GetTextureOffset("_MainTex"); } set { SetTextureOffset("_MainTex", value); } }
public Vector2 mainTextureScale { get { return GetTextureScale("_MainTex"); } set { SetTextureScale("_MainTex", value); } }
public Color color
{
get
{
// Try to find property with [MainColor] attribute and use that, otherwise fallback to old hardcoded one.
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainColor);
if (nameId >= 0)
return GetColor(nameId);
else
return GetColor("_Color");
}
set
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainColor);
if (nameId >= 0)
SetColor(nameId, value);
else
SetColor("_Color", value);
}
}
public Texture mainTexture
{
get
{
// Try to find property with [MainTexture] attribute and use that, otherwise fallback to old hardcoded one.
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
return GetTexture(nameId);
else
return GetTexture("_MainTex");
}
set
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
SetTexture(nameId, value);
else
SetTexture("_MainTex", value);
}
}
public Vector2 mainTextureOffset
{
get
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
return GetTextureOffset(nameId);
else
return GetTextureOffset("_MainTex");
}
set
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
SetTextureOffset(nameId, value);
else
SetTextureOffset("_MainTex", value);
}
}
public Vector2 mainTextureScale
{
get
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
return GetTextureScale(nameId);
else
return GetTextureScale("_MainTex");
}
set
{
int nameId = GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags.MainTexture);
if (nameId >= 0)
SetTextureScale(nameId, value);
else
SetTextureScale("_MainTex", value);
}
}
[NativeName("GetFirstPropertyNameIdByAttributeFromScript")] extern private int GetFirstPropertyNameIdByAttribute(ShaderPropertyFlags attributeFlag);

[NativeName("HasPropertyFromScript")] extern public bool HasProperty(int nameID);
public bool HasProperty(string name) { return HasProperty(Shader.PropertyToID(name)); }
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Export/Shaders/ShaderProperties.cs
Expand Up @@ -30,6 +30,8 @@ public enum ShaderPropertyFlags
HDR = 1 << 4,
Gamma = 1 << 5,
NonModifiableTextureData = 1 << 6,
MainTexture = 1 << 7,
MainColor = 1 << 8,
}
}

Expand Down