blob: 21ec9f1ee4548c7fd9ef7d0eaa255a723f7e9139 (
plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
using InControl;
using UnityEngine;
public class CharacterCreatorDragging : MonoBehaviour
{
public Vector2 rightStick;
private CharacterCreator creator;
private Transform draggedObject;
private Vector2 lastMouse = Vector3.zero;
private void Start()
{
creator = GetComponentInParent<CharacterCreator>();
}
private void Update()
{
if (creator.inputType == GeneralInput.InputType.Keyboard || creator.inputType == GeneralInput.InputType.Either)
{
DoMouse();
}
if (creator.inputType == GeneralInput.InputType.Controller || creator.inputType == GeneralInput.InputType.Either)
{
DoController();
}
}
private void DoController()
{
int num = -1;
int barPos = creator.nav.barPos;
for (int i = 0; i < base.transform.childCount; i++)
{
CharacterItem component = base.transform.GetChild(i).GetComponent<CharacterItem>();
if (barPos == 0 && component.itemType == CharacterItemType.Eyes)
{
num = i;
}
if (barPos == 1 && component.itemType == CharacterItemType.Mouth)
{
num = i;
}
if (barPos == 2 && component.itemType == CharacterItemType.Detail && component.slotNr == 0)
{
num = i;
}
if (barPos == 3 && component.itemType == CharacterItemType.Detail && component.slotNr == 1)
{
num = i;
}
}
if (num >= base.transform.childCount)
{
return;
}
Vector2 vector = Vector2.zero;
if (creator.playerActions != null)
{
vector = creator.playerActions.Aim.Value;
}
else
{
for (int j = 0; j < InputManager.ActiveDevices.Count; j++)
{
vector = InputManager.ActiveDevices[j].RightStick.Value;
}
}
base.transform.GetChild(num).transform.position += (Vector3)vector * Time.deltaTime * 3f;
if (vector != Vector2.zero)
{
CharacterItem component2 = base.transform.GetChild(num).GetComponent<CharacterItem>();
Vector2 offset = (Vector2)base.transform.GetChild(num).localPosition - component2.offset;
creator.SetOffset(offset, component2.itemType, component2.slotNr);
}
}
private void DoMouse()
{
Vector2 vector = MainCam.instance.cam.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetKeyDown(KeyCode.Mouse0))
{
float num = 2f;
int num2 = -1;
for (int i = 0; i < base.transform.childCount; i++)
{
float num3 = Vector2.Distance(vector, base.transform.GetChild(i).transform.position);
Debug.DrawLine(vector, base.transform.GetChild(i).GetComponent<SpriteRenderer>().bounds.center, Color.red, 2f);
if (num3 < num)
{
num = num3;
num2 = i;
}
}
if (num2 != -1)
{
draggedObject = base.transform.GetChild(num2);
}
}
if (Input.GetKeyUp(KeyCode.Mouse0) && (bool)draggedObject)
{
CharacterItem component = draggedObject.GetComponent<CharacterItem>();
Vector2 offset = (Vector2)draggedObject.transform.localPosition - component.offset;
creator.SetOffset(offset, component.itemType, component.slotNr);
draggedObject = null;
}
if ((bool)draggedObject)
{
draggedObject.transform.position += (Vector3)(vector - lastMouse);
draggedObject.transform.localPosition = Vector2.ClampMagnitude(draggedObject.transform.localPosition, 4.5f);
}
lastMouse = vector;
}
}
|