-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerInteraction.cs
100 lines (87 loc) · 3.19 KB
/
PlayerInteraction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//added onto main camera
//shoots rays to determine collisions with blueprints, gizmos
//gets positions to spawn objects
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheForest.Utils;
using UnityEngine;
namespace BuilderMenu
{
public class PlayerInteraction : MonoBehaviour
{
public Transform t;
private void Update()
{
if (t == null)
{
t = Camera.main.transform;
}
else
{
transform.position = t.position;
transform.rotation = t.rotation;
}
}
public Vector3 GetLookAtPos()
{
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward * 20, 20);
for (int i = 0; i < hits.Length; i++)
{
if (hits[i].transform.root != this.transform.root || hits[i].transform.root != LocalPlayer.Transform.root)
{
return hits[i].point;
}
}
return transform.position+transform.forward*20;
}
public Vector3 SelectGizmo()
{
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward * 50, 50);
for (int i = 0; i < hits.Length; i++)
{
Gizmo g = hits[i].transform.GetComponent<Gizmo>();
if (g != null)
{
Gizmo oldGizmo = EditorVariables.gizmo;
ModAPI.Console.Write("hit gizmo " + g.gameObject.name);
EditorVariables.SelectedGizmo = g.GizmoType;
ModAPI.Console.Write("selected gizmo " + EditorVariables.SelectedGizmo.ToString());
g.SetEnabled();
EditorVariables.gizmo = g;
oldGizmo.SetDisabled();
return hits[i].point;
}
}
return Vector3.zero;
}
public void SelectEdit()
{
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward * 50, 50, 0, QueryTriggerInteraction.Collide);
for (int i = 0; i < hits.Length; i++)
{
Blueprint b = hits[i].transform.root.GetComponent<Blueprint>();
if (b != null)
{
EditorVariables.EditedTransform = b.transform.root;
EditorVariables.isEditing = true;
b.Edited = true;
}
}
}
public Blueprint GetLookAtBlueprint()
{
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward * 50, 50, 1, QueryTriggerInteraction.Collide);
for (int i = 0; i < hits.Length; i++)
{
Blueprint b = hits[i].transform.root.GetComponent<Blueprint>();
if (b != null)
{
return b;
}
}
return null;
}
}
}