Skip to content

Commit

Permalink
Fixed Minor Bugs
Browse files Browse the repository at this point in the history
1. Scene load
2. Sound depends on distance
3. Light for vehicle
  • Loading branch information
werasik2aa authored Mar 13, 2022
1 parent be4e717 commit 9590506
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 153 deletions.
41 changes: 37 additions & 4 deletions MenuControll.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -20,6 +22,8 @@ public class MenuControll
private static Text CountCars;
private static Text CountSpeed;
private static Text NameTag;
private static GameObject template;
public static List<string[]> info = new List<string[]>();
public static void menuc()
{
GameObject key1 = GameObject.Instantiate(main.lb[0].LoadAsset<GameObject>("menucars"), Vector3.zero, Quaternion.identity);
Expand All @@ -28,13 +32,14 @@ public static void menuc()
key1.transform.Find("Menu").gameObject.SetActive(false);
key1.transform.Find("MenuCar").gameObject.SetActive(false);
key1.transform.Find("CarInfo").gameObject.SetActive(false);
key1.transform.Find("Templates").gameObject.SetActive(false);


CarStat = key1.transform.Find("CarInfo");
MenuMainCars = key1.transform.Find("Menu");
Content = MenuMainCars.transform.Find("FULL/WINDOW/CARS");
MenuMainStatCar = key1.transform.Find("Stat");
openmenu = key1.transform.Find("MenuCar");
template = key1.transform.Find("Templates/CARBTN").gameObject;

Fuel = MenuMainStatCar.Find("Fuel").GetComponent<Slider>();
Speed = MenuMainStatCar.Find("Speed").GetComponent<Slider>();
Expand All @@ -46,9 +51,37 @@ public static void menuc()

openmenu.GetComponent<Button>().onClick.AddListener(new Action(() => Open(0)));

Content.Find("CAR0").GetComponent<Button>().onClick.AddListener(new Action(() => main.SpawnCar(main.MyId, main.levelid, "sedan", Vector3.zero, Quaternion.identity)));
Content.Find("CAR1").GetComponent<Button>().onClick.AddListener(new Action(() => main.SpawnCar(main.MyId, main.levelid, "snowcar", Vector3.zero, Quaternion.identity)));

//Content.Find("CAR0").GetComponent<Button>().onClick.AddListener(new Action(() => main.SpawnCar(main.MyId, main.levelid, "sedan", Vector3.zero, Quaternion.identity)));
//Content.Find("CAR1").GetComponent<Button>().onClick.AddListener(new Action(() => main.SpawnCar(main.MyId, main.levelid, "snowcar", Vector3.zero, Quaternion.identity)));
ADDCARS();
}
private static void ADDCARS()
{
foreach (String[] i in info)
{
GameObject item = GameObject.Instantiate(template);
item.transform.SetParent(Content);

Button Car = item.GetComponent<Button>();
Text Tag = item.transform.Find("Info").GetComponent<Text>();
RawImage Icon = item.transform.Find("Icon").GetComponent<RawImage>();
Action spawncar = new Action(() => main.SpawnCar(main.MyId, main.levelid, i[3], Vector3.zero, Quaternion.identity));


Car.onClick.AddListener(spawncar);
Tag.text = i[4].Replace("/n", Environment.NewLine);

if (i[2] != "NaN")
{
Texture2D Texture = new Texture2D(1024, 1024);
Byte[] bytes = File.ReadAllBytes(i[0] + i[2]);
Texture.LoadRawTextureDataImplArray(bytes);
Texture.Apply();
Icon.texture = Texture;

}
item.SetActive(true);
}
}
public static void Update(int i)
{
Expand Down
11 changes: 11 additions & 0 deletions NETHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public static void NetSoundOff(int ID)

Send(packet);
}
public static void NetLightOn(int ID, bool state)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1101);
packet.Write(ID);
packet.Write(state);

Send(packet);
}
private static void Send(Packet packet)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.HOST)
Expand Down
19 changes: 15 additions & 4 deletions PACKETS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.engineSound(curspeed, ID);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.EngineSound(curspeed, ID, 1);
}
if (packetid == 1110) // SEND Sound OFF
{
Expand All @@ -82,9 +82,9 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.engineSoundOff(ID);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.EngineSound(0, ID, 0);
}
if (packetid == 1111) // SEND Sound OFF
if (packetid == 1111) // SIT SIT POS
{
int ID = _pak.ReadInt();
int SitID = _pak.ReadInt();
Expand All @@ -93,7 +93,18 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.CHANGESIT(data.GetObj(ID), SitID, from);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.CHANGESIT(ID, SitID, from);
}
if (packetid == 1101) // Turn LIGHT
{
int ID = _pak.ReadInt();
bool state = _pak.ReadBool();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && main.vehicles.ContainsKey(ID)) VehicleController.CarLight(ID, state);
}
}
private static bool CheckEnv(int from)
Expand Down
Loading

0 comments on commit 9590506

Please sign in to comment.