Code Monkey home page Code Monkey logo

cafu_scriptableobject's Introduction

CAFU ScriptableObject

What

  • Handle ScriptableObject for CAFU v3

Requirement

  • CAFU Core v3
  • Zenject

Install

yarn add "umm/cafu_scriptableobject#^1.0.0"

Usage

Key(Value|List)ScriptableObject を継承したクラスを作成する

using CAFU.ScriptableObject.Structure;
using ScriptableObjectSample.Application.Enumerate;
using UnityEngine;

namespace ScriptableObjectSample
{
    [CreateAssetMenu(menuName = "Master/Avatar")]
    public class Avatar : KeyValueScriptableObject<AvatarType, Sprite>
    {
    }
}

作成したクラスのScriptableObjectを作成する

  • Project view にて上記例だと Create > Master > AvaterFace

ScriptableObjectInstaller を作成する

  • Project view にて Installer > ScriptableObjectInstaller
  • Scriptable Object List に生成したScriptableObjectを設定する

SceneContextの設定

  • ScriptableObjectを読み込みたいSceneの任意のGameObjectに SceneContext をアタッチする
  • SceneContextScriptable Object Installer に生成した ScriptableObjectInstaller を指定する

ScriptableObject を呼び出す

using System.Linq;
using CAFU.Core;
using CAFUScriptableObject.Scripts.Domain.UseCase.Interface;
using Zenject;

namespace ScriptableObjectSample
{
    public class AvatarTranslator : ITranslator<AvatarType, IAvatarStructure>
    {
        [Inject] private IScriptableObjectRepository ScriptableObjectRepository { get; set; }

        public IAvatarStructure Translate(AvatarType type)
        {
            return
                new AvatarStructure(
                    ScriptableObjectRepository.GetList<Avatar>().First(x => x.Key == type).Value
                );
        }
    }
}

License

Copyright (c) 2018 Tetsuya Mori

Released under the MIT license, see LICENSE.txt

cafu_scriptableobject's People

Contributors

lycoris102 avatar monry avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.