728x90

(1) Object Pool 이란

인스턴스화하는 데 특히 비용이 많이 드는 많은 수의 개체로 작업해야하고 각 개체가 짧은 시간 동안 만 필요한 경우 전체 응용 프로그램의 성능이 저하를 해결하기 위한 디자인 패턴이며 오브젝트를 생성 / 삭제를 반복하지 않으며 생성 한 오브젝트를 가지고 재사용 하는 방식


(2) Object를 이용한 코드 (Unity Tutorial)

총알생성을 Object Pool로구현

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PoolManager : MonoBehaviour
{

    //ttruen this class into a singleton for easy accessbility.
    private static PoolManager _instance;
    public static PoolManager Instance
    {
        get
        {
            if (_instance == null)
                Debug.LogError("The PoolManager is NULL.");
            return _instance;
        }
    }

    [SerializeField]
    private GameObject _bulletContainer;
    [SerializeField]
    private GameObject _bulletPrefab;
    [SerializeField] //List로 관리
    private List<GameObject> _bulletPool;

    private void Awake()
    {
        _instance = this;
    }

    private void Start()
    {
        _bulletPool = GenerateBullets(10);
    }
    //pregenerate a list of bullets using the bullet prefab

    List<GameObject> GenerateBullets(int amountOfBullets)
    {
        for (int i = 0; i < amountOfBullets; i++)
        {
            GameObject bullet = Instantiate(_bulletPrefab);
            bullet.transform.parent = _bulletContainer.transform;
            bullet.SetActive(false);
            _bulletPool.Add(bullet);
        }
        return _bulletPool;
    }

    public GameObject RequestBullet()
    {
        //loop through the bullet list
        //현재 Hierarchy 창에 활성화가 되지 않은 Object를 찾음
        foreach (var bullet in _bulletPool)
        {
            if (bullet.activeInHierarchy == false)
            {
                //bullet is available
                bullet.SetActive(true);
                return bullet;
            }
        }

		//List의모든 Object가 활성화시 새로 생성
        //need to create a new bullet
        GameObject newBullet = Instantiate(_bulletPrefab);
        newBullet.transform.parent = _bulletContainer.transform;
        _bulletPool.Add(newBullet);

        return newBullet;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField]
    private GameObject _bulletPrefab;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //communicate with the object pool system
            //Request Bullet
            GameObject bullet = PoolManager.Instance.RequestBullet();
            bullet.transform.position = Vector3.zero;

        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour {

    private void OnEnable()
    {
        Invoke("Hide", 1);
    }

    void Hide()
    {
        //re-cycle the gameObject

        this.gameObject.SetActive(false);

        Debug.Log("Hiding GameObject");
    }
}

 

아래 링크는 Github에 있는 프로젝트입니다.

https://github.com/Loafly/ObjectPool

 

Loafly/ObjectPool

Contribute to Loafly/ObjectPool development by creating an account on GitHub.

github.com

 

반응형
728x90

(1) Git이 안되어있는 경우

원하는 프로젝트 폴더에서 Git 생성

git init

add와 Commit

git add *
git commit -m "Hello World"

기본 Branch 생성

git branch -M main

GitHub 사이트에서 Project 생성 후 원격저장소 연동

git remote add origin https://github.com/_RepositoriesName_/_NewProjectName_.git

GitHub 사이트에 폴더 push

git push -u origin main

(2) Git은 있으며 GitHub와 연동

기본 Branch 생성

git branch -M main

GitHub 사이트에서 Project 생성 후 원격저장소 연동

git remote add origin https://github.com/_RepositoriesName_/_NewProjectName_.git

GitHub 사이트에 폴더 push

git push -u origin main

 

반응형

'Study > Git' 카테고리의 다른 글

[Git] 기본 명령어  (0) 2020.10.13
728x90

(1) 저장소(Repository) 생성

원하는 폴더 들어간 후

$ git init

기존 github에 있는 저장소를 내 로컬로 복제

$ git clone (git 저장소의 URL)

(2) Staging 영역에 추가

현재 디렉토리에 있는 업데이트 된 파일을 전부 스테이징 영역으로 추가

$ git add .

수정된 파일 전부를 스테이징 영역에 추가

$ git add -A

현재 add 내역을 확인

$ git status

(3) Repository에 commit

-m 은 메세지의 약자이고, 뒤에 ""안에 공유할 메시지 내용을 적어 커밋

$ git commit -m "2020-10-13_Update"

(4) commit 정리

여러개의 commit을 하나의 commit으로 정리

$ git rebase -i

이전과 현재 커밋을 하나로 정리

git commit --amend

(5) commit 내역

현재 까지의 Commit한 내용출력

$ git log

(6) push

브랜치에 푸시

$ git push origin [브랜치명]

(7) pull

브랜치에 푸시

$ git pull [해당 링크]

(8) Branch

브랜치 만들기

$ git branch [브랜치명]

브랜치로 이동하기

$ git checkout [브랜치명]

 

반응형

'Study > Git' 카테고리의 다른 글

[Git] 로컬 저장소와 원격저장소 공유  (0) 2020.10.13

+ Recent posts