Tanoda
ExampleArrayController.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections.Generic;
10using UnityEngine;
11using Leap.Unity.Query;
13
14public class ExampleArrayController : MonoBehaviour {
15
16 #pragma warning disable 0649
17 [SerializeField]
18 private AnimationCurve _motionCurve;
19 #pragma warning restore 0649
20
21 [SerializeField]
22 private Gradient _gradient = null;
23
24 private List<LeapGraphic> _graphics = new List<LeapGraphic>();
25 private List<Vector3> _originalPositions = new List<Vector3>();
26 private List<LeapBlendShapeData> _blendShapeData = new List<LeapBlendShapeData>();
27 private List<LeapRuntimeTintData> _tintData = new List<LeapRuntimeTintData>();
28
29 private void Start() {
30 _graphics.AddRange(GetComponentsInChildren<LeapGraphic>());
31 _graphics.Query().Select(g => g.transform.localPosition).FillList(_originalPositions);
32 _graphics.Query().Select(g => g.GetFeatureData<LeapBlendShapeData>()).FillList(_blendShapeData);
33 _graphics.Query().Select(g => g.GetFeatureData<LeapRuntimeTintData>()).FillList(_tintData);
34 }
35
36 private void Update() {
37 float fade = Mathf.Clamp01(Time.time * 0.5f - 0.5f);
38
39 for (int i = 0; i < _graphics.Count; i++) {
40 _graphics[i].transform.localPosition = _originalPositions[i];
41
42 float a = fade * 10 * noise(_graphics[i].transform.position, 42.0f, 0.8f);
43 float b = noise(_graphics[i].transform.position * 1.7f, 23, 0.35f);
44 float c = fade * _motionCurve.Evaluate(b);
45 float d = fade * (c * 0.1f + a * (c * 0.03f + 0.01f) + _graphics[i].transform.position.z * 0.14f);
46
47 _blendShapeData[i].amount = c;
48 _graphics[i].transform.localPosition += Vector3.up * d;
49 _tintData[i].color = fade * _gradient.Evaluate(b);
50 }
51 }
52
53 private float noise(Vector3 offset, float seed, float speed) {
54 float x1 = seed * 23.1239879f;
55 float y1 = seed * 82.1239812f;
56 x1 -= (int)x1;
57 y1 -= (int)y1;
58 x1 *= 10;
59 y1 *= 10;
60
61 float x2 = seed * 23.1239879f;
62 float y2 = seed * 82.1239812f;
63 x2 -= (int)x2;
64 y2 -= (int)y2;
65 x2 *= 10;
66 y2 *= 10;
67
68 return Mathf.PerlinNoise(offset.x + x1 + Time.time * speed, offset.z + y1 + Time.time * speed) * 0.5f +
69 Mathf.PerlinNoise(offset.x + x2 - Time.time * speed, offset.z + y2 - Time.time * speed) * 0.5f;
70 }
71}