mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-24 04:53:05 +00:00
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using UnityEngine;
|
|
using SanAndreasUnity.Importing.Items.Placements;
|
|
|
|
namespace SanAndreasUnity.Behaviours.World
|
|
{
|
|
|
|
public class EntranceExitMapObject : MapObject
|
|
{
|
|
|
|
public static EntranceExitMapObject Create(EntranceExit info)
|
|
{
|
|
var obj = new GameObject().AddComponent<EntranceExitMapObject>();
|
|
obj.Initialize(info);
|
|
return obj;
|
|
}
|
|
|
|
public EntranceExit Info { get; private set; }
|
|
|
|
void Initialize(EntranceExit info)
|
|
{
|
|
Info = info;
|
|
|
|
name = string.Format("ENEX ({0})", info.Name);
|
|
|
|
Initialize(info.EntrancePos, Quaternion.identity);
|
|
|
|
gameObject.SetActive(false);
|
|
gameObject.isStatic = true;
|
|
|
|
// add box collider
|
|
var collider = gameObject.AddComponent<BoxCollider>();
|
|
collider.size = new Vector3(info.Size.x, 2f, info.Size.y);
|
|
collider.isTrigger = true;
|
|
|
|
// need rigid body for detecting collisions
|
|
var rb = gameObject.AddComponent<Rigidbody>();
|
|
rb.mass = 0f;
|
|
rb.isKinematic = true;
|
|
|
|
}
|
|
|
|
void OnDrawGizmosSelected()
|
|
{
|
|
Utilities.F.HandlesDrawText(this.transform.position, this.name, Color.yellow);
|
|
}
|
|
|
|
protected override float OnRefreshLoadOrder(Vector3 from)
|
|
{
|
|
|
|
float dist = Vector3.Distance(from, this.transform.position);
|
|
if (dist > 100f)
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
return float.PositiveInfinity;
|
|
}
|
|
|
|
if (this.HasLoaded)
|
|
return float.PositiveInfinity;
|
|
|
|
return dist * dist;
|
|
}
|
|
|
|
protected override void OnLoad()
|
|
{
|
|
Debug.LogFormat("OnLoad() - {0}", this.gameObject.name);
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
Debug.LogFormat("OnShow() - {0}", this.gameObject.name);
|
|
this.gameObject.SetActive(true);
|
|
}
|
|
|
|
void OnTriggerEnter(Collider collider)
|
|
{
|
|
Debug.LogFormat("OnTriggerEnter() - with {0}", collider.gameObject.name);
|
|
}
|
|
|
|
}
|
|
|
|
}
|