AgentStack
SKILL verified MIT Self-run

Godot Singleton Pattern

skill-fenixnix-godot-skills-godot-singleton-pattern · by fenixnix

Godot单例模式指南。当用户需要单例模式实现相关信息时使用。

No reviews yet
0 installs
9 views
0.0% view→install

Install

$ agentstack add skill-fenixnix-godot-skills-godot-singleton-pattern

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Godot Singleton Pattern? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

godot-singleton-pattern

何时使用

当用户需要了解Godot单例模式实现和使用方法时使用此技能。

执行指示

  1. 提供Godot单例模式的详细说明
  2. 回答用户关于单例模式实现、Autoload配置、最佳实践等问题
  3. 提供单例模式的示例代码

输出格式

返回Godot单例模式指南内容,包括单例实现和使用示例。

示例

用户请求: 我需要了解如何在Godot中实现单例模式。

执行过程:

  1. 查找单例模式相关内容
  2. 提供详细说明和示例代码

输出: Godot中实现单例模式的方法:

使用Autoload实现单例

  1. 注册Autoload:在Godot编辑器中,进入Project → Autoload,添加需要全局访问的脚本
  2. 访问方式:直接使用注册的名称访问,如GameUIManager

示例单例脚本

# GameManager.gd
class_name GameManager

# 单例实例
var instance: GameManager

# 游戏状态
var game_state: String = "menu"
var score: int = 0
var lives: int = 3

# 初始化
func _ready() -> void:
    # 确保只存在一个实例
    if instance:
        queue_free()
        return
    instance = self
    set_process(false)

# 游戏状态管理
func set_game_state(new_state: String) -> void:
    game_state = new_state
    print("Game state changed to: %s" % new_state)

func add_score(points: int) -> void:
    score += points
    print("Score: %d" % score)

func lose_life() -> void:
    lives -= 1
    if lives  void:
    set_game_state("game_over")
    print("Game Over!")

# 静态访问方法
static func get_instance() -> GameManager:
    return instance

使用单例

# 在其他脚本中访问
GameManager.set_game_state("playing")
GameManager.add_score(100)
GameManager.lose_life()

# 检查游戏状态
if GameManager.game_state == "game_over":
    print("Game over detected!")

最佳实践

  • 职责单一:每个单例负责一个特定功能
  • 最小化使用:只在必要时使用单例,避免过度依赖
  • 状态管理:使用单例管理全局游戏状态
  • 服务提供:使用单例提供全局服务(如音频管理、网络请求等)

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.