# @umm/gameobject_extension_component

> Extension class for UnityEngine.GameObject to handling Component

Latest version **1.1.7** (published 2017-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @umm/gameobject_extension_component
pnpm add @umm/gameobject_extension_component
yarn add @umm/gameobject_extension_component
bun add @umm/gameobject_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.7 |
| Published | 2017-09-11 |
| First published | 2017-07-21 |
| 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 | takyama, risacankidsstar, mkaya, hanage, fakestarbaby, monry |

## Links

- npm: https://www.npmjs.com/package/@umm/gameobject_extension_component
- Repository: https://github.com/umm-projects/gameobject_extension_component
- Issues: https://github.com/umm-projects/gameobject_extension_component/issues
- npm.io page: https://npm.io/package/@umm/gameobject_extension_component

## Dependencies (4)

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

## Recent versions

- 1.1.7 (latest) — 2017-09-11
- 1.1.8 — 2017-09-11
- 1.1.6 — 2017-08-29
- 1.1.5 — 2017-08-11
- 1.1.4 — 2017-08-02
- 1.1.3 — 2017-07-27
- 1.1.2 — 2017-07-25
- 1.1.1 — 2017-07-21

## README

# What?

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

# Why?

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

# Install

```shell
$ npm install github:umm-projects/gameobject_extension_component.git
```

# 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/gameobject_extension_component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
