* Scriptable Object?
ํ์ผ๋ก ์ ์ฅํ ์ ์๋ ๊ตฌ์กฐ์ฒด๋ผ๊ณ ์๊ฐํ๋ฉด ์ดํดํ๊ธฐ ์ฝ๋ค. Script๋ฅผ ์์ ์ผ๋ก ๋ง๋ค์ด์ ๊ฐ์ ์ ์ฅ ๋ฐ ๊ด๋ฆฌํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
ํนํ ์์ ์ผ๋ก ๋ง๋ค๊ณ AssetBundle์ด๋ Addressable Asset์ผ๋ก ๊ด๋ฆฌํ๋ฉด ๋ฐ์ดํฐ ์์ ์ ๋น๋&๋ฐฐํฌ๊ฐ ํ์ ์๊ธฐ ๋๋ฌธ์ ๊ทธ ํจ์จ์ด ๊ทน๋ํ ๋๋ค.(Scriptable Object ์ฅ์ )
* Scriptable Object ์ฌ์ฉ๋ฒ
1. ์ ์ ๋ฐ ์์ ์์ฑ
using UnityEngine;
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/SpawnManagerScriptableObject", order = 1)]
public class SpawnManagerScriptableObject : ScriptableObject
{
public string prefabName;
public int numberOfPrefabsToCreate;
public Vector3[] spawnPoints;
}
1) ScriptableObejct ํด๋์ค ์์๋ฐ๊ธฐ
2) CreateAssetMenu ๋ฅผ ์ฌ์ฉํด์ ์๋จ ๋ฉ๋ด์์ Asset์ ์์ฑํ๊ฒ ํ๊ธฐ.
2. Scriptable Object ์ฐ๊ฒฐ
using UnityEngine;
public class Spawner : MonoBehaviour
{
// The GameObject to instantiate.
public GameObject entityToSpawn;
// An instance of the ScriptableObject defined above.
public SpawnManagerScriptableObject spawnManagerValues;
// This will be appended to the name of the created entities and increment when each is created.
int instanceNumber = 1;
void Start()
{
SpawnEntities();
}
void SpawnEntities()
{
int currentSpawnPointIndex = 0;
for (int i = 0; i < spawnManagerValues.numberOfPrefabsToCreate; i++)
{
// Creates an instance of the prefab at the current spawn point.
GameObject currentEntity = Instantiate(entityToSpawn, spawnManagerValues.spawnPoints[currentSpawnPointIndex], Quaternion.identity);
// Sets the name of the instantiated entity to be the string defined in the ScriptableObject and then appends it with a unique number.
currentEntity.name = spawnManagerValues.prefabName + instanceNumber;
// Moves to the next spawn point index. If it goes out of range, it wraps back to the start.
currentSpawnPointIndex = (currentSpawnPointIndex + 1) % spawnManagerValues.spawnPoints.Length;
instanceNumber++;
}
}
}
public SpawnManagerScriptableObject spawnManagerValues; ๋ก Scriptable Object ์ฐ๊ฒฐํด์ ๊ฐ ์ฌ์ฉํ๊ธฐ.
* Unity Documentation ์ฐธ๊ณ
https://docs.unity3d.com/kr/2022.2/Manual/class-ScriptableObject.html
'๐ฎ Unity Study > Unity' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Unity] IL2CPP, Mono, JIT (1) | 2023.04.17 |
---|---|
[Unity] Texture Compression ๋ฐฉ์ (0) | 2023.04.13 |
[Unity] Editor Programming (0) | 2023.03.28 |
[Unity] Advanced InputField ์ฌ์ฉ๋ฒ (0) | 2023.02.01 |
[Unity] UGUI - Anchor(๊ธฐ์ค), Pivot(๋) (0) | 2022.12.15 |