# @umm/game-object-extension-component

> Extension class for UnityEngine.GameObject to handling Component

Latest version **1.1.0** (published 2017-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @umm/game-object-extension-component
pnpm add @umm/game-object-extension-component
yarn add @umm/game-object-extension-component
bun add @umm/game-object-extension-component
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-07-13 |
| First published | 2017-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 3 |
| Author | Tetsuya Mori |
| Maintainers | monry |

## Links

- npm: https://www.npmjs.com/package/@umm/game-object-extension-component
- Repository: https://github.com/monry/game-object-extension-component
- Issues: https://github.com/monry/game-object-extension-component/issues
- npm.io page: https://npm.io/package/@umm/game-object-extension-component

## Dependencies (4)

- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [rimraf](https://npm.io/package/rimraf.md) ^2.6.1
- [pascal-case](https://npm.io/package/pascal-case.md) ^2.0.1

## Recent versions

- 1.1.0 (latest) — 2017-07-13
- 0.1.2 — 2017-07-11
- 0.1.1 — 2017-07-11
- 0.1.0 — 2017-07-11

## README

# What?

* `UnityEngine.GameObject` の拡張クラスです。
* 主に GameObject に対する Component 関連の操作を拡張します。

# Why?

* 毎回 `if (gameObject.GetComponent<Hoge>() != null)` とか書くのが面倒だったのが発端。
* 「未追加なら追加」的な操作も何回書いたか分からんレベルだったので、同じく拡張する。
* AddComponent 後にインスタンスフィールドを初期化したくなる衝動に駆られることも多かったので、それも追加。

# Install

```shell
$ npm install @umm/game-object-extension-component
```

# Usage

```c#
using UnityEngine;
// ココがポイント
using GameObjectExtension;

public class Hoge : MonoBehaviour {
    
    public void Start() {
        // コンポーネントの有無をチェック
        if (this.gameObject.HasComponent<Fuga>()) {
            Debug.Log("Hoge has component: Fuga");
        }
        // AddComponent 直後 (= Awake() 直後) に呼び出される処理を記述
        this.gameObject.AddComponent<Piyo>(
            (piyoInstance) => {
                piyoInstance.isPonyo = true;
            }
        );
    }

}

public class Fuga : MonoBehaviour {
    
    public void Start() {
        Piyo piyo;
        // 未追加のハズなので、追加される
        piyo = this.gameObject.GetOrAddComponent<Piyo>();
        // 上で追加済なので、そのインスタンスを取得
        piyo = this.gameObject.GetOrAddComponent<Piyo>();
    }

}

public class Piyo : MonoBehaviour {

    public bool isPonyo = false;

}
```

* `GameObjectExtension` namespace を `using` するコトで拡張が有効になります。

# License

Copyright (c) 2017 Tetsuya Mori

Released under the MIT license, see [LICENSE.txt](LICENSE.txt)

---
_Source: https://npm.io/package/@umm/game-object-extension-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
