-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlayerSetup.cs
86 lines (76 loc) · 2.91 KB
/
PlayerSetup.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
using UnityEditor;
using UnityEngine;
// By B0N3head
// This script, although readable was not created out to be super readable for beginners.
// Its just for setup and is not used during gameplay
[CustomEditor(typeof(PlayerMovement))]
public class PlayerSetup : Editor
{
string dialogTitle = "Player Movement Setup v1.1", dialogYes = "Yeah", dialogNo = "No thanks";
public override void OnInspectorGUI()
{
DrawDefaultInspector();
PlayerMovement pmvmt = (PlayerMovement)target;
GUILayout.Space(10);
if (GUILayout.Button("Setup Player & World"))
{
if (EditorUtility.DisplayDialog(
dialogTitle,
"Would you like me to set custom world physics for you?\n\n" +
"This changes the gravity\n" +
"If this is a pre-existing project please use caution, it will change how anything using physics moves",
dialogYes,
dialogNo
))
{
Physics.gravity = new Vector3(0, -19F, 0);
Debug.Log("Physics set");
}
if (EditorUtility.DisplayDialog(
dialogTitle,
"Would you like me to create a \"Ground\" tag for you?",
dialogYes,
dialogNo
))
{
createTag("Ground");
}
pmvmt.setupCharacter();
EditorUtility.DisplayDialog(
dialogTitle,
"Character all setup\n\n" +
"Please don't forget to set the ground tag to the ground of your level/scenes",
"Awesome, will do"
);
}
}
// Mashup of code from ctwheels & Leslie-Young by B0N3head
// Dw about understanding this, it's just a tool for creating tags in editor for unity
public void createTag(string tagName)
{
SerializedObject tagM = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty tagsP = tagM.FindProperty("tags");
bool found = false;
if (tagsP.arraySize < 10000)
{
for (int i = 0; i < tagsP.arraySize; i++)
{
SerializedProperty t = tagsP.GetArrayElementAtIndex(i);
if (t.stringValue.Equals(tagName))
{
found = true;
Debug.Log($"The \"{tagName}\" tag already exists");
break;
}
}
if (!found)
{
tagsP.InsertArrayElementAtIndex(0);
SerializedProperty n = tagsP.GetArrayElementAtIndex(0);
n.stringValue = tagName;
Debug.Log($"The \"{tagName}\" tag has been added");
tagM.ApplyModifiedPropertiesWithoutUndo();
}
}
}
}