Exemplo n.º 1
0
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     position = new Vector3(position.x, 5, position.z);
     Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;
     if (Physics.CheckBox(position, halfext, rotation)) return false;
     return true;
 }
Exemplo n.º 2
0
    public void GenerateContent()
    {
        for (int i = 0; i < Desc.Spawnables.Count; i++)
        {
            for (int j = 0; j < Desc.Spawnables[i].AverageAmount; j++)
            {
                int nr = (int)(Desc.Spawnables[i].Asset.Count * Random.value);
                GameObject Asset = GetCache(Desc.Spawnables[i].Asset[nr]);

                Bounds Area = new Bounds(transform.position, transform.localScale);
                Vector3 Position = Area.min + new Vector3((Area.max.x - Area.min.x) * UnityEngine.Random.value, (Area.max.y - Area.min.y) * UnityEngine.Random.value, (Area.max.z - Area.min.z) * UnityEngine.Random.value);
                Quaternion Rotation = transform.rotation;
                bool no = false;
                SpawnConstraintOptions Options = new SpawnConstraintOptions();
                Options.SpawnArea = Area;
                for (int x = 0; x < Desc.Spawnables[i].SpawnRules.Count; x++)
                {
                    string s = Desc.Spawnables[i].SpawnRules[x];
                    no = no || !Spawnable.Factory(s).Run(ref Position, ref Rotation, Asset, ref Options);
                }
                if (!no)
                {
                    GameObject o = (GameObject)Instantiate(Asset, Position, Rotation);
                    if (Options.IsFixed)
                        o.GetComponent<Rigidbody>().isKinematic = true;
                }


            }
        }
    }
Exemplo n.º 3
0
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     if (Random.value > 0.2f)
     {
         return false;
     }
     return true;
 }
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     rotation *= Quaternion.LookRotation(Options.SpawnArea.center- position, new Vector3(0,1,0));
     rotation = rotation * Quaternion.Euler(0, -90, 0);
     Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;
     if (Physics.CheckBox(position, halfext, rotation)) return false;
     return true;
 }
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     if (orient == "Z")
     {
         rotation *= Quaternion.Euler(0, Random.value * 360.0f, 0);
     }
     Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;
     if (Physics.CheckBox(position, halfext, rotation)) return false;
     return true;
 }
Exemplo n.º 6
0
    public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
    {
        float Rotation = Random.value * 360.0f;
        Vector3 Center = Options.SpawnArea.center;
        Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;

        position = Center + Quaternion.Euler(0, Rotation, 0) * new Vector3(Options.SpawnArea.extents.x, 0, 0);
        if (Physics.CheckBox(position, halfext, rotation)) return false;
        return true;
    }
Exemplo n.º 7
0
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     Collider c = asset.GetComponent<Collider>();
     Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;
     RaycastHit[] hits = Physics.BoxCastAll(position,halfext , new Vector3(0, -1, 0));
     float mindist = float.PositiveInfinity;
     for (int i = 0;i < hits.Length;i++)
     {
         if (mindist > hits[i].distance) mindist = hits[i].distance;
     }
     if (float.IsInfinity(mindist)) return false;
     if (Physics.CheckBox(position, halfext)) return false;
     position = position + mindist * new Vector3(0, -1, 0) - new Vector3(0, -1, 0);
     return true;
 }
Exemplo n.º 8
0
    public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
    {
        Vector3 Direction = new Vector3();
        Quaternion Orientation = new Quaternion();
        int rnd = (int)(Random.value * 4);
        if (rnd == 0) { Direction = new Vector3(-1, 0, 0); Orientation = Quaternion.Euler(0,90,0); }
        if (rnd == 1) { Direction = new Vector3(1, 0, 0); Orientation = Quaternion.Euler(0, -90, 0); }
        if (rnd == 2) { Direction = new Vector3(0, 0, 1); Orientation = Quaternion.Euler(0, 180, 0); }
        if (rnd == 3) { Direction = new Vector3(0, 0, -1); Orientation = Quaternion.Euler(0, 0, 0); }

        Collider c = asset.GetComponent<Collider>();
        Vector3 halfext = asset.GetComponent<Collider>().bounds.extents / 2;
        RaycastHit[] hits = Physics.BoxCastAll(position,halfext , Direction);
        float mindist = float.PositiveInfinity;
        for (int i = 0;i < hits.Length;i++)
        {
            if (mindist > hits[i].distance) mindist = hits[i].distance;
        }
        if (float.IsInfinity(mindist)) return false;
        if (Physics.CheckBox(position, halfext,Orientation)) return false;
        position = position + mindist * Direction;
        rotation *= Orientation;
        return true;
    }
Exemplo n.º 9
0
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     position = Options.SpawnArea.center;
     return true;
 }
Exemplo n.º 10
0
 public bool Run(ref Vector3 position, ref Quaternion rotation, GameObject asset, ref SpawnConstraintOptions Options)
 {
     Options.IsFixed = true;
     return true;
 }