Tanoda
HandCopy.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class HandCopy : MonoBehaviour
6{
7 public bool clampFingers = false;
8 public int AvgClamp = 5;
9 public Vector3 thumbOffset = new Vector3(90, 0, 0f);
10 public GameObject[] from, to, thumb1, thumb2;
11
12 private List<Queue<Vector3>> fromQueue, thumbQueue;
13
14 void Start()
15 {
16 fromQueue = new List<Queue<Vector3>>();
17 thumbQueue = new List<Queue<Vector3>>();
18 for (int i = 0; i < @from.Length; i++)
19 {
20 fromQueue.Add(new Queue<Vector3>());
21 }
22 for (int i = 0; i < thumb1.Length; i++)
23 {
24 thumbQueue.Add(new Queue<Vector3>());
25 }
26 }
27
28 void Update()
29 {
30 for (int i = 0; i < @from.Length; i++)
31 {
32 fromQueue[i].Enqueue(
33 new Vector3(Macro.ClampAngle(@from[i].transform.localEulerAngles.y),
35 ? Mathf.Min(Macro.ClampAngle(@from[i].transform.localEulerAngles.z), 20f)
36 : @from[i].transform.localEulerAngles.z,
38 ? Mathf.Min(10, Mathf.Max(-10, Macro.ClampAngle(-@from[i].transform.localEulerAngles.x)))
39 : -@from[i].transform.localEulerAngles.x));
40
41 while (fromQueue[i].Count > AvgClamp)
42 {
43 fromQueue[i].Dequeue();
44 }
45
46
47 //to[i].transform.localEulerAngles = new Vector3(Macro.ClampAngle(@from[i].transform.localEulerAngles.y),
48 // clampFingers ? Mathf.Min(Macro.ClampAngle(@from[i].transform.localEulerAngles.z), 20f) : @from[i].transform.localEulerAngles.z,
49 // clampFingers
50 // ? Mathf.Min(20, Mathf.Max(-20, Macro.ClampAngle(-@from[i].transform.localEulerAngles.x)))
51 // : -@from[i].transform.localEulerAngles.x);
52 }
53
54 for (int i = 0; i < @from.Length; i++)
55 {
56 var avg = default(Vector3);
57 foreach (var v in fromQueue[i])
58 {
59 avg += v;
60 }
61
62 avg /= fromQueue[i].Count;
63
64 to[i].transform.localEulerAngles = avg;
65 }
66
67 var le0 = thumb1[0].transform.localEulerAngles;
68 thumb2[0].transform.localEulerAngles = new Vector3(-le0.y, clampFingers ? Mathf.Min(Macro.ClampAngle(-le0.x), 0f) : -le0.x, -le0.z) + thumbOffset;
69 for (int i = 1; i < thumb1.Length; i++)
70 {
71 var le = thumb1[i].transform.localEulerAngles;
72 thumb2[i].transform.localEulerAngles = new Vector3(-le.y, clampFingers ? Mathf.Min(Macro.ClampAngle(-le.x), 0f) : -le.x, -le.z);
73 }
74 }
75
76
77}
GameObject[] thumb2
Definition: HandCopy.cs:10
int AvgClamp
Definition: HandCopy.cs:8
bool clampFingers
Definition: HandCopy.cs:7
GameObject[] from
Definition: HandCopy.cs:10
Vector3 thumbOffset
Definition: HandCopy.cs:9
GameObject[] thumb1
Definition: HandCopy.cs:10
GameObject[] to
Definition: HandCopy.cs:10
Definition: Macro.cs:12
static Vector3 ClampAngle(Vector3 value)
Definition: Macro.cs:303