public override void setValues(GameObject obj) { RoundedCube rCube = obj.GetComponent <RoundedCube>(); rCube.setSizes(x, y, z); rCube.setRoundness(roundness); }
/// <summary> /// Create 10 new cubes with random sizes. /// Serialize the mesh and save it to a file. /// </summary> public void GenerateCubes() { int x = Random.Range(2, 8); int y = Random.Range(2, 8); int z = Random.Range(2, 8); Mesh mesh = null; for (int i = 0; i < 10; i++) { GameObject newCube = Instantiate(CubePrefab, new Vector3(Random.Range(-10, 10), Random.Range(-3, 3), Random.Range(-10, 10)), new Quaternion(0, 0, 0, 0)); RoundedCube roundedCube = newCube.GetComponent <RoundedCube>(); roundedCube.xSize = x; roundedCube.ySize = y; roundedCube.zSize = z; roundedCube.Generate(); mesh = roundedCube.GetComponent <MeshFilter>().mesh; } FileStream stream = new FileStream("OPS_Mesh.ser", FileMode.Create); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); OPS.Serialization.IO.Serializer.SerializeToStream(stream, mesh); stopwatch.Stop(); stream.Close(); UnityEngine.Debug.Log("Save Mesh: Size: " + mesh.bounds + " ElapsedMilliseconds: " + stopwatch.ElapsedMilliseconds); }
/// <summary> /// Create 10 Cubes basing on the last saved mesh. /// </summary> public void LoadCubes() { if (!File.Exists("OPS_Mesh.ser")) { UnityEngine.Debug.LogError("OPS_Mesh.ser does not exits. Please use first generate!"); } FileStream stream = new FileStream("OPS_Mesh.ser", FileMode.Open); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Mesh mesh = OPS.Serialization.IO.Serializer.DeSerializeFromStream <Mesh>(stream); stopwatch.Stop(); stream.Close(); UnityEngine.Debug.Log("Load Mesh: Size: " + mesh.bounds + " ElapsedMilliseconds: " + stopwatch.ElapsedMilliseconds); for (int i = 0; i < 10; i++) { GameObject newCube = Instantiate(CubePrefab, new Vector3(Random.Range(-10, 10), Random.Range(-3, 3), Random.Range(-10, 10)), new Quaternion(0, 0, 0, 0)); RoundedCube roundedCube = newCube.GetComponent <RoundedCube>(); roundedCube.Load(mesh); } }
// ================================================================================================================ // MAIN EVENT INTERFACE ------------------------------------------------------------------------------------------- public override void OnInspectorGUI() { RoundedCube roundedCube = (RoundedCube)target; roundedCube.width = EditorGUILayout.FloatField("Width", roundedCube.width); roundedCube.height = EditorGUILayout.FloatField("Height", roundedCube.height); roundedCube.depth = EditorGUILayout.FloatField("Depth", roundedCube.depth); roundedCube.cornerRadius = EditorGUILayout.FloatField("Corner radius", roundedCube.cornerRadius); roundedCube.offsetTopX = EditorGUILayout.FloatField("Top Offset (X)", roundedCube.offsetTopX); roundedCube.offsetTopY = EditorGUILayout.FloatField("Top Offset (Y)", roundedCube.offsetTopY); roundedCube.cornerSegments = EditorGUILayout.IntSlider("Corner segments", roundedCube.cornerSegments, 0, 32); roundedCube.color = EditorGUILayout.ColorField("Color", roundedCube.color); if (GUI.changed) { EditorUtility.SetDirty(roundedCube); } /* * serializedObject.Update(); * * // Totals * //GUILayout.LabelField("Triangles", 10.ToString()); * * //GUILayout.BeginVertical("Terrain", "box"); * //GUILayout.Space(20); * //GUILayout.EndVertical(); * * // Terrain info * //terrainTarget.title = EditorGUILayout.TextField("Terrain title", terrainTarget.title); * * // Other * terrainTarget.setTileTypeList((TiledTerrainTileTypes)EditorGUILayout.ObjectField("List of tile types", terrainTarget.getTileTypeList(), typeof(TiledTerrainTileTypes), true)); * * //((TiledTerrain)target).ping();//lookAtPoint = EditorGUILayout.Vector3Field ("Look At Point", target.lookAtPoint); * serializedObject.ApplyModifiedProperties(); */ }
// Token: 0x060041A6 RID: 16806 RVA: 0x0014C3B4 File Offset: 0x0014A7B4 public void OnButtonHit(int id) { this.animTimeout = this.animTimeMax; BaseObject baseObject = null; switch (id) { case 0: { baseObject = Triangle.Create(1f, 0); float[] array = new float[6]; array[0] = 4f; array[1] = 4f; this.shapeParamsMax = array; float[] array2 = new float[6]; array2[0] = 1f; array2[1] = 1f; this.shapeParamsStart = array2; break; } case 1: baseObject = PlaneObject.Create(1f, 1f, 1, 1); this.shapeParamsMax = new float[] { 4f, 4f, 1f, 1f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 1f, 1f, 0f, 0f }; break; case 2: { baseObject = Circle.Create(1f, 3); float[] array3 = new float[6]; array3[0] = 2.5f; array3[1] = 40f; this.shapeParamsMax = array3; float[] array4 = new float[6]; array4[0] = 1f; array4[1] = 3f; this.shapeParamsStart = array4; break; } case 3: baseObject = Ellipse.Create(1f, 0.5f, 3); this.shapeParamsMax = new float[] { 2.5f, 1.2f, 40f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 0.5f, 3f, 0f, 0f, 0f }; break; case 4: baseObject = Ring.Create(0.5f, 1f, 3); this.shapeParamsMax = new float[] { 1f, 2.5f, 40f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 0.5f, 1f, 3f, 0f, 0f, 0f }; break; case 5: baseObject = Box.Create(1f, 1f, 1f, 1, 1, 1, false, null, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 2.5f, 2.5f, 2.5f, 1f, 1f, 1f }; this.shapeParamsStart = new float[] { 1f, 1f, 1f, 1f, 1f, 1f }; break; case 6: baseObject = Cylinder.Create(1f, 3f, 3, 1, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.25f, 4f, 40f, 1f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 3f, 3f, 1f, 0f, 0f, 0f }; break; case 7: baseObject = Cone.Create(1f, 0f, 0f, 2f, 3, 10, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.25f, 0f, 4f, 40f, 10f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 2f, 3f, 10f, 0f, 0f }; break; case 8: { baseObject = Sphere.Create(1f, 4, 0f, 0f, 0f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); float[] array5 = new float[6]; array5[0] = 2.25f; array5[1] = 40f; this.shapeParamsMax = array5; float[] array6 = new float[6]; array6[0] = 1f; array6[1] = 4f; this.shapeParamsStart = array6; break; } case 9: baseObject = Ellipsoid.Create(1f, 1f, 1f, 4, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.25f, 2.45f, 2.5f, 40f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 1f, 4f, 0f, 0f, 0f }; break; case 10: baseObject = Pyramid.Create(1f, 1f, 1f, 1, 1, 1, false, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 2.7f, 2.7f, 1.7f, 1f, 1f, 1f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 0f, 0f, 0f }; break; case 11: { baseObject = GeoSphere.Create(1f, 0, GeoSpherePrimitive.BaseType.Icosahedron, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); float[] array7 = new float[6]; array7[0] = 2.45f; array7[1] = 4f; this.shapeParamsMax = array7; float[] array8 = new float[6]; array8[0] = 1f; this.shapeParamsStart = array8; break; } case 12: baseObject = Tube.Create(0.8f, 1f, 1f, 3, 1, 0f, false, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 0.8f, 1.5f, 4f, 40f, 0f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 0.8f, 1f, 1f, 3f, 0f, 0f, 0f, 0f }; break; case 13: baseObject = Capsule.Create(1f, 1f, 4, 1, false, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.2f, 4f, 40f, 1f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 4f, 1f, 0f, 0f, 0f }; break; case 14: baseObject = RoundedCube.Create(1f, 1f, 1f, 1, 0.2f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.6f, 1.6f, 1.6f, 20f, 0.6f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 1f, 1f, 1f, 0.2f, 0f, 0f, 0f }; break; case 15: baseObject = Torus.Create(1f, 0.5f, 4, 4, 0f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1.6f, 0.8f, 40f, 40f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 0.5f, 4f, 4f, 0f, 0f, 0f }; break; case 16: baseObject = TorusKnot.Create(0.5f, 0.3f, 10, 4, 2, 3, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 1f, 0.5f, 120f, 40f, 2f, 3f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 0.5f, 0.3f, 10f, 4f, 2f, 3f, 0f, 0f, 0f }; break; case 17: baseObject = Arc.Create(1f, 1f, 1f, 1f, 10, PivotPosition.Botttom); ((Arc)baseObject).gizmo.gameObject.transform.localPosition = new Vector3(-1f, -1f, 0f); this.shapeParamsMax = new float[] { 4f, 3f, 2f, 1f, 20f, -1f }; this.shapeParamsStart = new float[] { 0.5f, 0.5f, 0.1f, 0.5f, 0f, 0f }; break; case 18: baseObject = SphericalCone.Create(1f, 20, 180f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 2f, 40f, 20f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 1f, 20f, 360f, 0f, 0f, 0f }; break; case 19: baseObject = SuperEllipsoid.Create(1f, 1f, 1f, 20, 0.5f, 1f, (!this.flatNormals) ? NormalsType.Vertex : NormalsType.Face, PivotPosition.Botttom); this.shapeParamsMax = new float[] { 2f, 2f, 2f, 20f, 0.5f, 1f, 0f, 0f, 0f }; this.shapeParamsStart = new float[] { 0.5f, 0.5f, 0.5f, 1f, 0f, 0f, 0f, 0f, 0f }; break; case 20: this.textureToggle = !this.textureToggle; break; case 21: this.flatNormals = !this.flatNormals; break; } if (baseObject) { if (this.shapeOld) { UnityEngine.Object.Destroy(this.shapeOld.gameObject); } this.shapeOld = this.shapeMain; this.shapeMain = baseObject; this.shapeMain.gameObject.GetComponent <Renderer>().material = new Material(this.GetSpecularShader()); this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_Color", new Color(1f, 0.7058824f, 0.7058824f)); this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_SpecColor", Color.white); this.shapeMain.gameObject.transform.position = this.prevPosition.position; this.nextShowTimeout = this.nextShowTimeoutMax; this.shapeID = id; } if (this.textureToggle) { this.shapeMain.GetComponent <MeshRenderer>().sharedMaterial = (Resources.Load("Checker") as Material); } else { this.shapeMain.GetComponent <MeshRenderer>().sharedMaterial = new Material(this.GetSpecularShader()); this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_Color", new Color(1f, 0.7058824f, 0.7058824f)); this.shapeMain.gameObject.GetComponent <Renderer>().material.SetColor("_SpecColor", Color.white); } }