Skip to content

Commit f5b5e86

Browse files
author
Unity Technologies
committed
Unity 2017.2.0b4 C# reference source code
1 parent 64c7252 commit f5b5e86

File tree

69 files changed

+1273
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1273
-589
lines changed

Editor/Mono/BuildPlayerSceneTreeView.cs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@ internal class BuildPlayerSceneTreeViewItem : TreeViewItem
1616

1717
public bool active;
1818
public string fullName;
19+
public GUID guid;
20+
public void UpdateName()
21+
{
22+
var name = AssetDatabase.GUIDToAssetPath(guid.ToString());
23+
if (name != fullName)
24+
{
25+
fullName = name;
26+
27+
displayName = fullName;
28+
if (displayName.StartsWith(kAssetsFolder))
29+
displayName = displayName.Remove(0, kAssetsFolder.Length);
30+
var ext = displayName.LastIndexOf(kSceneExtension);
31+
if (ext > 0)
32+
displayName = displayName.Substring(0, ext);
33+
}
34+
}
35+
1936
public BuildPlayerSceneTreeViewItem(int id, int depth, string path, bool state) : base(id, depth)
2037
{
2138
active = state;
22-
fullName = path;
39+
guid = new GUID(AssetDatabase.AssetPathToGUID(path));
40+
fullName = "";
2341
displayName = path;
24-
if (fullName.StartsWith(kAssetsFolder))
25-
displayName = path.Remove(0, kAssetsFolder.Length);
26-
27-
var ext = displayName.LastIndexOf(kSceneExtension);
28-
if (ext > 0)
29-
displayName = displayName.Substring(0, ext);
42+
UpdateName();
3043
}
3144
}
3245
internal class BuildPlayerSceneTreeView : TreeView
@@ -58,6 +71,13 @@ protected override bool CanBeParent(TreeViewItem item)
5871

5972
protected override void BeforeRowsGUI()
6073
{
74+
foreach (var item in rootItem.children)
75+
{
76+
var bpst = item as BuildPlayerSceneTreeViewItem;
77+
if (bpst != null)
78+
bpst.UpdateName();
79+
}
80+
6181
base.BeforeRowsGUI();
6282
m_ActiveSceneCounter = 0;
6383
}
@@ -70,30 +90,31 @@ protected override void RowGUI(RowGUIArgs args)
7090
var sceneExists = File.Exists(sceneItem.fullName);
7191
using (new EditorGUI.DisabledScope(!sceneExists))
7292
{
93+
var newState = sceneItem.active;
7394
if (!sceneExists)
74-
sceneItem.active = false;
75-
var toggleState = GUI.Toggle(new Rect(args.rowRect.x, args.rowRect.y, 16f, 16f), sceneItem.active, "");
76-
if (toggleState != sceneItem.active)
95+
newState = false;
96+
newState = GUI.Toggle(new Rect(args.rowRect.x, args.rowRect.y, 16f, 16f), newState, "");
97+
if (newState != sceneItem.active)
7798
{
7899
if (GetSelection().Contains(sceneItem.id))
79100
{
80101
var selection = GetSelection();
81102
foreach (var id in selection)
82103
{
83104
var item = FindItem(id, rootItem) as BuildPlayerSceneTreeViewItem;
84-
item.active = toggleState;
105+
item.active = newState;
85106
}
86107
}
87108
else
88109
{
89-
sceneItem.active = toggleState;
110+
sceneItem.active = newState;
90111
}
91112

92113
EditorBuildSettings.scenes = GetSceneList();
93114
}
94115
base.RowGUI(args);
95116

96-
if (toggleState)
117+
if (newState)
97118
{
98119
TreeView.DefaultGUI.LabelRightAligned(args.rowRect, "" + m_ActiveSceneCounter, args.selected, args.focused);
99120
m_ActiveSceneCounter++;

Editor/Mono/Collab/Softlocks/SoftlockViewController.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private void RegisterDrawDelegates()
8989
UnregisterDrawDelegates();
9090
ObjectListArea.postAssetIconDrawCallback += Instance.DrawProjectBrowserGridUI;
9191
ObjectListArea.postAssetLabelDrawCallback += Instance.DrawProjectBrowserListUI;
92+
AssetsTreeViewGUI.postAssetLabelDrawCallback += Instance.DrawSingleColumnProjectBrowserUI;
9293
Editor.OnPostIconGUI += Instance.DrawInspectorUI;
9394
GameObjectTreeViewGUI.OnPostHeaderGUI += Instance.DrawSceneUI;
9495
}
@@ -225,8 +226,7 @@ private void DrawInspectorUI(Editor editor, Rect drawRect)
225226
}
226227

227228
// Assigned callback to ObjectListArea.OnPostAssetDrawDelegate.
228-
// Draws either overtop of the project browser asset (when in grid view) or
229-
// at the rightside when in list view.
229+
// Draws either overtop of the project browser asset (when in grid view).
230230
private void DrawProjectBrowserGridUI(Rect iconRect, string assetGUID, bool isListMode)
231231
{
232232
if (isListMode || !HasSoftlocks(assetGUID))
@@ -243,21 +243,43 @@ private void DrawProjectBrowserGridUI(Rect iconRect, string assetGUID, bool isLi
243243
}
244244
}
245245

246+
// Should draw only in listMode and expects 'drawRect' to be the designed space for the icon,
247+
// and not the entire row.
246248
private bool DrawProjectBrowserListUI(Rect drawRect, string assetGUID, bool isListMode)
247249
{
248-
if (!HasSoftlocks(assetGUID))
250+
if (!isListMode || !HasSoftlocks(assetGUID))
249251
{
250252
return false;
251253
}
252254

255+
// center icon.
256+
Rect iconRect = drawRect;
257+
iconRect.width = drawRect.height;
258+
iconRect.x = (float)Math.Round(drawRect.center.x - (iconRect.width / 2F));
259+
return DrawInProjectBrowserListMode(iconRect, assetGUID);
260+
}
261+
262+
// Expects 'drawRect' to be the available width of the row.
263+
private bool DrawSingleColumnProjectBrowserUI(Rect drawRect, string assetGUID)
264+
{
265+
if (ProjectBrowser.s_LastInteractedProjectBrowser.IsTwoColumns() || !HasSoftlocks(assetGUID))
266+
{
267+
return false;
268+
}
269+
270+
Rect iconRect = drawRect;
271+
iconRect.width = drawRect.height;
272+
float spacingFromEnd = (iconRect.width / 2F);
273+
iconRect.x = (float)Math.Round(drawRect.xMax - iconRect.width - spacingFromEnd);
274+
return DrawInProjectBrowserListMode(iconRect, assetGUID);
275+
}
276+
277+
private bool DrawInProjectBrowserListMode(Rect iconRect, string assetGUID)
278+
{
253279
Texture icon = SoftLockUIData.GetIconForSection(SoftLockUIData.SectionEnum.ProjectBrowser);
254280
bool didDraw = false;
255281
if (icon != null)
256282
{
257-
// center icon.
258-
Rect iconRect = drawRect;
259-
iconRect.width = drawRect.height;
260-
iconRect.x = (float)Math.Round(drawRect.center.x - (iconRect.width / 2F));
261283
DrawIconWithTooltips(iconRect, icon, assetGUID);
262284
didDraw = true;
263285
}

Editor/Mono/GUI/DockArea.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,6 @@ public bool PerformDrop(EditorWindow w, DropInfo info, Vector2 screenPos)
248248
return true;
249249
}
250250

251-
// without leaving this in here for HostView.Invoke(), commands are not delegated (e.g., keyboard-based delete in Hierarchy/Project)
252-
void OnGUI()
253-
{}
254-
255251
protected override void OldOnGUI()
256252
{
257253
ClearBackground();

Editor/Mono/GUI/FlexibleMenu/FlexibleMenu.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ class Styles
2424
int m_ShowEditWindowForIndex = -1;
2525
int m_HoverIndex;
2626
int[] m_SeperatorIndices;
27-
float m_MaxTextWidth = -1f;
27+
float m_CachedWidth = -1f;
28+
float m_MinTextWidth = 200f;
2829

2930
const float lineHeight = 18f;
3031
const float seperatorHeight = 8f;
3132
const float leftMargin = 25f;
3233
int maxIndex { get { return m_ShowAddNewPresetItem ? m_ItemProvider.Count() : m_ItemProvider.Count() - 1; } }
3334
public int selectedIndex { get; set; }
35+
protected float minTextWidth { get { return m_MinTextWidth; } set { m_MinTextWidth = value; ClearCachedWidth(); } }
3436

3537
// itemClickedCallback arguments is clicked index, clicked item object
3638
public FlexibleMenu(IFlexibleMenuItemProvider itemProvider, int selectionIndex, FlexibleMenuModifyItemUI modifyItemUi, Action<int, object> itemClickedCallback)
@@ -193,14 +195,14 @@ void SelectItem(int index)
193195
protected Vector2 CalcSize()
194196
{
195197
float height = (maxIndex + 1) * lineHeight + m_SeperatorIndices.Length * seperatorHeight;
196-
if (m_MaxTextWidth < 0)
197-
m_MaxTextWidth = Math.Max(200f, CalcWidth());
198-
return new Vector2(m_MaxTextWidth, height);
198+
if (m_CachedWidth < 0)
199+
m_CachedWidth = Math.Max(m_MinTextWidth, CalcWidth());
200+
return new Vector2(m_CachedWidth, height);
199201
}
200202

201203
void ClearCachedWidth()
202204
{
203-
m_MaxTextWidth = -1f;
205+
m_CachedWidth = -1f;
204206
}
205207

206208
float CalcWidth()

Editor/Mono/GUI/TreeView/AssetsTreeViewGUI.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using UnityEngine;
88
using UnityEditorInternal.VersionControl;
99
using UnityEditor.VersionControl;
10+
using System.Collections.Generic;
11+
using UnityEngine.Assertions;
1012

1113
namespace UnityEditor
1214
{
@@ -18,10 +20,16 @@ internal class AssetsTreeViewGUI : TreeViewGUI
1820
internal delegate void OnAssetIconDrawDelegate(Rect iconRect, string guid);
1921
internal static event OnAssetIconDrawDelegate postAssetIconDrawCallback = null;
2022

23+
internal delegate bool OnAssetLabelDrawDelegate(Rect drawRect, string guid);
24+
internal static event OnAssetLabelDrawDelegate postAssetLabelDrawCallback = null;
25+
26+
private static IDictionary<int, string> s_GUIDCache = null;
27+
2128
public AssetsTreeViewGUI(TreeViewController treeView)
2229
: base(treeView)
2330
{
2431
iconOverlayGUI += OnIconOverlayGUI;
32+
labelOverlayGUI += OnLabelOverlayGUI;
2533
k_TopRowMargin = 4f;
2634
}
2735

@@ -131,19 +139,47 @@ private void OnIconOverlayGUI(TreeViewItem item, Rect overlayRect)
131139
{
132140
if (postAssetIconDrawCallback != null && AssetDatabase.IsMainAsset(item.id))
133141
{
134-
string path = AssetDatabase.GetAssetPath(item.id);
135-
string guid = AssetDatabase.AssetPathToGUID(path);
142+
string guid = GetGUIDForInstanceID(item.id);
136143
postAssetIconDrawCallback(overlayRect, guid);
137144
}
138145

139146
// Draw vcs icons
140147
if (s_VCEnabled && AssetDatabase.IsMainAsset(item.id))
141148
{
142-
string path = AssetDatabase.GetAssetPath(item.id);
143-
string guid = AssetDatabase.AssetPathToGUID(path);
149+
string guid = GetGUIDForInstanceID(item.id);
144150
ProjectHooks.OnProjectWindowItem(guid, overlayRect);
145151
}
146152
}
153+
154+
private void OnLabelOverlayGUI(TreeViewItem item, Rect labelRect)
155+
{
156+
if (postAssetLabelDrawCallback != null && AssetDatabase.IsMainAsset(item.id))
157+
{
158+
string guid = GetGUIDForInstanceID(item.id);
159+
postAssetLabelDrawCallback(labelRect, guid);
160+
}
161+
}
162+
163+
// Returns a previously stored GUID for the given ID,
164+
// else retrieves it from the asset database and stores it.
165+
private static string GetGUIDForInstanceID(int instanceID)
166+
{
167+
if (s_GUIDCache == null)
168+
{
169+
s_GUIDCache = new Dictionary<int, string>();
170+
}
171+
172+
string GUID = null;
173+
if (!s_GUIDCache.TryGetValue(instanceID, out GUID))
174+
{
175+
string path = AssetDatabase.GetAssetPath(instanceID);
176+
GUID = AssetDatabase.AssetPathToGUID(path);
177+
Assert.IsTrue(!string.IsNullOrEmpty(GUID));
178+
s_GUIDCache.Add(instanceID, GUID);
179+
}
180+
181+
return GUID;
182+
}
147183
}
148184

149185

Editor/Mono/GUI/TreeView/TreeViewGUI.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal abstract class TreeViewGUI : ITreeViewGUI
2020
public float iconRightPadding { get; set; }
2121
public float iconTotalPadding { get { return iconLeftPadding + iconRightPadding; } }
2222
public System.Action<TreeViewItem, Rect> iconOverlayGUI { get; set; } // Rect includes iconLeftPadding and iconRightPadding
23+
public System.Action<TreeViewItem, Rect> labelOverlayGUI { get; set; }
2324

2425
private bool m_AnimateScrollBarOnExpandCollapse = true;
2526

@@ -382,6 +383,11 @@ protected virtual void OnContentGUI(Rect rect, int row, TreeViewItem item, strin
382383
if (icon != null)
383384
rect.xMin += k_IconWidth + iconTotalPadding + k_SpaceBetweenIconAndText;
384385
lineStyle.Draw(rect, label, false, false, selected, focused);
386+
387+
if (labelOverlayGUI != null)
388+
{
389+
labelOverlayGUI(item, rect);
390+
}
385391
}
386392

387393
// Ping Item

Editor/Mono/GUIView.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ protected virtual void OnDisable()
176176
visualTree.RemoveChild(imguiContainer);
177177
}
178178

179-
protected virtual void OldOnGUI()
180-
{
181-
}
179+
protected virtual void OldOnGUI() {}
180+
// Without leaving this in here for MonoBehaviour::DoGUI(), GetMethod(MonoScriptCache::kGUI) will return null.
181+
// In that case, commands are not delegated (e.g., keyboard-based delete in Hierarchy/Project)
182+
protected virtual void OnGUI() {}
182183

183184
protected override void SetPosition(Rect newPos)
184185
{

0 commit comments

Comments
 (0)