GameObject ChooseTarget ( MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_TargetList targetListScript ) { GameObject _bestTarget = null; float? _bestValue = null; foreach ( int key in targetListScript.targetList.Keys ) { // iterate through target list if ( receivingObjectScript.TargetWithinLimits( targetListScript.targetList[key].transform ) == true ) { // skip this target if out of object gimbal limits switch ( priority ) { case PriorityType.Closest : if ( _bestValue == null ) { _bestValue = Mathf.Infinity; } // initialize _bestValue if ( targetListScript.targetList[key].sqrMagnitude < _bestValue ) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; } break; case PriorityType.Furthest : if ( _bestValue == null ) { _bestValue = -Mathf.Infinity; } // initialize _bestValue if ( targetListScript.targetList[key].sqrMagnitude > _bestValue ) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; } break; // add additional priority types default : break; } } } return _bestTarget; }
public virtual void Awake() { if (CheckErrors() == true) { return; } if (receivingObject) { platformScript = receivingObject.GetComponent <MF_AbstractPlatform>(); navScript = receivingObject.GetComponent <MF_AbstractNavigation>(); receivingControllerScript = receivingObject.GetComponent <MF_AbstractPlatformControl>(); } if (dontAddToSelectScript == false) { MF_AbstractSelection selScript = transform.root.GetComponent <MF_AbstractSelection>(); if (selScript) { MF_AbstractTargeting[] temp = new MF_AbstractTargeting[selScript.otherTargScripts.Length + 1]; for (int i = 0; i < selScript.otherTargScripts.Length; i++) { temp[i] = selScript.otherTargScripts[i]; } temp[selScript.otherTargScripts.Length] = this; selScript.otherTargScripts = temp; } } }
bool CheckErrors () { string _object = gameObject.name; // look for defined receiving object if (receivingObject) { if ( receivingObject.GetComponent<MF_AbstractPlatform>() ) { receivingObjectScript = receivingObject.GetComponent<MF_AbstractPlatform>(); } else { Debug.Log(_object+": Receiving object script not found at defined location."); error = true; } } else { // if null, choose self to look for turret script if ( gameObject.GetComponent<MF_AbstractPlatform>() ) { receivingObject = gameObject; receivingObjectScript = gameObject.GetComponent<MF_AbstractPlatform>(); } else { // if null, choose root gameObject to look for turret script if ( transform.root.GetComponent<MF_AbstractPlatform>() ) { receivingObject = transform.root.gameObject; receivingObjectScript = transform.root.GetComponent<MF_AbstractPlatform>(); } else { Debug.Log(_object+": No receiving object script found."); error = true; } } } return error; }
public virtual void Start() { if (CheckErrors() == true) { return; } if (receivingObject) { platformScript = receivingObject.GetComponent <MF_AbstractPlatform>(); navScript = receivingObject.GetComponent <MF_AbstractNavigation>(); receivingControllerScript = receivingObject.GetComponent <MF_AbstractPlatformControl>(); } }
public override void Start() { base.Start(); // will CheckErrors() from base if (error == true) { return; } platformScript = GetComponent <MF_AbstractPlatform>(); loaded = true; OnValidate(); }
public virtual bool CheckErrors() { // look for defined receiving object if (!receivingObject && dontSearchForReceivingObject == false) { MF_AbstractPlatform ap = UtilityMF.GetComponentInParent <MF_AbstractPlatform>(transform); if (ap) { receivingObject = ap.gameObject; } } return(error); }
// Use this for initialization public virtual void Awake() { if (CheckErrors() == true) { return; } platformScript = GetComponent <MF_AbstractPlatform>(); // cache scripts for all weapons if (weapons.Length > 0) { for (int wd = 0; wd < weapons.Length; wd++) { if (weapons[wd].weapon) { weapons[wd].script = weapons[wd].weapon.GetComponent <MF_AbstractWeapon>(); } } } }
GameObject ChooseTarget ( MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_TargetList targetListScript ) { GameObject _bestTarget = null; float? _bestValue = null; foreach ( int key in targetListScript.targetList.Keys ) { // iterate through target list if ( targetListScript.targetList[key] == null ) { continue; } // skip null entries if ( targetListScript.targetList[key].bullseye == null ) { continue; } // skip missing objects if ( checkArcLimits == true && receivingObjectScript.TargetWithinLimits( targetListScript.targetList[key].bullseye ) == false ) { continue; } // check arc limits if (receivingControllerScript && checkWeapRange == true ) { if ( receivingControllerScript.weapons.Length > 0 ) { if ( receivingControllerScript.weapons[ receivingControllerScript.curWeapon ].script.RangeCheck( targetListScript.targetList[key].bullseye ) == false ) { continue; } // check weapon range } } switch ( priority ) { case PriorityType.Closest : if ( _bestValue == null ) { _bestValue = Mathf.Infinity; } // initialize _bestValue if ( targetListScript.targetList[key].sqrMagnitude < _bestValue ) { _bestTarget = targetListScript.targetList[key].bullseye.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; } break; case PriorityType.Furthest : if ( _bestValue == null ) { _bestValue = -Mathf.Infinity; } // initialize _bestValue if ( targetListScript.targetList[key].sqrMagnitude > _bestValue ) { _bestTarget = targetListScript.targetList[key].bullseye.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; } break; // add additional priority types default : break; } } return _bestTarget; }
GameObject ChooseTarget(MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_B_TargetList targetListScript) { GameObject _bestTarget = null; float? _bestValue = null; bool _priorityFound = false; foreach (int key in targetListScript.targetList.Keys) // iterate through target list { if (targetListScript.targetList[key] == null) { continue; } // skip null entries if (targetListScript.targetList[key].transform == null) { continue; } // skip missing objects if (checkArcLimits == true && receivingObjectScript) { if (receivingObjectScript.TargetWithinLimits(targetListScript.targetList[key].transform) == false) { continue; } // check arc limits } if (receivingControllerScript && checkWeapRange == true) { if (receivingControllerScript.weapons.Length > 0) { if (receivingControllerScript.weapons[receivingControllerScript.curWeapon].script.RangeCheck(targetListScript.targetList[key].transform) == false) { continue; } // check weapon range } } if (_priorityFound == true) { if (targetListScript.targetList[key].clickedPriority == false) { continue; } } else // _priorityFound == false { if (targetListScript.targetList[key].clickedPriority == true) // found first priority target { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; _priorityFound = true; continue; } } float?_value; switch (priority) { case PriorityType.Closest: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sqrMagnitude; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.Furthest: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sqrMagnitude; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.MostHealth: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.LeastHealth: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.MostHealthPercent: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health / targetListScript.targetList[key].script.maxHealth;; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.LeastHealthPercent: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health / targetListScript.targetList[key].script.maxHealth;; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; // add additional priority types default: break; } } return(_bestTarget); }
GameObject ChooseTarget(MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_B_TargetList targetListScript) { int? _bestKey = null; float?_bestValue = null; bool _priorityFound = false; foreach (int key in targetListScript.targetList.Keys) // iterate through target list { if (targetListScript.targetList[key] == null) { continue; } // skip null entries if (targetListScript.targetList[key].transform == null) { continue; } // skip missing objects // if ( targetListScript.targetList[key].poi.isPoi == true ) { continue; } // skip points of interest if (checkArcLimits == true && receivingObjectScript) { if (receivingObjectScript.TargetWithinLimits(targetListScript.targetList[key].transform) == false) { continue; } // check arc limits } if (receivingControllerScript && checkWeapRange == true) { if (receivingControllerScript.weapons.Length > 0) { if (receivingControllerScript.weapons[receivingControllerScript.curWeapon].script.RangeCheck(targetListScript.targetList[key].transform) == false) { continue; } // check weapon range } } if (_priorityFound == true) { if (targetListScript.targetList[key].clickedPriority == false) { continue; } } else // _priorityFound == false { if (targetListScript.targetList[key].clickedPriority == true) // found first priority target { _bestKey = key; _bestValue = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; _priorityFound = true; continue; } } float?_value = null; switch (priority) { case PriorityType.Closest: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.Furthest: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.MostHealth: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.LeastHealth: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.MostHealthPercent: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health / targetListScript.targetList[key].sScript.healthMax; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.LeastHealthPercent: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health / targetListScript.targetList[key].sScript.healthMax; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; // add additional priority types default: break; } } if (_bestKey != null) { MF_B_TargetList.TargetData tlk = targetListScript.targetList[(int)_bestKey]; hasPrecision = tlk.hasPrecision; hasAngle = tlk.hasAngle; hasRange = tlk.hasRange; hasVelocity = tlk.hasVelocity; return(tlk.transform.gameObject); } else { hasPrecision = MFnum.ScanSource.None; hasAngle = MFnum.ScanSource.None; hasRange = MFnum.ScanSource.None; hasVelocity = MFnum.ScanSource.None; return(null); } }