Ejemplo n.º 1
0
    ///<summary>
    /// Instantiate a tileNameModel from gm and assign a name to it.
    ///</summary>
    ///<param name="_root">The root to parent the tile</param>
    ///<param name="_pos">The position of the current tile</param>
    ///<param name="_id">The id of the current tile</param>
    private void GenerateTileName(Transform _root, Vector2 _pos, string _id)
    {
        GameObject tileText = Instantiate(GameManager.gm.tileNameModel);

        tileText.name = $"Text_{_id}";
        tileText.transform.SetParent(_root);
        tileText.transform.localPosition    = new Vector3(_pos.x, 0, _pos.y);
        tileText.transform.localEulerAngles = new Vector3(90, 0, 0);

        // Select the right tile from attributes["tiles"]
        ReadFromJson.STile tileData = new ReadFromJson.STile();
        if (attributes.ContainsKey("tiles"))
        {
            List <ReadFromJson.STile> tiles = JsonConvert.DeserializeObject <List <ReadFromJson.STile> >(attributes["tiles"]);
            foreach (ReadFromJson.STile tile in tiles)
            {
                if (tile.location.Trim() == _id)
                {
                    tileData = tile;
                }
            }
        }

        if (!string.IsNullOrEmpty(tileData.location) && !string.IsNullOrEmpty(tileData.label))
        {
            tileText.GetComponent <TextMeshPro>().text = tileData.label;
        }
        else
        {
            tileText.GetComponent <TextMeshPro>().text = _id;
        }
    }
Ejemplo n.º 2
0
    ///<summary>
    /// Update singlePanel texts from an OgreeObject.
    ///</summary>
    ///<param name="_obj">The object whose information are displayed</param>
    private void UpdateFields(OgreeObject _obj)
    {
        int i = 1;

        tmpName.text = _obj.hierarchyName;
        if (!string.IsNullOrEmpty(_obj.domain))
        {
            OgreeObject domain = ((GameObject)GameManager.gm.allItems[_obj.domain]).GetComponent <OgreeObject>();
            tmpTenantName.text    = domain.name;
            tmpTenantContact.text = IfInDictionary(domain.attributes, "mainContact");
            tmpTenantPhone.text   = IfInDictionary(domain.attributes, "mainPhone");
            tmpTenantEmail.text   = IfInDictionary(domain.attributes, "mainEmail");
        }
        // Display category
        tmpAttributes.text = $"<b><u>{_obj.category}</u></b>\n";

        // Display posXY if available
        if (_obj.attributes.ContainsKey("posXY") && _obj.attributes.ContainsKey("posXYUnit") &&
            !string.IsNullOrEmpty(_obj.attributes["posXY"]) && !string.IsNullOrEmpty(_obj.attributes["posXYUnit"]))
        {
            Vector2 posXY = JsonUtility.FromJson <Vector2>(_obj.attributes["posXY"]);
            tmpAttributes.text += $"<b>posXY:</b> {posXY.x.ToString("0.##")}/{posXY.y.ToString("0.##")} ({_obj.attributes["posXYUnit"]})\n";
            i++;

            // If rack, display pos by tile name if available
            if (_obj.category == "rack")
            {
                Room room = _obj.transform.parent.GetComponent <Room>();
                if (room.attributes.ContainsKey("tiles"))
                {
                    List <ReadFromJson.STile> tiles    = JsonConvert.DeserializeObject <List <ReadFromJson.STile> >(room.attributes["tiles"]);
                    ReadFromJson.STile        tileData = new ReadFromJson.STile();
                    foreach (ReadFromJson.STile t in tiles)
                    {
                        if (t.location == $"{posXY.x.ToString("0")}/{posXY.y.ToString("0")}")
                        {
                            tileData = t;
                        }
                    }
                    if (!string.IsNullOrEmpty(tileData.location) && !string.IsNullOrEmpty(tileData.label))
                    {
                        tmpAttributes.text += $"<b>tile's label:</b> {tileData.label}\n";
                        i++;
                    }
                }
            }
        }

        // Display orientation if available
        if (_obj.attributes.ContainsKey("orientation"))
        {
            tmpAttributes.text += $"<b>orientation:</b> {_obj.attributes["orientation"]}\n";
            i++;
        }

        // Display size if available
        if (_obj.attributes.ContainsKey("size") && _obj.attributes.ContainsKey("sizeUnit"))
        {
            Vector2 size = JsonUtility.FromJson <Vector2>(_obj.attributes["size"]);
            tmpAttributes.text += $"<b>size:</b> {size.x}{_obj.attributes["sizeUnit"]} x {size.y}{_obj.attributes["sizeUnit"]} x {_obj.attributes["height"]}{_obj.attributes["heightUnit"]}\n";
            i++;
        }

        // Display template if available
        if (_obj.attributes.ContainsKey("template") && !string.IsNullOrEmpty(_obj.attributes["template"]))
        {
            tmpAttributes.text += $"<b>template:</b> {_obj.attributes["template"]}\n";
            i++;
        }

        // Display all other attributes
        foreach (KeyValuePair <string, string> kvp in _obj.attributes)
        {
            if (!string.IsNullOrEmpty(kvp.Value) && (kvp.Key != "posXY" && kvp.Key != "posXYUnit" && kvp.Key != "orientation" &&
                                                     kvp.Key != "size" && kvp.Key != "sizeUnit" && kvp.Key != "template"))
            {
                tmpAttributes.text += $"<b>{kvp.Key}:</b> {kvp.Value}\n";
                i++;
            }
        }

        // Display all descriptions
        if (_obj.description.Count != 0)
        {
            tmpAttributes.text += "<b>description:</b>\n";
            for (int j = 0; j < _obj.description.Count; j++)
            {
                tmpAttributes.text += $"<b>{j + 1}:</b> {_obj.description[j]}\n";
                i++;
            }
        }

        // Set correct height for scroll view
        RectTransform rt = tmpAttributes.transform.parent.GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2(0, i * 30);
    }
Ejemplo n.º 3
0
    ///<summary>
    /// Instantiate a plane as a tile and assign a texture and/or a color to it.
    ///</summary>
    ///<param name="_root">The root to parent the tile</param>
    ///<param name="_pos"> The position of the current tile</param>
    ///<param name="_id">The id of the current tile</param>
    private void GenerateTileColor(Transform _root, Vector2 _pos, string _id)
    {
        // Select the right tile from attributes["tiles"]
        ReadFromJson.STile tileData = new ReadFromJson.STile();
        if (attributes.ContainsKey("tiles"))
        {
            List <ReadFromJson.STile> tiles = JsonConvert.DeserializeObject <List <ReadFromJson.STile> >(attributes["tiles"]);
            foreach (ReadFromJson.STile tile in tiles)
            {
                if (tile.location.Trim() == _id)
                {
                    tileData = tile;
                }
            }
        }

        List <ReadFromJson.SColor> customColors = new List <ReadFromJson.SColor>();

        if (attributes.ContainsKey("customColors"))
        {
            customColors = JsonConvert.DeserializeObject <List <ReadFromJson.SColor> >(attributes["customColors"]);
        }

        if (!string.IsNullOrEmpty(tileData.location))
        {
            if (!string.IsNullOrEmpty(tileData.texture) || !string.IsNullOrEmpty(tileData.color))
            {
                GameObject tile = GameObject.CreatePrimitive(PrimitiveType.Plane);
                tile.name                       = $"Color_{_id}";
                tile.transform.parent           = _root;
                tile.transform.localScale       = Vector3.one * GameManager.gm.tileSize / 10;
                tile.transform.localPosition    = new Vector3(_pos.x, 0, _pos.y);
                tile.transform.localEulerAngles = new Vector3(0, 180, 0);
                if (!string.IsNullOrEmpty(tileData.texture))
                {
                    Renderer rend = tile.GetComponent <Renderer>();
                    if (GameManager.gm.textures.ContainsKey(tileData.texture))
                    {
                        rend.material = new Material(GameManager.gm.perfMat)
                        {
                            mainTexture = GameManager.gm.textures[tileData.texture]
                        };
                    }
                    else
                    {
                        GameManager.gm.AppendLogLine($"Unknow texture: {tileData.texture}", false, eLogtype.warning);
                    }
                }
                if (!string.IsNullOrEmpty(tileData.color))
                {
                    Material mat         = tile.GetComponent <Renderer>().material;
                    Color    customColor = new Color();
                    if (tileData.color.StartsWith("@"))
                    {
                        foreach (ReadFromJson.SColor color in customColors)
                        {
                            if (color.name == tileData.color.Substring(1))
                            {
                                ColorUtility.TryParseHtmlString($"#{color.value}", out customColor);
                            }
                        }
                    }
                    else
                    {
                        ColorUtility.TryParseHtmlString($"#{tileData.color}", out customColor);
                    }
                    mat.color = customColor;
                }
            }
        }
    }