Skip to content

Commit 488c3da

Browse files
author
Unity Technologies
committed
Unity 2019.2.0b7 C# reference source code
1 parent 87e545f commit 488c3da

38 files changed

+705
-269
lines changed

Editor/Mono/AssetModificationProcessor.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ static void FileModeChanged(string[] assets, UnityEditor.VersionControl.FileMode
116116
// that we have the most recent status
117117
if (Provider.enabled)
118118
{
119-
if (Provider.PromptAndCheckoutIfNeeded(assets, ""))
119+
var editableAssets = new string[assets.Length];
120+
if (Provider.MakeEditable(assets, editableAssets))
121+
{
122+
// TODO: handle partial results from MakeEditable i.e. editableassets
120123
Provider.SetFileMode(assets, mode);
124+
}
121125
}
122126
}
123127

@@ -168,12 +172,16 @@ static void OnWillSaveAssets(string[] assets, out string[] assetsThatShouldBeSav
168172
}
169173
assets = assetsNotOpened.ToArray();
170174

171-
// Try to checkout if needed. This may fail but is catched below.
172-
if (assets.Length != 0 && !Provider.PromptAndCheckoutIfNeeded(assets, ""))
175+
// Try to checkout if needed. This may fail but is caught below.
176+
var editableAssets = new string[assets.Length];
177+
if (assets.Length != 0 && !Provider.MakeEditable(assets, editableAssets))
173178
{
174-
Debug.LogError("Could not check out the following files in version control before saving: " +
175-
string.Join(", ", assets));
176-
assetsThatShouldBeSaved = new string[0];
179+
// TODO: fix this behaviour to make save asset honour version control result
180+
// keep previous behaviour which is save all assets even if checkout fails
181+
// TODO: this needs to consider and handle saving assets which have not been
182+
// added to version control. They have to be added to version control before
183+
// calling MakeEditable.
184+
//assetsThatShouldBeSaved = editableAssets;
177185
return;
178186
}
179187
}

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
}

Editor/Mono/Inspector/AudioClipInspector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class AudioClipInspector : Editor
1212
{
1313
private PreviewRenderUtility m_PreviewUtility;
1414
private AudioClip m_Clip;
15-
private bool playing => s_PlayingInstance == this && AudioUtil.IsClipPlaying(m_Clip);
15+
private bool playing => s_PlayingInstance == this && m_Clip != null && AudioUtil.IsClipPlaying(m_Clip);
1616
Vector2 m_Position = Vector2.zero;
1717
private bool m_MultiEditing;
1818

@@ -143,7 +143,10 @@ public override void OnPreviewSettings()
143143
if (newPlaying)
144144
PlayClip(clip, 0, s_Loop);
145145
else
146+
{
147+
AudioUtil.StopAllClips();
146148
m_Clip = null;
149+
}
147150
}
148151
}
149152
}

Editor/Mono/Inspector/Editor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ public partial class Editor : ScriptableObject, IPreviewable, IToolModeOwner
325325
int m_ReferenceTargetIndex = 0;
326326
PropertyHandlerCache m_PropertyHandlerCache = new PropertyHandlerCache();
327327
IPreviewable m_DummyPreview;
328+
AudioFilterGUI m_AudioFilterGUI;
328329

329330
internal SerializedObject m_SerializedObject = null;
330331
internal SerializedProperty m_EnabledProperty = null;
@@ -668,7 +669,17 @@ internal static bool DoDrawDefaultInspector(SerializedObject obj)
668669

669670
internal bool DoDrawDefaultInspector()
670671
{
671-
return DoDrawDefaultInspector(serializedObject);
672+
bool res = DoDrawDefaultInspector(serializedObject);
673+
674+
var behaviour = target as MonoBehaviour;
675+
if (behaviour == null || !AudioUtil.HasAudioCallback(behaviour) || AudioUtil.GetCustomFilterChannelCount(behaviour) <= 0)
676+
return res;
677+
678+
// If we have an OnAudioFilterRead callback, draw vu meter
679+
if (m_AudioFilterGUI == null)
680+
m_AudioFilterGUI = new AudioFilterGUI();
681+
m_AudioFilterGUI.DrawAudioFilterGUI(behaviour);
682+
return res;
672683
}
673684

674685
// Repaint any inspectors that shows this editor.

Editor/Mono/Inspector/GameObjectInspector.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void Dispose()
126126
bool m_IsMissing;
127127
bool m_IsPrefabInstanceAnyRoot;
128128
bool m_IsPrefabInstanceOutermostRoot;
129+
bool m_IsAssetRoot;
129130
bool m_AllOfSamePrefabType = true;
130131

131132
public void OnEnable()
@@ -158,6 +159,7 @@ void CalculatePrefabStatus()
158159
m_IsPrefabInstanceAnyRoot = true;
159160
m_IsPrefabInstanceOutermostRoot = true;
160161
m_AllOfSamePrefabType = true;
162+
m_IsAssetRoot = false;
161163
PrefabAssetType firstType = PrefabUtility.GetPrefabAssetType(targets[0]);
162164
PrefabInstanceStatus firstStatus = PrefabUtility.GetPrefabInstanceStatus(targets[0]);
163165

@@ -174,8 +176,14 @@ void CalculatePrefabStatus()
174176
m_IsPrefabInstanceAnyRoot = false; // Conservative is false if any is false
175177
if (!m_IsPrefabInstanceAnyRoot || !PrefabUtility.IsOutermostPrefabInstanceRoot(go))
176178
m_IsPrefabInstanceOutermostRoot = false; // Conservative is false if any is false
179+
177180
if (PrefabUtility.IsPartOfPrefabAsset(go))
181+
{
178182
m_IsAsset = true; // Conservative is true if any is true
183+
if (go.transform.parent == null)
184+
m_IsAssetRoot = true;
185+
}
186+
179187
if (m_IsAsset && PrefabUtility.IsPartOfImmutablePrefab(go))
180188
m_ImmutableSelf = true; // Conservative is true if any is true
181189
GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
@@ -275,8 +283,12 @@ internal bool DrawInspector()
275283
}
276284
EditorGUILayout.EndHorizontal();
277285

278-
// Name
279-
EditorGUILayout.DelayedTextField(m_Name, GUIContent.none);
286+
// Disable the name field of root GO in prefab asset
287+
using (new EditorGUI.DisabledScope(m_IsAsset && m_IsAssetRoot))
288+
{
289+
// Name
290+
EditorGUILayout.DelayedTextField(m_Name, GUIContent.none);
291+
}
280292

281293
// Static flags toggle
282294
DoStaticToggleField(go);

Editor/Mono/Inspector/GenericInspector.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ private enum OptimizedBlockState
1515
NoOptimizedBlock
1616
}
1717

18-
private AudioFilterGUI m_AudioFilterGUI;
1918
private float m_LastHeight;
2019
private Rect m_LastVisibleRect;
2120
private OptimizedBlockState m_OptimizedBlockState = OptimizedBlockState.CheckOptimizedBlock;
@@ -204,18 +203,6 @@ public override void OnInspectorGUI()
204203
return;
205204

206205
base.OnInspectorGUI();
207-
208-
var behaviour = target as MonoBehaviour;
209-
if (behaviour != null)
210-
{
211-
// Does this have a AudioRead callback?
212-
if (AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
213-
{
214-
if (m_AudioFilterGUI == null)
215-
m_AudioFilterGUI = new AudioFilterGUI();
216-
m_AudioFilterGUI.DrawAudioFilterGUI(behaviour);
217-
}
218-
}
219206
}
220207
}
221208
}

Editor/Mono/Prefabs/PrefabOverrides/PrefabOverridesWindow.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ public override void OnGUI(Rect rect)
287287
GUILayout.EndHorizontal();
288288
}
289289

290+
struct ApplyAllUndo
291+
{
292+
public GameObject correspondingSourceObject;
293+
public HashSet<int> prefabHierarchy;
294+
};
295+
290296
bool ApplyAll()
291297
{
292298
// Collect Prefab Asset paths and also check if there's more than one of the same.
@@ -313,11 +319,37 @@ bool ApplyAll()
313319
if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(prefabAssetPaths.ToArray(), PrefabUtility.SaveVerb.Apply))
314320
return false;
315321

322+
var undoStructs = new List<ApplyAllUndo>();
323+
var actionName = "ApplyAll";
324+
for (var i = 0; i < m_SelectedGameObjects.Length; i++)
325+
{
326+
var us = new ApplyAllUndo();
327+
us.correspondingSourceObject = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(m_SelectedGameObjects[i]);
328+
Undo.RegisterFullObjectHierarchyUndo(us.correspondingSourceObject, actionName); // handles changes to existing objects and object what will be deleted but not objects that are created
329+
GameObject prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(m_SelectedGameObjects[i]);
330+
Undo.RegisterFullObjectHierarchyUndo(prefabInstanceRoot, actionName);
331+
332+
us.prefabHierarchy = new HashSet<int>();
333+
PrefabUtility.GetObjectListFromHierarchy(us.prefabHierarchy, us.correspondingSourceObject);
334+
undoStructs.Add(us);
335+
}
336+
316337
// Apply sequentially.
317338
AssetDatabase.StartAssetEditing();
318-
for (int i = 0; i < m_SelectedGameObjects.Length; i++)
319-
PrefabUtility.ApplyPrefabInstance(m_SelectedGameObjects[i], InteractionMode.UserAction);
320-
AssetDatabase.StopAssetEditing();
339+
try
340+
{
341+
foreach (var t in m_SelectedGameObjects)
342+
PrefabUtility.ApplyPrefabInstance(t, InteractionMode.UserAction);
343+
}
344+
finally
345+
{
346+
AssetDatabase.StopAssetEditing();
347+
}
348+
349+
foreach (var t in undoStructs)
350+
{
351+
PrefabUtility.RegisterNewObjects(t.correspondingSourceObject, t.prefabHierarchy, actionName);
352+
}
321353

322354
EditorUtility.ForceRebuildInspectors();
323355
return true;
@@ -328,7 +360,6 @@ bool RevertAll()
328360
for (int i = 0; i < m_SelectedGameObjects.Length; i++)
329361
PrefabUtility.RevertPrefabInstance(m_SelectedGameObjects[i], InteractionMode.UserAction);
330362

331-
332363
EditorUtility.ForceRebuildInspectors();
333364
return true;
334365
}

Editor/Mono/Prefabs/PrefabUtility.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ internal static void ExtractMaterialsFromAsset(Object[] targets, string destinat
158158
}
159159
}
160160

161-
private static void GetObjectListFromHierarchy(HashSet<int> hierarchyInstanceIDs, GameObject gameObject)
161+
internal static void GetObjectListFromHierarchy(HashSet<int> hierarchyInstanceIDs, GameObject gameObject)
162162
{
163163
Transform transform = null;
164164
List<Component> components = new List<Component>();
@@ -221,7 +221,7 @@ private static void CollectAddedObjects(GameObject gameObject, HashSet<int> hier
221221
}
222222
}
223223

224-
private static void RegisterNewObjects(GameObject newHierarchy, HashSet<int> hierarchyInstanceIDs, string actionName)
224+
internal static void RegisterNewObjects(GameObject newHierarchy, HashSet<int> hierarchyInstanceIDs, string actionName)
225225
{
226226
var danglingObjects = new List<Object>();
227227

@@ -503,17 +503,22 @@ static void ApplyPropertyOverrides(Object prefabInstanceObject, SerializedProper
503503
// Ensure importing of saved Prefab Assets only kicks in after all Prefab Asset have been saved
504504
AssetDatabase.StartAssetEditing();
505505

506-
// Write modified value to prefab source object.
507-
for (int i = 0; i < serializedObjects.Count; i++)
506+
try
508507
{
509-
if (serializedObjects[i].ApplyModifiedProperties())
510-
SaveChangesToPrefabFileIfPersistent(serializedObjects[i]);
508+
// Write modified value to prefab source object.
509+
for (int i = 0; i < serializedObjects.Count; i++)
510+
{
511+
if (serializedObjects[i].ApplyModifiedProperties())
512+
SaveChangesToPrefabFileIfPersistent(serializedObjects[i]);
511513

512-
if (action == InteractionMode.UserAction)
513-
Undo.FlushUndoRecordObjects(); // flush'es ensure that SavePrefab() on undo/redo on the source happens in the right order
514+
if (action == InteractionMode.UserAction)
515+
Undo.FlushUndoRecordObjects(); // flush'es ensure that SavePrefab() on undo/redo on the source happens in the right order
516+
}
517+
}
518+
finally
519+
{
520+
AssetDatabase.StopAssetEditing();
514521
}
515-
516-
AssetDatabase.StopAssetEditing();
517522
}
518523

519524
static void SaveChangesToPrefabFileIfPersistent(SerializedObject serializedObject)

Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStage.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ internal PrefabStage()
133133

134134
internal bool LoadStage(string prefabPath)
135135
{
136+
if (!File.Exists(prefabPath))
137+
{
138+
Debug.LogError("LoadStage with an invalid path: Prefab file not found " + prefabPath);
139+
return false;
140+
}
141+
136142
if (isValid)
137143
Cleanup();
138144

@@ -322,6 +328,10 @@ void HandlePrefabChangedOnDisk()
322328
if (m_PrefabWasChangedOnDisk)
323329
{
324330
m_PrefabWasChangedOnDisk = false;
331+
332+
if (!File.Exists(m_PrefabAssetPath))
333+
return;
334+
325335
if (HasSceneBeenModified())
326336
{
327337
var title = L10n.Tr("Prefab Has Been Changed on Disk");

0 commit comments

Comments
 (0)