Refactor Assets/Scripts: trim restating comments, minor structure cleanups
Sweep over 48 files (Editor/ excluded): remove comments that restate the code, condense class summaries, fix three stale doc statements (HsvColorPicker alpha bar, PaintHud layoutPrefab, MasterVolume FallbackDefault). Inline two single-use wrappers (IsPointerOverUi, BuildModes), drop an unused using, replace a magic literal with the existing ParallaxBase constant, and convert ~10 UnityEngine.Object null checks to the implicit-bool convention. No serialized fields, signatures, RPC/NetworkVariable names, defaults, or #if blocks touched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eeee5fc2f0
commit
6c03e5d3f6
48 files changed
+289
-481
No files matched your search
@@ -3,15 +3,9 @@ using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// Makes a UI panel draggable. Attach to the panel itself: it follows the pointer from any of the panel's
|
||||
/// non-interactive surface (title bar, padding, labels, background) but ignores presses that begin on a
|
||||
/// widget - a <see cref="Selectable"/> (toggle, slider, ...) or a <see cref="UiPointerSurface"/> (the
|
||||
/// colour-picker field) - so those keep their own click/drag behaviour. It keeps a slice of the panel on
|
||||
/// screen and raises it above its siblings while interacting.
|
||||
///
|
||||
/// Works under any canvas scale (it tracks the pointer in the drag area's local space and applies the
|
||||
/// movement delta) and under any anchor/pivot (the on-screen clamp is derived from the panel's real
|
||||
/// corners in its parent, not from a fixed top-left assumption).
|
||||
/// Makes a UI panel draggable from any non-interactive surface; presses that begin on a widget
|
||||
/// (<see cref="Selectable"/> or <see cref="UiPointerSurface"/>) keep their own click/drag behaviour.
|
||||
/// Keeps a slice of the panel on screen and raises it above siblings; canvas-scale/anchor/pivot-agnostic.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class DraggablePanel : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
@@ -40,8 +34,6 @@ public class DraggablePanel : MonoBehaviour, IPointerDownHandler, IBeginDragHand
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
// Raise the panel when pressing its own surface. (A press that lands on a widget is consumed by
|
||||
// that widget's own handler and never reaches us, so this rarely needs the guard - but it is cheap.)
|
||||
if (!StartedOnWidget(eventData)) BringToFront();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,11 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Compact runtime HSV colour picker: a saturation/value square, a hue bar and a live swatch. The
|
||||
/// square is a pure-hue base with two static gradient overlays on top (white-out -> saturation,
|
||||
/// black-out -> value), so only the base tint changes per hue - no per-frame texture rebuilds. Hue is
|
||||
/// never lost while dragging the square (the square only edits S/V, the bar only edits H). Alpha is
|
||||
/// edited separately by a standalone slider in the HUD, not by this picker; <see cref="SetColor"/>
|
||||
/// still stores the incoming alpha so <see cref="Value"/> round-trips it.
|
||||
///
|
||||
/// The child structure (stable names) comes from the baked HUD prefab. <see cref="Rebind"/>
|
||||
/// (re)assigns the runtime gradient sprites (which a prefab cannot store) and (re)hooks the drag
|
||||
/// relays. A leftover alpha bar from a pre-split prefab is hidden by <see cref="Rebind"/>, so no
|
||||
/// re-bake is required.
|
||||
/// Runtime HSV colour picker: SV square (pure-hue base + static gradient overlays, so no per-frame
|
||||
/// texture rebuilds; edits only S/V) plus hue bar (edits only H), so hue is never lost while dragging.
|
||||
/// Alpha is edited by a separate HUD slider, but <see cref="SetColor"/> stores it so <see cref="Value"/>
|
||||
/// round-trips it. Child structure (stable names) comes from the baked HUD prefab; <see cref="Rebind"/>
|
||||
/// (re)assigns the runtime gradient sprites (which a prefab cannot store) and (re)hooks the drag relays.
|
||||
/// </summary>
|
||||
public class HsvColorPicker : MonoBehaviour
|
||||
{
|
||||
@@ -49,8 +43,7 @@ public class HsvColorPicker : MonoBehaviour
|
||||
|
||||
/// <summary>
|
||||
/// Re-finds the child widgets, (re)assigns the runtime gradient sprites and (re)hooks the drag
|
||||
/// relays. Idempotent (unsubscribe-then-subscribe), so it is safe whether the structure was just
|
||||
/// built in code or instantiated from a prefab. Call before <see cref="SetColor"/>.
|
||||
/// relays. Idempotent. Call before <see cref="SetColor"/>.
|
||||
/// </summary>
|
||||
public void Rebind()
|
||||
{
|
||||
@@ -87,7 +80,6 @@ public class HsvColorPicker : MonoBehaviour
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// Idempotently hooks the handler to the surface's drag relay (unsubscribe-then-subscribe).
|
||||
private static void Rehook(Component surface, Action<Vector2> handler)
|
||||
{
|
||||
if (surface.TryGetComponent(out UiPointerSurface pointer))
|
||||
|
||||
@@ -5,14 +5,10 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Binder for the "Paintings" library panel. The panel's visual layout (Panel_Paintings, the scrollable
|
||||
/// list, an entry template, and the Save / Confirm dialogs) is authored inside the PaintHudPanel layout
|
||||
/// prefab - this code only finds those objects by their stable names and wires the behaviour, exactly like
|
||||
/// <see cref="WirePanel"/> does for the brush widgets. The list is populated by cloning the authored
|
||||
/// Lib_EntryTemplate per saved slot. Save opens a name dialog (an existing name is overwritten, with a
|
||||
/// warning shown while typing); Load applies the selected slot immediately; Delete goes through a
|
||||
/// confirmation dialog. Loading replaces the current painting and, when networked, re-broadcasts the
|
||||
/// loaded state to every other peer.
|
||||
/// Binder for the "Paintings" library panel, authored in the PaintHudPanel layout prefab and wired here
|
||||
/// by stable names (like <see cref="WirePanel"/> for the brush widgets). The list clones Lib_EntryTemplate
|
||||
/// per saved slot; Save overwrites by name (warned while typing), Load applies immediately (re-broadcast
|
||||
/// to peers when networked), Delete confirms.
|
||||
/// </summary>
|
||||
public partial class PaintHud
|
||||
{
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem.UI;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// In-game paint UI. Shows its panels only while the active <see cref="GameMode"/> is
|
||||
/// <see cref="PaintMode"/> (follows the manager's ModeChanged) and binds its widgets directly to the
|
||||
/// live <see cref="MeshPainter"/> fields, so edits apply immediately.
|
||||
///
|
||||
/// The layout (independently draggable sub-panels per channel + a global brush card) comes from the
|
||||
/// authored prefab (<see cref="layoutPrefab"/>). The BINDINGS live in code and are (re)applied at
|
||||
/// runtime by <see cref="WirePanel"/> against stable widget names - the prefab stores only the
|
||||
/// visual layout, never behaviour.
|
||||
/// In-game paint UI. Visible only while the active <see cref="GameMode"/> is <see cref="PaintMode"/>;
|
||||
/// binds its widgets directly to the live <see cref="MeshPainter"/> fields. The prefab stores only the
|
||||
/// visual layout; the bindings live in code, (re)applied by <see cref="WirePanel"/> against stable widget names.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public partial class PaintHud : MonoBehaviour
|
||||
@@ -119,7 +113,6 @@ public partial class PaintHud : MonoBehaviour
|
||||
// (in BindPainter) overwrites them. The reset button restores exactly these.
|
||||
CaptureAuthoredLayout();
|
||||
|
||||
// The paint library now lives inside the authored layout prefab; bind its widgets like the brush panel.
|
||||
BindLibrary(_panel ? _panel.transform : null);
|
||||
|
||||
// Bind as soon as a painter exists. With networked spawn-on-connect there is none at scene
|
||||
@@ -443,11 +436,8 @@ public partial class PaintHud : MonoBehaviour
|
||||
return s;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches (idempotently) a <see cref="DraggablePanel"/> to the whole panel so it can be dragged
|
||||
/// from any of its non-interactive surface (header, padding, labels, background); the component
|
||||
/// ignores presses that start on a widget (toggle, slider, colour picker).
|
||||
/// </summary>
|
||||
/// <summary>Attaches (idempotently) a <see cref="DraggablePanel"/> so the whole panel can be
|
||||
/// dragged from any non-widget surface.</summary>
|
||||
private void MakeDraggable(Transform root, string panelName)
|
||||
{
|
||||
var panel = GeometryUtil.FindDeep(root, panelName) as RectTransform;
|
||||
|
||||
@@ -3,19 +3,10 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Reshapes a UI <see cref="Slider"/>'s response with an <see cref="AnimationCurve"/> so the value runs
|
||||
/// non-linearly between the slider's authored <c>minValue</c>/<c>maxValue</c>. The curve maps the handle
|
||||
/// position (x, 0..1 - linear in screen space) to a value fraction (y, 0..1) that is then scaled to the
|
||||
/// slider's range. The slider's own min/max stays the single source of truth for the range; this only
|
||||
/// bends the mapping inside it - so dropping the component onto an existing slider needs no range re-entry.
|
||||
///
|
||||
/// <see cref="Value"/> is the curved output, <see cref="SetOutput"/> positions the handle to show a given
|
||||
/// output (inverting the curve), and <see cref="ValueChanged"/> raises the curved value whenever the
|
||||
/// handle moves - so the component is usable both standalone (wire <see cref="ValueChanged"/>) and from
|
||||
/// code that drives the raw slider (read <see cref="Value"/>).
|
||||
///
|
||||
/// The curve should be monotonic increasing (the default linear is); the inverse used by
|
||||
/// <see cref="SetOutput"/> assumes that.
|
||||
/// Reshapes a UI <see cref="Slider"/>'s response with an <see cref="AnimationCurve"/> mapping handle
|
||||
/// position (x, 0..1) to a value fraction (y, 0..1) scaled to the slider's own minValue/maxValue, which
|
||||
/// stays the single source of truth for the range. The curve must be monotonic increasing: the inverse
|
||||
/// used by <see cref="SetOutput"/> assumes that.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Slider))]
|
||||
[DisallowMultipleComponent]
|
||||
|
||||
@@ -3,10 +3,9 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// Turns a pointer press/drag on a UI graphic into a normalized (x, y) position in
|
||||
/// [0,1] within its RectTransform (origin bottom-left). Added in code to the colour
|
||||
/// picker's saturation/value field and hue bar so they react to both clicking and
|
||||
/// dragging. The graphic on the same object must be a raycast target.
|
||||
/// Turns a pointer press/drag on a UI graphic into a normalized (x, y) position in [0,1] within its
|
||||
/// RectTransform (origin bottom-left). Used by the colour picker's SV field and hue bar. The graphic
|
||||
/// on the same object must be a raycast target.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class UiPointerSurface : MonoBehaviour, IPointerDownHandler, IDragHandler
|
||||
|
||||
Reference in new issue
Block a user