// -------------------------------------- end of FxItem void OnValidate() { if (Application.isPlaying == true) { if (dying == true || dead == true) { return; } // don't change while effects are possibly detached if (validate == false) // prevent Add() running more than once { statsScript = UtilityMF.GetComponentInParent <MF_AbstractStats>(transform); if (statsScript) { statsScript.fxScript.Add(this); } } float dur = 0f; for (int i = 0; i < fxList.Length; i++) { fxList[i].thisScript = this; fxList[i].statsScript = statsScript; fxList[i].Validate(); dur = Mathf.Max(fxList[i].fxDuration, fxList[i].duration == true ? fxList[i].minTime : 0f); longestDuration = Mathf.Max(longestDuration, dur); } validate = true; CheckUnit(); } }
} // constructor with 0 arguments // for creating an entry via clicked target public TargetData(Transform transform, MF_AbstractClassify cScript, MF_AbstractStats sScript, bool clickedPriority, bool targetPersists) { this.transform = transform; this.cScript = cScript; this.sScript = sScript; this.clickedPriority = clickedPriority; this.targetPersists = targetPersists; this.lastDetected = Time.time; this.lastAnalyzed = Time.time; // this.sqrMagnitude = sqrMagnitude; }
public void DoDamage(Transform trans) { // do stuff to the target object when it gets hit MF_AbstractStats sScript = null; sScript = trans.GetComponentInParent <MF_AbstractStats>(); // look for script in parents if (sScript && !Mathf.Approximately(sScript.damageID, damageID + Time.time)) // don't apply damage if alread damaged by this source, this frame - so explosions don't damage more than once // apply damage to target { sScript.damageID = damageID + Time.time; // mark as damaged by this source, this frame sScript.DoDamage(damage); // Debug.Log( trans+" > "+sScript+" : "+damage ); } }
public virtual void Awake() { MF_AbstractStats sScript = null; if (transform.parent) { sScript = transform.parent.GetComponentInParent <MF_AbstractStats>(); } if (sScript) { sScript.statsScript.Add(this); } poolRefScript = gameObject.GetComponent <AP_Reference>(); if (size == 0) // Find size of object if not already defined { size = UtilityMF.FindColliderBoundsSize(transform, true); } }
private void DoScanner() { GameObject[] _targets = null; // generate initial target list // tags if (match.scanMethod == MFnum.ScanMethodType.Tags) { _targets = new GameObject[0]; MFnum.FactionType[] _factions = new MFnum.FactionType[0]; if (match.matchBy == MFnum.MatchType.Faction) { _factions = match.targetableFactions; } else // if by relation { if (cScript) // gather factions in appropriate relation type { if (match.targetableRelation == MFnum.Relation.Enemy) { _factions = cScript.factions.enemies; } else if (match.targetableRelation == MFnum.Relation.Ally) { _factions = cScript.factions.allies; } else if (match.targetableRelation == MFnum.Relation.Neutral) { _factions = cScript.factions.neutral; } } } for (int f = 0; f < _factions.Length; f++) // for each targetable faction { if (_factions[f] == MFnum.FactionType.None) { continue; } // no faction GameObject[] _thisFaction = GameObject.FindGameObjectsWithTag(_factions[f].ToString()); // find all targets with this targetable tag // combine exsisting array int _origLength = _targets.Length; System.Array.Resize <GameObject>(ref _targets, _targets.Length + _thisFaction.Length); System.Array.Copy(_thisFaction, 0, _targets, _origLength, _thisFaction.Length); } for (int t = 0; t < _targets.Length; t++) { ; if ((transform.position - _targets[t].transform.position).sqrMagnitude > detectorRange * detectorRange) { _targets[t] = null; // out of range continue; } // **** avoids a bug where unity leaves an invisible empty object when playing a scene if a prefab is selected in the project view. // **** but this also then requires each target to inherit MF_AbstractStatus (the 'ghost' objects don't have a script, so checking for one is the easiest way to weed them out) // **** alternately, just make sure you click off prefabs when playing a scene // if ( _targets[t].transform.root.GetComponent<MF_AbstractStatus>() == null ) { // _targets[t] = null; // continue; // } } } // layers if (match.scanMethod == MFnum.ScanMethodType.Layers) { Collider[] _colliders = Physics.OverlapSphere(transform.position, detectorRange, mask); _targets = new GameObject[_colliders.Length]; for (int c = 0; c < _colliders.Length; c++) { _targets[c] = _colliders[c].transform.root.gameObject; } } for (int d = 0; d < _targets.Length; d++) { targetCount = 0; if (_targets[d] == gameObject) { continue; } // skip self if (_targets[d] == gameObject.activeSelf == false) { continue; } // skip disabled if (_targets[d] == null) { continue; } // skip null int key = 0; if (targetRootObject == true) { _targets[d] = _targets[d].transform.root.gameObject; // make sure accessing root level key = _targets[d].transform.root.gameObject.GetInstanceID(); } else { key = _targets[d].GetInstanceID(); } if (requireLos == true && (transform.position - _targets[d].transform.position).sqrMagnitude > losMinRange * losMinRange) { RaycastHit _hit; Vector3 _targDir = transform.position - _targets[d].transform.position; Physics.Linecast(transform.position - (_targDir.normalized * losMinRange), _targets[d].transform.position, out _hit); if (_hit.transform.root != _targets[d].transform) { if (targetListScript.targetList.ContainsKey(key) == true) { targetListScript.targetList[key].transform = null; } continue; // los blocked } } targetCount++; if (targetCount > 0) { monitor = 1; } else { monitor = 0; } SendCheckUnit(); // add to targetList if (targetListScript.targetList.ContainsKey(key) == false) // don't try to overwrite exsisting key { MF_AbstractClassify _cScript = _targets[d].GetComponent <MF_AbstractClassify>(); MF_AbstractStats _sScript = _targets[d].GetComponent <MF_AbstractStats>(); // new record targetListScript.targetList.Add(key, new MF_B_TargetList.TargetData()); targetListScript.targetList[key].transform = _targets[d].transform; targetListScript.targetList[key].cScript = _cScript; targetListScript.targetList[key].sScript = _sScript; targetListScript.targetList[key].hasPrecision = MFnum.ScanSource.Detector; targetListScript.targetList[key].hasAngle = MFnum.ScanSource.Detector; targetListScript.targetList[key].hasRange = MFnum.ScanSource.Detector; targetListScript.targetList[key].hasVelocity = MFnum.ScanSource.Detector; targetListScript.targetList[key].hasFaction = MFnum.ScanSource.Detector; if (_cScript) // add to detectingMeList { if (_cScript.selectionScript && selectionScript) { _cScript.selectionScript.Add(instanceID, selectionScript); } } } // if ( targetListScript.targetList[key].poi.isPoi == true ) { continue; } // skip points of interest // update record targetListScript.targetList[key].lastDetected = Time.time; targetListScript.targetList[key].lastAnalyzed = Time.time; targetListScript.targetList[key].lingerTime = Time.time + detectorInterval + lingerAdjust; targetListScript.targetList[key].dataLingerTime = Time.time + detectorInterval + lingerAdjust; // targetListScript.targetList[key].sqrMagnitude = ( transform.position - _targets[d].transform.position ).sqrMagnitude; // other data gathered by scanner } }
public override void ClickAdd(int key, Transform transform, MF_AbstractClassify cScript, MF_AbstractStats sScript, bool clickedPriority, bool targetPersists) { targetList.Add(key, new TargetData(transform, cScript, sScript, clickedPriority, targetPersists)); }
public virtual void ClickAdd(int key, Transform transform, MF_AbstractClassify cScript, MF_AbstractStats sScript, bool clickedPriority, bool targetPersists) { }