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