// ================================================================================ Inspector public override void OnInspectorGui() { var settings = BGPrivateField.GetSettings(Curve); BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve); // Custom fields var warning = ""; BGEditorUtility.Assign(ref customUi, () => new BGTableView("Custom fields", new[] { "#", "Name", "Type", "?", "Delete" }, new[] { 5, 40, 40, 5, 10 }, () => { //add row customUi.NextColumn(rect => EditorGUI.LabelField(rect, "Name"), 12); customUi.NextColumn(rect => newFieldName = EditorGUI.TextField(rect, newFieldName), 28); customUi.NextColumn(rect => BGEditorUtility.PopupField(rect, newFieldType, @enum => newFieldType = (BGCurvePointField.TypeEnum)@enum), 50); customUi.NextColumn(rect => { if (!GUI.Button(rect, BGBinaryResources.BGAdd123)) { return; } if (NameHasError(Curve, newFieldName)) { return; } BGPrivateField.Invoke(Curve, BGCurve.MethodAddField, newFieldName, newFieldType, (Func <BGCurvePointField>)(() => Undo.AddComponent <BGCurvePointField>(Curve.gameObject))); GUIUtility.hotControl = 0; GUIUtility.ExitGUI(); }, 10); customUi.NextRow(); if (customFields == null || customFields.Length == 0) { customUi.NextRow("Name should be 16 chars max, starts with a letter and contain English chars and numbers only."); } else { //header customUi.DrawHeaders(); //fields var quaternionWithHandlesCount = 0; BGEditorUtility.ChangeCheck(() => { foreach (var customField in customFields) { if (customField.Field.Type == BGCurvePointField.TypeEnum.Quaternion && BGPrivateField.GetHandlesType(customField.Field) != 0) { quaternionWithHandlesCount++; } customField.Ui(customUi); } }, SceneView.RepaintAll); if (quaternionWithHandlesCount > 1) { warning = "You have more than one Quaternion field with Handles enabled. Only first field will be shown in Scene View"; } //footer customUi.NextRow("?- Show in Points Menu/Scene View"); } })); // System fields BGEditorUtility.Assign(ref systemUi, () => new BGTableView("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }, () => { BGEditorUtility.ChangeCheck(() => { foreach (var field in systemFields) { field.Ui(systemUi); } }, SceneView.RepaintAll); })); BGEditorUtility.Assign(ref systemFields, () => new[] { (SystemField) new SystemFieldPosition(settings), new SystemFieldControls(settings), new SystemFieldControlsType(settings), new SystemFieldTransform(settings), }); var fields = Curve.Fields; var hasFields = fields != null && fields.Length > 0; if (hasFields && (customFields == null || customFields.Length != fields.Length) || !hasFields && customFields != null && customFields.Length != fields.Length) { customFields = new PointField[fields.Length]; for (var i = 0; i < fields.Length; i++) { customFields[i] = new PointField(fields[i], i, BGBinaryResources.BGDelete123); } } //warnings BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled); BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled); //====================== Custom fields customUi.OnGui(); //warnings BGEditorUtility.HelpBox(warning, MessageType.Warning, warning.Length > 0); //====================== System fields systemUi.OnGui(); GUILayout.Space(4); }
private static bool SupportHandles(BGCurvePointField.TypeEnum typeEnum) { return(Type2SupportHandles.ContainsKey(typeEnum)); }
/// <summary> Get c# type(class), used for value of custom field with type "type"</summary> public static Type GetType(BGCurvePointField.TypeEnum type) { return(type2Type[type]); }
private static void Register(BGCurvePointField.TypeEnum typeEnum, Enum[] handlesTypes) { Type2SupportHandles[typeEnum] = true; Type2Handles[typeEnum] = handlesTypes; }
// register data about one type private static void Register(BGCurvePointField.TypeEnum typeEnum, Type type, Func <FieldsValues, int, object> getter, Action <FieldsValues, int, object> setter) { type2Type[typeEnum] = type; type2fieldGetter[type] = getter; type2fieldSetter[type] = setter; }