Exemplo n.º 1
0
    public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int texWidth, int texHeight)
    {
        MapPatternDefinition mapPattern = target as MapPatternDefinition;

        if (mapPattern == null)
        {
            return(null);
        }

        Texture2D staticPreview = new Texture2D(texWidth, texHeight);
        float     blockSize     = Mathf.Min(
            texWidth / mapPattern.Width,
            texHeight / mapPattern.Height
            );

        // Get size
        float offX = (texWidth - blockSize * mapPattern.Width) * 0.5f;
        float offY = (texHeight - blockSize * mapPattern.Height) * 0.5f;

        // Get max
        int   maxStrength = tileTypes.Length;
        float divMax      = 1.0f / maxStrength;

        // Set blank
        Color32 blankColor = new Color32(255, 255, 255, 0);

        Color32[] colBlock = new Color32[texWidth * texHeight];

        for (int i = 0; i < colBlock.Length; i++)
        {
            colBlock[i] = blankColor;
        }
        staticPreview.SetPixels32(colBlock);

        for (uint x = 0; x < mapPattern.Width; x++)
        {
            for (uint y = 0; y < mapPattern.Height; y++)
            {
                uint mapY = (uint)mapPattern.Height - 1 - y;
                if (mapPattern.GetData(x, mapY) != "")
                {
                    int sx = (int)(offX + (int)x * blockSize + 1);
                    int sy = (int)(texHeight - (offY + (int)y * blockSize + 1) - blockSize);

                    Color color = new Color(0, 0, 0, IndexOfTile(mapPattern.GetData(x, mapY)) * divMax);

                    for (int px = 0; px < blockSize - 2; px++)
                    {
                        for (int py = 0; py < blockSize - 2; py++)
                        {
                            staticPreview.SetPixel(sx + px, sy + py, color);
                        }
                    }
                }
            }
        }
        staticPreview.Apply();
        return(staticPreview);
    }
Exemplo n.º 2
0
    public override void OnPreviewGUI(Rect targetRect, GUIStyle background)
    {
        MapPatternDefinition mapPattern = target as MapPatternDefinition;

        if (mapPattern == null)
        {
            return;
        }

        float blockSize = Mathf.Min(
            targetRect.width / mapPattern.Width,
            targetRect.height / mapPattern.Height
            );

        // Get size
        float offX = (targetRect.width - blockSize * mapPattern.Width) * 0.5f + targetRect.x;
        float offY = (targetRect.height - blockSize * mapPattern.Height) * 0.5f + targetRect.y;

        // Get max
        int   maxStrength = tileTypes.Length;
        float divMax      = 1.0f / maxStrength;

        for (uint x = 0; x < mapPattern.Width; x++)
        {
            for (uint y = 0; y < mapPattern.Height; y++)
            {
                uint mapY = (uint)mapPattern.Height - 1 - y;
                if (mapPattern.GetData(x, mapY) != "")
                {
                    EditorGUI.DrawRect(
                        new Rect(
                            offX + (int)x * blockSize + 1,
                            offY + (int)y * blockSize + 1,
                            blockSize - 2,
                            blockSize - 2
                            ),
                        new Color(0, 0, 0, IndexOfTile(mapPattern.GetData(x, mapY)) * divMax)
                        );
                }
            }
        }
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        if (Event.current.type == EventType.Layout)
        {
            return;
        }

        Rect position = new Rect(0, 50, Screen.width, Screen.height - 50);


        foreach (var item in targets)
        {
            if (position.height < EditorGUIUtility.singleLineHeight * 2)
            {
                continue;
            }

            MapPatternDefinition mapPattern = item as MapPatternDefinition;
            float usedHeight = InspectMapPattern(position, mapPattern);
            position.y += usedHeight;
        }
    }
Exemplo n.º 4
0
    public static float InspectMapPattern(Rect position, MapPatternDefinition mapPattern)
    {
        float usedHeight       = 0f;
        float quarterPositionX = position.width * 0.5f;

        int newWidth = EditorGUI.IntField(
            new Rect(position.x + quarterPositionX * 0, position.y, quarterPositionX, EditorGUIUtility.singleLineHeight),
            "Width:",
            mapPattern.Width
            );

        int newHeight = EditorGUI.IntField(
            new Rect(position.x + quarterPositionX * 1, position.y, quarterPositionX, EditorGUIUtility.singleLineHeight),
            "Height:",
            mapPattern.Height
            );

        position.y += EditorGUIUtility.singleLineHeight;
        usedHeight += EditorGUIUtility.singleLineHeight;

        mapPattern.offset.x = EditorGUI.IntField(
            new Rect(position.x + quarterPositionX * 0, position.y, quarterPositionX, EditorGUIUtility.singleLineHeight),
            "OffsetX:",
            mapPattern.offset.x
            );

        mapPattern.offset.y = EditorGUI.IntField(
            new Rect(position.x + quarterPositionX * 1, position.y, quarterPositionX, EditorGUIUtility.singleLineHeight),
            "OffsetY:",
            mapPattern.offset.y
            );

        position.y += EditorGUIUtility.singleLineHeight;
        usedHeight += EditorGUIUtility.singleLineHeight;

        if (newWidth != mapPattern.Width || newHeight != mapPattern.Height)
        {
            GUI.changed = true;
            mapPattern.Resize(newWidth, newHeight);
        }
        else
        {
            GUI.changed = false;
        }

        float xWidth = Mathf.Min(
            position.width / Mathf.Max(1, mapPattern.Width),
            position.width / Mathf.Max(1, mapPattern.Height)
            );

        xWidth = Mathf.Min(xWidth, 40);

        GUIStyle fontStyle = new GUIStyle(EditorStyles.textField);

        fontStyle.fontSize = Mathf.FloorToInt(xWidth * 0.7f);

        // Draw map offset
        EditorGUI.DrawRect(new Rect(
                               position.x + mapPattern.offset.x * xWidth,
                               position.y + mapPattern.offset.y * xWidth,
                               (mapPattern.Width - mapPattern.offset.x * 2) * xWidth,
                               (mapPattern.Height - mapPattern.offset.y * 2) * xWidth
                               ), Color.red);


        for (uint x = 0; x < mapPattern.Width; x++)
        {
            for (uint y = 0; y < mapPattern.Height; y++)
            {
                uint mapY = (uint)mapPattern.Height - 1 - y;
                int  res  = EditorGUI.IntField(
                    new Rect(
                        position.x + xWidth * x,
                        position.y + xWidth * y,
                        xWidth,
                        xWidth
                        ),
                    IndexOfTile(mapPattern.GetData(x, mapY)),
                    fontStyle
                    );

                mapPattern.SetData(x, mapY, tileTypes[res]);
            }
        }

        usedHeight += mapPattern.Height * xWidth;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(mapPattern);
        }

        return(usedHeight);
    }
Exemplo n.º 5
0
    public GameState(int desiredPlayerCount, MapPatternDefinition mapPattern)
    {
        MapPattern = mapPattern;

        WinningPlayerId      = -1;
        MapPattern           = mapPattern;
        PlayerCount          = desiredPlayerCount;
        CurrentPhase         = GamePhase.WaitingForStart;
        ResultsFromLastPhase = new List <GameResultAction>();
        ResetPhaseToWaitingForAllPlayers();

        // manually deploy units
        players = new Dictionary <int, Player>();

        for (var i = 0; i < PlayerCount; i++)
        {
            var player = new Player {
                name = "Player " + (i + 1), id = i
            };
            player.units = new Dictionary <int, Unit>();
            players.Add(i, player);
        }

        var unitCounter             = 0;
        var unitContainerGameObject = GameObject.Find("UnitContainer");
        var unitContainerTransform  = unitContainerGameObject.gameObject.transform;

        for (int i = 0; i < unitContainerTransform.childCount; i++)
        {
            var unitTransform           = unitContainerTransform.GetChild(i);
            var unitTransformGameObject = unitTransform.gameObject;
            var unitController          = unitTransformGameObject.GetComponent <UnitController>();

            var unitData = unitController.unitData;
            var unitName = unitTransformGameObject.name;
            if (unitName.Contains("Red") && PlayerCount > 1)
            {
                unitData.owningPlayerId = 1;
            }
            else
            {
                unitData.owningPlayerId = 0;
            }

            if (unitName.Contains("Melee"))
            {
                unitData.definitionId = "meele_unit";
            }
            else if (unitName.Contains("Range"))
            {
                unitData.definitionId = "range_unit";
            }
            else if (unitName.Contains("Tank"))
            {
                unitData.definitionId = "heavy_unit";
            }
            else if (unitName.Contains("King"))
            {
                unitData.definitionId = "king_unit";
            }

            unitData.unitId       = unitCounter++;
            unitData.position.x   = (int)unitController.gameObject.transform.position.x;
            unitData.position.y   = (int)unitController.gameObject.transform.position.y;
            unitData.healthPoints = unitData.Definition.maxHealth;
            players[unitData.owningPlayerId].units.Add(unitData.unitId, unitData);
            unitTransformGameObject.name = "units_" + unitData.unitId;
        }
    }