Skip to content

Commit 9034442

Browse files
author
Unity Technologies
committed
Unity 2019.3.0a7 C# reference source code
1 parent 11aeafb commit 9034442

File tree

189 files changed

+6108
-6565
lines changed

Some content is hidden

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

189 files changed

+6108
-6565
lines changed

Editor/Mono/AssemblyValidation.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Runtime.InteropServices;
89
using Mono.Cecil;
10+
using UnityEditor.Scripting.ScriptCompilation;
911
using UnityEngine.Scripting;
1012

1113
namespace UnityEditor
@@ -20,13 +22,15 @@ public enum ErrorFlags
2022
ReferenceHasErrors = (1 << 0),
2123
UnresolvableReference = (1 << 1),
2224
IncompatibleWithEditor = (1 << 2),
25+
AsmdefPluginConflict = (1 << 3)
2326
}
2427

2528
[StructLayout(LayoutKind.Sequential)]
2629
public struct Error
2730
{
2831
public ErrorFlags flags;
2932
public string message;
33+
public string assemblyPath;
3034

3135
public void Add(ErrorFlags newFlags, string newMessage)
3236
{
@@ -131,6 +135,52 @@ public static Error[] ValidateAssemblies(string[] assemblyPaths, bool enableLogg
131135
return errors;
132136
}
133137

138+
[RequiredByNativeCode]
139+
public static Error[] ValidateAssemblyDefinitionFiles()
140+
{
141+
var customScriptAssemblies = EditorCompilationInterface.Instance.GetCustomScriptAssemblies();
142+
143+
if (customScriptAssemblies.Length == 0)
144+
return null;
145+
146+
var pluginImporters = PluginImporter.GetAllImporters();
147+
148+
if (pluginImporters == null || pluginImporters.Length == 0)
149+
return null;
150+
151+
var pluginFilenameToAssetPath = new Dictionary<string, string>();
152+
153+
foreach (var pluginImporter in pluginImporters)
154+
{
155+
var pluginAssetPath = pluginImporter.assetPath;
156+
var lowerPluginFilename = AssetPath.GetFileName(pluginAssetPath).ToLower(CultureInfo.InvariantCulture);
157+
pluginFilenameToAssetPath[lowerPluginFilename] = pluginAssetPath;
158+
}
159+
160+
var errors = new List<Error>();
161+
162+
foreach (var customScriptAssembly in customScriptAssemblies)
163+
{
164+
var lowerAsmdefFilename = $"{customScriptAssembly.Name.ToLower(CultureInfo.InvariantCulture)}.dll";
165+
166+
string pluginPath;
167+
168+
if (pluginFilenameToAssetPath.TryGetValue(lowerAsmdefFilename, out pluginPath))
169+
{
170+
var error = new Error()
171+
{
172+
message = $"Plugin '{pluginPath}' has the same filename as Assembly Definition File '{customScriptAssembly.FilePath}'. Rename the assemblies to avoid hard to diagnose issues and crashes.",
173+
flags = ErrorFlags.AsmdefPluginConflict,
174+
assemblyPath = pluginPath
175+
};
176+
177+
errors.Add(error);
178+
}
179+
}
180+
181+
return errors.ToArray();
182+
}
183+
134184
public static bool PluginCompatibleWithEditor(string path)
135185
{
136186
var pluginImporter = AssetImporter.GetAtPath(path) as PluginImporter;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Runtime.InteropServices;
8+
using UnityEngine;
9+
using UnityEngine.Bindings;
10+
using UnityEngine.Scripting;
11+
12+
namespace UnityEditor.AssetImporters
13+
{
14+
[NativeType(Header = "Editor/Src/AssetPipeline/ModelImporting/MaterialDescription.h")]
15+
public struct TexturePropertyDescription
16+
{
17+
public Vector2 offset;
18+
public Vector2 scale;
19+
public Texture texture;
20+
public string relativePath;
21+
public string path;
22+
};
23+
24+
[RequiredByNativeCode]
25+
[NativeHeader("Editor/Src/AssetPipeline/ModelImporting/MaterialDescription.h")]
26+
public class MaterialDescription
27+
{
28+
internal IntPtr m_Ptr;
29+
30+
public MaterialDescription()
31+
{
32+
m_Ptr = Internal_Create();
33+
}
34+
35+
~MaterialDescription()
36+
{
37+
Internal_Destroy(m_Ptr);
38+
}
39+
40+
[NativeProperty("materialName", TargetType.Field)]
41+
public extern string materialName { get; }
42+
public bool TryGetProperty(string propertyName, out float value) => TryGetFloatProperty(propertyName, out value);
43+
public bool TryGetProperty(string propertyName, out Vector4 value) => TryGetVector4Property(propertyName, out value);
44+
public bool TryGetProperty(string propertyName, out string value) => TryGetStringProperty(propertyName, out value);
45+
public bool TryGetProperty(string propertyName, out TexturePropertyDescription value) => TryGetTextureProperty(propertyName, out value);
46+
47+
public extern void GetVector4PropertyNames(List<string> names);
48+
public extern void GetFloatPropertyNames(List<string> names);
49+
public extern void GetTexturePropertyNames(List<string> names);
50+
public extern void GetStringPropertyNames(List<string> names);
51+
52+
extern bool TryGetVector4Property(string propertyName, out Vector4 value);
53+
extern bool TryGetFloatProperty(string propertyName, out float value);
54+
extern bool TryGetTextureProperty(string propertyName, out TexturePropertyDescription value);
55+
extern bool TryGetStringProperty(string propertyName, out string value);
56+
57+
public bool TryGetAnimationCurve(string clipName, string propertyName, out AnimationCurve value)
58+
{
59+
value = TryGetAnimationCurve(clipName, propertyName);
60+
return value != null;
61+
}
62+
63+
public extern bool HasAnimationCurveInClip(string clipName, string propertyName);
64+
public extern bool HasAnimationCurve(string propertyName);
65+
extern AnimationCurve TryGetAnimationCurve(string clipName, string propertyName);
66+
67+
static extern IntPtr Internal_Create();
68+
static extern void Internal_Destroy(IntPtr ptr);
69+
}
70+
}

Editor/Mono/AssetPostprocessor.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Generic;
1212
using System.Linq;
1313
using System.Reflection;
14+
using UnityEditor.AssetImporters;
1415
using Object = UnityEngine.Object;
1516
using UnityEditor.Experimental.AssetImporters;
1617

@@ -193,6 +194,16 @@ static void CleanupPostprocessors()
193194
}
194195
}
195196

197+
static bool ImplementsAnyOfTheses(Type type, string[] methods)
198+
{
199+
foreach (var method in methods)
200+
{
201+
if (type.GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null)
202+
return true;
203+
}
204+
return false;
205+
}
206+
196207
[RequiredByNativeCode]
197208
static string GetMeshProcessorsHashString()
198209
{
@@ -207,11 +218,21 @@ static string GetMeshProcessorsHashString()
207218
{
208219
var inst = Activator.CreateInstance(assetPostprocessorClass) as AssetPostprocessor;
209220
var type = inst.GetType();
210-
bool hasPreProcessMethod = type.GetMethod("OnPreprocessModel", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
211-
bool hasPostprocessMeshHierarchy = type.GetMethod("OnPostprocessMeshHierarchy", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
212-
bool hasPostProcessMethod = type.GetMethod("OnPostprocessModel", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
221+
bool hasAnyPostprocessMethod = ImplementsAnyOfTheses(type, new[]
222+
{
223+
"OnPreprocessModel",
224+
"OnPostprocessMeshHierarchy",
225+
"OnPostprocessModel",
226+
"OnPreprocessAnimation",
227+
"OnPostprocessAnimation",
228+
"OnPostprocessGameObjectWithAnimatedUserProperties",
229+
"OnPostprocessGameObjectWithUserProperties",
230+
"OnPostprocessMaterial",
231+
"OnAssignMaterialModel",
232+
"OnPreprocessMaterialDescription"
233+
});
213234
uint version = inst.GetVersion();
214-
if (version != 0 && (hasPreProcessMethod || hasPostprocessMeshHierarchy || hasPostProcessMethod))
235+
if (version != 0 && hasAnyPostprocessMethod)
215236
{
216237
versionsByType.Add(type.FullName, version);
217238
}
@@ -339,6 +360,16 @@ static void PostprocessMaterial(Material material)
339360
}
340361
}
341362

363+
[RequiredByNativeCode]
364+
static void PreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] animations)
365+
{
366+
object[] args = { description, material, animations };
367+
foreach (AssetPostprocessor inst in m_ImportProcessors)
368+
{
369+
InvokeMethodIfAvailable(inst, "OnPreprocessMaterialDescription", args);
370+
}
371+
}
372+
342373
[RequiredByNativeCode]
343374
static void PostprocessGameObjectWithUserProperties(GameObject go, string[] prop_names, object[] prop_values)
344375
{

Editor/Mono/Audio/Bindings/AudioUtil.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ extern public static bool canUseSpatializerEffect
8585
extern public static int GetCustomFilterProcessTime(MonoBehaviour behaviour);
8686
extern public static float GetCustomFilterMaxIn(MonoBehaviour behaviour, int channel);
8787
extern public static float GetCustomFilterMaxOut(MonoBehaviour behaviour, int channel);
88+
89+
extern internal static void SetProfilerShowAllGroups(bool value);
8890
}
8991
}

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void EffectSlot(Rect effectRect, AudioMixerSnapshotController snapshot, AudioMix
413413
// Active: Enabled, background for draggable bar
414414
// Focused: Enabled, foreground for draggable bar
415415

416-
float level = GetValueForEffect(effect, p.group, m_Controller, snapshot);
416+
float level = (effect != null) ? Mathf.Clamp(effect.GetValueForMixLevel(m_Controller, snapshot), AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect) : AudioMixerController.kMinVolume;
417417
bool showLevel = (effect != null) && ((effect.IsSend() && effect.sendTarget != null) || effect.enableWetMix);
418418
if (evt.type == EventType.Repaint)
419419
{
@@ -497,7 +497,7 @@ string GetEffectSlotName(AudioMixerEffectController effect, bool showLevel, Audi
497497
{
498498
if (m_ChangingWetMixIndex == m_IndexCounter && showLevel)
499499
{
500-
return UnityString.Format("{0:F1} dB", GetValueForEffect(effect, p.group, m_Controller, snapshot));
500+
return UnityString.Format("{0:F1} dB", effect.GetValueForMixLevel(m_Controller, snapshot));
501501
}
502502

503503
if (effect.IsSend() && effect.sendTarget != null)
@@ -683,14 +683,26 @@ private void EffectSlotDragging(Rect r, AudioMixerSnapshotController snapshot, A
683683
Undo.RecordObject(m_Controller.TargetSnapshot, "Change effect level");
684684
if (effect.IsSend() && m_Controller.CachedSelection.Count > 1 && m_Controller.CachedSelection.Contains(p.group))
685685
{
686-
foreach (var group in m_Controller.CachedSelection)
687-
foreach (var cachedEffect in group.effects)
688-
if (cachedEffect.effectName == effect.effectName && cachedEffect.sendTarget == effect.sendTarget)
689-
SetValueForEffect(cachedEffect, group, m_Controller, snapshot, GetValueForEffect(cachedEffect, group, m_Controller, snapshot) + deltaLevel);
686+
List<AudioMixerEffectController> changeEffects = new List<AudioMixerEffectController>();
687+
foreach (var g in m_Controller.CachedSelection)
688+
foreach (var e in g.effects)
689+
if (e.effectName == effect.effectName && e.sendTarget == effect.sendTarget)
690+
changeEffects.Add(e);
691+
foreach (var e in changeEffects)
692+
if (!e.IsSend() || e.sendTarget != null)
693+
e.SetValueForMixLevel(
694+
m_Controller,
695+
snapshot,
696+
Mathf.Clamp(e.GetValueForMixLevel(m_Controller, snapshot) + deltaLevel, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect));
690697
}
691698
else
692-
SetValueForEffect(effect, p.group, m_Controller, snapshot, level + deltaLevel);
693-
699+
{
700+
if (!effect.IsSend() || effect.sendTarget != null)
701+
effect.SetValueForMixLevel(
702+
m_Controller,
703+
snapshot,
704+
Mathf.Clamp(level + deltaLevel, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect));
705+
}
694706
InspectorWindow.RepaintAllInspectors();
695707
}
696708
evt.Use();
@@ -1722,25 +1734,5 @@ Rect GetContentRect(List<AudioMixerGroupController> sortedGroups, bool isShowing
17221734
float maxWidth = channelStripsOffset.x * 2 + (channelStripBaseWidth + channelStripSpacing) * sortedGroups.Count + (isShowingReferencedGroups ? spaceBetweenMainGroupsAndReferenced : 0f);
17231735
return new Rect(0, 0, maxWidth, maxHeight);
17241736
}
1725-
1726-
static float GetValueForEffect(AudioMixerEffectController effect, AudioMixerGroupController group, AudioMixerController controller, AudioMixerSnapshotController snapshot)
1727-
{
1728-
float level = AudioMixerController.kMinVolume;
1729-
if (effect == null)
1730-
return level;
1731-
level = (effect.IsSend() && effect.sendTarget != null) ? group.GetValueForSend(controller, snapshot) : effect.GetValueForMixLevel(controller, snapshot);
1732-
return Mathf.Clamp(level, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect);
1733-
}
1734-
1735-
static void SetValueForEffect(AudioMixerEffectController effect, AudioMixerGroupController group, AudioMixerController controller, AudioMixerSnapshotController snapshot, float level)
1736-
{
1737-
if (effect == null)
1738-
return;
1739-
level = Mathf.Clamp(level, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect);
1740-
if (effect.IsSend() && effect.sendTarget != null)
1741-
group.SetValueForSend(controller, snapshot, level);
1742-
else
1743-
effect.SetValueForMixLevel(controller, snapshot, level);
1744-
}
17451737
}
17461738
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ public void DoEffectGUI(int effectIndex, AudioMixerGroupController group, List<A
283283

284284
if (effect.sendTarget != null)
285285
{
286-
float wetLevel = group.GetValueForSend(controller, controller.TargetSnapshot);
286+
float wetLevel = effect.GetValueForMixLevel(controller, controller.TargetSnapshot);
287287
if (AudioMixerEffectGUI.Slider(Texts.sendLevel, ref wetLevel, 1.0f, 1.0f, Texts.dB, AudioMixerController.kMinVolume, AudioMixerController.kMaxEffect, controller, new AudioGroupParameterPath(group, group.GetGUIDForSend())))
288288
{
289289
Undo.RecordObject(controller.TargetSnapshot, "Change Send Level");
290-
group.SetValueForSend(controller, controller.TargetSnapshot, wetLevel);
290+
effect.SetValueForMixLevel(controller, controller.TargetSnapshot, wetLevel);
291291
AudioMixerUtility.RepaintAudioMixerAndInspectors();
292292
}
293293
}

0 commit comments

Comments
 (0)