/// <summary> /// Constructs a new animation field entry and appends the necessary GUI elements to the provided layouts. /// </summary> /// <param name="layouts">Layouts to append the GUI elements to.</param> /// <param name="path">Path of the curve field.</param> /// <param name="childEntries">Sub-path names of the child entries to display.</param> /// <param name="colors">Colors of the curves to display, for each child entry.</param> public GUIAnimComplexEntry(GUIAnimFieldLayouts layouts, string path, string[] childEntries, Color[] colors) : base(layouts, path, false, 20) { foldout = new GUIToggle("", EditorStyles.Expand); foldout.OnToggled += Toggle; GUILabel spacer = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); foldoutLayout = layouts.overlay.AddLayoutX(); foldoutLayout.AddSpace(5); foldoutLayout.AddElement(foldout); foldoutLayout.AddElement(spacer); foldoutLayout.AddFlexibleSpace(); underlaySpacing = new GUILabel("", GUIOption.FixedHeight(GetEntryHeight())); layouts.underlay.AddElement(underlaySpacing); children = new GUIAnimSimpleEntry[childEntries.Length]; for (int i = 0; i < childEntries.Length; i++) { Color color; if (i < colors.Length) { color = colors[i]; } else { color = Color.White; } children[i] = new GUIAnimSimpleEntry(layouts, path + childEntries[i], color, true); children[i].OnEntrySelected += x => { OnEntrySelected?.Invoke(x); }; } Toggle(false); }
/// <summary> /// Rebuilds the entire GUI based on the current field list and their properties. /// </summary> private void Rebuild() { scrollArea.Layout.Clear(); fields = null; if (fieldInfos == null || root == null) { return; } GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header); scrollArea.Layout.AddElement(header); layouts = new GUIAnimFieldLayouts(); GUIPanel rootPanel = scrollArea.Layout.AddPanel(); GUIPanel mainPanel = rootPanel.AddPanel(); GUIPanel underlayPanel = rootPanel.AddPanel(1); GUIPanel overlayPanel = rootPanel.AddPanel(-1); GUIPanel backgroundPanel = rootPanel.AddPanel(2); layouts.main = mainPanel.AddLayoutY(); layouts.underlay = underlayPanel.AddLayoutY(); layouts.overlay = overlayPanel.AddLayoutY(); layouts.background = backgroundPanel.AddLayoutY(); GUIButton catchAll = new GUIButton("", EditorStyles.Blank); catchAll.Bounds = new Rect2I(0, 0, width, height - header.Bounds.height); catchAll.OnClick += () => OnEntrySelected(null); underlayPanel.AddElement(catchAll); layouts.main.AddSpace(5); layouts.underlay.AddSpace(5); layouts.overlay.AddSpace(5); layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better fields = new GUIAnimFieldEntry[fieldInfos.Count]; for (int i = 0; i < fieldInfos.Count; i++) { if (string.IsNullOrEmpty(fieldInfos[i].path)) { continue; } bool entryIsMissing; if (fieldInfos[i].curveGroup.isPropertyCurve) { string pathSuffix; SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix); entryIsMissing = property == null; } else { entryIsMissing = false; } if (!entryIsMissing) { Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length]; for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++) { colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color; } switch (fieldInfos[i].curveGroup.type) { case SerializableProperty.FieldType.Vector2: fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Vector3: fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Vector4: fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Color: fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors); break; case SerializableProperty.FieldType.Bool: case SerializableProperty.FieldType.Int: case SerializableProperty.FieldType.Float: { Color color; if (colors.Length > 0) { color = colors[0]; } else { color = Color.White; } fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color); break; } } } else { fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path); } if (fields[i] != null) { fields[i].OnEntrySelected += OnEntrySelected; } } if (fieldInfos.Count == 0) { GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating.")); GUILayoutY vertLayout = layouts.main.AddLayoutY(); vertLayout.AddFlexibleSpace(); GUILayoutX horzLayout = vertLayout.AddLayoutX(); vertLayout.AddFlexibleSpace(); horzLayout.AddFlexibleSpace(); horzLayout.AddElement(warningLbl); horzLayout.AddFlexibleSpace(); } layouts.main.AddSpace(5); layouts.underlay.AddSpace(5); layouts.overlay.AddSpace(5); layouts.background.AddSpace(5); layouts.main.AddFlexibleSpace(); layouts.underlay.AddFlexibleSpace(); layouts.overlay.AddFlexibleSpace(); layouts.background.AddFlexibleSpace(); }