Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

hackplayerz/Unity-Singleton

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Unity-Singleton

유니티용 싱글턴 상속만 받으면 된다!

2022-12-05 Ver.

싱글톤 클래스를 dll화하고 LazyInstance 적용

사용법

namespace : UnitySingleton
사용할 MonoBehavior 클래스에 상속받고 제네릭 사용

예시

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnitySingleton; // 싱글턴 사용을 위한 네임스페이스 임포트.

public class GameManager : DontDestroySingleton<GameManager> // DontDestry가 싫으면 Singleton<T>
{
    public bool IsPaused { get; private set; } = false;
    public bool IsGameOver { get; private set; } = false;

    public void SetIsPaused(bool isPaused)
    {
        IsPaused = isPaused;
    }

    public void SetIsGameOver(bool isGameOver)
    {
        IsGameOver = isGameOver;
    }

    public bool IsPlaying()
    {
        return !IsPaused || !IsGameOver;
    }
    
    /// <summary>
    /// 게임패드 플레이중인지 검사
    /// </summary>
    /// <returns>게임패드가 인식되었다면 true.</returns>
    public bool IsGamePadPlaying()
    {
        var joystick = Input.GetJoystickNames();
        foreach (var value in joystick)
        {
            // 연결된 게임패드 발견
            if (value != string.Empty)
            {
                return true;
            }
        }

        return false;
    }
}




참고:https://dev-nicitis.tistory.com/4

About

유니티용 싱글턴 상속만 받으면 된다!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.