public void InitObject(MonoBehaviour monoBehaviourObj) { UninitObject(); _monoBehaviour = monoBehaviourObj; _selectable = _monoBehaviour.GetComponent <ISelectable>(); if (_selectable == null || !_selectable.CanSelect()) { UninitObject(); return; } _damageable = _monoBehaviour.GetComponent <IDamageable>(); _targetable = _monoBehaviour.GetComponent <ITargetable>(); _moveable = _monoBehaviour.GetComponent <IMoveable>(); _attackable = _monoBehaviour.GetComponent <IAttackable>(); _behaviorSwitchable = _monoBehaviour.GetComponent <IBehaviorSwitchable>(); _carriable = _monoBehaviour.GetComponent <ICarriable>(); if (_damageable != null) { // If enemy, don't select. if (_targetable.IsEnemy(_targetable.TeamId)) { UninitObject(); return; } } _selectable.Select(); _isInit = true; }
public void UninitObject() { if (_isInit) { _selectable.Unselect(); } _monoBehaviour = null; _damageable = null; _moveable = null; _attackable = null; _behaviorSwitchable = null; _carriable = null; _isInit = false; }