public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { // Hackjob way to get the target - needs to reference a serialized field in order to work. fc = (FloatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("_min")); return(CalculateHeight(fc)); }
private void drawRobotBody(Robot robot, Pen pen, Graphics g) { PointF[] spike = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.spike); PointF[] bottom = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.bottom); PointF robotPosition = robot.GetPosition(); Pen teamPen = DefaultDrawer.GetTeamPen(robot.TEAM_ID); lock (g) { lock (teamPen) { float oldTeamPenWidth = teamPen.Width; teamPen.Width = 5; g.DrawLines(teamPen, DrawerUtils.Translate(robotPosition, spike)); teamPen.Width = oldTeamPenWidth; } lock (pen) { pen.Width = 5; g.DrawLines(pen, DrawerUtils.Translate(robotPosition, bottom)); } lock (Brushes.Red) { g.FillEllipse(Brushes.Red, robotPosition.X - 1, robotPosition.Y - 1, 2, 2); } } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); // Hackjob way to get the target fc = (FloatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("_min")); height = CalculateHeight(fc); this.r = r; savedIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; line = r.yMin; colortex = (fc.axis == Axis.X) ? SolidTextures.red2D : (fc.axis == Axis.Y) ? SolidTextures.green2D : (fc.axis == Axis.Z) ? SolidTextures.blue2D : SolidTextures.gray2D; SolidTextures.DrawTexture(new Rect(r.xMin - 1, line - 1, r.width + 2, height + 2), SolidTextures.lowcontrast2D); SolidTextures.DrawTexture(new Rect(r.xMin, line, r.width, height), colortex); line += SPACING; DrawHeader(r, label); if (fc.enabled) { line += HHEIGHT + SPACING; DrawResolution(); DrawCodecSettings(property); line += LINEHEIGHT + 3; DrawFooter(); } EditorGUI.indentLevel = savedIndentLevel; EditorGUI.EndProperty(); }
public static void PolyObjectOnGUI <PO, T, A, B>(Rect rect, SerializedProperty polyObjProp, GUIContent label, System.Func <int, T> Int2Type, string aFieldLabel, string bFieldLabel ) where PO : PolyObject <T, A, B> where T : System.Enum where A : UnityEngine.Object where B : UnityEngine.Object { DrawerUtils.BeginIndentedPropertyDraw(ref rect, polyObjProp, label, out int indent, out Vector2 fieldSize); PO dummy = null; var typeProp = polyObjProp.FindPropertyRelative(nameof(dummy.type)); switch (typeProp.enumValueIndex) { case 0: DrawObjectField <A>(ref rect, fieldSize, polyObjProp, aFieldLabel, nameof(dummy.componentA)); break; case 1: DrawObjectField <B>(ref rect, fieldSize, polyObjProp, bFieldLabel, nameof(dummy.componentB)); break; } DrawTypeField <T>(ref rect, fieldSize, polyObjProp, nameof(dummy.type), Int2Type); DrawerUtils.EndIndentedPropertyDraw(polyObjProp, indent); }
/// <summary> /// Draw robot on graphics context. When robot HP is 0, then it will not be drawn. /// </summary> /// <param name="robot">robot with should be drawn</param> /// <param name="g">graphics context</param> public void DrawRobot(Robot robot, Graphics g) { if (robot.HIT_POINTS <= 0) { return; } Pen pen = GetRobotPen(robot); drawRobotBody(robot, pen, g); Font drawFont = new Font("Arial", 10); string drawString = $"{robot.NAME}:{robot.ID} ({robot.HIT_POINTS})"; lock (g) { lock (pen) { g.DrawString(drawString, drawFont, pen.Brush, DrawerUtils.Translate(robot.GetPosition(), name)); } } }
/// <inheritdoc /> public void DrawScan(Scan scan, Graphics g, int turn) { int index = turn; Pen pen = scannerPen[index]; double startAngle = scan.ANGLE - scan.PRECISION + 360; double stopAngle = scan.ANGLE + scan.PRECISION + 360; if (turn == 0) { PointF scanPosition = scan.GetPosition(); PointF endScan1 = DrawerUtils.Translate(scanPosition, DrawerUtils.Rotate(AngleUtils.ToRads(startAngle), PointF.Empty, new PointF((float)scan.DISTANCE, 0F))); PointF endScan2 = DrawerUtils.Translate(scanPosition, DrawerUtils.Rotate(AngleUtils.ToRads(stopAngle), PointF.Empty, new PointF((float)scan.DISTANCE, 0F))); lock (g) { lock (pen) { pen.Width = 2; g.DrawLine(pen, scanPosition, endScan1); g.DrawLine(pen, scanPosition, endScan2); } } } RectangleF circle = new RectangleF( (float)(scan.X - scan.DISTANCE), (float)(scan.Y - scan.DISTANCE), (float)scan.DISTANCE * 2, (float)scan.DISTANCE * 2 ); if (scan.PRECISION > 0 && scan.DISTANCE > 0) { lock (g) { lock (pen) { g.DrawArc(pen, circle, (float)startAngle, (float)scan.PRECISION * 2); } } } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { gc.text = label.text; gc.tooltip = label.tooltip; EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); //property.serializedObject.ApplyModifiedProperties(); //property.serializedObject.Update(); //haschanged = true; // Hacky way to get the real object TransformCrusher target = (TransformCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("posCrusher")); float currentline = r.yMin; SerializedProperty pos = property.FindPropertyRelative("posCrusher"); SerializedProperty rot = property.FindPropertyRelative("rotCrusher"); SerializedProperty scl = property.FindPropertyRelative("sclCrusher"); SerializedProperty isExpanded = property.FindPropertyRelative("isExpanded"); float ph = EditorGUI.GetPropertyHeight(pos); float rh = EditorGUI.GetPropertyHeight(rot); float sh = EditorGUI.GetPropertyHeight(scl); /// Header bool _isExpanded = EditorGUI.Foldout(new Rect(r.xMin, currentline, r.width, TITL_HGHT), isExpanded.boolValue, ""); if (isExpanded.boolValue != _isExpanded) { isExpanded.boolValue = _isExpanded; property.serializedObject.ApplyModifiedProperties(); } EditorGUI.LabelField(new Rect(r.xMin, currentline, r.width, TITL_HGHT), gc); // property.displayName /*new GUIContent("Transform Crusher " + label)*//*, (GUIStyle)"BoldLabel"*/); int totalbits = target.TallyBits(); int frag0bits = Mathf.Clamp(totalbits, 0, 64); int frag1bits = Mathf.Clamp(totalbits - 64, 0, 64); int frag2bits = Mathf.Clamp(totalbits - 128, 0, 64); int frag3bits = Mathf.Clamp(totalbits - 192, 0, 64); string bitstr = frag0bits.ToString(); if (frag1bits > 0) { bitstr += "|" + frag1bits; } if (frag2bits > 0) { bitstr += "|" + frag2bits; } if (frag3bits > 0) { bitstr += "|" + frag3bits; } bitstr = bitstr + " bits"; EditorGUI.LabelField(new Rect(paddedleft, currentline, paddedwidth, 16), bitstr, miniLabelRight); if (isExpanded.boolValue) { Rect ir = r; // EditorGUI.IndentedRect(r);; ir.yMin = ir.yMin + HEADR_HGHT + 2; ir.xMin -= BOUNDING_PADDING; ir.xMax += BOUNDING_PADDING; ir.yMax -= 6; currentline += BOUNDING_PADDING; //EditorGUI.LabelField(ir, GUIContent.none, /*(GUIStyle)"RectangleToolVBar");// */(GUIStyle)"HelpBox"); ir = EditorGUI.IndentedRect(ir); //ir.xMin += 1; ir.xMax -= 1; //ir.yMin += 1; ir.yMax -= 1; SolidTextures.DrawTexture(ir, SolidTextures.darken202D); /// TRS Element Boxes currentline += TITL_HGHT; //float leftConnectorY = currentline; DrawSet(r, currentline, ph, pos); currentline += ph + SET_PAD; DrawSet(r, currentline, rh, rot); currentline += rh + SET_PAD; DrawSet(r, currentline, sh, scl); currentline += sh /*+ SET_PAD*/; /// Connecting line between TRS Elements //SolidTextures.DrawTexture(new Rect(4, leftConnectorY + 4, 4, currentline - leftConnectorY), SolidTextures.lowcontrast2D); //EditorGUI.LabelField(new Rect(0, leftConnectorY + 4, 4, currentline - leftConnectorY - 12), GUIContent.none, (GUIStyle)"MiniSliderVertical"); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); property.serializedObject.Update(); target = (QuatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("bits")); MonoBehaviour component = (MonoBehaviour)property.serializedObject.targetObject; if (target.transform == null) { target.transform = component.transform; } line = r.yMin; float standalonesheight = target.isStandalone ? (SPACING + LINEHEIGHT) * 2 : 0; float boxheight = SPACING + HHEIGHT + SPACING + LINEHEIGHT + standalonesheight + SPACING; SolidTextures.DrawTexture(new Rect(r.xMin - 1, line - 1, r.width + 2, boxheight + 2), SolidTextures.lowcontrast2D); SolidTextures.DrawTexture(new Rect(r.xMin, line, r.width, boxheight), SolidTextures.gray2D); line += SPACING; DrawHeader(new Rect(r)); line += HHEIGHT + SPACING; CompressLevel clvl = (CompressLevel)EditorGUI.EnumPopup(new Rect(paddedleft, line, labelwidth - PADDING, LINEHEIGHT), GUIContent.none, target.CompressLevel); if (!QC_ISPRO) { // In case we went from pro to free... quietly set this back to non-custom. if (target.CompressLevel == CompressLevel.SetBits) { target.Bits = (int)target.CompressLevel; // CompressLevel = CompressLevel.uint32Med; } else if (clvl == CompressLevel.SetBits) { ProFeatureDialog(""); target.CompressLevel = (CompressLevel)target.Bits; } else { target.CompressLevel = clvl; } } else if (clvl != target.CompressLevel) { target.CompressLevel = clvl; } var bitssp = property.FindPropertyRelative("bits"); GUI.enabled = (QC_ISPRO); EditorGUI.PropertyField(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), bitssp, GUIContent.none); GUI.enabled = true; if (QC_ISPRO && bitssp.intValue != target.Bits) { target.CompressLevel = CompressLevel.SetBits; } if (target.isStandalone) { line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("transform")); line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("local")); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); haschanged = false; p = property; base.OnGUI(r, property, label); bool isWrappedInElementCrusher = DrawerUtils.GetParent(property) is ElementCrusher; bool disableRange = (label.tooltip != null && label.tooltip.Contains("DISABLE_RANGE")); gc_fc.text = label.text; gc_fc.tooltip = (disableRange) ? null : label.tooltip; holdindent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; int hash = fc.GetHashCode(); height = CalculateHeight(fc, hash); this.r = r; line = r.yMin; colortex = (fc.axis == Axis.X) ? SolidTextures.red2D : (fc.axis == Axis.Y) ? SolidTextures.green2D : (fc.axis == Axis.Z) ? SolidTextures.blue2D : SolidTextures.gray2D; if (!isWrappedInElementCrusher) { Rect outline = ir; outline.xMin--; outline.yMin--; outline.xMax++; outline.yMax++; SolidTextures.DrawTexture(outline, SolidTextures.lowcontrast2D); } SolidTextures.DrawTexture(ir, colortex); //SolidTextures.DrawTexture(new Rect(ir.xMin, line, ir.width, height), colortex); //SolidTextures.DrawTexture(new Rect(ir.xMin + 1, ir.yMin + 1, ir.width - 2, ir.height - 2), colortex); line++; line += SPACING; fc.expanded = DrawHeader(r, gc_fc, fc.expanded); line += PADDING + HEADR_HGHT; if (fc.Enabled && fc.expanded) { bool noSettings = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat || fc.BitsDeterminedBy == BitsDeterminedBy.Uncompressed || fc.BitsDeterminedBy == BitsDeterminedBy.Disabled); DrawCompressionMethod(); EditorGUI.BeginDisabledGroup(disableRange); if (!noSettings && !(fc.TRSType == TRSType.Normal)) { DrawCodecSettings(property); } EditorGUI.EndDisabledGroup(); if (!noSettings) { DrawAccurateCenter(); } if (!noSettings && fc.showBCL) { DrawBCL(); } if (!noSettings) { DrawActualValues(); } } if (haschanged) { EditorUtility.SetDirty(property.serializedObject.targetObject); } EditorGUI.indentLevel = holdindent; EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { base.OnGUI(r, property, label); // Hacky way to get the real object TransformCrusher target = (TransformCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("posCrusher")); float currentline = r.yMin; SerializedProperty pos = property.FindPropertyRelative("posCrusher"); SerializedProperty rot = property.FindPropertyRelative("rotCrusher"); SerializedProperty scl = property.FindPropertyRelative("sclCrusher"); float ph = EditorGUI.GetPropertyHeight(pos); float rh = EditorGUI.GetPropertyHeight(rot); float sh = EditorGUI.GetPropertyHeight(scl); /// Header EditorGUI.LabelField(new Rect(r.xMin, currentline, r.width, TITL_HGHT), new GUIContent("Transform Crusher"), (GUIStyle)"BoldLabel"); int totalbits = target.TallyBits(); int frag0bits = Mathf.Clamp(totalbits, 0, 64); int frag1bits = Mathf.Clamp(totalbits - 64, 0, 64); int frag2bits = Mathf.Clamp(totalbits - 128, 0, 64); int frag3bits = Mathf.Clamp(totalbits - 192, 0, 64); string bitstr = frag0bits.ToString(); if (frag1bits > 0) { bitstr += " | " + frag1bits; } if (frag2bits > 0) { bitstr += " | " + frag2bits; } if (frag3bits > 0) { bitstr += " | " + frag3bits; } bitstr = bitstr + " Bits"; EditorGUI.LabelField(new Rect(paddedleft, currentline, paddedwidth, 16), bitstr, miniLabelRight); ///GameObject target currentline += LINEHEIGHT; target.defaultTransform = (Transform)EditorGUI.ObjectField(new Rect(r.xMin, currentline, r.width, 16), new GUIContent("Target"), target.defaultTransform, typeof(Transform), true); if (target.defaultTransform == null) { target.defaultTransform = (property.serializedObject.targetObject as Component).transform; } /// TRS Element Boxes currentline += TITL_HGHT; DrawSet(r, currentline, ph, pos); currentline += ph + SET_PAD; DrawSet(r, currentline, rh, rot); currentline += rh + SET_PAD; DrawSet(r, currentline, sh, scl); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); haschanged = false; base.OnGUI(r, property, label); holdindent = EditorGUI.indentLevel; property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); target = (QuatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("bits")); line = r.yMin; //float standalonesheight = target.isStandalone ? (SPACING + LINEHEIGHT) * 2 : 0; //float boxheight = SPACING + HEADR_HGHT + SPACING + LINEHEIGHT + standalonesheight + SPACING; SolidTextures.DrawTexture(ir, SolidTextures.gray2D); //SolidTextures.DrawTexture(new Rect(ir.xMin - 1, line - 1, r.width + 2, boxheight + 2), SolidTextures.lowcontrast2D); //SolidTextures.DrawTexture(new Rect(ir.xMin, line, r.width, boxheight), SolidTextures.gray2D); line += SPACING; DrawHeader(new Rect(r)); line += HEADR_HGHT + SPACING + SPACING; EditorGUI.indentLevel = 0; CompressLevel clvl = (CompressLevel)EditorGUI.EnumPopup(new Rect(ir.xMin + PADDING, line, labelwidth - PADDING, LINEHEIGHT), GUIContent.none, target.CompressLevel); EditorGUI.indentLevel = holdindent; if (!QC_ISPRO) { // In case we went from pro to free... quietly set this back to non-custom. if (target.CompressLevel == CompressLevel.SetBits) { if (target.Bits != (int)target.CompressLevel) { haschanged = true; target.Enabled = true; target.Bits = (int)target.CompressLevel; // CompressLevel = CompressLevel.uint32Med; } } else if (clvl == CompressLevel.SetBits) { ProFeatureDialog(""); if (target.CompressLevel != (CompressLevel)target.Bits) { haschanged = true; target.CompressLevel = (CompressLevel)target.Bits; } } else { if (target.CompressLevel != clvl) { target.Enabled = true; haschanged = true; target.CompressLevel = clvl; } } } else if (clvl != target.CompressLevel) { haschanged = true; target.CompressLevel = clvl; } //var bitssp = property.FindPropertyRelative("bits"); GUI.enabled = (QC_ISPRO); int newbits = EditorGUI.IntSlider(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), GUIContent.none, target.Bits, 16, 64); //bool bitschanged = EditorGUI.PropertyField(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), bitssp, GUIContent.none); GUI.enabled = true; if (QC_ISPRO && newbits != target.Bits) { //if (target.CompressLevel != CompressLevel.SetBits) //{ haschanged = true; target.Bits = newbits; //target.CompressLevel = CompressLevel.SetBits; //} property.serializedObject.Update(); } if (target.isStandalone) { line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("transform")); line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("local")); } property.serializedObject.ApplyModifiedProperties(); if (haschanged) { EditorUtility.SetDirty(property.serializedObject.targetObject); //AssetDatabase.SaveAssets(); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); // Hacky way to get the real object ElementCrusher target = (ElementCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("xcrusher")); SerializedProperty uniformAxes = property.FindPropertyRelative("uniformAxes"); SerializedProperty x = property.FindPropertyRelative("xcrusher"); SerializedProperty y = property.FindPropertyRelative("ycrusher"); SerializedProperty z = property.FindPropertyRelative("zcrusher"); SerializedProperty u = property.FindPropertyRelative("ucrusher"); SerializedProperty q = property.FindPropertyRelative("qcrusher"); float xh = EditorGUI.GetPropertyHeight(x); float yh = EditorGUI.GetPropertyHeight(y); float zh = EditorGUI.GetPropertyHeight(z); float wh = EditorGUI.GetPropertyHeight(u); float qh = EditorGUI.GetPropertyHeight(q); bool isQuatCrush = target.TRSType == TRSType.Quaternion; bool isUniformScale = target.TRSType == TRSType.Scale && target.uniformAxes != 0; float boxesheight = isQuatCrush ? qh : isUniformScale ? wh : xh + yh + zh; float currentline = r.yMin + TOP_PAD; GUI.Box(new Rect(r.xMin - 1, currentline - 1, r.width + 2, TITL_HGHT + boxesheight + 2), GUIContent.none, (GUIStyle)"flow shader node 0 on"); SolidTextures.DrawTexture(new Rect(r.xMin - 1, currentline - 1, r.width + 2, 16 + 2), SolidTextures.lowcontrast2D); SolidTextures.DrawTexture(new Rect(r.xMin, currentline, r.width, 16 + SPACING), SolidTextures.contrastgray2D); if (target.enableTRSTypeSelector) { target.TRSType = (TRSType)EditorGUI.EnumPopup(new Rect(r.xMin, currentline + 1, 78, LINEHEIGHT), target.TRSType); } else if (target.TRSType == TRSType.Quaternion || target.TRSType == TRSType.Euler) { target.TRSType = (TRSType)EditorGUI.EnumPopup(new Rect(r.xMin, currentline + 1, 78, LINEHEIGHT), (RotationType)target.TRSType); } else { GUIContent title = new GUIContent(System.Enum.GetName(typeof(TRSType), target.TRSType)); // + " Crshr"); EditorGUI.LabelField(new Rect(paddedleft, currentline, r.width, LINEHEIGHT), title, (GUIStyle)"MiniBoldLabel"); } int localtoggleleft = 80; target.local = GUI.Toggle(new Rect(paddedright - localtoggleleft, currentline + 1, 20, LINEHEIGHT), target.local, GUIContent.none, (GUIStyle)"OL Toggle"); EditorGUI.LabelField(new Rect(paddedright - localtoggleleft + 14, currentline, 80, LINEHEIGHT), new GUIContent("Lcl"), (GUIStyle)"MiniLabel"); EditorGUI.LabelField(new Rect(paddedleft, currentline, paddedwidth, 16), target.TallyBits() + " Bits", FloatCrusherDrawer.miniLabelRight); // Scale Uniform Enum if (target.TRSType == TRSType.Scale) { target.uniformAxes = (ElementCrusher.UniformAxes)EditorGUI.EnumPopup(new Rect(paddedright - 78 - 84, currentline + 1, 78, 16), GUIContent.none, target.uniformAxes); } currentline += TITL_HGHT; if (target.TRSType == TRSType.Scale && uniformAxes.enumValueIndex != 0) { //SolidTextures.DrawTexture(new Rect(r.xMin - 3, currentline - 1, r.width + 6, wh + 2), SolidTextures.black2D); EditorGUI.PropertyField(new Rect(r.xMin, currentline, r.width, wh), u); } else if (target.TRSType == TRSType.Quaternion) { EditorGUI.PropertyField(new Rect(r.xMin, currentline, r.width, wh), q); } else { //SolidTextures.DrawTexture(new Rect(r.xMin - 3, currentline - 1, r.width + 6, xh + yh +zh + 2), SolidTextures.black2D); EditorGUI.PropertyField(new Rect(r.xMin, currentline, r.width, xh), x); currentline += xh; EditorGUI.PropertyField(new Rect(r.xMin, currentline, r.width, yh), y); currentline += yh; EditorGUI.PropertyField(new Rect(r.xMin, currentline, r.width, zh), z); } EditorGUI.EndProperty(); }