Skip to content

Commit 7038d6c

Browse files
author
Unity Technologies
committed
Unity 2019.1.0a1 C# reference source code
1 parent b9bc712 commit 7038d6c

File tree

165 files changed

+3477
-1671
lines changed

Some content is hidden

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

165 files changed

+3477
-1671
lines changed

Editor/Mono/Animation/AnimationMode.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ internal static void StartAnimationRecording()
146146
[NativeThrows]
147147
extern public static void AddPropertyModification(EditorCurveBinding binding, PropertyModification modification, bool keepPrefabOverride);
148148

149+
[NativeThrows]
150+
extern public static void AddEditorCurveBinding([NotNull] GameObject gameObject, EditorCurveBinding binding);
151+
149152
[NativeThrows]
150153
extern internal static void AddTransformTR([NotNull] GameObject root, string path);
151154

Editor/Mono/Animation/AnimationUtility.bindings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ internal static EditorCurveBinding[] GetAnimatableBindings(ScriptableObject scri
143143
return Internal_GetScriptableObjectAnimatableBindings(scriptableObject);
144144
}
145145

146+
internal static EditorCurveBinding[] GetAdditionalAnimatorBindings(GameObject targetObject)
147+
{
148+
return Internal_GetAdditionalAnimatorBindings(targetObject);
149+
}
150+
146151
extern private static EditorCurveBinding[] Internal_GetGameObjectAnimatableBindings([NotNull] GameObject targetObject, [NotNull] GameObject root);
147152
extern private static EditorCurveBinding[] Internal_GetScriptableObjectAnimatableBindings([NotNull] ScriptableObject scriptableObject);
153+
extern private static EditorCurveBinding[] Internal_GetAdditionalAnimatorBindings([NotNull] GameObject targetObject);
148154

149155
// Binds the property and returns the type of the bound value (Can be used to display special UI for it and to enforce correct drag and drop)
150156
// null if it can't be bound.

Editor/Mono/Animation/AnimationWindow/AddCurvesPopup.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,37 @@ namespace UnityEditorInternal
1313
internal class AddCurvesPopup : EditorWindow
1414
{
1515
const float k_WindowPadding = 3;
16+
const float k_SpaceForSlider = 16;
17+
18+
const float k_WindowMaxWidth = 450;
19+
const float k_WindowMinWidth = 240;
20+
const float k_WindowFixedHeight = 250;
1621

1722
internal static AnimationWindowState s_State;
1823

1924
private static AddCurvesPopup s_AddCurvesPopup;
2025
private static long s_LastClosedTime;
2126
private static AddCurvesPopupHierarchy s_Hierarchy;
2227

23-
private static Vector2 windowSize = new Vector2(240, 250);
24-
2528
public delegate void OnNewCurveAdded(AddCurvesPopupPropertyNode node);
2629

2730
private static OnNewCurveAdded NewCurveAddedCallback;
2831

32+
Vector2 GetWindowSize()
33+
{
34+
float contentWidth = s_Hierarchy.GetContentWidth();
35+
float width = Mathf.Clamp(contentWidth + k_SpaceForSlider + k_WindowPadding, k_WindowMinWidth, k_WindowMaxWidth);
36+
return new Vector2(width, k_WindowFixedHeight);
37+
}
38+
2939
void Init(Rect buttonRect)
3040
{
41+
s_Hierarchy = new AddCurvesPopupHierarchy();
42+
s_Hierarchy.InitIfNeeded(this, new Rect(0, 0, k_WindowMinWidth, k_WindowFixedHeight));
43+
3144
buttonRect = GUIUtility.GUIToScreenRect(buttonRect);
32-
ShowAsDropDown(buttonRect, windowSize, new[] { PopupLocation.Right });
45+
46+
ShowAsDropDown(buttonRect, GetWindowSize(), new[] { PopupLocation.Right });
3347
}
3448

3549
void OnEnable()
@@ -77,8 +91,7 @@ internal void OnGUI()
7791
if (Event.current.type == EventType.Layout)
7892
return;
7993

80-
if (s_Hierarchy == null)
81-
s_Hierarchy = new AddCurvesPopupHierarchy();
94+
Vector2 windowSize = GetWindowSize();
8295

8396
Rect rect = new Rect(1, 1, windowSize.x - k_WindowPadding, windowSize.y - k_WindowPadding);
8497
GUI.Box(new Rect(0, 0, windowSize.x, windowSize.y), GUIContent.none, "grey_border");

Editor/Mono/Animation/AnimationWindow/AddCurvesPopupHierarchy.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ internal class AddCurvesPopupHierarchy
1414
private TreeViewState m_TreeViewState;
1515
private AddCurvesPopupHierarchyDataSource m_TreeViewDataSource;
1616

17+
private float m_ContentWidth = 0f;
18+
19+
public float GetContentWidth()
20+
{
21+
return m_ContentWidth;
22+
}
23+
1724
public void OnGUI(Rect position, EditorWindow owner)
1825
{
19-
InitIfNeeded(owner, position);
26+
m_TreeView.SetTotalRect(position);
2027
m_TreeView.OnEvent();
2128
m_TreeView.OnGUI(position, GUIUtility.GetControlID(FocusType.Keyboard));
2229
}
@@ -33,7 +40,7 @@ public void InitIfNeeded(EditorWindow owner, Rect rect)
3340
m_TreeView.deselectOnUnhandledMouseDown = true;
3441

3542
m_TreeViewDataSource = new AddCurvesPopupHierarchyDataSource(m_TreeView);
36-
TreeViewGUI gui = new AddCurvesPopupHierarchyGUI(m_TreeView, owner);
43+
AddCurvesPopupHierarchyGUI gui = new AddCurvesPopupHierarchyGUI(m_TreeView, owner);
3744

3845
m_TreeView.Init(rect,
3946
m_TreeViewDataSource,
@@ -42,6 +49,8 @@ public void InitIfNeeded(EditorWindow owner, Rect rect)
4249
);
4350

4451
m_TreeViewDataSource.UpdateData();
52+
53+
m_ContentWidth = gui.GetContentWidth();
4554
}
4655

4756
internal virtual bool IsRenamingNodeAllowed(TreeViewItem node)

Editor/Mono/Animation/AnimationWindow/AddCurvesPopupHierarchyDataSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private void SetupRootNodeSettings()
3131

3232
public override void FetchData()
3333
{
34+
m_RootItem = null;
3435
if (AddCurvesPopup.s_State.selection.canAddCurves)
3536
{
3637
GameObject rootGameObject = AddCurvesPopup.s_State.activeRootGameObject;

Editor/Mono/Animation/AnimationWindow/AddCurvesPopupHierarchyGUI.cs

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEditor;
66
using UnityEditor.IMGUI.Controls;
77
using UnityEngine;
8+
using System.Collections.Generic;
89

910
namespace UnityEditorInternal
1011
{
@@ -14,6 +15,7 @@ internal class AddCurvesPopupHierarchyGUI : TreeViewGUI
1415
public bool showPlusButton { get; set; }
1516
private GUIStyle plusButtonStyle = "OL Plus";
1617
private GUIStyle plusButtonBackgroundStyle = "Tag MenuItem";
18+
private GUIContent addPropertiesContent = EditorGUIUtility.TrTextContent("Add Properties");
1719
private const float plusButtonWidth = 17;
1820

1921
public AddCurvesPopupHierarchyGUI(TreeViewController treeView, EditorWindow owner)
@@ -25,7 +27,12 @@ public AddCurvesPopupHierarchyGUI(TreeViewController treeView, EditorWindow owne
2527
public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused)
2628
{
2729
base.OnRowGUI(rowRect, node, row, selected, focused);
30+
DoAddCurveButton(rowRect, node);
31+
HandleContextMenu(rowRect, node);
32+
}
2833

34+
private void DoAddCurveButton(Rect rowRect, TreeViewItem node)
35+
{
2936
// Is it propertynode. If not, then we don't need plusButton so quit here
3037
AddCurvesPopupPropertyNode hierarchyNode = node as AddCurvesPopupPropertyNode;
3138
if (hierarchyNode == null || hierarchyNode.curveBindings == null || hierarchyNode.curveBindings.Length == 0)
@@ -41,10 +48,85 @@ public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool sel
4148
if (GUI.Button(buttonRect, GUIContent.none, plusButtonStyle))
4249
{
4350
AddCurvesPopup.AddNewCurve(hierarchyNode);
44-
owner.Close();
51+
52+
// Hold shift key to add new curves and keep window opened.
53+
if (Event.current.shift)
54+
m_TreeView.ReloadData();
55+
else
56+
owner.Close();
4557
}
4658
}
4759

60+
private void HandleContextMenu(Rect rowRect, TreeViewItem node)
61+
{
62+
if (Event.current.type != EventType.ContextClick)
63+
return;
64+
65+
if (rowRect.Contains(Event.current.mousePosition))
66+
{
67+
// Add current node to selection
68+
var ids = new List<int>(m_TreeView.GetSelection());
69+
ids.Add(node.id);
70+
m_TreeView.SetSelection(ids.ToArray(), false, false);
71+
72+
GenerateMenu().ShowAsContext();
73+
Event.current.Use();
74+
}
75+
}
76+
77+
private GenericMenu GenerateMenu()
78+
{
79+
GenericMenu menu = new GenericMenu();
80+
menu.AddItem(addPropertiesContent, false, AddPropertiesFromSelectedNodes);
81+
82+
return menu;
83+
}
84+
85+
private void AddPropertiesFromSelectedNodes()
86+
{
87+
int[] ids = m_TreeView.GetSelection();
88+
for (int i = 0; i < ids.Length; ++i)
89+
{
90+
var node = m_TreeView.FindItem(ids[i]);
91+
var propertyNode = node as AddCurvesPopupPropertyNode;
92+
93+
if (propertyNode != null)
94+
{
95+
AddCurvesPopup.AddNewCurve(propertyNode);
96+
}
97+
else if (node.hasChildren)
98+
{
99+
foreach (var childNode in node.children)
100+
{
101+
var childPropertyNode = childNode as AddCurvesPopupPropertyNode;
102+
if (childPropertyNode != null)
103+
{
104+
AddCurvesPopup.AddNewCurve(childPropertyNode);
105+
}
106+
}
107+
}
108+
}
109+
110+
m_TreeView.ReloadData();
111+
}
112+
113+
public float GetContentWidth()
114+
{
115+
IList<TreeViewItem> rows = m_TreeView.data.GetRows();
116+
List<TreeViewItem> allRows = new List<TreeViewItem>();
117+
allRows.AddRange(rows);
118+
119+
for (int i = 0; i < allRows.Count; ++i)
120+
{
121+
var row = allRows[i];
122+
if (row.hasChildren)
123+
allRows.AddRange(row.children);
124+
}
125+
126+
float rowWidth = GetMaxWidth(allRows);
127+
return rowWidth + plusButtonWidth;
128+
}
129+
48130
override protected void SyncFakeItem()
49131
{
50132
//base.SyncFakeItem();

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,29 +377,38 @@ public void SetShownHRange(float min, float max)
377377

378378
public void SetShownVRangeInsideMargins(float min, float max)
379379
{
380+
float heightInsideMargins = drawRect.height - topmargin - bottommargin;
381+
if (heightInsideMargins < kMinHeight) heightInsideMargins = kMinHeight;
382+
383+
float denum = max - min;
384+
if (denum < kMinHeight) denum = kMinHeight;
385+
380386
if (m_UpDirection == YDirection.Positive)
381387
{
382-
m_Scale.y = -(drawRect.height - topmargin - bottommargin) / (max - min);
388+
m_Scale.y = -heightInsideMargins / denum;
383389
m_Translation.y = drawRect.height - min * m_Scale.y - topmargin;
384390
}
385391
else
386392
{
387-
m_Scale.y = (drawRect.height - topmargin - bottommargin) / (max - min);
393+
m_Scale.y = heightInsideMargins / denum;
388394
m_Translation.y = -min * m_Scale.y - bottommargin;
389395
}
390396
EnforceScaleAndRange();
391397
}
392398

393399
public void SetShownVRange(float min, float max)
394400
{
401+
float denum = max - min;
402+
if (denum < kMinHeight) denum = kMinHeight;
403+
395404
if (m_UpDirection == YDirection.Positive)
396405
{
397-
m_Scale.y = -drawRect.height / (max - min);
406+
m_Scale.y = -drawRect.height / denum;
398407
m_Translation.y = drawRect.height - min * m_Scale.y;
399408
}
400409
else
401410
{
402-
m_Scale.y = drawRect.height / (max - min);
411+
m_Scale.y = drawRect.height / denum;
403412
m_Translation.y = -min * m_Scale.y;
404413
}
405414
EnforceScaleAndRange();

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
[assembly: InternalsVisibleTo("Unity.PackageManagerStandalone")]
2020
[assembly: InternalsVisibleTo("Unity.AndroidBuildPipeline")]
2121
[assembly: InternalsVisibleTo("Unity.Automation")]
22+
[assembly: InternalsVisibleTo("UnityEngine.Common")]
2223
[assembly: InternalsVisibleTo("Unity.PureCSharpTests")]
2324
[assembly: InternalsVisibleTo("Unity.IntegrationTests")]
2425
[assembly: InternalsVisibleTo("Unity.DeploymentTests.Services")]

Editor/Mono/AssetStore/AssetStoreContext.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Linq;
1313
using System.IO;
1414
using UnityEditor.Web;
15+
using UnityEditor.Analytics;
1516

1617
namespace UnityEditor
1718
{
@@ -163,6 +164,15 @@ public void OpenBrowser(string url)
163164
Application.OpenURL(url);
164165
}
165166

167+
[Serializable]
168+
public struct DownloadAssetInfo
169+
{
170+
public string package_id;
171+
public string package_name;
172+
public string publisher_name;
173+
public string category_name;
174+
}
175+
166176
public void Download(Package package, DownloadInfo downloadInfo)
167177
{
168178
Download(
@@ -205,6 +215,13 @@ public static void Download(string package_id, string url, string key, string pa
205215
parameters["download"] = download;
206216

207217
AssetStoreUtils.Download(package_id, url, dest, key, parameters.ToString(), resumeOK, doneCallback);
218+
EditorAnalytics.SendAssetDownloadEvent(new DownloadAssetInfo()
219+
{
220+
package_id = package_id,
221+
package_name = package_name,
222+
publisher_name = publisher_name,
223+
category_name = category_name
224+
});
208225
}
209226

210227
/// <summary>

Editor/Mono/Audio/Mixer/GUI/AudioMixerExposedParameterView.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
106106

107107
public Vector2 CalcSize()
108108
{
109+
if (m_ReorderableListWithRenameAndScrollView.list.count != m_Controller.exposedParameters.Length)
110+
{
111+
RecreateListControl();
112+
}
109113
float maxWidth = 0;
110114
for (int index = 0; index < m_ReorderableListWithRenameAndScrollView.list.count; index++)
111115
{

0 commit comments

Comments
 (0)