Beispiel #1
0
    ///<summary>
    /// Create an OgreeObject of "site" category and assign given values to it
    ///</summary>
    ///<param name="_si">The site data to apply</param>
    ///<param name="_parent">The parent of the created site. Leave null if _bd contains the parendId</param>
    ///<returns>The created Site</returns>
    public OgreeObject CreateSite(SApiObject _si, Transform _parent = null)
    {
        Transform tn = Utils.FindParent(_parent, _si.parentId);

        if (!tn || tn.GetComponent <OgreeObject>().category != "tenant")
        {
            GameManager.gm.AppendLogLine($"Parent tenant not found", true, eLogtype.error);
            return(null);
        }

        string hierarchyName = $"{tn.GetComponent<OgreeObject>().hierarchyName}.{_si.name}";

        if (GameManager.gm.allItems.Contains(hierarchyName))
        {
            GameManager.gm.AppendLogLine($"{hierarchyName} already exists.", true, eLogtype.warning);
            return(null);
        }

        GameObject newSite = new GameObject(_si.name);

        newSite.transform.parent = tn;

        OgreeObject site = newSite.AddComponent <OgreeObject>();

        site.UpdateFromSApiObject(_si);

        switch (site.attributes["orientation"])
        {
        case "EN":
            newSite.transform.localEulerAngles = new Vector3(0, 0, 0);
            break;

        case "WS":
            newSite.transform.localEulerAngles = new Vector3(0, 180, 0);
            break;

        case "NW":
            newSite.transform.localEulerAngles = new Vector3(0, -90, 0);
            break;

        case "SE":
            newSite.transform.localEulerAngles = new Vector3(0, 90, 0);
            break;
        }

        string hn = site.UpdateHierarchyName();

        GameManager.gm.allItems.Add(hn, newSite);

        return(site);
    }
Beispiel #2
0
    ///<summary>
    /// Create OgreeObject of "tenant" category from given data.
    ///</summary>
    ///<param name="_tn">The tenant data to apply</param>
    ///<returns>The created Tenant</returns>
    public OgreeObject CreateTenant(SApiObject _tn)
    {
        if (GameManager.gm.allItems.Contains(_tn.name))
        {
            GameManager.gm.AppendLogLine($"{_tn.name} already exists.", true, eLogtype.error);
            return(null);
        }

        GameObject  newTenant = new GameObject(_tn.name);
        OgreeObject tenant    = newTenant.AddComponent <OgreeObject>();

        tenant.UpdateFromSApiObject(_tn);
        tenant.UpdateHierarchyName();
        GameManager.gm.allItems.Add(_tn.name, newTenant);

        return(tenant);
    }
Beispiel #3
0
    ///<summary>
    /// Deserialize given SApiObject and apply modification to corresponding object.
    ///</summary>
    ///<param name="_input">The SApiObject to deserialize</param>
    private void ModifyObject(string _input)
    {
        SApiObject  newData = JsonConvert.DeserializeObject <SApiObject>(_input);
        OgreeObject obj     = Utils.GetObjectById(newData.id).GetComponent <OgreeObject>();

        // Case domain for all OgreeObjects
        bool tenantColorChanged = false;

        if (newData.category == "tenant" && obj.attributes["color"] != newData.attributes["color"])
        {
            tenantColorChanged = true;
        }

        // Case color/temperature for racks & devices
        if (newData.category == "rack" || newData.category == "device")
        {
            OObject item = (OObject)obj;
            if (newData.attributes.ContainsKey("color"))
            {
                if ((obj.attributes.ContainsKey("color") && obj.attributes["color"] != newData.attributes["color"]) ||
                    !item.attributes.ContainsKey("color"))
                {
                    item.SetColor(newData.attributes["color"]);
                }
            }
            if (newData.attributes.ContainsKey("temperature"))
            {
                if ((obj.attributes.ContainsKey("temperature") && obj.attributes["temperature"] != newData.attributes["temperature"]) ||
                    !item.attributes.ContainsKey("temperature"))
                {
                    item.SetTemperature(newData.attributes["temperature"]);
                }
            }
        }

        // Case of a separator/areas modification in a room
        if (newData.category == "room")
        {
            Room room = (Room)obj;
            if (newData.attributes.ContainsKey("separators"))
            {
                if ((room.attributes.ContainsKey("separators") && room.attributes["separators"] != newData.attributes["separators"]) ||
                    !room.attributes.ContainsKey("separators"))
                {
                    foreach (Transform wall in room.walls)
                    {
                        if (wall.name.Contains("separator"))
                        {
                            Object.Destroy(wall.gameObject);
                        }
                    }
                    List <ReadFromJson.SSeparator> separators = JsonConvert.DeserializeObject <List <ReadFromJson.SSeparator> >(newData.attributes["separators"]);
                    foreach (ReadFromJson.SSeparator sep in separators)
                    {
                        room.AddSeparator(sep);
                    }
                }
            }
            if (newData.attributes.ContainsKey("reserved"))
            {
                if ((room.attributes.ContainsKey("reserved") && room.attributes["reserved"] != newData.attributes["reserved"]) ||
                    !room.attributes.ContainsKey("reserved"))
                {
                    SMargin reserved  = JsonUtility.FromJson <SMargin>(newData.attributes["reserved"]);
                    SMargin technical = JsonUtility.FromJson <SMargin>(newData.attributes["technical"]);
                    room.SetAreas(reserved, technical);
                }
            }
        }

        obj.UpdateFromSApiObject(newData);
        if (tenantColorChanged)
        {
            EventManager.Instance.Raise(new UpdateTenantEvent {
                name = newData.name
            });
        }
    }