protected void MeshGenerationToggle() { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn")); if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"), GUILayout.Width(120))) { return; } if (MeshColliderAbstract.IsMeshGenerationOn) { BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first."); return; } var renderer = MeshColliderAbstract.GetComponent <MeshRenderer>(); if (renderer != null) { BGCurve.DestroyIt(renderer); } var filter = MeshColliderAbstract.GetComponent <MeshFilter>(); if (filter != null) { BGCurve.DestroyIt(filter); } }); }
private void OnGUI() { BGEditorUtility.SwapLabelWidth(60, () => { BGEditorUtility.Horizontal(BGEditorUtility.Assign(ref boxStyle, () => new GUIStyle("Box") { padding = new RectOffset(8, 8, 8, 8) }), () => { ccName = EditorGUILayout.TextField("Name", ccName); GUILayout.Space(8); if (GUILayout.Button("Save and Close")) { if (!string.Equals(ccName, current.CcName)) { Undo.RecordObject(current, "Change name"); current.CcName = ccName; EditorUtility.SetDirty(current); } instance.Close(); } }); }); }
protected override void InternalOnInspectorGUI() { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("fields")); // if (GUILayout.Button("Update")) Math.Recalculate(); }); BGEditorUtility.VerticalBox(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("mathType")); switch (Math.MathType) { case BGCcMath.MathTypeEnum.Base: EditorGUILayout.PropertyField(serializedObject.FindProperty("sectionParts")); break; case BGCcMath.MathTypeEnum.Adaptive: EditorGUILayout.PropertyField(serializedObject.FindProperty("tolerance")); break; } }); EditorGUILayout.PropertyField(serializedObject.FindProperty("optimizeStraightLines")); if (Math.Fields == BGCurveBaseMath.Fields.PositionAndTangent) { EditorGUILayout.PropertyField(serializedObject.FindProperty("usePositionToCalculateTangents")); } BGEditorUtility.VerticalBox(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("updateMode")); if (Math.UpdateMode == BGCcMath.UpdateModeEnum.RendererVisible) { EditorGUILayout.PropertyField(serializedObject.FindProperty("rendererForUpdateCheck")); } }); try { //by some reason NullReferenceException exceptions are fired at certain GUI passes EditorGUILayout.PropertyField(serializedObject.FindProperty("mathChangedEvent")); } catch (NullReferenceException) { } }
private void MiscParams() { EditorGUILayout.PropertyField(serializedObject.FindProperty("material")); EditorGUILayout.PropertyField(serializedObject.FindProperty("isTrigger")); EditorGUILayout.PropertyField(serializedObject.FindProperty("usedByEffector")); BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("effector"), true); if (GUILayout.Button("Sync")) { Collider2DBox.UpdateUi(); } }); }
public override void OnInspectorGUI() { //adjust math if needed AdjustMath(BGPrivateField.GetSettings(Curve), Math); //styles BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") {fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {textColor = Color.white}}); serializedObject.Update(); // =========== Header DrawLogo(); // =========== lock view BGEditorUtility.Horizontal(() => { var temp = BGCurveSettingsForEditor.LockView; BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of any object in the scene, except points", LockViewActiveColor, new GUIContent("Turn Off", "Click to turn this mode off"), new GUIContent("Turn On", "Click to turn this mode on")); if (GUILayout.Button(BGBinaryResources.BGSettingsIcon123, GUILayout.MaxWidth(24), GUILayout.MaxHeight(24))) BGCurveSettingsForEditorWindow.Open(BGCurveSettingsForEditor.I); }); //warning BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8)); // =========== Tabs var currentTab = BGCurveSettingsForEditor.CurrentTab; if (currentTab < 0 || currentTab > headers.Length - 1) currentTab = 0; var newTab = GUILayout.Toolbar(currentTab, headers, GUILayout.Height(ToolBarHeight)); //do not move this method(GUILayoutUtility.GetLastRect() is used) ShowStickers(); if (currentTab != newTab) GUI.FocusControl(""); BGCurveSettingsForEditor.CurrentTab = newTab; editors[newTab].OnInspectorGui(); if (!GUI.changed) return; // if no change- return foreach (var editor in editors) editor.OnApply(); transformMonitor.CheckForChange(); }
private void MeshGeneratorEditor() { BGEditorUtility.VerticalBox(() => { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn")); if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"), GUILayout.Width(120))) { return; } if (Collider3DBox.IsMeshGenerationOn) { BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first."); return; } var colliders = new List <BoxCollider>(); Collider3DBox.FillChildrenColliders(colliders); foreach (var collider in colliders) { var renderer = collider.GetComponent <MeshRenderer>(); if (renderer != null) { BGCurve.DestroyIt(renderer); } var filter = collider.GetComponent <MeshFilter>(); if (filter != null) { BGCurve.DestroyIt(filter); } } }); if (Collider3DBox.IsMeshGenerationOn) { EditorGUILayout.PropertyField(serializedObject.FindProperty("MeshMaterial")); } }); }
private void InspectorTopSection() { if (Curve.PointsCount == 0) { EditorGUILayout.HelpBox( "1) Ctrl + LeftClick in scene view to add a point and snap it to " + "\r\n a) 3D mode: mesh with collider" + "\r\n b) 2D mode: curve's 2D plane." + "\r\n" + "\r\n2) Ctrl + Shift + LeftClick in Scene View to add a point unconditionally at some distance, specified in the settings." + "\r\n" + "\r\n3) Hold control over existing point or selection to access Scene View menu" + "\r\n" + "\r\n4) Hold shift + drag to use rectangular selection in Scene View" , MessageType.Info); } EditorGUILayout.PropertyField(closedProperty); EditorGUILayout.PropertyField(mode2DProperty); BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(controlTypeProperty); if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "Convert control types for all existing points ", 44)) { return; } var settings = Settings; foreach (var point in Curve.Points.Where(point => point.ControlType != settings.ControlType)) { point.ControlType = settings.ControlType; } }); }
protected override void AdditionalParams() { BGEditorUtility.VerticalBox(() => { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("profileMode")); if (!GUILayout.Button("Rebuild")) { return; } Sweep2D.UpdateUI(); }); if (Sweep2D.ProfileMode == BGCcSweep2D.ProfileModeEnum.Line) { EditorGUILayout.PropertyField(serializedObject.FindProperty("lineWidth")); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("profileSpline")); if (Sweep2D.ProfileSpline != null) { // BGEditorUtility.CustomField(new GUIContent("U Coord Field"), Sweep2D.ProfileSpline.Curve, Sweep2D.UCoordinateField, BGCurvePointField.TypeEnum.Float, field => Sweep2D.UCoordinateField = field); } } }); EditorGUILayout.PropertyField(serializedObject.FindProperty("uCoordinateStart")); EditorGUILayout.PropertyField(serializedObject.FindProperty("uCoordinateEnd")); EditorGUILayout.PropertyField(serializedObject.FindProperty("swapUV")); EditorGUILayout.PropertyField(serializedObject.FindProperty("swapNormals")); EditorGUILayout.PropertyField(serializedObject.FindProperty("vCoordinateScale")); }
private void InspectorTopSection() { if (Curve.PointsCount == 0) { EditorGUILayout.HelpBox( "1) Ctrl + LeftClick in scene view to add a point and snap it to " + "\r\n a) 3D mode: mesh with collider" + "\r\n b) 2D mode: curve's 2D plane." + "\r\n" + "\r\n2) Ctrl + Shift + LeftClick in Scene View to add a point unconditionally at some distance, specified in the settings." + "\r\n" + "\r\n3) Hold control over existing point or selection to access Scene View menu" + "\r\n" + "\r\n4) Hold shift + drag to use rectangular selection in Scene View" + "\r\n" + "\r\n5) Ctrl + LeftClick over existing spline to insert a point" , MessageType.Info); } try { // Curve's block BGEditorUtility.VerticalBox(() => { //closed EditorGUILayout.PropertyField(closedProperty); //point's store mode BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(pointsModeProperty); BGEditorUtility.DisableGui(() => { BGEditorUtility.Assign(ref syncContent, () => new GUIContent("Sync", "Sort points Game Objects and update names")); if (!GUILayout.Button(syncContent)) { return; } BGPrivateField.Invoke(Curve, BGCurve.MethodSetPointsNames); }, !BGCurve.IsGoMode(Curve.PointsMode)); }); //2D mode BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(mode2DProperty); BGEditorUtility.DisableGui(() => { if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80))) { return; } Curve.FireBeforeChange(BGCurve.Event2D); Curve.Apply2D(Curve.Mode2D); Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.Event2D)); }, mode2DProperty.enumValueIndex == 0); }); //snapping BGEditorUtility.VerticalBox(() => { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(snapTypeProperty); BGEditorUtility.DisableGui(() => { if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80))) { return; } Curve.FireBeforeChange(BGCurve.EventSnapType); Curve.ApplySnapping(); Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapType)); }, snapTypeProperty.enumValueIndex == 0); }); if (snapTypeProperty.enumValueIndex == 0) { return; } EditorGUILayout.PropertyField(snapAxisProperty); EditorGUILayout.PropertyField(snapDistanceProperty); EditorGUILayout.PropertyField(snapTriggerInteractionProperty); EditorGUILayout.PropertyField(snapToBackFacesProperty); BGEditorUtility.LayerMaskField("Snap Layer Mask", Curve.SnapLayerMask, i => { Curve.FireBeforeChange(BGCurve.EventSnapTrigger); Curve.SnapLayerMask = i; Curve.ApplySnapping(); Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapTrigger)); }); EditorGUILayout.PropertyField(snapMonitoringProperty); if (Curve.SnapMonitoring && Curve.SnapType != BGCurve.SnapTypeEnum.Off) { EditorGUILayout.HelpBox("You enabled snap monitoring, which monitor environment every frame and snap to it. Be aware, this is a very costly function", MessageType.Warning); } }); //event mode EditorGUILayout.PropertyField(eventModeProperty); //force update EditorGUILayout.PropertyField(forceChangedEventModeProperty); //convert control type BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(controlTypeProperty); if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGConvertAll123, "Convert control types for all existing points ", 44)) { return; } var settings = Settings; foreach (var point in Curve.Points.Where(point => point.ControlType != settings.ControlType)) { point.ControlType = settings.ControlType; } }); }); } catch (BGEditorUtility.ExitException) { GUIUtility.ExitGUI(); } }
//OnInspectorGui for selection public void InspectorSelectionOperations() { BGEditorUtility.VerticalBox(() => { // ================================================ Global operations BGEditorUtility.HorizontalBox(() => { BGEditorUtility.SwapLabelWidth(80, () => EditorGUILayout.LabelField("Selected (" + points.Count + ")")); if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete selected points")) { if (!DeleteSelected()) { return; } } GUILayout.Space(4); if (BGEditorUtility.ButtonWithIcon(selectAllTexture, "Select all points", 35)) { Changed = Changed || points.Count != curve.PointsCount; points.Clear(); foreach (var point1 in curve.Points) { points.Add(point1); } } GUILayout.Space(4); if (BGEditorUtility.ButtonWithIcon(deselectAllTexture, "Deselect all points", 35)) { Clear(); } }); // ================================================ Selections operations // skip mouse buttons events which change selection if (Changed) { return; } GUILayout.Space(5); if (HasSelected()) { BGEditorUtility.SwapGuiBackgroundColor(SelectedBackgroundColor, () => { BGEditorUtility.VerticalBox(() => { var averagePositionSelected = GetAveragePosition(); // ===================================================== Control handles BGEditorUtility.Horizontal(() => { controlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Controls", controlType); if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "Set control type for all selected points", 44)) { return; } SetControlTypeForSelected(controlType); }); // ===================================================== Average positions & delete BGEditorUtility.Vector3Field("Average position", "Average points position. Change several points positions at once, keeping distance difference intact", averagePositionSelected, newAverage => { var delta = newAverage - averagePositionSelected; curve.Transaction(() => { foreach (var point in points) { point.PositionWorld += delta; } }); }); // ===================================================== Set position directly BGEditorUtility.Vector3Field("Set position", "Set points position directly", averagePositionSelected, newPosition => { curve.Transaction(() => { if (BGEditorUtility.AnyChange(averagePositionSelected.x, newPosition.x)) { SetX(newPosition.x); } if (BGEditorUtility.AnyChange(averagePositionSelected.y, newPosition.y)) { SetY(newPosition.y); } if (BGEditorUtility.AnyChange(averagePositionSelected.z, newPosition.z)) { SetZ(newPosition.z); } }); }); // ===================================================== Set control positions directly var count = 0; var averageControl1Sum = Vector3.zero; var averageControl2Sum = Vector3.zero; foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { count++; averageControl1Sum += point.ControlFirstLocal; averageControl2Sum += point.ControlSecondLocal; } if (count == 0) { return; } //has points with bezier controls BGEditorUtility.Vector3Field("Set Control 1", "Set 1st control position directly", averageControl1Sum / count, newPosition => { curve.Transaction( () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { point.ControlFirstLocal = newPosition; } }); }); BGEditorUtility.Vector3Field("Set Control 2", "Set 2nd control position directly", averageControl2Sum / count, newPosition => { curve.Transaction( () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { point.ControlSecondLocal = newPosition; } }); }); }); }); } else { BGEditorUtility.HelpBox("Hold shift to use rectangular selection\r\nClick or click+drag over tick icons to (de)select points", MessageType.Info, curve.PointsCount > 0); } }); }
public override void OnInspectorGUI() { serializedObject.Update(); var componentChanged = BGEditorUtility.ChangeCheck(() => { //custom fields InternalOnInspectorGUI(); // ------------- parents if (parentClass != null) { var possibleParents = cc.GetComponents(parentClass); if (possibleParents.Length > 1) { BGEditorUtility.Horizontal(() => { GUILayout.Space(10); BGEditorUtility.VerticalBox(() => { var myParent = cc.GetParent(parentClass); var options = new string[possibleParents.Length]; var index = 0; for (var i = 0; i < possibleParents.Length; i++) { var possibleParent = possibleParents[i]; if (possibleParent == myParent) { index = i; } options[i] = ((BGCc)possibleParent).CcName; } //show popup var label = BGCc.GetDescriptor(parentClass).Name ?? parentClass.Name; var newIndex = EditorGUILayout.Popup(label, index, options); if (newIndex != index) { Undo.RecordObject(cc, "parent change"); cc.SetParent((BGCc)possibleParents[newIndex]); if (ChangedParent != null) { ChangedParent(this, null); } } }); }); } } }); //-------------- handles if (cc.SupportHandles && !BGCurveSettingsForEditor.CcInspectorHandlesOff && !cc.HideHandlesInInspector) { BGEditorUtility.Horizontal(() => { GUILayout.Space(10); BGEditorUtility.VerticalBox(() => { var showHandlesProperty = serializedObject.FindProperty("showHandles"); EditorGUILayout.PropertyField(showHandlesProperty); if (cc.SupportHandlesSettings && showHandlesProperty.boolValue) { BGEditorUtility.Indent(1, ShowHandlesSettings); } }); }); } //-------------- status var info = cc.Info; BGEditorUtility.HelpBox(info, MessageType.Info, !string.IsNullOrEmpty(info)); //-------------- warning var warning = cc.Warning; BGEditorUtility.HelpBox(warning, MessageType.Warning, !string.IsNullOrEmpty(warning)); //-------------- error var error = cc.Error; BGEditorUtility.HelpBox(error, MessageType.Error, !string.IsNullOrEmpty(error)); if (!GUI.changed) { return; } Undo.RecordObject(cc, "fields change"); serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(cc); if (componentChanged) { cc.FireChangedParams(); } InternalOnInspectorGUIPost(); }
public override void OnInspectorGui() { settings = SerializedObject.FindProperty("settings"); var settingsObj = Settings; // Save & Load showSaveLoad = EditorGUILayout.Foldout(showSaveLoad, "Save and load settings"); if (showSaveLoad) { BGEditorUtility.VerticalBox(() => { var path = BGCurveSettingsOperations.GetPath(); BGEditorUtility.HelpBox("Folder is not set", MessageType.Info, path == null, () => { EditorGUILayout.LabelField("Folder", path); BGEditorUtility.HelpBox("Folder is not found", MessageType.Warning, !BGCurveSettingsOperations.IsValid(path), () => { // ================================= Load settings var all = BGCurveSettingsOperations.GetAll(); BGEditorUtility.HelpBox("Folder does not have any settings", MessageType.Warning, all == null || all.Length == 0, () => { BGEditorUtility.Horizontal(() => { var options = new List <GUIContent> { new GUIContent("") }; options.AddRange(all.Select(setting => new GUIContent(setting))); var selected = EditorGUILayout.Popup(new GUIContent("Load", "Load a specified settings for current object"), 0, options.ToArray()); if (selected > 0) { var newSettings = BGCurveSettingsOperations.Load(options[selected].text); if (newSettings != null) { BGPrivateField.SetSettings(Curve, newSettings); EditorUtility.SetDirty(Curve); lastOperation = options[selected].text + " was loaded"; } else { lastOperation = "Unable to load a settings " + options[selected].text; } } if (GUILayout.Button(new GUIContent("Reload", "Reload settings from disk. This operation does not change settings for the curent object."))) { BGCurveSettingsOperations.Reload(BGCurveSettingsOperations.GetPath()); lastOperation = "Settings was reloaded from disk"; } }); }); // ================================= Save settings BGEditorUtility.Horizontal(() => { newAssetName = EditorGUILayout.TextField(new GUIContent("Save", "Save current setting on disk"), newAssetName); if (!GUILayout.Button(new GUIContent("Save", "Save current setting on disk"))) { return; } if (newAssetName == null || newAssetName.Trim().Equals("")) { BGEditorUtility.Inform("Invalid asset name", "Please, enter the name for new asset"); } else { lastOperation = BGCurveSettingsOperations.Save(settingsObj, newAssetName) ? newAssetName + " was saved on disk" : "Unable to save " + newAssetName + " on disk"; } }); BGEditorUtility.HelpBox(lastOperation, MessageType.Info, lastOperation != null); }); }); BGEditorUtility.Horizontal(() => { if (GUILayout.Button(new GUIContent("Save as default", "Save current settings as default for future curves"))) { lastOperation = BGCurveSettingsOperations.SaveDefault(settingsObj) ? "Current settings was saved as default" : "Unable to save settings on disk as default"; } if (GUILayout.Button(new GUIContent("Chose a folder", "Chose a folder where to store settings files"))) { BGCurveSettingsOperations.ChoseDir(); } }); }); } EditorGUILayout.HelpBox("All fields settings are under Fields tab", MessageType.Warning); BGEditorUtility.ChangeCheck(() => { //Points BGEditorUtility.VerticalBox(() => { //Hide handles EditorGUILayout.PropertyField(Find("hideHandles")); EditorGUILayout.PropertyField(Find("newPointDistance")); EditorGUILayout.PropertyField(Find("showPointMenu")); EditorGUILayout.PropertyField(Find("restrictGizmoz")); if (settingsObj.RestrictGizmozSettings.Valid && settingsObj.RestrictGizmozSettings.HasValue) { EditorGUILayout.HelpBox("Gizmos are shown for specified points only", MessageType.Warning); } }); var tangentProp = Find("showTangents"); //curve BGEditorUtility.FadeGroup(showCurveProp, () => { // EditorGUILayout.PropertyField(Find("showCurveMode")); EditorGUILayout.PropertyField(Find("showCurveOption")); EditorGUILayout.PropertyField(Find("sections")); EditorGUILayout.PropertyField(Find("vRay")); EditorGUILayout.PropertyField(Find("lineColor")); //tangents BGEditorUtility.VerticalBox(() => { EditorGUILayout.PropertyField(tangentProp); if (settingsObj.ShowTangents) { BGEditorUtility.Indent(1, () => { EditorGUILayout.PropertyField(Find("tangentsSize")); EditorGUILayout.PropertyField(Find("tangentsPerSection")); EditorGUILayout.PropertyField(Find("tangentsColor")); }); } }); }); }, () => { //if any change SerializedObject.ApplyModifiedProperties(); SceneView.RepaintAll(); }); }
private void HeaderUi(int level, bool hasError) { var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0)); BGEditorUtility.SwapGuiBackgroundColor(color, () => { BGEditorUtility.Horizontal(headerBoxStyle, () => { BGEditorUtility.Indent(1, () => { var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")", descriptor == null ? null : descriptor.Description); var width = headerFoldoutStyle.CalcSize(content).x + 16; BGEditorUtility.SwapLabelWidth((int)width, () => { //foldout (we dont use layout version cause it does not support clickin on labels) Collapsed = EditorGUI.Foldout( GUILayoutUtility.GetRect(width, 16f), Collapsed, content, true, Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled); }); }); GUILayout.FlexibleSpace(); // status(error or Ok) EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle); //help url if (!String.IsNullOrEmpty(Cc.HelpURL)) { if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGHelp123, "Open help in the browser")) { Application.OpenURL(Cc.HelpURL); } EditorGUILayout.Separator(); } //change visibility if (BGEditorUtility.ButtonWithIcon(Cc.Hidden ? BGBinaryResources.BGHiddenOn123 : BGBinaryResources.BGHiddenOff123, "Hide/Show properties")) { Cc.Hidden = !Cc.Hidden; } EditorGUILayout.Separator(); //change name if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCcEditName123, "Change the name")) { BGCcChangeNameWindow.Open(Cc); } EditorGUILayout.Separator(); //add a child if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add a component, which is dependant on this component")) { BGCcAddWindow.Open(MyTree.Curve, type => { //cache some data var gameObject = Cc.Curve.gameObject; var oldComponents = gameObject.GetComponents <BGCc>(); var currentCcType = Cc.GetType(); //add var addedCc = AddComponent(MyTree.Curve, type); if (addedCc == null) { return; } //we need to process all the way up to the Cc and link Ccs to right (newly created) parents var parentClass = addedCc.GetParentClass(); var recursionLimit = 16; var cc = addedCc; while (parentClass != null && recursionLimit-- > 0) { if (currentCcType == parentClass) { //we reached the current Cc cc.SetParent(Cc); break; } //going up var possibleParents = gameObject.GetComponents(parentClass); var parent = possibleParents.Where(possibleParent => !oldComponents.Contains(possibleParent)).Cast <BGCc>().FirstOrDefault(); if (parent == null) { break; } cc.SetParent(parent); cc = parent; parentClass = cc.GetParentClass(); } }, Cc.GetType()); } EditorGUILayout.Separator(); //enable/disable if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? BGBinaryResources.BGTickYes123 : BGBinaryResources.BGTickNo123, "Enable/disable a component")) { Enable(!Cc.enabled); } EditorGUILayout.Separator(); //delete if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Remove this component")) { return; } //remove Delete(); EditorUtility.SetDirty(MyTree.Curve.gameObject); //not sure how to make proper exit throw new BGEditorUtility.ExitException(); }); }); }
public override void OnInspectorGUI() { //adjust math if needed AdjustMath(BGPrivateField.GetSettings(Curve), Math); //styles BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") { fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState { textColor = Color.white } }); BGEditorUtility.Assign(ref settingsTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSettingsIcon123)); serializedObject.Update(); // =========== Header DrawLogo(); // =========== lock view BGEditorUtility.Horizontal(() => { var temp = BGCurveSettingsForEditor.LockView; BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of other objects in the scene", LockViewActiveColor, new GUIContent("Turn Off", "Click to turn this mode off"), new GUIContent("Turn On", "Click to turn this mode on")); if (BGEditorUtility.ButtonWithIcon(settingsTexture, "Open BGCurve Editor Settings", 24, 24)) { BGCurveSettingsForEditorWindow.Open(); } }); //warning BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.\r\n Use rectangular selection without pressing shift", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8)); // =========== Tabs if (BGCurveSettingsForEditor.CurrentTab < 0 || BGCurveSettingsForEditor.CurrentTab > headers.Length - 1) { BGCurveSettingsForEditor.CurrentTab = 0; } BGCurveSettingsForEditor.CurrentTab = GUILayout.Toolbar(BGCurveSettingsForEditor.CurrentTab, headers, GUILayout.Height(ToolBarHeight)); //do not move this method(GUILayoutUtility.GetLastRect() is used) ShowStickers(); editors[BGCurveSettingsForEditor.CurrentTab].OnInspectorGui(); if (!GUI.changed) { return; // if no change- return } foreach (var editor in editors) { editor.OnBeforeApply(); } serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(Curve); foreach (var editor in editors) { editor.OnApply(); } transformMonitor.Check(); }
internal void OnInspectorGui(BGCurvePointI point, int index, BGCurveSettings settings) { var mode2D = point.Curve.Mode2D; //point transform if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined && point.PointTransform != null) { var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point); if (referenceToPoint == null) { point.PointTransform.gameObject.AddComponent <BGCurveReferenceToPoint>().Point = point; } } BGEditorUtility.HorizontalBox(() => { if (editorSelection != null) { editorSelection.InspectorSelectionRect(point); } BGEditorUtility.VerticalBox(() => { BGEditorUtility.SwapLabelWidth(60, () => { if (!settings.ShowPointPosition && !settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { //nothing to show- only label EditorGUILayout.LabelField("Point " + index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { //control type if (settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { point.ControlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Point " + index, point.ControlType); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } //position if (settings.ShowPointPosition) { if (!settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { PositionField("Point " + index, point, mode2D, index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { PositionField("Pos", point, mode2D, index); } } } }); // control positions if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent && settings.ShowPointControlPositions) { // 1st ControlField(point, mode2D, 1); // 2nd ControlField(point, mode2D, 2); } //transform if (settings.ShowTransformField) { BGEditorUtility.ComponentField("Transform", point.PointTransform, transform => { if (transform != null) { Undo.RecordObject(transform, "Object moved"); if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined) { Undo.AddComponent <BGCurveReferenceToPoint>(transform.gameObject).Point = point; } } if (point.PointTransform != null) { var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point); if (referenceToPoint != null) { Undo.DestroyObjectImmediate(referenceToPoint); } } point.PointTransform = transform; }); } //fields if (point.Curve.FieldsCount > 0) { ShowFields(point); } BGEditorUtility.EndIndent(1); }); }); }
public virtual Rect OnInspectorGui() { var level = Level; var myRect = new Rect(); BGEditorUtility.Vertical(() => { BGEditorUtility.Horizontal(() => { if (level > 0 && tree.Configuration.HorizontalSpace > 0) { GUILayout.Space(tree.Configuration.HorizontalSpace * level); } BGEditorUtility.Vertical(() => { OnInspectorGuiInternal(level); }); myRect = GUILayoutUtility.GetLastRect(); }); }); if (Event.current.type == EventType.Repaint) { Rect = myRect; } if (children == null || children.Count == 0 || Collapsed) { return(myRect); } //Children var texture = tree.GetLinkTexture(level); var linkStartX = myRect.x + tree.Configuration.HorizontalLinkOffset; var childRect = new Rect(); var linkSize = tree.Configuration.LinkLineSize; if (postActions != null) { postActions.Clear(); } foreach (var child in children) { if (tree.Configuration.VerticalSpace > 0) { GUILayout.Space(tree.Configuration.VerticalSpace); } childRect = child.OnInspectorGui(); //horizontal link var linkWidth = childRect.x - linkStartX; if (!(linkWidth > 0)) { continue; } //child Y Center var childCenterY = childRect.y + childRect.size.y * .5f; //link var horizontalLink = new Rect( linkStartX, childCenterY - linkSize * .5f, linkWidth, linkSize); GUI.DrawTexture(horizontalLink, texture, ScaleMode.StretchToFill); //icon var iconSize = tree.Configuration.ExpandCollapseIconSize; if (iconSize > 0 && child.HasChildren) { BGEditorUtility.Assign(ref buttonStyle, () => new GUIStyle("Button") { margin = new RectOffset(), padding = new RectOffset(), border = new RectOffset() }); postActions = postActions ?? new List <Action>(); var childRef = child; postActions.Add(() => { var iconSizeHalf = iconSize * .5f; if (GUI.Button(new Rect( linkStartX - iconSizeHalf + linkSize * .5f, childCenterY - iconSizeHalf + linkSize * .5f, iconSize, iconSize), childRef.Collapsed ? tree.CollapsedIconTexture : tree.ExpandedIconTexture, buttonStyle)) { childRef.Collapsed = !childRef.Collapsed; } }); } } if (linkStartX < childRect.x) { //vertical link GUI.DrawTexture(new Rect( linkStartX, myRect.yMax, linkSize, childRect.center.y - myRect.yMax ), texture, ScaleMode.StretchToFill); } if (postActions != null && postActions.Count > 0) { foreach (var postAction in postActions) { postAction(); } } return(myRect); }
private void HeaderUi(int level, bool hasError) { var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0)); BGEditorUtility.SwapGuiBackgroundColor(color, () => { BGEditorUtility.Horizontal(headerBoxStyle, () => { BGEditorUtility.Indent(1, () => { var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")", descriptor == null ? null : descriptor.Description); var width = headerFoldoutStyle.CalcSize(content).x + 16; BGEditorUtility.SwapLabelWidth((int)width, () => { //foldout (we dont use layout version cause it does not support clickin on labels) Collapsed = EditorGUI.Foldout( GUILayoutUtility.GetRect(width, 16f), Collapsed, content, true, Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled); }); }); GUILayout.FlexibleSpace(); // status(error or Ok) EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle); //help url if (!String.IsNullOrEmpty(Cc.HelpURL)) { if (BGEditorUtility.ButtonWithIcon(helpTexture, "Open help in the browser")) { Application.OpenURL(Cc.HelpURL); } EditorGUILayout.Separator(); } //change name if (BGEditorUtility.ButtonWithIcon(changeNameTexture, "Change the name")) { BGCcChangeNameWindow.Open(Cc); } EditorGUILayout.Separator(); //add child if (BGEditorUtility.ButtonWithIcon(addTexture, "Add a component, which is dependant on this component")) { BGCcAddWindow.Open(MyTree.Curve, type => { var bgCc = AddComponent(MyTree.Curve, type); bgCc.SetParent(Cc); }, Cc.GetType()); } EditorGUILayout.Separator(); //enable/disable if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? enabledTexture : disabledTexture, "Enable/disable a component")) { Enable(!Cc.enabled); } EditorGUILayout.Separator(); //delete if (!BGEditorUtility.ButtonWithIcon(deleteTexture, "Remove this component")) { return; } //remove Delete(); EditorUtility.SetDirty(MyTree.Curve.gameObject); //not sure how to make proper exit throw new ExitException(); }); }); }
protected override void AdditionalParams() { EditorGUILayout.PropertyField(serializedObject.FindProperty("width")); EditorGUILayout.PropertyField(serializedObject.FindProperty("height")); EditorGUILayout.PropertyField(serializedObject.FindProperty("heightOffset")); EditorGUILayout.PropertyField(serializedObject.FindProperty("lengthExtends")); EditorGUILayout.PropertyField(serializedObject.FindProperty("material")); EditorGUILayout.PropertyField(serializedObject.FindProperty("isTrigger")); BGEditorUtility.VerticalBox(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("heightAxisMode")); if (Collider3DBox.HeightAxisMode == BGCcCollider3DBox.HeightAxisModeEnum.Custom) { EditorGUILayout.PropertyField(serializedObject.FindProperty("customHeightAxis")); } EditorGUILayout.PropertyField(serializedObject.FindProperty("heightAxisRotation")); }); BGEditorUtility.VerticalBox(() => { BGEditorUtility.Horizontal(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn")); if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"), GUILayout.Width(120))) { return; } if (Collider3DBox.IsMeshGenerationOn) { BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first."); return; } var colliders = new List <BoxCollider>(); Collider3DBox.FillChildrenColliders(colliders); foreach (var collider in colliders) { var renderer = collider.GetComponent <MeshRenderer>(); if (renderer != null) { BGCurve.DestroyIt(renderer); } var filter = collider.GetComponent <MeshFilter>(); if (filter != null) { BGCurve.DestroyIt(filter); } } }); if (Collider3DBox.IsMeshGenerationOn) { EditorGUILayout.PropertyField(serializedObject.FindProperty("MeshMaterial")); } }); BGEditorUtility.VerticalBox(() => { EditorGUILayout.PropertyField(serializedObject.FindProperty("generateKinematicRigidbody")); if (!Collider3DBox.GenerateKinematicRigidbody) { EditorGUILayout.PropertyField(serializedObject.FindProperty("Rigidbody")); } }); base.AdditionalParams(); }
public static void ShowField(BGCurvePointI point, BGCurvePointField field, Action <string, AnimationCurve> animationCurveCallback = null) { var name = point.Curve.IndexOf(field) + ") " + field.FieldName; switch (field.Type) { case BGCurvePointField.TypeEnum.Bool: BGEditorUtility.BoolField(name, point.GetField <bool>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Int: BGEditorUtility.IntField(name, point.GetField <int>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Float: BGEditorUtility.FloatField(name, point.GetField <float>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Vector3: BGEditorUtility.Vector3Field(name, null, point.GetField <Vector3>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Bounds: BGEditorUtility.BoundsField(name, point.GetField <Bounds>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Color: BGEditorUtility.ColorField(name, point.GetField <Color>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.String: BGEditorUtility.TextField(name, point.GetField <string>(field.FieldName), v => point.SetField(field.FieldName, v), false); break; case BGCurvePointField.TypeEnum.AnimationCurve: BGEditorUtility.Horizontal(() => { BGEditorUtility.AnimationCurveField(name, point.GetField <AnimationCurve>(field.FieldName), v => point.SetField(field.FieldName, v)); if (animationCurveCallback != null && GUILayout.Button("Set", GUILayout.Width(40))) { animationCurveCallback(field.FieldName, point.GetField <AnimationCurve>(field.FieldName)); } }); break; case BGCurvePointField.TypeEnum.Quaternion: BGEditorUtility.QuaternionField(name, point.GetField <Quaternion>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.GameObject: BGEditorUtility.GameObjectField(name, point.GetField <GameObject>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.Component: BGEditorUtility.ComponentChoosableField(name, point.GetField <Component>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.BGCurve: BGEditorUtility.BGCurveField(name, point.GetField <BGCurve>(field.FieldName), v => point.SetField(field.FieldName, v)); break; case BGCurvePointField.TypeEnum.BGCurvePointComponent: BGEditorUtility.Horizontal(() => { BGEditorUtility.BGCurvePointComponentField(name, point.GetField <BGCurvePointComponent>(field.FieldName), v => point.SetField(field.FieldName, v)); var currentPoint = point.GetField <BGCurvePointComponent>(field.FieldName); if (currentPoint == null || currentPoint.Curve.PointsCount < 2) { return; } var indexOfField = currentPoint.Curve.IndexOf(currentPoint); if (GUILayout.Button("" + indexOfField, GUILayout.Width(40))) { BGCurveChosePointWindow.Open(indexOfField, currentPoint.Curve, c => point.SetField(field.FieldName, c)); } }); break; case BGCurvePointField.TypeEnum.BGCurvePointGO: BGEditorUtility.BGCurvePointGOField(name, point.GetField <BGCurvePointGO>(field.FieldName), v => point.SetField(field.FieldName, v)); break; } }
internal void OnInspectorGUI(BGCurvePoint point, int index, BGCurveSettings settings) { var maskField = point.Curve.Mode2DOn && Event.current.type == EventType.Repaint; BGEditorUtility.HorizontalBox(() => { editorSelection.InspectorSelectionRect(point); BGEditorUtility.VerticalBox(() => { BGEditorUtility.SwapLabelWidth(60, () => { if (!settings.ShowPointPosition && !settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { EditorGUILayout.LabelField("Point " + index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { //control type if (settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { point.ControlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Point " + index, point.ControlType); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } //position if (settings.ShowPointPosition) { var math = editor.Editor.Math; var positionWorld = math.GetPosition(index); if (!settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { BGEditorUtility.Vector3Field("Point " + index, "Point's position in world space", positionWorld, vector3 => point.PositionWorld = vector3); if (maskField) { MaskFieldFor2D(point); } PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { BGEditorUtility.Vector3Field("Pos", "Point's position in world space", positionWorld, vector3 => point.PositionWorld = vector3); if (maskField) { MaskFieldFor2D(point); } } } } }); // control positions if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent && settings.ShowPointControlPositions) { // 1st BGEditorUtility.Vector3Field("Control 1", "Point 1st control position (local)", point.ControlFirstLocal, vector3 => { point.ControlFirstLocal = vector3; }); if (maskField) { MaskFieldFor2D(point); } // 2nd BGEditorUtility.Vector3Field("Control 2", "Point 2nd control position (local)", point.ControlSecondLocal, vector3 => { point.ControlSecondLocal = vector3; }); if (maskField) { MaskFieldFor2D(point); } } BGEditorUtility.EndIndent(1); }); }); }