-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefs.cs
More file actions
58 lines (52 loc) · 2.5 KB
/
Copy pathRefs.cs
File metadata and controls
58 lines (52 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using HarmonyLib;
using RimWorld;
using System;
using System.Reflection;
using UnityEngine;
using Verse;
namespace SimpleCameraSetting
{
[StaticConstructorOnStartup]
internal static class Refs
{
public static readonly FieldInfo f_desiredSize;
public static readonly AccessTools.FieldRef<CameraDriver, float> desiredSize;
//ApplyPositionToGameObject가 private라 리플렉션으로 뺌
//매 프레임 따라가기에서 카메라 위치 바로 반영하려고 씀
public static readonly Action<CameraDriver> applyPositionToGameObject;
//rootPos도 private. 스무딩 시작할 때 현재 카메라 위치 시드용으로 읽음
public static readonly AccessTools.FieldRef<CameraDriver, Vector3> rootPos;
//리플렉션 실패 시 폴백용 더미
static float _dummySize;
static Vector3 _dummyRootPos;
static ref float DummySizeRef(CameraDriver _) => ref _dummySize;
static ref Vector3 DummyRootPosRef(CameraDriver _) => ref _dummyRootPos;
static Refs()
{
f_desiredSize = AccessTools.Field(typeof(CameraDriver), nameof(desiredSize));
try { desiredSize = AccessTools.FieldRefAccess<CameraDriver, float>(nameof(desiredSize)); }
catch (Exception e)
{
Log.Error("[SimpleCameraSetting] CameraDriver.desiredSize 참조 실패 - 줌속도 설정이 동작 안 할 수 있음: " + e.Message);
desiredSize = DummySizeRef;
}
try
{
var m = AccessTools.Method(typeof(CameraDriver), "ApplyPositionToGameObject");
if (m == null) throw new MissingMethodException("CameraDriver.ApplyPositionToGameObject");
applyPositionToGameObject = (Action<CameraDriver>)m.CreateDelegate(typeof(Action<CameraDriver>));
}
catch (Exception e)
{
Log.Error("[SimpleCameraSetting] CameraDriver.ApplyPositionToGameObject 참조 실패 - 따라가기가 1프레임 지연될 수 있음: " + e.Message);
applyPositionToGameObject = _ => { };
}
try { rootPos = AccessTools.FieldRefAccess<CameraDriver, Vector3>(nameof(rootPos)); }
catch (Exception e)
{
Log.Error("[SimpleCameraSetting] CameraDriver.rootPos 참조 실패 - 따라가기 스무딩 시드가 저하될 수 있음: " + e.Message);
rootPos = DummyRootPosRef;
}
}
}
}