コード例 #1
0
        public Color Add(Part part)
        {
            Color tint = map.Get(count++);

            tints.Add(part, tint);
            return(tint);
        }
コード例 #2
0
    protected void AnalyzeMap()
    {
        colorMap.CheckConnected();

        for (int x = colorMap.GetLeft(); x <= colorMap.GetRight(); ++x)
        {
            for (int y = colorMap.GetTop(); y <= colorMap.GetBottom(); ++y)
            {
                int val = colorMap.Get(x, y);
                if (val == /* null? */ 0)
                {
                    continue;
                }
                Group group = groups[val];
                if (group == null)
                {
                    group       = new Group(val);
                    groups[val] = group;
                }
                group.coords.Add(new Vector2Int(x, y));
            }
        }
        // Debug.Log(groups.Count + " groups");

        foreach (Group group in groups.Values)
        {
            foreach (Vector2Int xy in group.coords)
            {
                Vector2Int[] directions = new Vector2Int[] { Vector2Int.up, Vector2Int.right, Vector2Int.down, Vector2Int.left };
                foreach (Vector2Int d in directions)
                {
                    Vector2Int neighbor = xy + d;
                    if (group.coords.Contains(neighbor))
                    {
                        continue;
                    }
                    int val = colorMap.Get(neighbor.x, neighbor.y);
                    if (val != /* null? */ 0 && AllowRoomsToBeAdjacent(group.id, val))
                    {
                        group.adjacentGroups.Add(val);
                    }
                }
            }
        }

        CheckConnected();
    }
コード例 #3
0
        public object Get(string name, System.Type type)
        {
            object obj = null;

            if (type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                obj = objects.Get(name);
            }
            else if (type == typeof(float))
            {
                obj = floats.Get(name);
            }
            else if (type == typeof(int))
            {
                obj = ints.Get(name);
            }
            else if (type == typeof(string))
            {
                obj = strings.Get(name) ?? string.Empty;
            }
            else if (type == typeof(bool))
            {
                obj = bools.Get(name);
            }
            else if (type.IsSubclassOf(typeof(System.Enum)))
            {
                obj = enums.Get(name);
            }
            else if (type == typeof(Vector3))
            {
                obj = vector3s.Get(name);
            }
            else if (type == typeof(Vector2))
            {
                obj = vector2s.Get(name);
            }
            else if (type == typeof(Vector4))
            {
                obj = vector4s.Get(name);
            }
            else if (type == typeof(Color))
            {
                obj = colors.Get(name);
            }
            else if (type == typeof(LayerMaskMap))
            {
                obj = layerMasks.Get(name);
            }
            else
            {
                throw new NotSupportedException($"Type {type.AssemblyQualifiedName} is not supported. ({name})");
            }
            if (obj == null && type.IsValueType)
            {
                return(Activator.CreateInstance(type));
            }
            return(obj);
        }
コード例 #4
0
    private static int SelectTile(ColorMap map, int x, int y)
    {
        Color?color   = map.Get(x, y);
        int   bitMask = 0;

        if (map.Get(x, y + 1) == color)
        {
            bitMask = bitMask | 1;
        }
        if (map.Get(x + 1, y) == color)
        {
            bitMask = bitMask | 1 << 1;
        }
        if (map.Get(x, y - 1) == color)
        {
            bitMask = bitMask | 1 << 2;
        }
        if (map.Get(x - 1, y) == color)
        {
            bitMask = bitMask | 1 << 3;
        }
        return(bitMask);
    }