Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity 2018.3.0b1 C# reference source code #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Unity 2018.3.0b1 C# reference source code
Unity Technologies committed Sep 11, 2018
commit 73f36bfe71b68d241a6802e0396dc6d6822cb520
17 changes: 17 additions & 0 deletions Editor/Mono/AssetStore/AssetStoreContext.cs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
using System.Linq;
using System.IO;
using UnityEditor.Web;
using UnityEditor.Analytics;

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

[Serializable]
public struct DownloadAssetInfo
{
public string package_id;
public string package_name;
public string publisher_name;
public string category_name;
}

public void Download(Package package, DownloadInfo downloadInfo)
{
Download(
@@ -205,6 +215,13 @@ public static void Download(string package_id, string url, string key, string pa
parameters["download"] = download;

AssetStoreUtils.Download(package_id, url, dest, key, parameters.ToString(), resumeOK, doneCallback);
EditorAnalytics.SendAssetDownloadEvent(new DownloadAssetInfo()
{
package_id = package_id,
package_name = package_name,
publisher_name = publisher_name,
category_name = category_name
});
}

/// <summary>
4 changes: 4 additions & 0 deletions Editor/Mono/Audio/Mixer/GUI/AudioMixerExposedParameterView.cs
Original file line number Diff line number Diff line change
@@ -106,6 +106,10 @@ void DrawElement(Rect rect, int index, bool isActive, bool isFocused)

public Vector2 CalcSize()
{
if (m_ReorderableListWithRenameAndScrollView.list.count != m_Controller.exposedParameters.Length)
{
RecreateListControl();
}
float maxWidth = 0;
for (int index = 0; index < m_ReorderableListWithRenameAndScrollView.list.count; index++)
{
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ internal static void Popup(AudioMixerController controller, GUIStyle style, para
Rect buttonRect = GUILayoutUtility.GetRect(content, style, options);
if (EditorGUI.DropdownButton(buttonRect, content, FocusType.Passive, style))
{
PopupWindow.Show(buttonRect, new AudioMixerExposedParametersPopup(controller), null, ShowMode.PopupMenuWithKeyboardFocus);
PopupWindow.Show(buttonRect, new AudioMixerExposedParametersPopup(controller));
}
}

2 changes: 1 addition & 1 deletion Editor/Mono/BuildPipeline/AssemblyStripper.cs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
args.AddRange(additionalBlacklist.Select(path => "-x \"" + path + "\""));

args.AddRange(searchDirs.Select(d => "-d \"" + d + "\""));
args.AddRange(assemblies.Select(assembly => "-a \"" + Path.GetFullPath(assembly) + "\""));
args.AddRange(assemblies.Select(assembly => "--include-unity-root-assembly=\"" + Path.GetFullPath(assembly) + "\""));
args.Add($"--dotnetruntime={GetRuntimeArgumentValueForLinker(buildTargetGroup)}");
args.Add($"--dotnetprofile={GetProfileArgumentValueForLinker(buildTargetGroup)}");
args.Add("--use-editor-options");
5 changes: 5 additions & 0 deletions Editor/Mono/Collab/Collab.bindings.cs
Original file line number Diff line number Diff line change
@@ -206,12 +206,17 @@ public extern void TestClearSoftLockAsCollaborator(string projectGuid, string pr
[NativeMethod(HasExplicitThis = true, ThrowsException = true, IsThreadSafe = true)]
extern void SetChangesToPublishInternal(ChangeItem[] changes);

[NativeMethod(HasExplicitThis = true, ThrowsException = true, IsThreadSafe = true)]
extern Change[] GetSelectedChangesInternal();

[NativeMethod(Name = "GetJobProgress", HasExplicitThis = true, ThrowsException = true)]
extern bool GetJobProgressInternal([Out] ProgressInfo info, int jobId);

[NativeMethod(HasExplicitThis = true, ThrowsException = true)]
public extern void Publish(string comment, bool useSelectedAssets, bool confirmMatchesPrevious);

[NativeMethod(HasExplicitThis = true, ThrowsException = true, IsThreadSafe = true)]
public extern void ClearSelectedChangesToPublish();

[NativeMethod(HasExplicitThis = true, ThrowsException = true)]
public extern SoftLock[] GetSoftLocks(string assetGuid);
10 changes: 8 additions & 2 deletions Editor/Mono/Collab/Collab.cs
Original file line number Diff line number Diff line change
@@ -364,11 +364,17 @@ public bool SetConflictsResolvedTheirs(string[] paths)

public PublishInfo GetChangesToPublish()
{
Change[] changes = GetChangesToPublishInternal();
Change[] changes = GetSelectedChangesInternal();
bool isFiltered = false;
if (Toolbar.isLastShowRequestPartial)
{
isFiltered = true;
}

return new PublishInfo()
{
changes = changes,
filter = false
filter = isFiltered
};
}

7 changes: 6 additions & 1 deletion Editor/Mono/Commands/GOCreationCommands.cs
Original file line number Diff line number Diff line change
@@ -52,7 +52,12 @@ static void CreateEmptyChild(MenuCommand menuCommand)
{
var parent = menuCommand.context as GameObject;
if (parent == null)
parent = Selection.activeGameObject;
{
var activeGO = Selection.activeGameObject;
if (activeGO != null && !EditorUtility.IsPersistent(activeGO))
parent = activeGO;
}

var go = ObjectFactory.CreateGameObject("GameObject");
Place(go, parent);
}
6 changes: 3 additions & 3 deletions Editor/Mono/ContainerWindow.bindings.cs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ internal enum ShowMode
{
// Show as a normal window with max, min & close buttons.
NormalWindow = 0,
// Used for a popup menu and tooltip. On mac this means light shadow and no titlebar.
// Used for a popup menu. On mac this means light shadow and no titlebar.
PopupMenu = 1,
// Utility window - floats above the app. Disappears when app loses focus.
Utility = 2,
@@ -22,8 +22,8 @@ internal enum ShowMode
MainWindow = 4,
// Aux windows. The ones that close the moment you move the mouse out of them.
AuxWindow = 5,
// Like PopupMenu, but allows keyboard focus (e.g. AddComponentWindow)
PopupMenuWithKeyboardFocus = 6
// Like PopupMenu, but without keyboard focus
Tooltip = 6
}

//[StaticAccessor("ContainerWindowBindings", StaticAccessorType.DoubleColon)]
14 changes: 12 additions & 2 deletions Editor/Mono/ContainerWindow.cs
Original file line number Diff line number Diff line change
@@ -59,14 +59,24 @@ internal void __internalAwake()

internal static bool IsPopup(ShowMode mode)
{
return (ShowMode.PopupMenu == mode || ShowMode.PopupMenuWithKeyboardFocus == mode);
return (ShowMode.PopupMenu == mode);
}

internal bool isPopup { get { return IsPopup((ShowMode)m_ShowMode); } }

internal void ShowPopup()
{
m_ShowMode = (int)ShowMode.PopupMenu;
ShowPopupWithMode(ShowMode.PopupMenu);
}

internal void ShowTooltip()
{
ShowPopupWithMode(ShowMode.Tooltip);
}

internal void ShowPopupWithMode(ShowMode mode)
{
m_ShowMode = (int)mode;
Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);
if (m_RootView)
m_RootView.SetWindowRecurse(this);
11 changes: 11 additions & 0 deletions Editor/Mono/EditorApplication.cs
Original file line number Diff line number Diff line change
@@ -187,6 +187,9 @@ public static void DirtyHierarchyWindowSorting()
// Global key up/down event that was not handled by anyone
internal static CallbackFunction globalEventHandler;

// Returns true when the pressed keys are defined in the Trigger
internal static Func<bool> doPressedKeysTriggerAnyShortcut;

// Windows were reordered
internal static CallbackFunction windowsReordered;

@@ -313,6 +316,14 @@ static void Internal_CallWindowsReordered()
windowsReordered();
}

[RequiredByNativeCode]
static bool DoPressedKeysTriggerAnyShortcutHandler()
{
if (doPressedKeysTriggerAnyShortcut != null)
return doPressedKeysTriggerAnyShortcut();
return false;
}

[RequiredByNativeCode]
static void Internal_CallGlobalEventHandler()
{
65 changes: 50 additions & 15 deletions Editor/Mono/EditorGUI.cs
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
using UnityEditor.Build;
using UnityEditor.StyleSheets;
using UnityEngine.Internal;
using UnityEngine.Rendering;
using DescriptionAttribute = System.ComponentModel.DescriptionAttribute;

namespace UnityEditor
@@ -1050,6 +1051,7 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
// Note, OS X send characters for the following keys that we need to eat:
// ASCII 25: "End Of Medium" on pressing shift tab
// ASCII 27: "Escape" on pressing ESC
nonPrintableTab = true;
}
else if (editor.IsEditingControl(id))
{
@@ -4337,6 +4339,14 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
break;

case EventType.ExecuteCommand:

// Cancel EyeDropper if we change focus.
if (showEyedropper && Event.current.commandName == EventCommandNames.NewKeyboardFocus)
{
EyeDropper.End();
s_ColorPickID = 0;
}

// when ColorPicker sends an event back to this control's GUIView, it someties retains keyboardControl
if (GUIUtility.keyboardControl == id || ColorPicker.originalKeyboardControl == id)
{
@@ -5639,11 +5649,11 @@ internal static void ShowRepaints()
// Draws the alpha channel of a texture within a rectangle.
internal static void DrawTextureAlphaInternal(Rect position, Texture image, ScaleMode scaleMode, float imageAspect, float mipLevel)
{
DrawPreviewTextureInternal(position, image, alphaMaterial, scaleMode, imageAspect, mipLevel);
DrawPreviewTextureInternal(position, image, alphaMaterial, scaleMode, imageAspect, mipLevel, ColorWriteMask.All);
}

// Draws texture transparently using the alpha channel.
internal static void DrawTextureTransparentInternal(Rect position, Texture image, ScaleMode scaleMode, float imageAspect, float mipLevel)
internal static void DrawTextureTransparentInternal(Rect position, Texture image, ScaleMode scaleMode, float imageAspect, float mipLevel, ColorWriteMask colorWriteMask)
{
if (imageAspect == 0f && image == null)
{
@@ -5656,7 +5666,7 @@ internal static void DrawTextureTransparentInternal(Rect position, Texture image

DrawTransparencyCheckerTexture(position, scaleMode, imageAspect);
if (image != null)
DrawPreviewTexture(position, image, transparentMaterial, scaleMode, imageAspect, mipLevel);
DrawPreviewTexture(position, image, transparentMaterial, scaleMode, imageAspect, mipLevel, colorWriteMask);
}

internal static void DrawTransparencyCheckerTexture(Rect position, ScaleMode scaleMode, float imageAspect)
@@ -5678,15 +5688,27 @@ internal static void DrawTransparencyCheckerTexture(Rect position, ScaleMode sca
}

// Draws the texture within a rectangle.
internal static void DrawPreviewTextureInternal(Rect position, Texture image, Material mat, ScaleMode scaleMode, float imageAspect, float mipLevel)
internal static void DrawPreviewTextureInternal(Rect position, Texture image, Material mat, ScaleMode scaleMode, float imageAspect, float mipLevel, ColorWriteMask colorWriteMask)
{
if (Event.current.type == EventType.Repaint)
{
if (imageAspect == 0)
imageAspect = image.width / (float)image.height;

Color colorMask = new Color(1, 1, 1, 1);

if ((colorWriteMask & ColorWriteMask.Red) == 0)
colorMask.r = 0;
if ((colorWriteMask & ColorWriteMask.Green) == 0)
colorMask.g = 0;
if ((colorWriteMask & ColorWriteMask.Blue) == 0)
colorMask.b = 0;
if ((colorWriteMask & ColorWriteMask.Alpha) == 0)
colorMask.a = 0;

if (mat == null)
mat = GetMaterialForSpecialTexture(image, colorMaterial);
mat.SetColor("_ColorMask", colorMask);
mat.SetFloat("_Mip", mipLevel);

RenderTexture rt = image as RenderTexture;
@@ -6343,9 +6365,9 @@ public static void DrawTextureAlpha(Rect position, Texture image, ScaleMode scal
}

// Draws texture transparently using the alpha channel.
public static void DrawTextureTransparent(Rect position, Texture image, [DefaultValue("ScaleMode.StretchToFill")] ScaleMode scaleMode, [DefaultValue("0")] float imageAspect, [DefaultValue("-1")] float mipLevel)
public static void DrawTextureTransparent(Rect position, Texture image, [DefaultValue("ScaleMode.StretchToFill")] ScaleMode scaleMode, [DefaultValue("0")] float imageAspect, [DefaultValue("-1")] float mipLevel, [DefaultValue("ColorWriteMask.All")] ColorWriteMask colorWriteMask)
{
DrawTextureTransparentInternal(position, image, scaleMode, imageAspect, mipLevel);
DrawTextureTransparentInternal(position, image, scaleMode, imageAspect, mipLevel, colorWriteMask);
}

[ExcludeFromDocs]
@@ -6360,16 +6382,35 @@ public static void DrawTextureTransparent(Rect position, Texture image)
DrawTextureTransparent(position, image, ScaleMode.StretchToFill, 0);
}

[ExcludeFromDocs]
public static void DrawTextureTransparent(Rect position, Texture image, ScaleMode scaleMode, float imageAspect)
{
DrawTextureTransparentInternal(position, image, scaleMode, imageAspect, -1);
DrawTextureTransparent(position, image, scaleMode, imageAspect, -1);
}

[ExcludeFromDocs]
public static void DrawTextureTransparent(Rect position, Texture image, ScaleMode scaleMode, float imageAspect, float mipLevel)
{
DrawTextureTransparent(position, image, scaleMode, imageAspect, mipLevel, ColorWriteMask.All);
}

// Draws the texture within a rectangle.
public static void DrawPreviewTexture(Rect position, Texture image, [DefaultValue("null")] Material mat, [DefaultValue("ScaleMode.StretchToFill")] ScaleMode scaleMode,
[DefaultValue("0")] float imageAspect, [DefaultValue("-1")] float mipLevel)
[DefaultValue("0")] float imageAspect, [DefaultValue("-1")] float mipLevel, [DefaultValue("ColorWriteMask.All")] ColorWriteMask colorWriteMask)
{
DrawPreviewTextureInternal(position, image, mat, scaleMode, imageAspect, mipLevel);
DrawPreviewTextureInternal(position, image, mat, scaleMode, imageAspect, mipLevel, colorWriteMask);
}

[ExcludeFromDocs]
public static void DrawPreviewTexture(Rect position, Texture image, Material mat, ScaleMode scaleMode, float imageAspect, float mipLevel)
{
DrawPreviewTexture(position, image, mat, scaleMode, imageAspect, mipLevel, ColorWriteMask.All);
}

[ExcludeFromDocs]
public static void DrawPreviewTexture(Rect position, Texture image, Material mat, ScaleMode scaleMode, float imageAspect)
{
DrawPreviewTexture(position, image, mat, scaleMode, imageAspect, -1);
}

[ExcludeFromDocs]
@@ -6390,12 +6431,6 @@ public static void DrawPreviewTexture(Rect position, Texture image)
DrawPreviewTexture(position, image, null, ScaleMode.StretchToFill, 0);
}

[ExcludeFromDocs]
public static void DrawPreviewTexture(Rect position, Texture image, Material mat, ScaleMode scaleMode, float imageAspect)
{
DrawPreviewTextureInternal(position, image, mat, scaleMode, imageAspect, -1);
}

[ExcludeFromDocs]
public static void LabelField(Rect position, string label)
{
Original file line number Diff line number Diff line change
@@ -122,8 +122,8 @@ public void DrawHandle()

// handles
int prevHotControl = GUIUtility.hotControl;
Vector3 cameraLocalPos = Handles.inverseMatrix.MultiplyPoint(Camera.current.transform.position);
bool isCameraInsideBox = m_Bounds.Contains(cameraLocalPos);
bool isCameraInsideBox = Camera.current != null
&& m_Bounds.Contains(Handles.inverseMatrix.MultiplyPoint(Camera.current.transform.position));
EditorGUI.BeginChangeCheck();
using (new Handles.DrawingScope(Handles.color * handleColor))
MidpointHandles(ref minPos, ref maxPos, isCameraInsideBox);
8 changes: 5 additions & 3 deletions Editor/Mono/EditorHandles/JointAngularLimitHandle.cs
Original file line number Diff line number Diff line change
@@ -26,10 +26,12 @@ private static float GetSortingDistance(ArcHandle handle)
Vector3 worldPosition = Handles.matrix.MultiplyPoint3x4(
Quaternion.AngleAxis(handle.angle, Vector3.up) * Vector3.forward * handle.radius
);
Vector3 toHandle = worldPosition - Camera.current.transform.position;
if (Camera.current.orthographic)
Vector3 toHandle = Camera.current == null
? worldPosition
: worldPosition - Camera.current.transform.position;
if (Camera.current == null || Camera.current.orthographic)
{
Vector3 lookVector = Camera.current.transform.forward;
Vector3 lookVector = Camera.current == null ? Vector3.forward : Camera.current.transform.forward;
toHandle = lookVector * Vector3.Dot(lookVector, toHandle);
}
return toHandle.sqrMagnitude;
9 changes: 9 additions & 0 deletions Editor/Mono/EditorUserBuildSettings.bindings.cs
Original file line number Diff line number Diff line change
@@ -626,6 +626,15 @@ public static extern bool switchNVNShaderDebugging
set;
}

// Enable debug validation of NVN drawcalls
public static extern bool switchNVNDrawValidation
{
[NativeMethod("GetNVNDrawValidation")]
get;
[NativeMethod("SetNVNDrawValidation")]
set;
}

// Enable linkage of the Heap inspector tool for Nintendo Switch.
public static extern bool switchEnableHeapInspector
{
Loading