-
Notifications
You must be signed in to change notification settings - Fork 0
GridManager Grid
# Deleted at 2.0.0
Namespace: Syadeu.Mono
이 객체는 더 이상 사용되지 않습니다. Syadeu.Presentation.Map.GridSystem 으로 모든 기능이 이관되었습니다.
public struct Grid : IValidation, IEquatable<Grid>, IDisposableGridCell들을 담고있는 최상위 구조체입니다.
Inheritance: Object -> Grid
Implements: IValidation, IEquatable<T>, IDisposable
GridManager.Grid 는 오로지 데이터로만 그리드를 구성하기 위해 만들어진 struct 입니다.
필연적으로 그리드는 매우 방대한 데이터를 담고 있어야하는 경우가 많은데, C# 의 기본 시스템 설계는 모두 System.Object 를 참조하고 있어 상대적으로 하위 언어보다 접근속도가 느린 것을 나름 극복하려는 시도에 의해 탄생되었습니다.
성능면에서 어느정도 선으로 타협을 한 뒤, 실제 런타임에서 사용자가 쉽게 생성 및 접근하여 활용 할 수 있도록 편의성을 고려해 커스텀 데이터, 자식 GridCell 들과의 의존도 부여등 여러 추가 기능들이 개발되었습니다.
GridManager.Grid 는 사용자에 의해 생성시, 추가적인 Memory Allocation 을 피하기 위해 초기화 단계에서 전체 사이즈가 결정되는 Fixed-container 입니다.
유동적으로 그리드의 사이즈가 변경되야하는 경우, 적합하지 않습니다.
아래는 일반적인 사용방법에 대해 설명합니다.
using UnityEngine;
using Syadeu;
using Syadeu.Mono;
public class TestMono : Monobehaviour
{
private int m_GridIdx;
public void CreateGrid()
{
m_GridIdx = GridManager.CreateGrid
(
// 그리드의 총 크기를 넣습니다.
new Bounds(Vector3.zero, Vector3.one * 10),
// 그리드 셀의 크기를 결정합니다.
// 그리드 셀은 무조건 정사각형으로 생성되며,
// 입력한 값은 세로폭, 가로폭이 됩니다.
gridCellSize: 1,
// 이 그리드가 유니티 NavMesh 에 영향받는 그리드인지를 설정합니다.
// 이 설정이 true가 되었을 경우, GridCell.Enabled 는 해당 GridCell 위에
// NavMeshObstacle 이 존재하는 여부에 따라 영향을 받습니다.
enableNavMesh: false
);
}
public ref GridManager.Grid GetGrid()
{
// 앞에서 생성한 그리드를 가져옵니다.
return ref GridManager.GetGrid(m_GridIdx);
}
private void Awake()
{
ref GridManager.Grid _grid = GetGrid();
Debug.Log($"{m_GridIdx} == {_grid.Idx}");
}
}Grid 는 입력한 Bounds 로 이후 월드 좌표로 해당 그리드를 검출할 수 있습니다.
아래는 월드 좌표로 Grid 를 받아온 후, For 문으로 자식 GridCell 들을 빠르게 순회하는 방법에 대해 설명합니다.
// 커스텀 데이터는 ITag interface 를 무조건 상속받아야되고, struct 타입이어야됩니다.
// struct 데이터 타입에 unmanaged 타입이 되면 binary serialize 성능이 소폭 개선됩니다.
public struct TestDataStruct : ITag
{
public UserTagFlag UserTag { get; set; }
public CustomTagFlag CustomTag { get; set; }
// 의도치않은 데이터 수정을 미연에 방지하기 위해 Property 로 선언합니다.
// Member 이어도 상관없습니다.
public int TestInteger { get; set; }
public bool TestBoolen { get; set; }
}
public void TestGridFor()
{
// 이 예제에서는 Grid가 이미 Vector3(0, 0, 0)에 생성되었다고 가정합니다.
// 월드 좌표로 그리드를 가져옵니다. 해당 좌표에 그리드가 존재하지않으면
// CoreSystemException 을 Throw 합니다.
// 월드 좌표로 그리드를 가져올때에는 생성시 입력한 Bounds 가 기준이 됩니다.
ref GridManager.Grid _grid = ref GridManager.GetGrid(UnityEngine.Vector3.zero);
_grid.For(
// 매우 많은 자식들을 가진 그리드 탐색에 적합합니다.
// 이 For 문은 읽기 전용입니다.
(in int i, in GridManager.GridCell cell) =>
{
}
);
_grid.For(
// 자식들을 한번에 수정할때 적합합니다.
// 이 For 문은 읽기와 쓰기 모두 가능합니다.
(in int i, ref GridManager.GridCell cell) =>
{
}
);
_grid.For<TestDataStruct>(
// 자식들의 입력한 타입의 커스텀 데이터만 가진 GridCell 탐색에 적합합니다.
// 이 예제는 하나 이상의 GridCell 들이,
// TestDataStruct 타입의 커스텀 데이터가 할당되었다고 가정합니다.
// 이 For 문은 읽기 전용입니다.
(in int i, in TestDataStruct data) =>
{
}
);
_grid.For<TestDataStruct>(
// 자식들의 입력한 타입의 커스텀 데이터만 가진 GridCell 탐색에 적합합니다.
// 이 예제는 하나 이상의 GridCell 들이,
// TestDataStruct 타입의 커스텀 데이터가 할당되었다고 가정합니다.
// 이 For 문은 읽기와 쓰기 모두 가능합니다.
(in int i, ref TestDataStruct data) =>
{
}
);
#if CORESYSTEM_UNSAFE
// 아래는 위 For 문을 System.Threading.Tasks.Parallel 로
// 병렬 탐색하는 방법에 대해 설명합니다.
// 람다식 내부에는 ref 선언이 불가하고, struct 데이터를 넘겨받을 수 없기 때문에
// Unsafe가 아니면 접근할 수 없습니다.
// ParallelFor 는 System.Threading.Tasks.ParallelLoopResult 를 반환합니다.
_grid.ParallelFor(
(in int t, in GridManager.GridCell cell) =>
{
}
);
_grid.ParallelFor(
(in int t, ref GridManager.GridCell cell) =>
{
}
);
_grid.ParallelFor<TestDataStruct>(
(in int t, in TestDataStruct data) =>
{
}
);
_grid.ParallelFor<TestDataStruct>(
(in int t, ref TestDataStruct data) =>
{
}
);
#endif
}자식 GridCell 이 GridManager.GridCell.SetDirty() 로 인해 Dirty Marked 되었을 때, 실행될 delegate 를 설정할 수 있습니다. 아래는 해당 방법에 대해 설명합니다.
public void GridDirtyFlagTest()
{
// 먼저 그리드를 받아옵니다. 해당 예제에서는 Vector(0, 0, 0)에 그리드가 있다고 가정합니다.
ref GridManager.Grid _grid = ref GridManager.GetGrid(Vector3.zero);
// 유니티 스레드에서 작동할 delegate를 지정합니다.
// _targetGrid 는 Dirty Marked 된 상위 Grid 이며, _targetCell 은 주체가 된 GridCell 입니다.
_grid.OnDirtyMarked(
(ref GridManager.Grid _targetGrid, ref GridManager.GridCell _targetCell) =>
});
// 백그라운드 스레드에서 비동기로 작동할 delegate를 지정합니다.
// _targetGrid 는 Dirty Marked 된 상위 Grid 이며, _targetCell 은 주체가 된 GridCell 입니다.
_grid.OnDirtyMarkedAsync(
(ref GridManager.Grid _targetGrid, ref GridManager.GridCell _targetCell) =>
});
ref GridManager.GridCell _cell = ref _grid.GetCell(Vector3.zero);
// 해당 셀을 Dirty Mark 함으로써, 위에서 지정한 delegate 가 실행되도록 합니다.
_cell.SetDirty();
}| Name | Description |
|---|---|
| Guid | 이 그리드의 고유 Guid 입니다. |
| Idx | 이 그리드의 고유 인덱스 입니다. |
| CellSize | 이 그리드 내 GridCell의 실제 넓이와 폭 길이 입니다. |
| Length | 이 그리드이 가진 GridCell의 총 갯수입니다. |
| EnableNavMesh | Unity NavMesh 에 영향받는 그리드인가요? |
| EnableDrawGL | GridCell들을 GL 로 그릴까요? |
| EnableDrawIdx | 디버그용으로 Unity 씬뷰에 GridCell 인덱스를 표기할까요? |
| Name | Description |
|---|---|
| FromBytes | 바이너리에서 GridManager.Grid 로 변환합니다. |
| Name | Description |
|---|---|
| IsValid | 이 그리드가 유효한지 반환합니다. |
| Equals | 이 그리드와 해당 그리드가 같은 그리드인지 반환합니다. |
| HasCell | 해당 값에 GridCell이 존재하는지 반환합니다. |
Unsafe Only GetCellPointer |
해당 GridCell의 포인터를 가져옵니다. |
| GetCell | 해당 GridCell을 가져옵니다. |
| GetCells | 해당 조건에 맞는 GridCell들을 가져옵니다. |
| GetRange | 지정한 GridCell 인덱스를 기준으로 입력한 범위내 모든 셀을 GridRange 에 담아 반환합니다. |
| For | 빠르게 GridCell을 탐색합니다. |
| For<T> | 빠르게 해당 타입의 커스텀 데이터를 가지고있는 셀을 탐색합니다. |
Unsafe Only ParallelFor |
병렬로 GridCell을 탐색합니다. |
Unsafe Only ParallelFor<T> |
병렬로 해당 타입의 커스텀 데이터를 가지고 있는 GridCell을 탐색합니다. |
| GetCustomData | 커스텀 데이터를 가져옵니다. |
| GetCustomData<T> | 해당 타입의 커스텀 데이터를 가져옵니다. |
| SetCustomData | 입력한 데이터를 이 GridCell에 넣습니다. |
| RemoveCustomData | 이 셀의 커스텀 데이터를 삭제합니다. |
| ConvertToWrapper | 바이너리로 변환 가능한 형태로 변환하여 반환합니다. |
| OnDirtyMarked |
GridCell이 Dirty 마크 되었을때, 유니티 스레드에서 실행할 delegate를 설정합니다. |
| OnDirtyMarkedAsync |
GridCell이 Dirty 마크 되었을때, 백그라운드 스레드에서 실행할 delegate를 설정합니다. |
| Dispose | 사용하지마세요. 이 그리드를 방출합니다. |
- Interfaces
- Enums
- SystemFlag
- CoreSystemExceptionFlag
- UserTagFlag
- CustomTagFlag
- ObValueDetection
- ConsoleFlag
- CommandSetting
- Attributes
- Abstract Classes
- Classes
- CoreSystem
- CoreSystemSettings
- PrefabManager
- PrefabList
- RenderManager
- RenderController
-
ConsoleWindow
- CommandDefinition
- CommandField
- CommandRequires
- FMODSystem
- UserTagNameModule
- CustomTagNameModule
- Timer
- BackgroundJob
- ForegroundJob
- WaitForBackgroundJob
- WaitForBackgroundJobWorker
- WaitForForegroundJob
- WaitForTimer
- BackgroundJobWorker
- ObArray
- ObClass
- ObDictionary
- ObList
- ObQueue
- ObValue
- ExtensionMethods
- ThreadSafe
- Structs
- CoreRoutine
- SQLiteDatabase
- SQLiteTable
- SQLiteColumn
- SQLiteVersionInfoTableData
- Bound
- Pole
- Vector2
- Vector3
- Exceptions
- Syadeu.Presentation
- PresentationManager
- SceneList
- EntityDataList
- CustomLoadingScene
- DefaultPresentationGroup
- PresentationGroupEntity
- IPresentationSystemGroup
- PresentationSystemGroup<T>
- PresentationSystem<T>
- PresentationSystem<TGroup, TSystem>
- PresentationSystemEntity<T>
- PresentationSystemModule<TSystem>
- PresentationSystemID
- INotifySystemModule<TModule>
- IExecutable<T>
- PresentationLoop
- PresentationResult
- IReference
- Reference
- SubSystemAttribute
- LoadingSceneSetupEntity
- SceneReference
- SceneSystem
- EntitySystem
- EntityBoundSystem
- EntityRaycastSystem
- EntityExtensionMethods
- AttributeAcceptOnlyAttribute
- EntityAcceptOnlyAttribute
- CoroutineSystem
- CoroutineJob
- ICoroutineJob
- UpdateLoop
- RaycastInfo
- ObjectBase
- ProcessorBase
- WaitForPresentationSystem<T>
- WaitForProxy<T>
- Syadeu.Collections
- AABB
- Plane
- PropertyBlockBase
- PropertyBlock<T>
- ActionWrapper
- BinaryGrid
- CLRContainer
- CLRSingleTone
- CLSTypedDictionary<TValue>
- CLSTypedDictionary<TKey, TValue>
- Direction
- EntityID
- EntityShortID
- IEntityDataID
- IInstance
- IInstance<T>
- Instance
- Instance<T>
- InstanceID
- FixedInstanceList16<T>
- FixedInstanceList64<T>
- IFixedReference
- IFixedReference<T>
- FixedReference
- FixedReference<T>
- FixedReferenceList16<T>
- FixedReferenceList64<T>
- IFixedReferenceList<T>
- FixedListExtensionMethods
- IEntity
- IEntityData
- IAttribute
- IObject
- IEntityComponent
- IPrefabReference
- IPrefabResource
- IEmpty
- IValidation
- FNV1a32
- FNV1a64
- Hash
- Syadeu.Collections.Converters
- Syadeu.Collections.Proxy
- Syadeu.Presentation.Proxy
- Syadeu.Presentation.Internal
- Syadeu.Presentation.Entities
- Syadeu.Presentation.Attributes
- Syadeu.Presentation.Components
- Syadeu.Presentation.Actions
- Syadeu.Presentation.Render
- CameraData
- CameraFrustum
- IntersectionType
- RenderSystem
- WorldCanvasSystem
- Syadeu.Presentation.Data
- DataContainerSystem
- DataObjectBase
- EntityAnimationClipEventData