Skip to content

Commit

Permalink
Unity 2020.1.0a3 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Sep 5, 2019
1 parent 0cf7cda commit 02d565c
Show file tree
Hide file tree
Showing 532 changed files with 10,153 additions and 6,549 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void FetchData()
private TreeViewItem AddGameObjectToHierarchy(GameObject gameObject, GameObject rootGameObject, AnimationClip animationClip, TreeViewItem parent)
{
string path = AnimationUtility.CalculateTransformPath(gameObject.transform, rootGameObject.transform);
TreeViewItem node = new AddCurvesPopupGameObjectNode(gameObject, parent, gameObject.name);
AddCurvesPopupGameObjectNode node = new AddCurvesPopupGameObjectNode(gameObject, parent, gameObject.name);
List<TreeViewItem> childNodes = new List<TreeViewItem>();

if (m_RootItem == null)
Expand Down Expand Up @@ -111,6 +111,20 @@ private TreeViewItem AddGameObjectToHierarchy(GameObject gameObject, GameObject
}
}

var animator = rootGameObject.GetComponent<Animator>();
if (animator != null)
{
//If the Animator has a human avatar, we need to check if the avatar's hierarchy matches that of the current GameObject. If they do not match, disable the node.
if (animator.avatarRoot != null && animator.isHuman)
{
if (animator.avatarRoot.Find(path) == null)
{
node.propertyPathMismatchWithHumanAvatar = true;
}
}
}


if (showEntireHierarchy)
{
// Iterate over all child GOs
Expand Down Expand Up @@ -220,6 +234,7 @@ public void UpdateData()

internal class AddCurvesPopupGameObjectNode : TreeViewItem
{
internal bool propertyPathMismatchWithHumanAvatar = false;
public AddCurvesPopupGameObjectNode(GameObject gameObject, TreeViewItem parent, string displayName)
: base(gameObject.GetInstanceID(), parent != null ? parent.depth + 1 : -1, parent, displayName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor.ShortcutManagement;

namespace UnityEditorInternal
{
Expand All @@ -18,17 +19,38 @@ internal class AddCurvesPopupHierarchyGUI : TreeViewGUI
private GUIContent addPropertiesContent = EditorGUIUtility.TrTextContent("Add Properties");
private const float plusButtonWidth = 17;

static Texture2D warningIcon = (Texture2D)EditorGUIUtility.LoadRequired("Icons/ShortcutManager/alertDialog.png");
public static GUIStyle warningIconStyle;

public AddCurvesPopupHierarchyGUI(TreeViewController treeView, EditorWindow owner)
: base(treeView, true)
{
this.owner = owner;
warningIconStyle = new GUIStyle();
warningIconStyle.margin = new RectOffset(15, 15, 15, 15);
}

public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused)
{
base.OnRowGUI(rowRect, node, row, selected, focused);
DoAddCurveButton(rowRect, node);
HandleContextMenu(rowRect, node);
bool propertyPathMismatchWithHumanAvatar = false;
AddCurvesPopupGameObjectNode addCurvesPopupNode = node as AddCurvesPopupGameObjectNode;
if (addCurvesPopupNode != null)
{
propertyPathMismatchWithHumanAvatar = addCurvesPopupNode.propertyPathMismatchWithHumanAvatar;
}

using (new EditorGUI.DisabledScope(propertyPathMismatchWithHumanAvatar))
{
base.OnRowGUI(rowRect, node, row, selected, focused);
DoAddCurveButton(rowRect, node);
HandleContextMenu(rowRect, node);
}

if (propertyPathMismatchWithHumanAvatar)
{
Rect iconRect = new Rect(rowRect.width - plusButtonWidth, rowRect.yMin, plusButtonWidth, plusButtonStyle.fixedHeight);
GUI.Label(iconRect, new GUIContent(warningIcon, "The Avatar definition does not match the property path. Please author using a hierarchy the Avatar was built with."), warningIconStyle);
}
}

private void DoAddCurveButton(Rect rowRect, TreeViewItem node)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Mono/Animation/AnimationWindow/AnimEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public FrameRateMenuEntry(GUIContent content, float value)

public GUIContent content;
public float value;
};
}

internal static FrameRateMenuEntry[] kAvailableFrameRates = new FrameRateMenuEntry[]
{
Expand Down
11 changes: 0 additions & 11 deletions Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static bool HasAnyRecordableModifications(GameObject root, UndoPropertyModificat

static private UndoPropertyModification[] FilterModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject rootGameObject = state.activeRootGameObject;

List<UndoPropertyModification> discardedModifications = new List<UndoPropertyModification>();
Expand Down Expand Up @@ -163,7 +162,6 @@ static private void DiscardRotationModification(RotationModification rotationMod

static private UndoPropertyModification[] FilterRotationModifications(IAnimationRecordingState state, ref Dictionary<object, RotationModification> rotationModifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject rootGameObject = state.activeRootGameObject;

List<object> itemsToRemove = new List<object>();
Expand Down Expand Up @@ -213,9 +211,6 @@ static private void AddRotationPropertyModification(IAnimationRecordingState sta

static private void ProcessRotationModifications(IAnimationRecordingState state, ref Dictionary<object, RotationModification> rotationModifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject root = state.activeRootGameObject;

foreach (KeyValuePair<object, RotationModification> item in rotationModifications)
{
RotationModification m = item.Value;
Expand Down Expand Up @@ -387,9 +382,6 @@ static private void ProcessVector3Modification(IAnimationRecordingState state, E

static public void ProcessVector3Modifications(IAnimationRecordingState state, ref Dictionary<object, Vector3Modification> vector3Modifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject root = state.activeRootGameObject;

foreach (KeyValuePair<object, Vector3Modification> item in vector3Modifications)
{
Vector3Modification m = item.Value;
Expand All @@ -411,7 +403,6 @@ static public void ProcessVector3Modifications(IAnimationRecordingState state, r

static public void ProcessModifications(IAnimationRecordingState state, UndoPropertyModification[] modifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject root = state.activeRootGameObject;

// Record modified properties
Expand Down Expand Up @@ -500,7 +491,6 @@ static bool ValueFromPropertyModification(PropertyModification modification, Edi

static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, Type type, object previousValue, object currentValue)
{
GameObject root = state.activeRootGameObject;
AnimationClip clip = state.activeAnimationClip;

if ((clip.hideFlags & HideFlags.NotEditable) != 0)
Expand Down Expand Up @@ -573,7 +563,6 @@ internal class RootMotionModification
static private void ProcessRootMotionModifications(IAnimationRecordingState state,
ref Dictionary<object, RootMotionModification> rootMotionModifications)
{
AnimationClip clip = state.activeAnimationClip;
GameObject root = state.activeRootGameObject;
Animator animator = root.GetComponent<Animator>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum RecordingStateMode
{
ManualKey,
AutoKey
};
}

class RecordingState : IAnimationRecordingState
{
Expand Down Expand Up @@ -105,7 +105,7 @@ enum ResampleFlags
FlushUndos = 1 << 2,

Default = RefreshViews | FlushUndos
};
}

private static bool HasFlag(ResampleFlags flags, ResampleFlags flag)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,7 @@ private static int EnumPopup(string label, Type enumType, int selected)

private static bool IsSupportedMethodName(string name)
{
if (name == "Main" || name == "Start" || name == "Awake" || name == "Update")
return false;

return true;
return name != "Main" && name != "Start" && name != "Awake" && name != "Update";
}

private static string FormatEventArguments(IEnumerable<Type> paramTypes, AnimationEvent evt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public override bool IsRenamingItemAllowed(TreeViewItem item)
if (item is AnimationWindowHierarchyAddButtonNode || item is AnimationWindowHierarchyMasterNode || item is AnimationWindowHierarchyClipNode)
return false;

if ((item as AnimationWindowHierarchyNode).path.Length == 0)
return false;

return true;
return (item as AnimationWindowHierarchyNode).path.Length != 0;
}

public List<AnimationWindowHierarchyNode> CreateTreeFromCurves()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,6 @@ override public bool BeginRename(TreeViewItem item, float delay)
{
m_RenamedNode = item as AnimationWindowHierarchyNode;

GameObject rootGameObject = null;
if (m_RenamedNode.curves.Length > 0)
{
AnimationWindowSelectionItem selectionBinding = m_RenamedNode.curves[0].selectionBinding;
if (selectionBinding != null)
rootGameObject = selectionBinding.rootGameObject;
}

return GetRenameOverlay().BeginRename(m_RenamedNode.path, item.id, delay);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public enum Alignment
Center,
Left,
Right
};
}

public Alignment alignment;
public Color headColor;
Expand Down
8 changes: 4 additions & 4 deletions Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public enum RefreshType
None = 0,
CurvesOnly = 1,
Everything = 2
};
}

public enum SnapMode
{
Disabled = 0,
SnapToFrame = 1,
SnapToClipFrame = 2
};
}

[SerializeField] public AnimationWindowHierarchyState hierarchyState; // Persistent state of treeview on the left side of window
[SerializeField] public AnimEditor animEditor; // Reference to owner of this state. Used to trigger repaints.
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public void PasteKeys()
clipboardCurves.Add(keyframe.curve);

// If we have equal number of target and source curves, then match by index. If not, then try to match with AnimationWindowUtility.BestMatchForPaste.
bool matchCurveByIndex = clipboardCurves.Count() == activeCurves.Count();
bool matchCurveByIndex = clipboardCurves.Count == activeCurves.Count;
int targetIndex = 0;

foreach (AnimationWindowKeyframe keyframe in s_KeyframeClipboard)
Expand Down Expand Up @@ -1737,7 +1737,7 @@ public Vector2 timeRange

public string FormatFrame(int frame, int frameDigits)
{
return (frame / (int)frameRate).ToString() + ":" + (frame % frameRate).ToString().PadLeft(frameDigits, '0');
return (frame / (int)frameRate) + ":" + (frame % frameRate).ToString().PadLeft(frameDigits, '0');
}

//@TODO: Remove. Replace with animationkeytime
Expand Down
18 changes: 11 additions & 7 deletions Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Object = UnityEngine.Object;

using TangentMode = UnityEditor.AnimationUtility.TangentMode;
using CurveModifiedType = UnityEditor.AnimationUtility.CurveModifiedType;

namespace UnityEditorInternal
{
Expand Down Expand Up @@ -849,7 +848,7 @@ public static float GetNextKeyframeTime(AnimationWindowCurve[] curves, float cur

public static float GetPreviousKeyframeTime(AnimationWindowCurve[] curves, float currentTime, float frameRate)
{
float candidate = float.MinValue;
AnimationKeyTime candidateKeyTime = AnimationKeyTime.Time(float.MinValue, frameRate);
AnimationKeyTime time = AnimationKeyTime.Time(currentTime, frameRate);
AnimationKeyTime previousTime = AnimationKeyTime.Frame(time.frame - 1, frameRate);

Expand All @@ -859,14 +858,19 @@ public static float GetPreviousKeyframeTime(AnimationWindowCurve[] curves, float
{
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
{
if (keyframe.time > candidate && keyframe.time <= previousTime.time)
AnimationKeyTime keyTime = AnimationKeyTime.Time(keyframe.time, frameRate);
if (keyTime.frame >= candidateKeyTime.frame && keyTime.frame <= previousTime.frame)
{
candidate = keyframe.time;
found = true;
if (keyTime.time >= candidateKeyTime.time)
{
candidateKeyTime = keyTime;
found = true;
}
}
}
}
return found ? candidate : time.time;

return found ? candidateKeyTime.time : time.time;
}

// Add animator, controller and clip to gameobject if they are missing to make this gameobject animatable
Expand Down Expand Up @@ -1045,7 +1049,7 @@ internal static AnimationClip AllocateAndSetupClip(bool useAnimator)

public static int GetPropertyNodeID(int setId, string path, System.Type type, string propertyName)
{
return (setId.ToString() + path + type.Name + propertyName).GetHashCode();
return (setId + path + type.Name + propertyName).GetHashCode();
}

// What is the first animation player component (Animator or Animation) when recursing parent tree toward root
Expand Down
2 changes: 1 addition & 1 deletion Editor/Mono/Animation/AnimationWindow/CurveEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3861,7 +3861,7 @@ private void SetAxisUiScalars(Vector2 newScalars, List<CurveWrapper> curvesInSam
}
}

internal enum PickMode { None, Click, Marquee };
internal enum PickMode { None, Click, Marquee }

public void GridGUI()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void EventLineGUI(Rect rect, AnimationWindowState state)

public void DrawInstantTooltip(Rect position)
{
if (m_InstantTooltipText != null && m_InstantTooltipText != "")
if (!string.IsNullOrEmpty(m_InstantTooltipText))
{
// Draw body of tooltip
GUIStyle style = (GUIStyle)"AnimationEventTooltip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ static bool DoRepeatButton(Rect position, GUIContent content, GUIStyle style, Fo
}
return false;
case EventType.Repaint:
style.Draw(position, content, id);
// Handles.Repaint ();
style.Draw(position, content, id, false, position.Contains(Event.current.mousePosition));
return id == GUIUtility.hotControl && position.Contains(Event.current.mousePosition);
}
return false;
Expand Down Expand Up @@ -133,17 +132,13 @@ public static void MinMaxScroller(Rect position, int id, ref float value, ref fl

MinMaxSlider(sliderRect, ref value, ref size, newVisualStart, newVisualEnd, newVisualStart, newVisualEnd, slider, thumb, horiz);

bool wasMouseUpEvent = false;
if (Event.current.type == EventType.MouseUp)
wasMouseUpEvent = true;

if (ScrollerRepeatButton(id, minRect, leftButton))
value -= scrollStepSize * (visualStart < visualEnd ? 1f : -1f);

if (ScrollerRepeatButton(id, maxRect, rightButton))
value += scrollStepSize * (visualStart < visualEnd ? 1f : -1f);

if (wasMouseUpEvent && Event.current.type == EventType.Used) // repeat buttons ate mouse up event - release scrolling
if (Event.current.type == EventType.MouseUp && Event.current.type == EventType.Used) // repeat buttons ate mouse up event - release scrolling
scrollControlID = 0;

if (startLimit < endLimit)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Mono/Animation/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void DoUndo(Object target, string undoOperation)
}

public bool m_PushUndo;
};
}
}


Expand Down
4 changes: 2 additions & 2 deletions Editor/Mono/Animation/TimeArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum TimeFormat
None, // Unformatted time
TimeFrame, // Time:Frame
Frame // Integer frame
};
}

class Styles2
{
Expand Down Expand Up @@ -501,7 +501,7 @@ public string FormatTime(float time, float frameRate, TimeFormat timeFormat)
sign = "-";
frame = -frame;
}
return sign + (frame / (int)frameRate).ToString() + ":" +
return sign + (frame / (int)frameRate) + ":" +
(frame % frameRate).ToString().PadLeft(frameDigits, '0');
}
else
Expand Down
Loading

0 comments on commit 02d565c

Please sign in to comment.