Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
PlayerModelWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public enum Shot {
9 }
10
12
14
16
18
19 public float m_rotation;
20
23 set {
24 if (value != null) {
27 }
28 else {
30 }
31 }
32 }
33
34 public Shot CameraShot { get; set; }
35
36 public int AnimateHeadSeed { get; set; }
37
38 public int AnimateHandsSeed { get; set; }
39
40 public bool OuterClothing { get; set; }
41
42 public PlayerClass PlayerClass { get; set; }
43
44 public PlayerData PlayerData { //目前仅赋值,游戏里没有使用该属性,但勿删,模组可能会用到
45 get;
46 set;
47 }
48
49 public string CharacterSkinName { get; set; }
50
51 public Texture2D CharacterSkinTexture { get; set; }
52
53 public Texture2D OuterClothingTexture { get; set; }
54
55 public Model OuterClothingModel { get; set; }
56 public Model PlayerModel { get; set; }
57
59 m_modelWidget = new ModelWidget { UseAlphaThreshold = true, IsPerspective = true };
61 IsHitTestVisible = false;
64 }
65
66 public override void Update() {
67 if (Input.Press.HasValue) {
68 if (m_lastDrag.HasValue) {
69 m_rotation += 0.01f * (Input.Press.Value.X - m_lastDrag.Value.X);
70 m_lastDrag = Input.Press.Value;
71 Input.Clear();
72 }
73 else if (HitTestGlobal(Input.Press.Value) == this) {
74 m_lastDrag = Input.Press.Value;
75 }
76 }
77 else {
78 m_lastDrag = null;
80 if (MathF.Abs(m_rotation) > 0.01f) {
82 }
83 else {
84 m_rotation = 0f;
85 }
86 }
87 m_modelWidget.ModelMatrix = m_rotation != 0f ? Matrix.CreateRotationY(m_rotation) : Matrix.Identity;
88 }
89
90 public override void MeasureOverride(Vector2 parentAvailableSize) {
91 if (OuterClothing) {
92 return;
93 }
94 m_modelWidget.RemoveModel(PlayerModel);
98 m_modelWidget.AddModel(PlayerModel);
100 if (CameraShot == Shot.Body) {
101 m_modelWidget.ViewPosition = PlayerClass == PlayerClass.Male ? new Vector3(0f, 1.46f, -3.2f) : new Vector3(0f, 1.39f, -3.04f);
102 m_modelWidget.ViewTarget = PlayerClass == PlayerClass.Male ? new Vector3(0f, 0.9f, 0f) : new Vector3(0f, 0.86f, 0f);
103 m_modelWidget.ViewFov = 0.57f;
104 }
105 else {
106 if (CameraShot != Shot.Bust) {
107 throw new InvalidOperationException("Unknown shot.");
108 }
109 m_modelWidget.ViewPosition = PlayerClass == PlayerClass.Male ? new Vector3(0f, 1.5f, -1.05f) : new Vector3(0f, 1.43f, -1f);
110 m_modelWidget.ViewTarget = PlayerClass == PlayerClass.Male ? new Vector3(0f, 1.5f, 0f) : new Vector3(0f, 1.43f, 0f);
111 m_modelWidget.ViewFov = 0.57f;
112 }
116 //OuterClothingTexture ??= new RenderTarget2D(m_modelWidget.Textures[PlayerModel].Width, m_modelWidget.Textures[PlayerModel].Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
118 if (AnimateHeadSeed != 0) {
119 int num = AnimateHeadSeed < 0 ? GetHashCode() : AnimateHeadSeed;
120 float num2 = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * num, 10000.0);
121 float rotationZ = MathUtils.Lerp(-0.75f, 0.75f, SimplexNoise.OctavedNoise(num2 + 100f, 0.2f, 1, 2f, 0.5f));
122 float rotationX = MathUtils.Lerp(-0.5f, 0.5f, SimplexNoise.OctavedNoise(num2 + 200f, 0.17f, 1, 2f, 0.5f));
123 Matrix value = Matrix.CreateRotationX(rotationX) * Matrix.CreateRotationZ(rotationZ);
124 m_modelWidget.SetBoneTransform(OuterClothingModel, OuterClothingModel.FindBone("Head").Index, value);
125 m_modelWidget.SetBoneTransform(PlayerModel, PlayerModel.FindBone("Head").Index, value);
126 }
127 if (AnimateHandsSeed != 0) {
128 int num3 = AnimateHandsSeed < 0 ? GetHashCode() : AnimateHandsSeed;
129 float num4 = (float)MathUtils.Remainder(Time.FrameStartTime + 1000.0 * num3, 10000.0);
130 Vector2 vector2 = default;
131 vector2.X = MathUtils.Lerp(0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 100f, 0.7f, 1, 2f, 0.5f));
132 vector2.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 200f, 0.7f, 1, 2f, 0.5f));
133 Vector2 vector3 = default;
134 vector3.X = MathUtils.Lerp(-0.2f, 0f, SimplexNoise.OctavedNoise(num4 + 300f, 0.7f, 1, 2f, 0.5f));
135 vector3.Y = MathUtils.Lerp(-0.3f, 0.3f, SimplexNoise.OctavedNoise(num4 + 400f, 0.7f, 1, 2f, 0.5f));
136 Matrix value2 = Matrix.CreateRotationX(vector2.Y) * Matrix.CreateRotationY(vector2.X);
137 Matrix value3 = Matrix.CreateRotationX(vector3.Y) * Matrix.CreateRotationY(vector3.X);
138 m_modelWidget.SetBoneTransform(PlayerModel, PlayerModel.FindBone("Hand1").Index, value2);
139 m_modelWidget.SetBoneTransform(PlayerModel, PlayerModel.FindBone("Hand2").Index, value3);
140 }
142 "OnPlayerModelWidgetMeasureOverride",
143 loader => {
144 loader.OnPlayerModelWidgetMeasureOverride(this);
145 return false;
146 }
147 );
148 base.MeasureOverride(parentAvailableSize);
149 }
150
151 public override void UpdateCeases() {
152 if (RootWidget == null) {
153 if (m_publicCharacterSkinsCache.ContainsTexture(m_modelWidget.Textures[PlayerModel])) {
154 m_modelWidget.Textures[PlayerModel] = null;
155 }
157 }
158 base.UpdateCeases();
159 }
160 }
161}
Engine.Vector3 Vector3
static float Remainder(float x, float y)
static float NormalizeAngle(float angle)
static float PowSign(float x, float n)
static float Lerp(float x1, float x2, float f)
static float FrameDuration
定义 Time.cs:46
static double FrameStartTime
定义 Time.cs:42
static Model GetOuterClothingModel(PlayerClass playerClass)
static Model GetPlayerModel(PlayerClass playerClass)
readonly WidgetsList Children
CharacterSkinsCache m_publicCharacterSkinsCache
override void MeasureOverride(Vector2 parentAvailableSize)
CharacterSkinsCache CharacterSkinsCache
CharacterSkinsCache m_characterSkinsCache
static float OctavedNoise(float x, float frequency, int octaves, float frequencyStep, float amplitudeStep, bool ridged=false)
Widget RootWidget
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
WidgetInput Input
virtual bool IsHitTestVisible
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Matrix CreateRotationX(float radians)
static Matrix CreateRotationZ(float radians)
static readonly Matrix Identity
static Matrix CreateRotationY(float radians)