BITFALL/Assets/Artists/Scripts/Props/Prop_Fixed.cs

54 lines
1.1 KiB
C#
Raw Normal View History

2023-12-03 17:35:43 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2024-03-18 18:20:23 +08:00
using NGS.AdvancedCullingSystem.Dynamic;
2023-12-03 17:35:43 +08:00
using UnityEngine;
using UnityEngine.Animations;
namespace BITKit
{
public class Prop_Fixed : MonoBehaviour
{
[SerializeField] private new Rigidbody rigidbody;
[SerializeField] private LayerMask allowLayer;
private Collider _collider;
private void Start()
{
2023-12-16 23:30:08 +08:00
if (!rigidbody.isKinematic) return;
2024-03-18 18:20:23 +08:00
DestorySelf();
2023-12-03 17:35:43 +08:00
}
private void Update()
{
if (!rigidbody.IsSleeping() || !_collider) return;
if (_collider.gameObject.isStatic)
{
2024-03-18 18:20:23 +08:00
DestorySelf();
2023-12-03 17:35:43 +08:00
return;
}
enabled = false;
transform.SetParentConstraint(_collider.transform);
rigidbody.isKinematic = true;
}
private void OnCollisionStay(Collision other)
{
if (allowLayer.value is not 0 && allowLayer.Includes(other.gameObject.layer) is false) return;
_collider = other.collider;
}
2024-03-18 18:20:23 +08:00
private void DestorySelf()
{
foreach (var x in GetComponentsInChildren<Renderer>())
{
Destroy(this);
if(rigidbody)Destroy(rigidbody);
var dc = x.gameObject.AddComponent<DC_SourceSettings>();
dc.ControllerID = 1;
}
}
2023-12-03 17:35:43 +08:00
}
}