2020-05-31 17:07:22 +00:00
|
|
|
|
using SanAndreasUnity.Behaviours;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2019-07-05 22:52:22 +00:00
|
|
|
|
namespace SanAndreasUnity.Behaviours
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
2019-07-05 22:52:22 +00:00
|
|
|
|
public class CharacterModelChanger : MonoBehaviour
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
2019-07-05 22:52:22 +00:00
|
|
|
|
public KeyCode actionKey = KeyCode.P;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
2019-07-05 22:52:22 +00:00
|
|
|
|
// Use this for initialization
|
|
|
|
|
private void Start()
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 22:52:22 +00:00
|
|
|
|
// Update is called once per frame
|
|
|
|
|
private void Update()
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
2019-07-05 22:52:22 +00:00
|
|
|
|
if (Input.GetKeyDown(actionKey))
|
|
|
|
|
{
|
|
|
|
|
if (Utilities.NetUtils.IsServer)
|
|
|
|
|
ChangePedestrianModel();
|
|
|
|
|
else if (Net.PlayerRequests.Local != null)
|
|
|
|
|
Net.PlayerRequests.Local.RequestPedModelChange();
|
|
|
|
|
}
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 22:52:22 +00:00
|
|
|
|
public static void ChangePedestrianModel()
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
2019-07-05 22:52:22 +00:00
|
|
|
|
if (Ped.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
ChangePedestrianModel(Ped.Instance.PlayerModel, -1);
|
|
|
|
|
}
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
2019-07-05 22:52:22 +00:00
|
|
|
|
|
|
|
|
|
public static void ChangePedestrianModel(PedModel ped, int newModelId)
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
2019-07-05 22:52:22 +00:00
|
|
|
|
|
|
|
|
|
if (-1 == newModelId)
|
|
|
|
|
newModelId = Ped.RandomPedId;
|
|
|
|
|
|
|
|
|
|
// Retry with another random model if this one doesn't work
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ped.Load(newModelId);
|
|
|
|
|
}
|
|
|
|
|
catch (System.NullReferenceException ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogException (ex);
|
|
|
|
|
ChangePedestrianModel(ped, -1);
|
|
|
|
|
}
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 22:52:22 +00:00
|
|
|
|
|
|
|
|
|
}
|