Skip to content

Commit

Permalink
Unity 2020.1.0a22 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Feb 5, 2020
1 parent 9832fc8 commit fbd4f2b
Show file tree
Hide file tree
Showing 93 changed files with 1,055 additions and 443 deletions.
3 changes: 3 additions & 0 deletions Editor/Mono/ActiveEditorTracker.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public override int GetHashCode()
static extern Array Internal_GetActiveEditors(ActiveEditorTracker self);
public Editor[] activeEditors { get { return (Editor[])Internal_GetActiveEditors(this); } }

[FreeFunction]
internal static extern void Internal_GetActiveEditorsNonAlloc(ActiveEditorTracker self, Editor[] editors);

// List<T> version
internal void GetObjectsLockedByThisTracker(List<UnityObject> lockedObjects)
{
Expand Down
37 changes: 37 additions & 0 deletions Editor/Mono/Animation/AnimationUtility.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ public static void SetObjectReferenceCurve(AnimationClip clip, EditorCurveBindin
Internal_InvokeOnCurveWasModified(clip, binding, keyframes != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
}

public static void SetObjectReferenceCurves(AnimationClip clip, EditorCurveBinding[] bindings, ObjectReferenceKeyframe[][] keyframes)
{
if (bindings == null)
throw new ArgumentNullException(nameof(bindings), $"{nameof(bindings)} must be non-null");
if (keyframes == null)
throw new ArgumentNullException(nameof(keyframes), $"{nameof(keyframes)} must be non-null");
if (bindings.Length != keyframes.Length)
throw new InvalidOperationException($"{nameof(bindings)} and {nameof(keyframes)} must be of equal length");

int length = bindings.Length;
for (int i = 0; i < length; i++)
{
SetObjectReferenceCurveNoSync(clip, bindings[i], keyframes[i]);
}
SyncEditorCurves(clip);
Internal_InvokeOnCurveWasModified(clip, new EditorCurveBinding(), CurveModifiedType.ClipModified);
}

internal static void SetObjectReferenceCurveNoSync(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)
{
Internal_SetObjectReferenceCurve(clip, binding, keyframes, false);
Expand All @@ -220,6 +238,25 @@ public static void SetEditorCurve(AnimationClip clip, EditorCurveBinding binding
Internal_InvokeOnCurveWasModified(clip, binding, curve != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
}

public static void SetEditorCurves(AnimationClip clip, EditorCurveBinding[] bindings, AnimationCurve[] curves)
{
if (bindings == null)
throw new ArgumentNullException(nameof(bindings), $"{nameof(bindings)} must be non-null");
if (curves == null)
throw new ArgumentNullException(nameof(curves), $"{nameof(curves)} must be non-null");
if (bindings.Length != curves.Length)
throw new InvalidOperationException($"{nameof(bindings)} and {nameof(curves)} must be of equal length");

int length = bindings.Length;
for (int i = 0; i < length; i++)
{
SetEditorCurveNoSync(clip, bindings[i], curves[i]);
}
SyncEditorCurves(clip);

Internal_InvokeOnCurveWasModified(clip, new EditorCurveBinding(), AnimationUtility.CurveModifiedType.ClipModified);
}

internal static void SetEditorCurveNoSync(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve)
{
Internal_SetEditorCurve(clip, binding, curve, false);
Expand Down
3 changes: 3 additions & 0 deletions Editor/Mono/Collab/Collab.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public static extern int GetRevisionsData(
[FreeFunction(HasExplicitThis = true, ThrowsException = true)]
public extern void RevertFile(string path, bool forceOverwrite);

[FreeFunction(HasExplicitThis = true, ThrowsException = true)]
public extern void RevertFiles(ChangeItem[] changeItems, bool forceOverwrite);

[FreeFunction(HasExplicitThis = true, ThrowsException = true)]
public extern void LaunchConflictExternalMerge(string path);

Expand Down
4 changes: 3 additions & 1 deletion Editor/Mono/Collab/Collab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace UnityEditor.Collaboration
internal delegate bool ShowToolbarAtPositionDelegate(Rect screenRect);
internal delegate bool IsToolbarVisibleDelegate();
internal delegate void ShowHistoryWindowDelegate();
internal delegate void ShowChangesWindowDelegate();
internal delegate void CloseToolbarDelegate();
internal delegate void ChangesChangedDelegate(Change[] changes, bool isFiltered);
internal delegate void ChangeItemsChangedDelegate(ChangeItem[] changes, bool isFiltered);
Expand Down Expand Up @@ -62,8 +63,9 @@ internal partial class Collab
public static IsToolbarVisibleDelegate IsToolbarVisible = null;
public static CloseToolbarDelegate CloseToolbar = null;

// History delegates
// Preferences link delegates
public static ShowHistoryWindowDelegate ShowHistoryWindow = null;
public static ShowChangesWindowDelegate ShowChangesWindow = null;

private static Collab s_Instance;
private static bool s_IsFirstStateChange = true;
Expand Down
13 changes: 9 additions & 4 deletions Editor/Mono/ContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System;
using System.Linq;

namespace UnityEditor
{
Expand Down Expand Up @@ -198,8 +199,6 @@ internal void InternalCloseWindow()
Save();
if (m_RootView)
{
if (m_RootView is GUIView)
((GUIView)m_RootView).RemoveFromAuxWindowList();
DestroyImmediate(m_RootView, true);
m_RootView = null;
}
Expand Down Expand Up @@ -241,8 +240,14 @@ internal string GetWindowID()
return rootView.GetType().ToString();

if (rootView.children.Length > 0)
return (m_ShowMode == (int)ShowMode.Utility || m_ShowMode == (int)ShowMode.AuxWindow) ? v.actualView.GetType().ToString()
: ((DockArea)rootView.children[0]).m_Panes[0].GetType().ToString();
{
var dockArea = rootView.children.FirstOrDefault(c => c is DockArea) as DockArea;
if (dockArea && dockArea.m_Panes.Count > 0)
{
return (m_ShowMode == (int)ShowMode.Utility || m_ShowMode == (int)ShowMode.AuxWindow) ? v.actualView.GetType().ToString()
: dockArea.m_Panes[0].GetType().ToString();
}
}

return v.actualView.GetType().ToString();
}
Expand Down
6 changes: 4 additions & 2 deletions Editor/Mono/EditorResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,18 @@ internal static void BuildCatalog()
using (new EditorPerformanceTracker(nameof(BuildCatalog)))
{
s_StyleCatalog = new StyleCatalog();
s_RefreshGlobalStyleCatalog = false;

var paths = GetDefaultStyleCatalogPaths();
foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet").Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet))
paths.Add(editorUssPath);

var forceRebuild = s_RefreshGlobalStyleCatalog;
s_RefreshGlobalStyleCatalog = false;

bool rebuildCatalog = true;
string catalogHash = ComputeCatalogHash(paths);
const string k_GlobalStyleCatalogCacheFilePath = "Library/Style.catalog";
if (File.Exists(k_GlobalStyleCatalogCacheFilePath))
if (!forceRebuild && File.Exists(k_GlobalStyleCatalogCacheFilePath))
{
using (var cacheCatalogStream = new FileStream(k_GlobalStyleCatalogCacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
Expand Down
3 changes: 3 additions & 0 deletions Editor/Mono/EditorSettings.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ internal static extern string Internal_ProjectGenerationUserExtensions
[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
public static extern bool useLegacyProbeSampleCount { get; set; }

[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
public static extern bool disableCookiesInLightmapper { get; set; }

[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
public static extern bool enterPlayModeOptionsEnabled { get; set; }

Expand Down
9 changes: 0 additions & 9 deletions Editor/Mono/EditorUserBuildSettings.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,6 @@ public static extern iOSBuildType iOSBuildConfigType
set;
}

// Instead of creating a ROM file, create a buildable Visual Studio 2015 solution.
public static extern bool switchCreateSolutionFile
{
[NativeMethod("GetCreateSolutionFileForSwitch")]
get;
[NativeMethod("SetCreateSolutionFileForSwitch")]
set;
}


// Create a .nsp ROM file out of the loose-files .nspd folder
public static extern bool switchCreateRomFile
Expand Down
35 changes: 28 additions & 7 deletions Editor/Mono/EnumDataUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,45 @@ internal static EnumData GetCachedEnumData(Type enumType, bool excludeObsolete =
return enumData;
if (!excludeObsolete && s_EnumData.TryGetValue(enumType, out enumData))
return enumData;
enumData = new EnumData {underlyingType = Enum.GetUnderlyingType(enumType)};
enumData = new EnumData { underlyingType = Enum.GetUnderlyingType(enumType) };
enumData.unsigned =
enumData.underlyingType == typeof(byte)
|| enumData.underlyingType == typeof(ushort)
|| enumData.underlyingType == typeof(uint)
|| enumData.underlyingType == typeof(ulong);
var enumFields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public)
.Where(f => CheckObsoleteAddition(f, excludeObsolete))
.OrderBy(f => f.MetadataToken).ToList();
enumData.displayNames = enumFields.Select(f => EnumNameFromEnumField(f)).ToArray();
var enumFields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
List<FieldInfo> enumfieldlist = new List<FieldInfo>();
int enumFieldslen = enumFields.Length;
for (int j = 0; j < enumFieldslen; j++)
{
if (CheckObsoleteAddition(enumFields[j], excludeObsolete))
enumfieldlist.Add(enumFields[j]);
}

// For Empty List Scenario
if (!enumfieldlist.Any())
{
string[] defaultstr = { "" };
Enum[] defaultenum = {};
int[] defaultarr = { 0 };
enumData.values = defaultenum;
enumData.flagValues = defaultarr;
enumData.displayNames = defaultstr;
enumData.tooltip = defaultstr;
enumData.flags = true;
enumData.serializable = true;
return enumData;
}
enumfieldlist.OrderBy(f => f.MetadataToken);
enumData.displayNames = enumfieldlist.Select(f => EnumNameFromEnumField(f)).ToArray();
if (enumData.displayNames.Distinct().Count() != enumData.displayNames.Length)
{
Debug.LogWarning(
$"Enum {enumType.Name} has multiple entries with the same display name, this prevents selection in EnumPopup.");
}

enumData.tooltip = enumFields.Select(f => EnumTooltipFromEnumField(f)).ToArray();
enumData.values = enumFields.Select(f => (Enum)f.GetValue(null)).ToArray();
enumData.tooltip = enumfieldlist.Select(f => EnumTooltipFromEnumField(f)).ToArray();
enumData.values = enumfieldlist.Select(f => (Enum)f.GetValue(null)).ToArray();
enumData.flagValues = enumData.unsigned
? enumData.values.Select(v => unchecked((int)Convert.ToUInt64(v))).ToArray()
: enumData.values.Select(v => unchecked((int)Convert.ToInt64(v))).ToArray();
Expand Down
9 changes: 6 additions & 3 deletions Editor/Mono/GI/LightingSettings.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public bool autoGenerate
[NativeName("RealtimeEnvironmentLighting")]
public extern bool realtimeEnvironmentLighting { get; set; }

[NativeName("MixedBakeMode")]
public extern MixedLightingMode mixedBakeMode { get; set; }

[NativeName("AlbedoBoost")]
public extern float albedoBoost { get; set; }

[NativeName("IndirectOutputScale")]
public extern float indirectScale { get; set; }

[NativeName("BakeBackend")]
public extern Lightmapper lightmapper { get; set; }

Expand Down Expand Up @@ -156,6 +156,9 @@ public bool autoGenerate
[NativeName("ExtractAO")]
public extern bool extractAO { get; set; }

[NativeName("MixedBakeMode")]
public extern MixedLightingMode mixedBakeMode { get; set; }

[NativeName("LightmapsBakeMode")]
public extern LightmapsMode directionalityMode { get; set; }

Expand Down
9 changes: 6 additions & 3 deletions Editor/Mono/GI/Lightmapping.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ public static bool bakedGI
set { GetOrCreateLightingsSettings().bakedGI = value; }
}

[Obsolete("Lightmapping.indirectOutputScale is obsolete, use DynamicGI.indirectScale instead. ", false)]
[StaticAccessor("GetGISettings()")]
public static extern float indirectOutputScale { get; set; }
[Obsolete("Lightmapping.indirectOutputScale is obsolete, use Lightmapping.lightingSettings.indirectScale instead. ", false)]
public static float indirectOutputScale
{
get { return GetLightingSettingsOrDefaultsFallback().indirectScale; }
set { GetOrCreateLightingsSettings().indirectScale = value; }
}

[Obsolete("Lightmapping.bounceBoost is obsolete, use Lightmapping.lightingSettings.albedoBoost instead. ", false)]
public static float bounceBoost
Expand Down
13 changes: 5 additions & 8 deletions Editor/Mono/GUI/DockArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,10 @@ public DockArea()

private void RemoveNullWindows()
{
List<EditorWindow> result = new List<EditorWindow>();
foreach (EditorWindow i in m_Panes)
{
if (i != null)
result.Add(i);
}
m_Panes = result;
m_Panes = m_Panes.Where(w => w).ToList();
// Restore dock area actual view if there is no valid pane left.
if (m_Panes.Count == 0 && actualView)
m_Panes.Add(actualView);
s_GUIContents.Clear();
}

Expand All @@ -128,7 +125,7 @@ protected override void OnDestroy()
m_IsBeingDestroyed = true;

if (hasFocus)
Invoke("OnLostFocus");
m_OnLostFocus?.Invoke();

actualView = null;

Expand Down
1 change: 0 additions & 1 deletion Editor/Mono/GUI/Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ static class Styles

public static Toolbar get;

internal static bool requestShowCollabToolbar;
public static bool isLastShowRequestPartial = true;


Expand Down
1 change: 0 additions & 1 deletion Editor/Mono/GUIView.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal partial class GUIView

internal extern void SetTitle(string title);
internal extern void AddToAuxWindowList();
internal extern void RemoveFromAuxWindowList();
internal extern void SetInternalGameViewDimensions(Rect rect, Rect clippedRect, Vector2 targetSize);
internal extern void SetMainPlayModeViewSize(Vector2 targetSize);
internal extern void SetAsStartView();
Expand Down
5 changes: 3 additions & 2 deletions Editor/Mono/GameView/GameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ private void DoToolbarGUI()
if (PlayerSettings.virtualRealitySupported || m_DisplaySubsystemDescs.Count != 0)
{
EditorGUI.BeginChangeCheck();
int selectedRenderMode = EditorGUILayout.Popup(m_XRRenderMode, Styles.xrRenderingModes, EditorStyles.toolbarPopup, GUILayout.Width(80));
if (EditorGUI.EndChangeCheck())
GameViewRenderMode currentGameViewRenderMode = UnityEngine.XR.XRSettings.gameViewRenderMode;
int selectedRenderMode = EditorGUILayout.Popup(Mathf.Clamp(((int)currentGameViewRenderMode) - 1, 0, Styles.xrRenderingModes.Length - 1), Styles.xrRenderingModes, EditorStyles.toolbarPopup, GUILayout.Width(80));
if (EditorGUI.EndChangeCheck() && currentGameViewRenderMode != GameViewRenderMode.None)
{
SetXRRenderMode(selectedRenderMode);
}
Expand Down
35 changes: 35 additions & 0 deletions Editor/Mono/HandleUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,41 @@ public static object RaySnap(Ray ray)
return null;
}

public delegate bool PlaceObjectDelegate(Vector2 guiPosition, out Vector3 position, out Vector3 normal);
public static event PlaceObjectDelegate placeObjectCustomPasses;

public static bool PlaceObject(Vector2 guiPosition, out Vector3 position, out Vector3 normal)
{
Ray ray = GUIPointToWorldRay(guiPosition);
object hit = RaySnap(ray);
bool objectIntersected = hit != null;
float bestDistance = objectIntersected ? ((RaycastHit)hit).distance : Mathf.Infinity;
position = objectIntersected ? ray.GetPoint(((RaycastHit)hit).distance) : Vector3.zero;
normal = objectIntersected ? ((RaycastHit)hit).normal : Vector3.up;

if (placeObjectCustomPasses != null)
{
foreach (var del in placeObjectCustomPasses.GetInvocationList())
{
Vector3 pos, nrm;

if (((PlaceObjectDelegate)del)(guiPosition, out pos, out nrm))
{
var dst = Vector3.Distance(ray.origin, pos);
if (dst < bestDistance)
{
objectIntersected = true;
bestDistance = dst;
position = pos;
normal = nrm;
}
}
}
}

return objectIntersected;
}

// Repaint the current view
public static void Repaint()
{
Expand Down
Loading

0 comments on commit fbd4f2b

Please sign in to comment.