Tanoda
DobotGrabber.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using GILES;
4using NaughtyAttributes;
5using UnityEngine;
6
7public class DobotGrabber : MonoBehaviour
8{
9 public static DobotGrabber instance;
10
11 public Transform from, to;
12 public GameObject grabbedObject;
13 private Transform originalParent;
14
15 private void Awake()
16 {
17 if (instance)
18 {
19 var d = instance;
20 Destroy(d);
21 }
22 instance = this;
23 }
24
25 [Button]
26 public void GrabNow()
27 {
28 Ray ray = new Ray(@from.position, to.position - @from.position);
29 Debug.DrawLine(ray.origin, ray.GetPoint(Vector3.Distance(@from.position, to.position)), Color.green, 3);
30 GameObject hit = pb_HandleUtility.ObjectRaycast(ray, pb_Scene.Children(), Vector3.Distance(@from.position, to.position), true, new List<GameObject>() { from.gameObject, to.gameObject, from.transform.parent.gameObject, to.transform.parent.gameObject });
31
32 if (hit)
33 {
34 var tcd = hit.GetComponentInParent<ThrowableCanDisable>();
35
36 if (tcd)
37 {
38 Macro.SetStatic(tcd.gameObject);
39 originalParent = tcd.transform.parent;
40 tcd.gameObject.transform.SetParent(transform, true);
41 grabbedObject = tcd.gameObject;
42 }
43 }
44 }
45
46 [Button]
47 public void ReleaseNow()
48 {
49 if (grabbedObject)
50 {
52 grabbedObject.transform.SetParent(originalParent, true);
53 grabbedObject = null;
54 }
55 }
56}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Color Color
Definition: TestScript.cs:32
void ReleaseNow()
Definition: DobotGrabber.cs:47
GameObject grabbedObject
Definition: DobotGrabber.cs:12
Transform to
Definition: DobotGrabber.cs:11
static DobotGrabber instance
Definition: DobotGrabber.cs:9
void GrabNow()
Definition: DobotGrabber.cs:26
Transform from
Definition: DobotGrabber.cs:11
static GameObject ObjectRaycast(Ray ray, IEnumerable< GameObject > objects, bool ignoreSelection=false)
static List< GameObject > Children()
Definition: pb_Scene.cs:1193
Definition: Macro.cs:12
static void SetStatic(GameObject go)
Definition: Macro.cs:388
static void SetInteractable(GameObject go, bool isKinematic=true)
Definition: Macro.cs:439