Ejemplo n.º 1
0
        }                               // 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;
        }
Ejemplo n.º 2
0
    public virtual void Awake()
    {
        if (error)
        {
            return;
        }

        // cache instanceID
        if (!clickObjectBase)
        {
            clickObjectBase = gameObject;
        }
        myId    = clickObjectBase.GetInstanceID();
        cScript = transform.root.GetComponent <MF_AbstractClassify>();
    }
Ejemplo n.º 3
0
    private bool CheckErrors()
    {
        if (!targetListScript)
        {
            targetListScript = UtilityMF.GetComponentInParent <MF_B_TargetList>(transform);
            if (targetListScript == null)
            {
                Debug.Log(this + ": Target list location not found."); error = true;
            }
        }

        cScript = UtilityMF.GetComponentInParent <MF_AbstractClassify>(transform);
        if (cScript == null)
        {
            Debug.Log(this + ": Classify script not found."); error = true;
        }

        return(error);
    }
Ejemplo n.º 4
0
    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
        }
    }
Ejemplo n.º 5
0
 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));
 }
Ejemplo n.º 6
0
 public virtual void ClickAdd(int key, Transform transform, MF_AbstractClassify cScript, MF_AbstractStats sScript, bool clickedPriority, bool targetPersists)
 {
 }