Beispiel #1
0
    public void CreateObstacles()
    {
        int count = floorList.Count
                    - (Mathf.FloorToInt(roomBounds.size.y) - GameConst.RoomOutsize * 2) * 2      //上下地板边
                    - (Mathf.FloorToInt(roomBounds.size.x) - GameConst.RoomOutsize * 2 - 2) * 2; //左右地板边

        for (int i = 0; i < ornamentList.Count; i++)
        {
            OrnamentObject ornamentObject = objList[ornamentList[i]] as OrnamentObject;
            if (ornamentObject.OrnamentTemp.OrnamentType == (int)GameConst.OrnamentType.Floor)
            {
                count--;
            }
        }

        count = Mathf.FloorToInt(count * 60 / 100);

        for (int i = 0; i < floorList.Count; i++)
        {
            Floor floor = objList[floorList[i]] as Floor;
            if (floor.OrnamentId != 0)
            {
                continue;
            }
            if (UnityEngine.Random.value < 0.5)
            {
                continue;
            }

            if (!AddObstacle(floor))
            {
                continue;
            }

            count--;
            if (count <= 0)
            {
                break;
            }
        }
    }
Beispiel #2
0
    void AddOrnamentExcute(RoomElement element, OrnamentTemplate temp)
    {
        GameObject Prefab = (ResourceManager.instance.GetAsset <GameObject>("Prefabs/Ornament"));

        try
        {
            GameObject     ornamentObject = Instantiate(Prefab);
            string         name           = gameObject.name + "Ornament_" + element.Position.x + "_" + element.Position.y;
            OrnamentObject ornament       = ornamentObject.GetComponent <OrnamentObject>();
            ornament.Init(LevelManager.GetElementID(), roomId, name, element.Position.x, element.Position.y, temp);
            objList[ornament.ID] = ornament;
            ornamentList.Add(ornament.ID);
            ornamentDictionary[GetPosKey(Mathf.FloorToInt(element.Position.x), Mathf.FloorToInt(element.Position.y))] = ornament.ID;

            element.OrnamentId = ornament.ID;
        }
        finally
        {
            Prefab = null;
        }
    }