comparison Orchestland/Assets/LeapMotion+OVR/DemoResources/Scripts/RandomBlocksGenerator.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 using UnityEngine;
2 using System.Collections;
3 using System.Linq;
4
5 public class RandomBlocksGenerator : MonoBehaviour {
6 public GameObject CubePrimitive;
7 public float minRadius;
8 public float maxRadius;
9 public int numberOfBlocks;
10 public float size;
11
12 private Color[] list_of_colors =
13 {
14 //new Color(1.00f, 1.00f, 0.94f), // (255,255,240) Ivory
15 //new Color(0.96f, 0.96f, 0.86f), // (245,245,220) Beige
16 //new Color(0.96f, 0.87f, 0.70f), // (245,222,179) Wheat
17 //new Color(0.82f, 0.71f, 0.55f), // (210,180,140) Tan
18 //new Color(0.76f, 0.69f, 0.57f), // (195,176,145) Khaki
19 //new Color(0.75f, 0.75f, 0.75f), // (192,192,192) Silver
20 //new Color(0.50f, 0.50f, 0.50f), // (128,128,128) Gray
21 //new Color(0.27f, 0.27f, 0.27f), // (070,070,070) Charcoal
22 new Color(0.00f, 0.00f, 1.00f), // (000,000,255) Navy Blue
23 new Color(0.02f, 0.30f, 0.62f), // (008,076,158) Royal Blue
24 new Color(0.00f, 0.00f, 0.80f), // (000,000,205) Medium Blue
25 new Color(0.00f, 0.50f, 1.00f), // (000,127,255) Azure
26 new Color(0.00f, 1.00f, 1.00f), // (000,255,255) Cyan
27 new Color(0.50f, 1.00f, 0.83f), // (127,255,212) Aquamarine
28 new Color(0.00f, 0.50f, 0.50f), // (000,127,127) Teal
29 new Color(0.13f, 0.55f, 0.13f), // (034,139,034) Forest Green
30 new Color(0.50f, 0.50f, 0.00f), // (127,127,000) Olive
31 new Color(0.50f, 1.00f, 0.00f), // (127,255,000) Chartreuse
32 new Color(0.75f, 1.00f, 0.00f), // (192,255,000) Lime
33 new Color(1.00f, 0.84f, 0.00f), // (255,215,000) Golden
34 new Color(0.85f, 0.65f, 0.13f), // (218,165,032) Goldenrod
35 new Color(1.00f, 0.50f, 0.31f), // (255,127,080) Coral
36 new Color(0.98f, 0.50f, 0.45f), // (250,128,114) Salmon
37 new Color(0.99f, 0.06f, 0.75f), // (252,015,192) Hot Pink
38 new Color(1.00f, 0.47f, 1.00f), // (255,119,255) Fuchsia
39 new Color(0.80f, 0.53f, 0.60f), // (204,136,153) Puce
40 new Color(0.88f, 0.69f, 1.00f), // (224,176,225) Mauve
41 new Color(0.71f, 0.49f, 0.86f), // (181,126,220) Lavender
42 new Color(0.52f, 0.19f, 0.47f), // (132,049,121) Plum
43 new Color(0.29f, 0.00f, 0.51f), // (075,000,130) Indigo
44 new Color(0.50f, 0.00f, 0.00f), // (127,000,000) Maroon
45 new Color(0.86f, 0.08f, 0.24f) // (220,020,060) Crimson
46 };
47
48 private void Reset()
49 {
50 if (maxRadius < minRadius)
51 return;
52
53 GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
54 sphere.transform.parent = transform;
55 sphere.transform.localScale = Vector3.one * (maxRadius + size * 2.0f) * 2.0f;
56 sphere.transform.localPosition = Vector3.zero;
57
58 Mesh sphereMesh = sphere.GetComponent<MeshFilter>().mesh;
59 sphereMesh.triangles = sphereMesh.triangles.Reverse().ToArray();
60 sphereMesh.RecalculateNormals();
61 sphere.GetComponent<SphereCollider>().enabled = false;
62 Destroy(sphere.GetComponent<SphereCollider>());
63 sphere.AddComponent<MeshCollider>();
64 sphere.GetComponent<Renderer>().enabled = false;
65
66 for (int i = 0; i < numberOfBlocks; ++i)
67 {
68 float radius = Random.Range(minRadius, maxRadius);
69 float theta = Random.Range(0.0f, 2 * Mathf.PI);
70 float phi = Random.Range(0.0f, 2 * Mathf.PI);
71
72 Vector3 position = new Vector3(
73 radius * Mathf.Sin(theta) * Mathf.Cos(phi),
74 radius * Mathf.Sin(theta) * Mathf.Sin(phi),
75 radius * Mathf.Cos(theta)
76 );
77
78 GameObject cube = GameObject.Instantiate(CubePrimitive) as GameObject;
79 cube.transform.parent = transform;
80 cube.transform.rotation = Quaternion.Euler(Random.Range(0.0f, 360.0f), Random.Range(0.0f, 360.0f), Random.Range(0.0f, 360.0f));
81 cube.transform.localScale = Vector3.one * size;
82 cube.transform.localPosition = position;
83 cube.AddComponent<Rigidbody>();
84 cube.GetComponent<Rigidbody>().useGravity = false;
85 cube.SetActive(true);
86
87 cube.GetComponent<Renderer>().material.color = list_of_colors[Random.Range(0,list_of_colors.Length - 1)];
88 }
89 }
90
91 // Use this for initialization
92 void Start () {
93 Reset();
94 }
95
96 // Update is called once per frame
97 void Update () {
98 }
99 }