Esempio n. 1
0
    // Add a new sprite temporarily for the house being constructed
    private void DisplayNewComponent(Vector3 newLocation, string component)
    {
        // Create the new game object while construction takes place
        // reate a new game object with the name part [number]
        GameObject nextPart = new GameObject("Part " + count);

        count++;
        // Attach the parent to the currently being built house component list
        nextPart.transform.parent = GameObject.Find("building a house").transform;
        // Create a new sprite renderer and attach it to the new part!
        SpriteRenderer sr = nextPart.AddComponent <SpriteRenderer>();

        sr.sprite = GetSpriteFromString(component);
        // if it is a floor component move it to the back
        if (currentView.GetComponentTypeFromString(component).type.Contains("floor"))
        {
            sr.sortingOrder = -1;
        }
        // Give it the appropriate coordinates (scale x and y by the appropriate amount)
        newLocation.Scale(new Vector3(GAME_UNITS_PER_TILE, GAME_UNITS_PER_TILE, 1));
        // For border components, and floor-offset components offset by half a tile else if it is vertical shift up, horizontal shift right
        if (currentView.GetComponentTypeFromString(component).type == "border" || currentView.GetComponentTypeFromString(component).type == "floor-offset")
        {
            if (vertical)
            {
                newLocation.y += GAME_UNITS_PER_TILE / 2f;
            }
            else
            {
                newLocation.x += GAME_UNITS_PER_TILE / 2f;
            }
        }
        else
        {
            if (vertical)
            {
                newLocation.x += Math.Max(currentView.GetComponentTypeFromString(component).area.y, 1);
                newLocation.y += Math.Max(currentView.GetComponentTypeFromString(component).area.x, 1);
            }
            else
            {
                newLocation.x += Math.Max(currentView.GetComponentTypeFromString(component).area.x, 1);
                newLocation.y += Math.Max(currentView.GetComponentTypeFromString(component).area.y, 1);
            }
        }
        nextPart.transform.localPosition = newLocation;
        // Scale the new sprite to the world's scale
        nextPart.transform.localScale = new Vector3(PIXEL_TO_UNIT_CONVERSION, PIXEL_TO_UNIT_CONVERSION, 1);
    }