//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Get Any Free Side //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public AI_ExplosiveUnit.AttachSide GetAnyFreeSide() { AI_ExplosiveUnit.AttachSide[] aeSlots = new AI_ExplosiveUnit.AttachSide[3] { AI_ExplosiveUnit.AttachSide.FRONT, AI_ExplosiveUnit.AttachSide.LEFT, AI_ExplosiveUnit.AttachSide.RIGHT }; // Randomising Array Elements, do it twice for (int i = 0; i < 2; ++i) { int iRandomIndexOne = Random.Range(0, 3); int iRandomIndexTwo = Random.Range(0, 3); AI_ExplosiveUnit.AttachSide eFirstSwapIndexValue = aeSlots[iRandomIndexOne]; aeSlots[iRandomIndexOne] = aeSlots[iRandomIndexTwo]; aeSlots[iRandomIndexTwo] = eFirstSwapIndexValue; } // Go Through Each Element To Determine a Position foreach (AI_ExplosiveUnit.AttachSide Side in aeSlots) { if (CheckForFreeSide(Side)) { return(Side); } } // If All Are Full, Return Unavailable return(AI_ExplosiveUnit.AttachSide.NOT_ATTACHED); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Set Attached Side //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void SetAttachedSide(AI_ExplosiveUnit.AttachSide WhichSide, bool Attached) { int index = (WhichSide == AI_ExplosiveUnit.AttachSide.FRONT) ? 0 : (WhichSide == AI_ExplosiveUnit.AttachSide.LEFT) ? 1 : 2; m_abAttachedSides[index] = Attached; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Check Attached Sides //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public bool CheckForFreeSide(AI_ExplosiveUnit.AttachSide WhichSide) { switch (WhichSide) { case AI_ExplosiveUnit.AttachSide.FRONT: return(!m_abAttachedSides[0]); case AI_ExplosiveUnit.AttachSide.LEFT: return(!m_abAttachedSides[1]); case AI_ExplosiveUnit.AttachSide.RIGHT: return(!m_abAttachedSides[2]); default: return(false); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Check Closest Side //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public AI_ExplosiveUnit.AttachSide GetClosestSide(Transform SelfTransform, Transform TargetTransform) { float fDistanceFront = Mathf.Abs((SelfTransform.position - (TargetTransform.transform.position + TargetTransform.forward)).magnitude); float fDistanceLeft = Mathf.Abs((SelfTransform.position - (TargetTransform.transform.position + -TargetTransform.right)).magnitude); float fDistanceRight = Mathf.Abs((SelfTransform.position - (TargetTransform.transform.position + TargetTransform.right)).magnitude); // Get Closest Side AI_ExplosiveUnit.AttachSide eAttachSide = ((fDistanceFront < fDistanceLeft) && (fDistanceFront < fDistanceRight)) ? AI_ExplosiveUnit.AttachSide.FRONT : ((fDistanceLeft < fDistanceFront) && (fDistanceLeft < fDistanceRight)) ? AI_ExplosiveUnit.AttachSide.LEFT : AI_ExplosiveUnit.AttachSide.RIGHT; // Return Side if it's available, else return N/A return((CheckForFreeSide(eAttachSide)) ? eAttachSide : AI_ExplosiveUnit.AttachSide.NOT_ATTACHED); }