git checkout [old-hashcode] or [new-hashcode]
2021년 12월 23일 목요일
2021년 11월 15일 월요일
How to set TextureSheetAnimationModule.startFrame constant value by script
if 8x8 texture atlas sheet,
Set Texture Sprite of column index = 3, row index = 1.
var ps = flame.textureSheetAnimation;
ps.numTilesX = 8;
ps.numTilesY = 8;
ps.animation = ParticleSystemAnimationType.SingleRow;
ps.startFrame = 1f / flameTextureSheets.numTilesX * 3f;
ps.rowIndex = 1;
2021년 7월 1일 목요일
When custom view autolayout doesn't work correclty
if updateLayout() is called in another methods except layoutSubivews(),
view's autolayout doesn't work appropriately.
i don't know why ...
class MyView:UIView {
override func layoutSubviews() {
super.layoutSubviews()
updateLayout()
}
func updateLayout(){
// setting height, constraints
}
}
2021년 5월 25일 화요일
Using Generic Type Monobehavior class
public class ExGeneric<T> : MonoBehaviour
{
public T data;
}
This ExGeneric<T> component can't be shown in Unity Inspector.
public class ExGenericFloat : ExGeneric<float>
{
}
This ExGenericFloat component is shown in Inspector.
2021년 4월 23일 금요일
Unity Inspector variable Lifecycle
1. Setting Test = 7
output:
Awake: test = 7
2. Setting Test default value
outputAwake: test = 1
3.
output
ExInspector: test = 2
ExInspector: test = 2
Awake: test = 1
Conclusion : Setting value order
1. Setting class member default value
2. Setting value in Inspector
3. Setting value in Awake()
2021년 3월 16일 화요일
Unity Animation Rigging 사용시 주의점
Two Bone IK Constraint 를 적용할때
Tip, Mid, Root 에 해당하는 Bone들을 알맞게 설정해야 애니메이션이 정상적으로 작동된다. 그러므로 설정시 주의깊게 체크해서 입력하도록 하자.
2021년 3월 8일 월요일
Unity C# Job System - tips and troubleshooting
- Job내에 있는 Static data에 접근하지 말라
예를들어 Job내에서 MonoBehaviour 멤버에 접근하면 크래쉬를 야기 시킨다.
- Flush scheduled batches
- NativeContainer 데이타를 바로 변경하지 말라
- 소유권을 얻기위해서는 JobHandle.Complete 호출하라
- Schedule, Complete를 메인 스레드에서 사용해라
- Schedule, Complete를 적절한 시간에 사용해라
- NativeContainer 타입은 readonly로 설정하라
- 데이타 의존성을 체크해라
- Debugging jobs
- Job내에서 managed memory를 생성하지 말아라
2021년 3월 3일 수요일
Unity C# Job System 5
ParallelFor jobs
Scheduling ParallelFor Jobs
An example of scheduling a ParallelFor job
ParallelForTransform jobs
2021년 3월 1일 월요일
Unity C# Job System 4
JobHandle and dependencies
Job의 Schedule() 메서드를 호출하면 JobHandle을 반환한다. 이것으로 다른 Job들과 의존성으로 사용할수 있다. 한개의 Job이 다른 Job의 결과에 의존적이라면, 첫번째 Job의 JobHandle을 두번째 Job의 Schedule 메서드에 변수로 넣는다.
JobHandle firstJobHandle = firstJob.Schedule();
secondJob.Schedule(firstJobHandle);
Combining dependencies
Waiting for jobs in the main thread
Note
2021년 2월 25일 목요일
Unity C# Job System 3
Creating Jobs
- Job을 만들기 위해서는 IJob 인터페이스를 구현한다
- 해당 Job 사용할 멤버변수들을 추가한다
- Execute 함수를 Job내에 구현한다.
public float a;
public float b;
public NativeArray<float> result;
public void Execute(){
result[0] = a + b;
}
}
Scheduling Jobs
- Instantiate the job
- Populate the Job's data
- Call the Schedule method
Unity C# Job System 2
The safety system in the C# Job system
Race conditions
멀티스레드 코드를 작성할때, 항상 Race Conditions 에 빠지는 것을 주의해야 한다. 이는 하나의 작업 결과값이 다른 스레드 영역에 있는 처리 결과가 완료될때까지 한없이 기다리게 되는 현상을 말한다. 이를 Race Conditions or Race Hazard라 한다.
이는 디버깅하기가 매우 힘들게 하고, 원인을 찾는 데 매우 어렵다. 그러므로 이런 코드를 작성하면 안된다.
Safety system
NativeContainer
데이타 복사처리의 단점은 이들 데이터들이 각 쓰레드 영역에서 분리되어 있다는 것이다. 이를 보완하기위해 나온것이 NativeContainer라 불리는 공유 메모리 타입이다.
What is a NativeContainer?
What types of NativeContainer are available?
- NativeList - a resizable NativeArray
- NativeHashMap - key and value pairs
- NativeMultiHashMap - multiple values per key
- NativeQueue - a first in , first out (FIFO) queue
NativeContainer and the safety system
[ReadOnly]
public NativeArray<int> input;
NativeContainer Allocator
- Allocator.Temp
- 가장 빠른 할당.
- 1 frame 혹은 그보다 적은 수명을 갖는다.
- you should not pass NativeContainer allocations using Temp to Jobs.
- Dispose 메서드를 호출해야 한다. ( Native 에서 Managed로 복귀할때)
- Allocator.TempJob
- Temp보다는 느리지만, Persistent 보다 빠른 할당.
- 4 frame 의 수명. thread-safe.
- 4 frame내에서 dispose를 호출하지 않으면, Warning이 뜬다.
- 대부분의 작은 Job들이 사용하는 타입이다.
- Allocator.Persistent
- 가장 느린 할당. 필요하다면 앱이 실행중인 내내 지속된다.
- 작업량이 많은 Job일 경우 사용.
- 성능이 필수적이라면 이 타입의 사용을 자제한다.
Unity C# Job System
Job System
Burst compiler 와 함께 사용하면, 더 좋다.
Job system은 Unity내부적으로 돌아가는 Native Job system과 자연스럽게 통합된다. 그래서 유저가 작성한 Job System코드와 유니티가 worker thread를 공유한다. 이러한 협력이 cpu cores보다 더 많은 스레드를 만드는것을 막아준다. 이로 인한 cpu 자원을 낭비하는 것을 줄일수 있다.