Mercurial > hg > Game > Games
comparison Orchestland/Assets/LeapMotion/DemoResources/Scripts/FlowerGrower.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 /******************************************************************************\ | |
2 * Copyright (C) Leap Motion, Inc. 2011-2014. * | |
3 * Leap Motion proprietary. Licensed under Apache 2.0 * | |
4 * Available at http://www.apache.org/licenses/LICENSE-2.0.html * | |
5 \******************************************************************************/ | |
6 | |
7 using UnityEngine; | |
8 using System.Collections; | |
9 | |
10 public class FlowerGrower : MonoBehaviour { | |
11 | |
12 public float growthRate = 1.0f; | |
13 public float deathRate = 1.0f; | |
14 public float growthProgress = 0.0f; | |
15 | |
16 public StemMesh stem; | |
17 public float stemStartGrowth = 0.0f; | |
18 public float stemEndGrowth = 0.6f; | |
19 | |
20 public Transform flowerHead; | |
21 public float flowerHeadStartGrowth = 0.5f; | |
22 public float flowerHeadEndGrowth = 0.8f; | |
23 | |
24 public Light lightSource; | |
25 public float lightSourceStartGrowth = 0.0f; | |
26 public float lightSourceEndGrowth = 0.8f; | |
27 | |
28 public PetalMesh[] leaves; | |
29 public float leavesStartGrowth = 0.4f; | |
30 public float leavesEndGrowth = 0.8f; | |
31 | |
32 public PetalMesh[] pedals; | |
33 public float pedalsStartGrowth = 0.8f; | |
34 public float pedalsEndGrowth = 1.0f; | |
35 | |
36 public FlowerBloom flowerToBloom; | |
37 | |
38 private Vector3 flower_head_scale_ = Vector3.zero; | |
39 private float light_source_intensity_ = 0.0f; | |
40 private bool growing_ = true; | |
41 private bool dieing_ = false; | |
42 | |
43 void Start() { | |
44 flower_head_scale_ = flowerHead.localScale; | |
45 light_source_intensity_ = lightSource.intensity; | |
46 flowerHead.localScale = Vector3.zero; | |
47 | |
48 foreach (PetalMesh pedal in pedals) | |
49 pedal.growthProgress = 0; | |
50 | |
51 foreach (PetalMesh leaf in leaves) | |
52 leaf.growthProgress = 0; | |
53 } | |
54 | |
55 float ComputeGrowthAmount(float start, float end) { | |
56 return Mathf.Clamp((growthProgress - start) / (end - start), 0.0f, 1.0f); | |
57 } | |
58 | |
59 void SetSizes() { | |
60 stem.growthProgress = ComputeGrowthAmount(stemStartGrowth, stemEndGrowth); | |
61 | |
62 float flower_head_growth = ComputeGrowthAmount(flowerHeadStartGrowth, flowerHeadEndGrowth); | |
63 flowerHead.localScale = flower_head_growth * flower_head_scale_; | |
64 | |
65 float light_source_growth = ComputeGrowthAmount(lightSourceStartGrowth, lightSourceEndGrowth); | |
66 lightSource.intensity = light_source_growth * light_source_intensity_; | |
67 | |
68 float leaf_growth = ComputeGrowthAmount(leavesStartGrowth, leavesEndGrowth); | |
69 foreach (PetalMesh leaf in leaves) | |
70 leaf.growthProgress = leaf_growth; | |
71 | |
72 float pedal_growth = ComputeGrowthAmount(pedalsStartGrowth, pedalsEndGrowth); | |
73 foreach (PetalMesh pedal in pedals) | |
74 pedal.growthProgress = pedal_growth; | |
75 } | |
76 | |
77 public void RemoveStump() { | |
78 stem.RemoveStump(); | |
79 } | |
80 | |
81 public bool IsStumpClear() { | |
82 return stem.IsStumpClear(); | |
83 } | |
84 | |
85 public void Die() { | |
86 dieing_ = true; | |
87 } | |
88 | |
89 public bool IsDead() { | |
90 return growthProgress == 0.0f; | |
91 } | |
92 | |
93 public bool IsBroken() { | |
94 return stem.IsBroken(); | |
95 } | |
96 | |
97 public bool IsGrabbed() { | |
98 GrabbableObject[] grabbables = GetComponentsInChildren<GrabbableObject>(); | |
99 foreach (GrabbableObject grabbable in grabbables) { | |
100 if (grabbable.IsGrabbed()) | |
101 return true; | |
102 } | |
103 return false; | |
104 } | |
105 | |
106 void Update() { | |
107 if (dieing_) | |
108 growthProgress = Mathf.Clamp(growthProgress - Time.deltaTime * deathRate, 0.0f, 1.0f); | |
109 else if (growing_) | |
110 growthProgress = Mathf.Clamp(growthProgress + Time.deltaTime * growthRate, 0.0f, 1.0f); | |
111 | |
112 SetSizes(); | |
113 | |
114 if (growthProgress == 1.0f && flowerToBloom != null) | |
115 flowerToBloom.open = true; | |
116 } | |
117 } |