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;
         }
     }
 }
 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 virtual bool CheckErrors()
    {
        error = false;

        Transform rps;

        if (selectionManager)
        {
            if (!selectionManager.GetComponent <MF_SelectionManager>())
            {
                Debug.Log(this + ": No MF_SelectionManager script found on defined selection manager."); error = true;
            }
        }
        else
        {
            Debug.Log(this + ": No Selection Manager defined."); error = true;
        }

        if (!targetListScript && NoTargetList == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractTargetList", transform);
            if (rps != null)
            {
                targetListScript = rps.GetComponent <MF_AbstractTargetList>();
            }
        }

        if (!targetingScript && NoTargetingScript == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractTargeting", transform);
            if (rps != null)
            {
                targetingScript = rps.GetComponent <MF_AbstractTargeting>();
            }
        }

        if (!navigationScript && NoNavigationScript == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractNavigation", transform);
            if (rps != null)
            {
                navigationScript = rps.GetComponent <MF_AbstractNavigation>();
            }
        }

        return(error);
    }
    public virtual bool CheckErrors()
    {
        error = false;

        if (!targetListScript && NoTargetList == false)
        {
            targetListScript = UtilityMF.GetComponentInParent <MF_AbstractTargetList>(transform);
        }

        if (!targetingScript && NoTargetingScript == false)
        {
            targetingScript = UtilityMF.GetComponentInParent <MF_AbstractTargeting>(transform);
        }

        if (!navigationScript && NoNavigationScript == false)
        {
            navigationScript = UtilityMF.GetComponentInParent <MF_AbstractNavigation>(transform);
        }

        return(error);
    }
Exemple #5
0
    void Spawn(int num)
    {
        if (spawnsPoints.Length > 0)             // at least 1 spawn point defined
        // find total chance number
        {
            float _spawnRollMax = 0;
            for (int t = 0; t < spawnTypes.Length; t++)
            {
                _spawnRollMax += spawnTypes[t].chance;
            }
            for (int s = 0; s < num; s++)             // for every spawn requested
            {
                float     _spawnRoll  = Random.Range(0f, _spawnRollMax);
                SpawnType _spawnEntry = null;
                // find which unit spawn roll picked
                float _count = 0;
                for (int t = 0; t < spawnTypes.Length; t++)
                {
                    if (_spawnRoll > _count && _spawnRoll < _count + spawnTypes[t].chance)
                    {
                        _spawnEntry = spawnTypes[t];
                        break;
                    }
                    _count += spawnTypes[t].chance;
                }

                Vector3 _locRand = Random.insideUnitSphere * spawnRandomRadius;
                // if spawn point provided, use it. Else pick random from default list
                Vector3 _spawnCenter;
                if (_spawnEntry.spawn)
                {
                    _spawnCenter = _spawnEntry.spawn.position;
                }
                else
                {
                    _spawnCenter = spawnsPoints[Random.Range(0, spawnsPoints.Length)].position;
                }
                Vector3 _spawnLoc = _spawnCenter + _locRand;
                if (sameHeight == true)
                {
                    _spawnLoc = new Vector3(_spawnLoc.x, _spawnCenter.y, _spawnLoc.z);
                }
                // if waypoint group provided, use it. Else pick random from default list
                Transform _wptGroup;
                if (_spawnEntry.wpt)
                {
                    _wptGroup = _spawnEntry.wpt;
                }
                else
                {
                    _wptGroup = waypointGroups[Random.Range(0, waypointGroups.Length)];
                }

                GameObject _unit  = (GameObject)Instantiate(_spawnEntry.unit, _spawnLoc, Quaternion.identity);
                float      _angle = MFmath.AngleSigned(Vector3.forward, _spawnLoc - _spawnCenter, Vector3.up);
                _unit.transform.rotation = Quaternion.Euler(new Vector3(0f, _angle, 0f));
                if (_spawnEntry.overrideFaction == true && _spawnEntry.faction != MFnum.FactionType.None)
                {
                    _unit.tag = _spawnEntry.faction.ToString();
                    MF_AbstractStatus _unitStatusScript = _unit.GetComponent <MF_AbstractStatus>();
                    if (_unitStatusScript && _unitStatusScript.layerColliderLocation)
                    {
                        _unitStatusScript.layerColliderLocation.gameObject.layer = LayerMask.NameToLayer(_spawnEntry.faction.ToString());
                    }
                }

                //shipsCounter.addShip(_unit);

                MF_AbstractNavigation _unitNavScript = _unit.GetComponent <MF_AbstractNavigation>();
                if (_unitNavScript)
                {
                    _unitNavScript.waypointGroup = _wptGroup;
                    _unitNavScript.randomWpt     = _spawnEntry.randomWpt;
                }
            }
        }
    }
Exemple #6
0
    void Spawn(int num)
    {
        if (spawnsPoints.Length > 0)             // at least 1 spawn point defined
        // find total chance number
        {
            float spawnRollMax = 0;
            for (int i = 0; i < spawnTypes.Length; i++)
            {
                if (spawnTypes[i].prefab)
                {
                    spawnRollMax += spawnTypes[i].chance;
                }
            }
            for (int i = 0; i < num; i++)             // for every spawn requested
            {
                float     spawnRoll  = Random.Range(0f, spawnRollMax);
                SpawnType spawnEntry = null;
                // find which unit spawn roll picked
                float count = 0;
                for (int t = 0; t < spawnTypes.Length; t++)
                {
                    if (spawnTypes[t].prefab)
                    {
                        if (spawnRoll > count && spawnRoll < count + spawnTypes[t].chance)
                        {
                            spawnEntry = spawnTypes[t];
                            break;
                        }
                        count += spawnTypes[t].chance;
                    }
                }

                if (spawnEntry != null && spawnEntry.prefab)
                {
                    int     spawnIndex  = Random.Range(0, spawnsPoints.Length);
                    Vector3 spawnCenter = spawnsPoints[spawnIndex].position;
                    Vector3 spawnLoc    = spawnCenter + (Random.insideUnitSphere * randomRadius);
                    if (sameHeight == true)
                    {
                        spawnLoc = new Vector3(spawnLoc.x, spawnCenter.y, spawnLoc.z);
                    }

                    GameObject unit = null;
                    if (spawnEntry.objectPool == true)
                    {
                        unit = MF_AutoPool.Spawn(spawnEntry.prefab, spawnLoc, spawnsPoints[spawnIndex].rotation);
                    }
                    else
                    {
                        unit = (GameObject)Instantiate(spawnEntry.prefab, spawnLoc, spawnsPoints[spawnIndex].rotation);
                    }

                    if (unit)
                    {
                        MF_AbstractNavigation unitNavScript = unit.GetComponent <MF_AbstractNavigation>();
                        if (unitNavScript)
                        {
                            unitNavScript.waypointGroup = waypointGroups[Random.Range(0, waypointGroups.Length)];
                            unitNavScript.randomWpt     = randomWpt;
                        }
                    }
                }
            }
        }
    }