com.xmobitea.changx.mini-helper
v1.5.2
Published
Static Unity helpers for Unix-millisecond time, energy refill math, clamped remap, casual random values, and editor screenshots
Downloads
122
Readme
XmobiTea Helper
Static Unity helper package for Unix-millisecond time, local reset timestamps, stateless energy math, clamped remap, casual random values, and one editor screenshot menu item.
AI Entry Points
Open the smallest file for the task:
| Need | Use |
| --- | --- |
| Generate common helper code | AI_USAGE.md |
| Setup, imports, editor/runtime boundary, menu path | AI_SETUP.md |
| Unix ms, TTL, cooldown, local day/week/month reset | AI_CustomDateTime.md |
| Stamina, refill, bonus energy, spend/add logic | AI_CustomEnergy.md |
| Clamped float remap | AI_CustomMath.md |
| Casual random int/float | AI_CustomRandom.md |
| Editor screenshot menu item | AI_TakeScreenShotEditor.md |
| Exact API index | AI_API_REFERENCE.md |
| Behavior index | AI_BEHAVIOR.md |
| Agent guardrails | AGENTS.md |
| Missing or conflicting docs | source files |
Runtime Contract
- Runtime namespace:
XmobiTea.MiniHelper - Runtime helpers are static and require no scene setup.
- Time values are Unix milliseconds.
CustomDateTime.GetDateTime(long)returns UTCDateTime.- Local reset helpers use local calendar boundaries.
CustomEnergyderives normal energy fromtsDoneRefillEnergy.CustomEnergykeeps bonus energy as separate caller-owned state.CustomRandomuses one staticSystem.Random.TakeScreenShotEditoris editor-only.
Setup
- Add
using XmobiTea.MiniHelper;for runtime helpers. - Call static helpers directly. No component, asset, prefab, or initialization call is required.
- Capture one
nowMsfor each time or energy operation. - Validate energy and math inputs before mutation.
- Use
XmobiTea.MiniHelper.Editoronly from editor assemblies when calling the screenshot API directly.
See AI_SETUP.md for exact setup rules and error cases.
Usage
Current time or TTL:
using XmobiTea.MiniHelper;
var nowMs = CustomDateTime.CurrentMillitime();
var expiresAtMs = nowMs + CustomDateTime.ONE_MINUTE_MILLITIME * 5L;Next local daily reset:
using XmobiTea.MiniHelper;
var nowMs = CustomDateTime.CurrentMillitime();
var nextResetMs = CustomDateTime.Tomorrow0hMillitime(nowMs);Safe energy spend:
using XmobiTea.MiniHelper;
var nowMs = CustomDateTime.CurrentMillitime();
if (amount >= 0 &&
refillOneMs > 0 &&
maxEnergy > 0 &&
bonusEnergy >= 0 &&
CustomEnergy.CanUse(amount, bonusEnergy, tsDoneRefillEnergy, refillOneMs, nowMs, maxEnergy))
{
CustomEnergy.Use(amount, ref bonusEnergy, ref tsDoneRefillEnergy, refillOneMs, nowMs);
}Clamped remap and random index:
using XmobiTea.MiniHelper;
var normalized = minInput < maxInput
? CustomMath.Lerp(input, minInput, maxInput, 0f, 1f)
: 0f;
var index = itemCount > 0
? CustomRandom.Range(0, itemCount)
: -1;Editor screenshot:
Unity menu: XmobiTea Tools/Helper/TakeScreenShot
Shortcut: Ctrl/Cmd+G
Output: project-root ScreenShot/{width}x{height}_{DateTime.Now.Ticks}.pngImportant Behavior Notes
CustomEnergytreats full normal energy astsDoneRefillEnergy < nowMs, not<=.- At exact equality,
CustomEnergy.GetRefillNextIn(...)andCustomEnergy.GetRefillFullIn(...)can return zero whileIsFull(...)is stillfalseandGetNormal(...)can still bemaxEnergy - 1. CustomEnergydoes not validate refill interval, energy signs, affordability, or corrupt stored state.CustomMath.Lerp(...)clampsxwithx0as the lower bound andx1as the upper bound; usex0 < x1.CustomRandom.Range(int, int)uses exclusivemax.
Do And Do Not
- Do use
CustomDateTimefor Unix-millisecond timestamps and simple local reset boundaries. - Do convert
CustomDateTime.GetDateTime(ms).ToLocalTime()for player-facing local display. - Do validate energy input and persist
bonusEnergyplustsDoneRefillEnergytogether. - Do keep screenshot code in editor-only assemblies.
- Do not treat local reset helpers as UTC-day helpers.
- Do not treat
tsDoneRefillEnergyas a last-refill timestamp. - Do not call
CustomEnergy.Use(...)withoutCanUse(...)when failure must be rejected. - Do not assume
CustomRandommatchesUnityEngine.Randomseeding or determinism.
Common Mistakes
- Passing .NET ticks instead of Unix milliseconds.
- Treating
GetDateTime(...)as local time without callingToLocalTime(). - Using
tsDoneRefillEnergy == nowMsas a clean full-energy state. - Calling
CustomMath.Lerp(...)with identical bounds. - Calling
CustomMath.Lerp(...)with reversed source bounds. - Using
CustomRandom.Range(0, itemCount)as a collection index without checkingitemCount > 0. - Using the screenshot helper from runtime gameplay code.
Package Metadata
- Package:
com.xmobitea.changx.mini-helper - Runtime assembly:
com.xmobitea.changx.mini-helper.runtime - Editor assembly:
com.xmobitea.changx.mini-helper.editor - Declared package dependency:
com.xmobitea.changx.app1.5.2 - Minimum Unity version declared:
2022.3 - License:
Apache-2.0
