🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@umm/accessor-utility-core

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@umm/accessor-utility-core

Accessor Utility

1.0.1
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

What?

アクセサ (もどき) として任意のオブジェクトからアクセスさせる際の型ベースのデータストアを提供します。

Why?

  • ConditionalWeakTable が使いたい!
  • しかし Unity は2017年7月現在、 .NET 3.5 系である
    • Experimental として .NET 4.6 を選択可能ではある
  • 無いなら作っちまおう!

Install

$ npm install @umm/accessor-utility-core

Usage

  • 正直、このパッケージだけでは殆ど何もできません。
  • こいつが提供する AccessorUtility を継承したクラスをこさえてください。
  • んで、それっぽい interface でも書いて、それの拡張クラスとしてアクセサもどきを実装します。
using UnityEngine;
using AccessorUtility;

// 別に継承しなくても良いんだけど、毎回 Generic 書くのダルいので
public class SampleAccessor : AccessorUtility<MonoBehaviour, Component> {}

// interface として提供するコトで、ちょっと DI っぽく実装できます
public interface IRectTransformAccessor {
}

public static class RectTransformAccessorExtension {

    // この拡張メソッド内でデータストアにインスタンスを保持します
    // 型ベースなので、複数のキーを持たせて…、みたいなのは無理っす
    public static RectTransform RectTransform(this IRectTransformAccessor self) {
        // ココが強引なんだよなぁ…。
        MonoBehaviour instance = (MonoBehaviour)self;
        return SampleAccessor.instanceMapMap[instance][typeof(RectTransform)];
    }

}

public class Hoge : MonoBehaviour, IRectTransformAccessor {

    public void Start() {
        Debug.Log(this.RectTransform().sizeDelta);
    }

}

License

Copyright (c) 2017 Tetsuya Mori

Released under the MIT license, see LICENSE.txt

FAQs

Package last updated on 14 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts