Token导航 LogoToken导航TokenDH.com
待分类只读github未标认证来源可访问许可证需确认审计通过

unity-scriptingUnity scripting 命令行

Agent Skill

unity-scripting 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

318

周安装

13

GitHub Stars

14

下载量

103
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:unity-scripting(Unity scripting 命令行)
来源仓库:https://github.com/nice-wolf-studio/unity-claude-skills
仓库路径:skills/unity-scripting
安装命令:
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-scripting
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-scripting

简介

Unity 脚本命令行工具,用于处理 GitHub 仓库协作事务。

  • 适合在 CI/CD 或团队协作中自动化处理 Issue 和 PR 流程。
  • 可在主流 AI 编辑器中调用以增强项目管理能力。
  • 安装命令:npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-scripting
  • 需确认是否要求登录凭证或访问私有仓库权限

SKILL.md

Unity C# Scripting

Script Fundamentals

C# scripts (.cs files) are stored in the Assets folder. Scripts gain Unity functionality by inheriting from built-in types:

  • UnityEngine.Object -- Makes custom types assignable to Inspector fields
  • MonoBehaviour -- Attaches to GameObjects as components to control behavior in a scene
  • ScriptableObject -- Standalone data assets not attached to GameObjects

Scripts operate in two contexts:

  • Runtime scripts -- Execute in the Player build (use UnityEngine namespace)
  • Editor scripts -- Run only in the Editor (use UnityEditor namespace, place in Editor folders)

MonoBehaviour Lifecycle

MonoBehaviours always exist as a Component of a GameObject. The lifecycle event functions execute in a strict order. You cannot rely on the order in which the same event function is invoked for different GameObjects unless configured via Script Execution Order settings.

Execution Order (ASCII Diagram)

INITIALIZATION
  |
  v
[Awake] ---------> Called when script instance loads (once per lifetime)
  |
  v
[OnEnable] ------> Called when object/component becomes enabled
  |
  v
(SceneManager.sceneLoaded fires here -- after OnEnable, before Start)
  |
  v
[Start] ---------> Called before first frame Update (once per lifetime)
  |
  |
  |  +===========================================+
  |  |          PHYSICS LOOP (fixed timestep)    |
  |  |                                           |
  +->| [FixedUpdate] --> Internal Physics ------>|
  |  |       |                                   |
  |  | [yield WaitForFixedUpdate resumes]        |
  |  +===========================================+
  |
  v
[Update] --------> Called once per frame
  |
  v
[yield null / yield WaitForSeconds resumes]
  |
  v
(Internal Animation Update)
  |   [OnAnimatorMove]
  |   [OnAnimatorIK]
  |
  v
[LateUpdate] ----> Called after all Update functions complete
  |
  v
RENDERING
  | [OnWillRenderObject]
  | [OnPreCull] [OnBecameVisible/Invisible]
  | [OnPreRender]
  | [OnRenderObject]
  | [OnPostRender]
  | [OnRenderImage]
  |
  v
[OnGUI] ---------> Called for GUI rendering events
  |
  v
[yield WaitForEndOfFrame resumes]
  |
  v
DEACTIVATION / TEARDOWN
  |
  v
[OnDisable] -----> Called when component/object is disabled
  |
  v
[OnDestroy] -----> Called before object destruction

Key Lifecycle Callbacks

CallbackTimingUse For
Awake()Script instance loadsOne-time init, cache references
OnEnable()Component enabledSubscribe to events
Start()Before first UpdateInit that depends on other Awake() calls
FixedUpdate()Fixed timestep (default 0.02s)Physics calculations, Rigidbody forces
Update()Every frameInput, non-physics game logic
LateUpdate()After all Update callsCamera follow, post-Update adjustments
OnDisable()Component disabledUnsubscribe from events
OnDestroy()Before destructionFinal cleanup

Physics Callbacks

// 3D Physics
void OnCollisionEnter(Collision collision) { }
void OnCollisionStay(Collision collision) { }
void OnCollisionExit(Collision collision) { }
void OnTriggerEnter(Collider other) { }
void OnTriggerStay(Collider other) { }
void OnTriggerExit(Collider other) { }

// 2D Physics
void OnCollisionEnter2D(Collision2D collision) { }
void OnTriggerEnter2D(Collider2D other) { }

MonoBehaviour Properties (Unity 6)

PropertyPurpose
destroyCancellationTokenToken raised when MonoBehaviour is destroyed (for async cancellation)
didAwakeWhether Awake has been called
didStartWhether Start has been called
runInEditModeAllow script execution in editor
Full lifecycle reference: references/monobehaviour-lifecycle.md

Coroutines vs Async/Await

Unity supports two patterns for operations spanning multiple frames.

Coroutines (IEnumerator)

Methods that suspend with yield return and resume based on the yield instruction.

IEnumerator Fade()
{
    Color c = renderer.material.color;
    for (float alpha = 1f; alpha >= 0; alpha -= 0.1f)
    {
        c.a = alpha;
        renderer.material.color = c;
        yield return new WaitForSeconds(0.1f);
    }
}

void Update()
{
    if (Input.GetKeyDown("f"))
    {
        StartCoroutine(Fade());
    }
}

Yield Instructions:

  • yield return null -- Resume next frame (after Update)
  • yield return new WaitForSeconds(t) -- Resume after t seconds
  • yield return new WaitForFixedUpdate() -- Resume after FixedUpdate
  • yield return new WaitForEndOfFrame() -- Resume after rendering
  • yield return new WaitUntil(() => condition) -- Resume when condition is true
  • yield return StartCoroutine(other) -- Wait for nested coroutine

Important: Coroutines run on the main thread. Disabling the MonoBehaviour via enabled = false does NOT stop coroutines. Deactivating the GameObject or destroying the MonoBehaviour does stop them.

Awaitable (Unity 6 Async/Await)

Awaitable is Unity's custom async type -- usually more efficient than iterator-based coroutines. It is pooled to limit allocations.

async Awaitable SampleSchedulingJobsForNextFrame()
{
    await Awaitable.EndOfFrameAsync();
    var jobHandle = ScheduleSomethingWithJobSystem();
    await Awaitable.NextFrameAsync();
    jobHandle.Complete();
}

Awaitable Methods:

  • Awaitable.NextFrameAsync() -- Resume next frame
  • Awaitable.FixedUpdateAsync() -- Resume at next FixedUpdate
  • Awaitable.EndOfFrameAsync() -- Resume at end of frame
  • Awaitable.WaitForSecondsAsync(float) -- Resume after delay
  • Awaitable.MainThreadAsync() -- Force continuation on main thread
  • Awaitable.BackgroundThreadAsync() -- Force continuation on background thread

Critical constraint: Awaitable instances are pooled -- never await the same instance more than once. Multiple awaits cause undefined behavior.

FeatureCoroutineAwaitable
Return valuesNoYes (Awaitable<T>)
Thread switchingNoYes
Memory allocationPer-yield overheadPooled, minimal
CancellationManual StopCoroutineCancellationToken support
Error handlingNo try/catchFull try/catch/finally
Full async reference: references/coroutines-and-async.md

Events and Communication Patterns

C# Events and Delegates

public class Health : MonoBehaviour
{
    public event System.Action<float> OnDamageTaken;
    public event System.Action OnDeath;

    private float _hp = 100f;

    public void TakeDamage(float amount)
    {
        _hp -= amount;
        OnDamageTaken?.Invoke(amount);
        if (_hp <= 0f)
            OnDeath?.Invoke();
    }
}

public class UIHealthBar : MonoBehaviour
{
    [SerializeField] private Health _health;

    void OnEnable()
    {
        _health.OnDamageTaken += HandleDamage;
    }

    void OnDisable()
    {
        _health.OnDamageTaken -= HandleDamage;
    }

    private void HandleDamage(float amount)
    {
        // Update UI
    }
}

UnityEvents (Inspector-assignable)

using UnityEngine.Events;

public class GameManager : MonoBehaviour
{
    public UnityEvent OnGameStart;
    public UnityEvent<int> OnScoreChanged;

    public void StartGame()
    {
        OnGameStart?.Invoke();
    }
}

ScriptableObject Event Channels

[CreateAssetMenu(menuName = "Events/Void Event Channel")]
public class VoidEventChannel : ScriptableObject
{
    private System.Action _onEventRaised;

    public void RaiseEvent()
    {
        _onEventRaised?.Invoke();
    }

    public void Subscribe(System.Action listener) => _onEventRaised += listener;
    public void Unsubscribe(System.Action listener) => _onEventRaised -= listener;
}

ScriptableObjects

ScriptableObjects are serializable Unity types derived from UnityEngine.Object. They exist as independent project assets, not attached to GameObjects. Use them for shared data, configuration, and event channels.

[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/SpawnManagerScriptableObject", order = 1)]
public class SpawnManagerScriptableObject : ScriptableObject
{
    public string prefabName;
    public int numberOfPrefabsToCreate;
    public Vector3[] spawnPoints;
}

Key behaviors:

  • In Edit mode, Inspector modifications save automatically; script changes require EditorUtility.SetDirty()
  • At runtime, players can read ScriptableObject data but not persist modifications to disk
  • Memory efficient: multiple objects reference the same asset instance instead of duplicating data
Full ScriptableObject reference: references/scriptableobjects.md

Serialization Quick Reference

Unity serializes fields that meet ALL conditions:

  1. public OR has [SerializeField] attribute
  2. Not static, const, or readonly
  3. Is a serializable type

Serializable types: primitives, enums (32-bit or smaller), Unity built-in types (Vector2, Vector3, Rect, Color, AnimationCurve, etc.), [Serializable] custom classes/structs, UnityEngine.Object references, List<T> and arrays of any above type.

Key attributes:

[SerializeField] private float _speed = 5f;        // Serialize private field
[field: SerializeField] public float Speed { get; private set; } // Auto-property
[NonSerialized] public float tempValue;             // Exclude from serialization
[HideInInspector] public float hiddenValue;         // Serialize but hide from Inspector
[SerializeReference] private IMyInterface _impl;    // Polymorphic serialization

Not supported: Multidimensional arrays, jagged arrays, dictionaries, nested containers. Use ISerializationCallbackReceiver for custom serialization of unsupported types.

Core API Quick Reference

Vector3

// Static direction shortcuts
Vector3.zero;      // (0, 0, 0)
Vector3.one;       // (1, 1, 1)
Vector3.up;        // (0, 1, 0)
Vector3.forward;   // (0, 0, 1)
Vector3.right;     // (1, 0, 0)

// Common operations
float dist = Vector3.Distance(a, b);
float dot = Vector3.Dot(a.normalized, b.normalized);
Vector3 cross = Vector3.Cross(a, b);
Vector3 smoothed = Vector3.Lerp(from, to, t);
Vector3 moved = Vector3.MoveTowards(current, target, maxDelta);
Vector3 projected = Vector3.ProjectOnPlane(velocity, groundNormal);

Properties: magnitude, sqrMagnitude (use for comparisons -- avoids sqrt), normalized.

Quaternion

// Creation
Quaternion.identity;                             // No rotation
Quaternion.Euler(0f, 90f, 0f);                  // From Euler angles (degrees)
Quaternion.LookRotation(direction, Vector3.up);  // Face a direction
Quaternion.AngleAxis(45f, Vector3.up);           // Rotate around axis
Quaternion.FromToRotation(Vector3.up, normal);   // Rotation between directions

// Interpolation
Quaternion.Slerp(from, to, t);                  // Spherical interpolation
Quaternion.Lerp(from, to, t);                   // Linear interpolation

// Operations
float angle = Quaternion.Angle(a, b);           // Angle in degrees (0-180)
Vector3 rotatedPoint = rotation * point;         // Rotate a vector
Quaternion combined = rotA * rotB;               // Combine rotations

Never modify x, y, z, w directly. Use Euler(), AngleAxis(), or LookRotation().

Time

Time.deltaTime       // Seconds since last frame (use in Update)
Time.fixedDeltaTime  // Fixed timestep interval (use in FixedUpdate)
Time.time            // Time since game start
Time.timeScale       // 0 = paused, 1 = normal, 2 = double speed
Time.unscaledDeltaTime // Ignores timeScale (for UI animations during pause)

Debug

Debug.Log("Message");
Debug.LogWarning("Warning");
Debug.LogError("Error");
Debug.DrawRay(origin, direction, Color.red, duration);
Debug.DrawLine(start, end, Color.green, duration);

Common Patterns

Cached Component References

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody _rb;
    private Transform _transform;

    void Awake()
    {
        _rb = GetComponent<Rigidbody>();
        _transform = transform; // Cache the transform property
    }

    void FixedUpdate()
    {
        // Use cached references -- never call GetComponent in Update/FixedUpdate
        _rb.AddForce(Vector3.up * 10f);
    }
}

Singleton Pattern

public class GameManager : MonoBehaviour
{
    public static GameManager Instance { get; private set; }

    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
        DontDestroyOnLoad(gameObject);
    }
}

Async with Cancellation (Unity 6)

public class AsyncExample : MonoBehaviour
{
    async void Start()
    {
        try
        {
            await LoadAndProcessAsync(destroyCancellationToken);
        }
        catch (OperationCanceledException) { }
    }

    async Awaitable LoadAndProcessAsync(CancellationToken token)
    {
        await Awaitable.BackgroundThreadAsync();
        // Heavy computation here (off main thread)
        var result = ComputeExpensiveData();

        await Awaitable.MainThreadAsync();
        // Back on main thread -- safe to use Unity API
        ApplyResult(result);
    }
}

Conditional Wait (Awaitable replacement for WaitUntil)

public static async Awaitable AwaitableUntil(Func<bool> condition, CancellationToken token)
{
    while (!condition())
    {
        token.ThrowIfCancellationRequested();
        await Awaitable.NextFrameAsync();
    }
}

Anti-Patterns

Anti-PatternProblemFix
GetComponent<T>() in Update()Allocates and searches every frameCache in Awake()
GameObject.Find() in Update()Expensive string search every frameCache reference or use serialized field
Repeated new Vector3() in hot pathsUnnecessary constructor overhead each frameUse Vector3.zero, Vector3.one, or cache reusable values
Modifying Quaternion.x/y/z/w directlyProduces invalid rotationsUse Euler(), AngleAxis(), LookRotation()
Physics logic in Update()Inconsistent at variable frameratesUse FixedUpdate() for Rigidbody forces
Time.deltaTime in FixedUpdate()Works (Unity returns fixedDeltaTime implicitly) but is unclear to readersUse Time.fixedDeltaTime explicitly for clarity
Forgetting to unsubscribe events in OnDisableMemory leaks, null reference errorsAlways unsubscribe in OnDisable()
await-ing same Awaitable twiceUndefined behavior (pooled instances)Await once, or wrap with .AsTask()
Empty Update() / FixedUpdate() methodsUnity still calls them (overhead)Remove empty event functions
String-based Invoke("MethodName", t)No compile-time safety, breaks on renameUse coroutines or Awaitable instead

Related Skills

  • unity-foundations -- GameObjects, Components, Transforms, Scenes, Prefabs
  • unity-physics -- Rigidbody, Colliders, Raycasting, Physics materials
  • unity-input -- Input System, InputActions, PlayerInput component

Additional Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.77%
按下载量换算38

Claude

29.88%
按下载量换算31

Cursor

19.73%
按下载量换算20

Gemini CLI

9.6%
按下载量换算10

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills