Esempio n. 1
0
	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;
	}
Esempio n. 2
0
	void Start () {
		if ( CheckErrors() == true ) { return; }
		
		targetListScript = targetListObject.GetComponent<MF_TargetList>();
		lastDetect = Random.Range( -detectorInterval * 1.0f, 0.0f ); // add random time to stager scan pulses that would otherwise be on the same frame
		
		// **** need to be able to rebuild this on the fly !!
		// build the layermask of targetable factions. Only needed for layer faction method
		string[] _layerNames = new string[ targetableFactions.Length ]; // array to hold layer names
		for (int f=0; f < targetableFactions.Length; f++) { // for each targetable faction
			_layerNames[f] = targetableFactions[f].ToString(); // convert enum to string
		}
		mask = LayerMask.GetMask(_layerNames); // final layermask
	}
Esempio n. 3
0
	new void Start () {
		base.Start();
		if (CheckErrors() == true) { return; }

		// look for defined target list
		if (targetListObject) {
			if ( targetListObject.GetComponent<MF_TargetList>() ) {
				targetListScript = targetListObject.GetComponent<MF_TargetList>();
			}
		} else { // if null, choose self to look for target list
			if ( gameObject.GetComponent<MF_TargetList>() ) {
				targetListScript = gameObject.GetComponent<MF_TargetList>();
			} else { // if null, choose root gameObject to look for target list
				if ( transform.root.GetComponent<MF_TargetList>() ) {
					targetListScript = transform.root.GetComponent<MF_TargetList>();
				}
			}	
		}
	}
Esempio n. 4
0
	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;
	}
Esempio n. 5
0
	public static void RemoveAnalyzeData ( MF_TargetList script, int key ) {
		script.targetList[key] = null;
	}