public Goal(int _playerNum, char _dimension, Transform _target) { Init(_playerNum, _dimension, _target.position); Target = _target; m_TargetStructureComp = Target.GetComponent <Selectable.Structures.NonTerrainObstacle>(); m_TargetUnitComp = Target.GetComponent <Selectable.Units.Unit>(); m_IsStructure = m_TargetStructureComp == null ? false : true; m_IsUnit = m_TargetUnitComp == null ? false : true; if (m_IsUnit) { m_GoalPtr = NativeMethods.NewGoal_s(_playerNum, _dimension, _target.position.x, _target.position.y, _target.position.z); GoalManager.Instance.StartCoroutine(this.UpdateTargetLocationAndRepath()); } else if (m_IsStructure) { Vector3 bottomLeft = m_TargetStructureComp.BottomLeftCorner; Vector3 topRight = m_TargetStructureComp.TopRightCorner; m_GoalPtr = NativeMethods.NewStructureGoal_s(_playerNum, _dimension, bottomLeft.x, bottomLeft.y, bottomLeft.z, topRight.x, topRight.y, topRight.z); } m_TargetOwnerComp = Target.GetComponent <Selectable.Owner>(); if (m_TargetOwnerComp != null) { m_TargetOwnerComp.AddOnDeathCall(TargetDied); } }
public void RemoveOwner(Selectable.Owner _own) { if (NativeMethods.RemoveOwner_s(m_GoalPtr, _own.gameObject.GetInstanceID())) { GoalManager.Instance.StopCoroutine(this.UpdateTargetLocationAndRepath()); GoalManager.Instance.RemoveGoal(this); if (m_TargetOwnerComp != null) { m_TargetOwnerComp.RemoveOnDeathCall(TargetDied); } m_GoalPtr = (IntPtr)0; } RemoveOnTargetDeathCall(_own.TargetDeathFunction()); }
public void TargetDied(Selectable.Owner _owner) { Target = null; OnTargetDeathEvent(null); }
public void AddOwner(Selectable.Owner _own) { NativeMethods.AddOwner_s(m_GoalPtr, _own.gameObject.GetInstanceID()); AddOnTargetDeathCall(_own.TargetDeathFunction()); }