ControllableByEventOrbital.cs (1524B)
1 using System; 2 using UnityEngine; 3 4 namespace Slimecing.Swords.Orbitals 5 { 6 public class ControllableByEventOrbital : MonoBehaviour 7 { 8 [SerializeField] private TakesOrbitals ownerOfThisOrbital; 9 [SerializeField] private OrbitalLogic orbitalLogicToSetTo; 10 11 private GameObject _oldOwner; 12 private OrbitalLogic _oldOrbitalLogic; 13 14 private void OnEnable() 15 { 16 var orbital = ownerOfThisOrbital.GetOrbital(gameObject); 17 if (orbital == null) return; 18 _oldOwner = orbital.ownerControlObject; 19 _oldOrbitalLogic = orbital.currentOrbitalLogic; 20 } 21 22 public void SetOwnerOfThisOrbital(GameObject owner) 23 { 24 var orbital = ownerOfThisOrbital.GetOrbital(gameObject); 25 if (orbital == null) return; 26 _oldOwner = orbital.ownerControlObject; 27 _oldOrbitalLogic = orbital.currentOrbitalLogic; 28 orbital.ownerControlObject = owner; 29 orbital.currentOrbitalLogic = orbitalLogicToSetTo; 30 orbital.Initialize(orbital.ownerObject); 31 } 32 33 public void UnSetOwnerOfThisOrbital() 34 { 35 if (_oldOwner == null || _oldOrbitalLogic == null) return; 36 var orbital = ownerOfThisOrbital.GetOrbital(gameObject); 37 if (orbital == null) return; 38 orbital.ownerControlObject = _oldOwner; 39 orbital.currentOrbitalLogic = _oldOrbitalLogic; 40 orbital.Initialize(orbital.ownerObject); 41 } 42 } 43 }