Example #1
0
    ///<summary>
    /// Call the good CreateX function according to the item's category.
    ///</summary>
    ///<param name="_obj">The item to generate</param>
    public async Task <OgreeObject> CreateItemFromSApiObject(SApiObject _obj, Transform _parent = null)
    {
        OgreeObject newItem;

        // Get dependencies from API
        if (_obj.category != "tenant" && !string.IsNullOrEmpty(_obj.domain) &&
            !GameManager.gm.allItems.Contains(_obj.domain))
        {
            await ApiManager.instance.GetObject($"tenants?name={_obj.domain}", ApiManager.instance.DrawObject);
        }

        if (_obj.category == "room" && !string.IsNullOrEmpty(_obj.attributes["template"]) &&
            !GameManager.gm.roomTemplates.ContainsKey(_obj.attributes["template"]))
        {
            Debug.Log($"Get template \"{_obj.attributes["template"]}\" from API");
            await ApiManager.instance.GetObject($"room-templates/{_obj.attributes["template"]}", ApiManager.instance.DrawObject);
        }

        if ((_obj.category == "rack" || _obj.category == "device") && !string.IsNullOrEmpty(_obj.attributes["template"]) &&
            !GameManager.gm.objectTemplates.ContainsKey(_obj.attributes["template"]))
        {
            Debug.Log($"Get template \"{_obj.attributes["template"]}\" from API");
            await ApiManager.instance.GetObject($"obj-templates/{_obj.attributes["template"]}", ApiManager.instance.DrawObject);
        }

        // Call Create function
        switch (_obj.category)
        {
        case "tenant":
            newItem = customerGenerator.CreateTenant(_obj);
            break;

        case "site":
            newItem = customerGenerator.CreateSite(_obj, _parent);
            break;

        case "building":
            newItem = buildingGenerator.CreateBuilding(_obj, _parent);
            break;

        case "room":
            newItem = buildingGenerator.CreateRoom(_obj, _parent);
            break;

        case "rack":
            newItem = objectGenerator.CreateRack(_obj, _parent);
            break;

        case "device":
            newItem = objectGenerator.CreateDevice(_obj, _parent);
            break;

        case "corridor":
            newItem = objectGenerator.CreateCorridor(_obj, _parent);
            break;

        case "group":
            newItem = objectGenerator.CreateGroup(_obj, _parent);
            break;

        case "sensor":
            newItem = objectGenerator.CreateSensor(_obj, _parent);
            break;

        default:
            newItem = null;
            GameManager.gm.AppendLogLine($"Unknown object type ({_obj.category})", true, eLogtype.error);
            break;
        }
        ResetCoroutine();
        return(newItem);
    }