Tanoda
ConstrainManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Runtime.Serialization;
5using GILES;
6using NaughtyAttributes;
7using UnityEngine;
8using UnityEngine.UI;
9using Random = UnityEngine.Random;
11using System.Globalization;
12
13public class ConstrainManager : MonoBehaviour
14{
15 public Camera cam;
16 public GameObject cube;
18 private MeshRenderer meshRenderer;
19 Mesh mesh;
20 Vector3[] vertices;
21 int[] triangles;
22 Transform originalParent1, originalParent2;
23 GameObject GO1, GO2;
24 internal bool constrain = false;
25 internal bool reparent = false;
26
27#if DANA
28
29 private void Start()
30 {
31 //mesh = transform.GetComponent<MeshFilter>().mesh;
32 //vertices = mesh.vertices;
33
35 //colorArray = new Color[vertices.Length];
36 //for (int k = 0; k < vertices.Length; k++)
37 //{
38 // colorArray[k] = Color.white;
39 //}
40 //mesh.colors = colorArray;
41 //triangles = mesh.triangles;
42 }
43
44 void Update()
45 {
46 if (!constrain) return;
47
48 if (Input.GetMouseButtonDown(0))
49 {
50 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
51
52 if (Physics.Raycast(ray, out RaycastHit hit))
53 {
54 mesh = hit.collider.gameObject.GetComponent<MeshFilter>().mesh;
55 vertices = mesh.vertices;
56
57 if (originalParent1 == null)
58 {
59 originalParent1 = hit.collider.gameObject.transform.parent;
60 GO1 = hit.collider.gameObject.GetComponentInParent<OffsetHolder>(true).gameObject;
61 }
62 //else
63 //{
64 // originalParent2 = hit.collider.gameObject.transform.parent;
65 // GO2 = hit.collider.gameObject;
66 //}
67
68 MeshCollider meshCollider = hit.collider as MeshCollider;
69 if (meshCollider == null || meshCollider.sharedMesh == null)
70 return;
71
72 cube.transform.position = hit.point;
73 //colorArray[hit.triangleIndex] = Color.red;
74
75 if (cube.transform.childCount == 0) cube.transform.forward = hit.normal;
76 else cube.transform.forward = -hit.normal;
77 if (cube.transform.childCount == 0)
78 {
79 hit.collider.gameObject.transform.SetParent(cube.transform);
80 }
81 else
82 {
83 reparent = true;
84 }
85
86 if (reparent)
87 {
88 GO1.transform.SetParent(originalParent1);
89 //GO2.transform.SetParent(originalParent2);
90 originalParent1 = null;
91 reparent = false;
92
93 }
94 }
95 else
96 {
97 Debug.Log("no hit");
98 }
99 }
100
101
102
103 }
104 public void isConstrain()
105 {
106 if (!constrain)
107 {
108 cube.SetActive(true);
109 constrain = true;
110 icon.color = new Color(0f, 38f/255f, 137f/255f);
111 background.color = Color.white;
112 }
113 else
114 {
115 cube.SetActive(false);
116 constrain = false;
117 icon.color = Color.white;
118 background.color = new Color(0f, 38f / 255f, 137f / 255f);
119 }
120
121 }
122#endif
123}
UnityEngine.Random Random
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32