public static string SerializeToHex(this NodeColor nodeColor)
        {
            var colorField = nodeColor.GetType().GetField(nodeColor.ToString());

            Debug.Assert(colorField != null);

            var hexColorAttribute = colorField.GetCustomAttribute(typeof(HexColor));

            Debug.Assert(hexColorAttribute != null);

            return(((HexColor)hexColorAttribute).Value);
        }
Exemple #2
0
    /// <summary>
    /// Fake constructor that creates a node via Instantiate().
    /// </summary>
    /// <param name="prefab">A reference to a prefab.</param>
    /// <param name="position">Where said node will lie in (world position).</param>
    /// <param name="team">Which team it currently belongs to.</param>
    /// <param name="parent">A designated parent for sorting.</param>
    /// <param name="boardCoord">A boardCoordinate to reference the real array's node.</param>
    /// <returns>A newrly created view node.</returns>
    public static NodeObject CreateNodeObject(NodeObject prefab, Vector2 position, NodeColor team, Transform parent, Vector2Int boardCoord)
    {
        NodeObject newNode = Instantiate(prefab, position, Quaternion.identity, parent);

        newNode.name = team.ToString();
        newNode.SetTeamColor(team);
        newNode.boardCoordinate = boardCoord;
        newNode.childRenderer   = newNode.transform.GetChild(0).gameObject.GetComponentInChildren <SpriteRenderer> ();
        newNode.evenCounter     = newNode.GetComponentInChildren <TMP_Text> ();
        newNode.coordinate      = $"{newNode.boardCoordinate}";
        return(newNode);
    }
 public static string Serialize(this NodeColor nodeColor) => nodeColor.ToString().ToLowerInvariant();