-
Notifications
You must be signed in to change notification settings - Fork 0
/
IKMantik.cs
201 lines (164 loc) · 4.9 KB
/
IKMantik.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Experimental.GraphView.GraphView;
public class IKMantik : MonoBehaviour
{
bool duraksatildi;
public Slider zamanSlider;
public enum UzanmaHedefi { SOL_EL, SAG_EL};
bool sagElUzat;
bool solElUzat;
public Animator karsiAnimator;
public int animasyonNo;
public int animasyonNoKarsi;
[Range(0,1)] public float uzanmaSiddeti;
public UzanmaHedefi uHedef;
Animator animator;
private int eskiAnimasyonNo;
private int eskiAnimasyonNoKarsi;
bool bastanBasla = false;
float kendiZaman;
float karsiZaman;
float zamanKatSayisi;
float baslangic, bitis;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
eskiAnimasyonNo = animasyonNo;
animator.Play("" + animasyonNo);
if(karsiAnimator != null)
{
eskiAnimasyonNoKarsi = animasyonNoKarsi;
karsiAnimator.Play("" + animasyonNoKarsi);
}
}
// Update is called once per frame
void Update()
{
if(animasyonNo != eskiAnimasyonNo)
{
eskiAnimasyonNo = animasyonNo;
bastanBasla = true;
}
if (karsiAnimator != null && eskiAnimasyonNoKarsi != animasyonNoKarsi)
{
eskiAnimasyonNoKarsi = animasyonNoKarsi;
bastanBasla = true;
}
AnimatorStateInfo animState = animator.GetCurrentAnimatorStateInfo(0);
kendiZaman = animState.normalizedTime;
if(karsiAnimator != null)
{
AnimatorStateInfo animStateKarsi = karsiAnimator.GetCurrentAnimatorStateInfo(0);
karsiZaman = animStateKarsi.normalizedTime;
zamanKatSayisi = animState.length / animStateKarsi.length;
}
if(kendiZaman >= 1 && karsiZaman >= 1)
{
bastanBasla = true;
}
if (bastanBasla)
{
bastanBasla = false;
animator.Play("" + animasyonNo,0,0);
if(karsiAnimator != null)
{
karsiAnimator.Play("" + animasyonNoKarsi,0,0);
}
}
if (zamanSlider != null)
{
if (duraksatildi)
{
animator.Play("" + animasyonNo, 0, zamanSlider.value);
if(karsiAnimator != null)
{
karsiAnimator.Play("" + animasyonNoKarsi, 0, zamanSlider.value * zamanKatSayisi);
}
}
else
{
zamanSlider.value = kendiZaman % 1;
}
}
}
public void DuraksatCevir()
{
duraksatildi = !duraksatildi;
}
public void BaslangicEkle()
{
baslangic = zamanSlider.value;
}
public void BitisEkle()
{
bitis = zamanSlider.value;
}
int elModu = 0;
public void ElDegistir()
{
elModu = (elModu + 1) % 4;
switch(elModu)
{
case 0:
sagElUzat = false;
solElUzat = false;
break;
case 1:
sagElUzat = true;
solElUzat = false;
break;
case 2:
sagElUzat = false;
solElUzat = true;
break;
case 3:
sagElUzat = true;
solElUzat = true;
break;
}
}
private void OnAnimatorIK(int layerIndex)
{
if(karsiAnimator != null && animator != null)
{
float zamanParcasi = kendiZaman % 1;
if (zamanParcasi < baslangic)
{
uzanmaSiddeti = 0;
}
else if (zamanParcasi < bitis)
{
uzanmaSiddeti += Mathf.Lerp(0,1,Time.deltaTime);
}
else
{
uzanmaSiddeti -= Mathf.Lerp(0, 1, Time.deltaTime);
}
uzanmaSiddeti = Mathf.Clamp(uzanmaSiddeti, 0, 1);
Vector3 pos = Vector3.zero;
if(uHedef == UzanmaHedefi.SOL_EL)
{
pos = karsiAnimator.GetBoneTransform(HumanBodyBones.LeftHand).position;
}
else if (uHedef == UzanmaHedefi.SAG_EL)
{
pos = karsiAnimator.GetBoneTransform(HumanBodyBones.RightHand).position;
}
if(sagElUzat)
{
animator.SetIKPosition(AvatarIKGoal.RightHand, pos);
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, uzanmaSiddeti);
}
if(solElUzat)
{
animator.SetIKPosition(AvatarIKGoal.LeftHand, pos);
animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, uzanmaSiddeti);
}
}
}
}