Пример #1
0
    ///<summary>
    /// Set usable/reserved/technical areas.
    ///</summary>
    ///<param name="_resDim">The dimensions of the reserved zone</param>
    ///<param name="_techDim">The dimensions of the technical zone</param>
    public void SetAreas(SMargin _resDim, SMargin _techDim)
    {
        if (transform.GetComponentInChildren <Rack>())
        {
            GameManager.gm.AppendLogLine("Can't modify areas if room has a rack drawn in it.", true, eLogtype.error);
            return;
        }
        tilesEdges.gameObject.SetActive(true);

        reserved  = new SMargin(_resDim);
        technical = new SMargin(_techDim);

        // Reset  ->  techzone is always full size of a room
        usableZone.localScale    = technicalZone.localScale;
        usableZone.localPosition = new Vector3(technicalZone.localPosition.x,
                                               usableZone.localPosition.y, technicalZone.localPosition.z);
        reservedZone.localScale    = technicalZone.localScale;
        reservedZone.localPosition = new Vector3(technicalZone.localPosition.x,
                                                 reservedZone.localPosition.y, technicalZone.localPosition.z);

        // Reduce zones
        ReduceZone(reservedZone, _techDim);
        ReduceZone(usableZone, _techDim);
        ReduceZone(usableZone, _resDim);

        // Save areas in attributes
        attributes["reserved"]  = JsonUtility.ToJson(_resDim);
        attributes["technical"] = JsonUtility.ToJson(_techDim);
    }
Пример #2
0
 public SMargin(SMargin _data)
 {
     top    = _data.top;
     bottom = _data.bottom;
     right  = _data.right;
     left   = _data.left;
 }
Пример #3
0
    ///<summary>
    /// Remove tiles from a zone.
    ///</summary>
    ///<param name ="_zone">The zone to reduce</param>
    ///<param name="_dim">The dimensions of the reduction</param>
    private void ReduceZone(Transform _zone, SMargin _dim)
    {
        _zone.localScale    -= new Vector3(0, 0, _dim.top) * GameManager.gm.tileSize / 10;
        _zone.localPosition -= new Vector3(0, 0, _dim.top) * GameManager.gm.tileSize / 2;

        _zone.localScale    -= new Vector3(0, 0, _dim.bottom) * GameManager.gm.tileSize / 10;
        _zone.localPosition += new Vector3(0, 0, _dim.bottom) * GameManager.gm.tileSize / 2;

        _zone.localScale    -= new Vector3(_dim.right, 0, 0) * GameManager.gm.tileSize / 10;
        _zone.localPosition -= new Vector3(_dim.right, 0, 0) * GameManager.gm.tileSize / 2;

        _zone.localScale    -= new Vector3(_dim.left, 0, 0) * GameManager.gm.tileSize / 10;
        _zone.localPosition += new Vector3(_dim.left, 0, 0) * GameManager.gm.tileSize / 2;
    }
Пример #4
0
    ///<summary>
    /// Parse a "areas" command and call SetZones().
    ///</summary>
    ///<param name="_input">String with zones data to parse</param>
    private void ParseAreas(string _input)
    {
        string patern = "^\\[([0-9.]+,){3}[0-9.]+\\]@\\[([0-9.]+,){3}[0-9.]+\\]$";

        if (Regex.IsMatch(_input, patern))
        {
            _input = _input.Replace("[", "");
            _input = _input.Replace("]", "");
            string[] data = _input.Split('@', ',');

            SMargin resDim  = new SMargin(data[0], data[1], data[2], data[3]);
            SMargin techDim = new SMargin(data[4], data[5], data[6], data[7]);
            SetAreas(resDim, techDim);
        }
        else
        {
            GameManager.gm.AppendLogLine("Syntax error", true, eLogtype.error);
        }
    }
Пример #5
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
            });
        }
    }
Пример #6
0
    ///<summary>
    /// Instantiate a roomModel (from GameManager) and apply given data to it.
    ///</summary>
    ///<param name="_ro">The room data to apply</param>
    ///<param name="_parent">The parent of the created room. Leave null if _bd contains the parendId</param>
    ///<returns>The created Room</returns>
    public Room CreateRoom(SApiObject _ro, Transform _parent = null)
    {
        Transform bd = Utils.FindParent(_parent, _ro.parentId);

        if (!bd || bd.GetComponent <OgreeObject>().category != "building")
        {
            GameManager.gm.AppendLogLine($"Parent building not found", true, eLogtype.error);
            return(null);
        }
        string hierarchyName = $"{bd.GetComponent<OgreeObject>().hierarchyName}.{_ro.name}";

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

        // Position and size data from _ro.attributes
        Vector2 posXY  = JsonUtility.FromJson <Vector2>(_ro.attributes["posXY"]);
        Vector2 size   = JsonUtility.FromJson <Vector2>(_ro.attributes["size"]);
        float   height = float.Parse(_ro.attributes["height"]);

        GameObject newRoom = Instantiate(GameManager.gm.roomModel);

        newRoom.name             = _ro.name;
        newRoom.transform.parent = bd;

        Room room = newRoom.GetComponent <Room>();

        room.UpdateFromSApiObject(_ro);

        Vector3 originalSize = room.usableZone.localScale;

        room.usableZone.localScale    = new Vector3(originalSize.x * size.x, originalSize.y, originalSize.z * size.y);
        room.reservedZone.localScale  = room.usableZone.localScale;
        room.technicalZone.localScale = room.usableZone.localScale;
        room.tilesEdges.localScale    = room.usableZone.localScale;
        room.tilesEdges.GetComponent <Renderer>().material.mainTextureScale  = size / 0.6f;
        room.tilesEdges.GetComponent <Renderer>().material.mainTextureOffset = new Vector2(size.x / 0.6f % 1, size.y / 0.6f % 1);
        BuildWalls(room.walls, new Vector3(room.usableZone.localScale.x * 10, height, room.usableZone.localScale.z * 10), -0.001f);

        Vector3 bdOrigin = bd.GetChild(0).localScale / -0.2f;
        Vector3 roOrigin = room.usableZone.localScale / 0.2f;

        newRoom.transform.position       = bd.position;
        newRoom.transform.localPosition += new Vector3(bdOrigin.x, 0, bdOrigin.z);
        newRoom.transform.localPosition += new Vector3(posXY.x, 0, posXY.y);

        if (Regex.IsMatch(room.attributes["orientation"], "(\\+|\\-)E(\\+|\\-)N"))
        {
            newRoom.transform.eulerAngles = new Vector3(0, 0, 0);
            newRoom.transform.position   += new Vector3(roOrigin.x, 0, roOrigin.z);
        }
        else if (Regex.IsMatch(room.attributes["orientation"], "(\\+|\\-)W(\\+|\\-)S"))
        {
            newRoom.transform.eulerAngles = new Vector3(0, 180, 0);
            newRoom.transform.position   += new Vector3(-roOrigin.x, 0, -roOrigin.z);
        }
        else if (Regex.IsMatch(room.attributes["orientation"], "(\\+|\\-)N(\\+|\\-)W"))
        {
            newRoom.transform.eulerAngles = new Vector3(0, -90, 0);
            newRoom.transform.position   += new Vector3(-roOrigin.z, 0, roOrigin.x);
        }
        else if (Regex.IsMatch(room.attributes["orientation"], "(\\+|\\-)S(\\+|\\-)E"))
        {
            newRoom.transform.eulerAngles = new Vector3(0, 90, 0);
            newRoom.transform.position   += new Vector3(roOrigin.z, 0, -roOrigin.x);
        }

        // Set UI room's name
        room.nameText.text = newRoom.name;
        room.nameText.rectTransform.sizeDelta = size;
        room.UpdateZonesColor();

        string hn = room.UpdateHierarchyName();

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

        if (_ro.attributes.ContainsKey("reserved") && _ro.attributes.ContainsKey("technical") &&
            !string.IsNullOrEmpty(_ro.attributes["reserved"]) && !string.IsNullOrEmpty(_ro.attributes["technical"]))
        {
            SMargin reserved  = JsonUtility.FromJson <SMargin>(_ro.attributes["reserved"]);
            SMargin technical = JsonUtility.FromJson <SMargin>(_ro.attributes["technical"]);
            room.SetAreas(reserved, technical);
        }

        if (!string.IsNullOrEmpty(_ro.attributes["template"]) && GameManager.gm.roomTemplates.ContainsKey(_ro.attributes["template"]))
        {
            ReadFromJson.SRoomFromJson template = GameManager.gm.roomTemplates[_ro.attributes["template"]];

            room.SetAreas(new SMargin(template.reservedArea), new SMargin(template.technicalArea));

            if (template.separators != null)
            {
                foreach (ReadFromJson.SSeparator sep in template.separators)
                {
                    room.AddSeparator(sep);
                }
            }

            if (template.tiles != null)
            {
                List <ReadFromJson.STile> tiles = new List <ReadFromJson.STile>();
                foreach (ReadFromJson.STile t in template.tiles)
                {
                    tiles.Add(t);
                }
                room.attributes["tiles"] = JsonConvert.SerializeObject(tiles);
            }

            if (template.rows != null)
            {
                List <ReadFromJson.SRow> rows = new List <ReadFromJson.SRow>();
                foreach (ReadFromJson.SRow r in template.rows)
                {
                    rows.Add(r);
                }
                room.attributes["rows"] = JsonConvert.SerializeObject(rows);
            }

            if (template.colors != null)
            {
                List <ReadFromJson.SColor> colors = new List <ReadFromJson.SColor>();
                foreach (ReadFromJson.SColor c in template.colors)
                {
                    colors.Add(c);
                }
                room.attributes["customColors"] = JsonConvert.SerializeObject(colors);
            }
        }

        return(room);
    }