SanAndreasUnity/Assets/Scripts/UI/UtilitiesWindow.cs

140 lines
2.6 KiB
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using System.Collections.Generic;
using UnityEngine;
using SanAndreasUnity.Behaviours;
using System.Linq;
2021-02-22 19:21:14 +00:00
using SanAndreasUnity.Behaviours.Vehicles;
2020-05-31 17:07:22 +00:00
namespace SanAndreasUnity.UI {
public class UtilitiesWindow : PauseMenuWindow {
UtilitiesWindow() {
// set default parameters
this.windowName = "Utilities";
this.useScrollView = true;
}
void Start () {
this.RegisterButtonInPauseMenu ();
// adjust rect
float width = 240;
2019-07-28 22:58:50 +00:00
float height = 210;
2019-07-28 20:38:10 +00:00
if (Utilities.F.ScreenHasHighDensity)
{
2019-07-28 22:58:50 +00:00
width = Screen.width * 0.375f;
height = Screen.height * 0.4f;
2019-07-28 20:38:10 +00:00
}
this.windowRect = new Rect(Screen.width / 2 - width / 2, 10, width, height);
2020-05-31 17:07:22 +00:00
}
protected override void OnWindowGUI ()
{
if (Ped.Instance) {
// display player position
// Vector2 pos = new Vector2 (_player.transform.position.x + 3000, 6000 - (_player.transform.position.z + 3000));
GUILayout.Label ("Pos: " + Ped.InstancePos);
}
2019-07-05 19:01:29 +00:00
if (Utilities.NetUtils.IsServer)
DisplayServerGui();
else if (Net.Player.Local != null)
2019-07-05 22:39:47 +00:00
DisplayClientOnlyGui();
2019-07-05 19:01:29 +00:00
}
void DisplayServerGui()
{
Transform nearbyTransform = Ped.Instance != null ? Ped.Instance.transform : null;
2019-07-05 19:01:29 +00:00
2021-09-12 23:17:17 +00:00
if (GUILayout.Button ("Spawn vehicle")) {
if (Ped.Instance != null)
2021-02-22 19:21:14 +00:00
Vehicle.CreateRandomInFrontOf(nearbyTransform);
2020-05-31 17:07:22 +00:00
}
if (GUILayout.Button("Change player model"))
{
2021-09-12 23:17:17 +00:00
SendCommand("/skin");
2020-05-31 17:07:22 +00:00
}
if (GUILayout.Button("Spawn 5 peds"))
{
for (int i = 0; i < 5; i++)
{
2021-09-12 22:12:41 +00:00
Ped.SpawnPedAI(Ped.RandomPedId, nearbyTransform);
2020-05-31 17:07:22 +00:00
}
}
2021-09-12 23:17:17 +00:00
if (GUILayout.Button("Spawn stalker ped"))
2020-05-31 17:07:22 +00:00
{
2021-09-12 23:17:17 +00:00
SendCommand("/stalker");
2020-05-31 17:07:22 +00:00
}
2021-09-12 22:24:26 +00:00
if (GUILayout.Button("Spawn enemy ped"))
{
SendCommand("/enemy");
}
2020-05-31 17:07:22 +00:00
if (GUILayout.Button("Destroy all vehicles"))
{
var vehicles = Behaviours.Vehicles.Vehicle.AllVehicles.ToArray();
2020-05-31 17:07:22 +00:00
foreach (var v in vehicles) {
v.Explode();
2020-05-31 17:07:22 +00:00
}
}
}
void SendCommand(string command)
2019-07-05 22:39:47 +00:00
{
Chat.ChatManager.SendChatMessageToAllPlayersAsLocalPlayer(command);
}
2019-07-05 22:39:47 +00:00
void DisplayClientOnlyGui()
{
2019-07-05 22:39:47 +00:00
2019-07-08 19:48:06 +00:00
if (GUILayout.Button("Request vehicle"))
2019-07-05 22:39:47 +00:00
{
2021-02-22 18:53:41 +00:00
SendCommand("/veh");
2019-07-05 22:39:47 +00:00
}
2019-07-08 19:48:06 +00:00
if (GUILayout.Button("Request ped model change"))
2019-07-05 22:39:47 +00:00
{
SendCommand("/skin");
2019-07-05 22:39:47 +00:00
}
if (GUILayout.Button("Request suicide"))
{
SendCommand("/suicide");
2019-07-05 22:39:47 +00:00
}
2019-07-08 19:48:06 +00:00
if (GUILayout.Button("Request ped stalker"))
2019-07-08 19:45:33 +00:00
{
SendCommand("/stalker");
2019-07-08 19:45:33 +00:00
}
2021-09-12 22:24:26 +00:00
if (GUILayout.Button("Request enemy ped"))
{
SendCommand("/enemy");
}
if (GUILayout.Button("Request to destroy my vehicles"))
2019-07-05 22:39:47 +00:00
{
SendCommand("/dveh");
2019-07-05 22:39:47 +00:00
}
}
2020-05-31 17:07:22 +00:00
}
}