/// <summary>
    /// 设置地板纹理物体
    /// </summary>
    /// <returns></returns>
    public List <GameObject> SetGroundItems(CaveRegion region, uint count, Transform parent)
    {
        List <GameObject> objs = new List <GameObject>();

        for (int i = 0; i < count; i++)
        {
            item = groundItemList.GetRandomItem();
            obj  = Instantiate(item.prefab, map.GetPosition(region.GetRandomCoord()), Quaternion.Euler(GameMathf.RandomY()), parent);
            obj.transform.localScale = new Vector3(obj.transform.localScale.x * GameMathf.RandomPlusOrMinus(), obj.transform.localScale.y, obj.transform.localScale.z);
            objs.Add(obj);
        }
        return(objs);
    }
示例#2
0
    /// <summary>
    /// 通过所需大小,获取合理物体
    /// </summary>
    /// <param name="size">所需大小</param>
    /// <param name="scale">输出物体的缩放值</param>
    /// <param name="approximate">索引的容差值</param>
    public CaveItem GetRandomItem(float size, ref float scale, uint approximate = 1)
    {
        List <CaveItem> items = GetItemsWithSize(size, approximate);

        if (items.Count == 0)
        {
            return(null);
        }
        CaveItem item = items[Random.Range(0, items.Count)];

        scale = Mathf.Sqrt(size / item.AreaSize);
        return(item);
    }
    /// <summary>
    /// 设置主要物件
    /// </summary>
    public GameObject SetMainItems(CaveRegion region, Transform parent)
    {
        float scale = 0f;

        item = mainItemList.GetRandomItem(region.RegionSize, ref scale, approximate);
        if (item == null)
        {
            item = mainItemList.GetRandomItem(region.RegionSize, ref scale, approximate + 1);
        }
        pos = map.GetPosition(region.averageCoord) + item.offset;
        if (item.randomRotationY)
        {
            quat = Quaternion.Euler(GameMathf.RandomY());
        }
        else
        {
            quat = Quaternion.Euler(0, GameMathf.RandomNumber(0, 180) - GameMathf.RadianToAngle(Mathf.Atan2(region.deviation.y, region.deviation.x)), 0);
        }
        obj = Instantiate(item.prefab, pos, quat, parent);
        obj.transform.localScale = Vector3.one * scale;
        return(obj);
    }
示例#4
0
    }                                                           // 占地面积

    /// <summary>
    /// 比较两个洞穴物体的占地面积大小:x.Area - y.Area
    /// </summary>
    static public int CompareArea(CaveItem x, CaveItem y)
    {
        return((int)(x.AreaSize - y.AreaSize));
    }