Exemplo n.º 1
0
    public void clickNanobot(Nanobot nanobotPrefab)
    {
        if (SoundManager.instance != null)
        {
            SoundManager.instance.PlaySingle(GetComponent <AudioSource>(), selectBotSound);
        }

        if (mouseFollowingSprite != null)
        {
            Destroy(mouseFollowingSprite);
        }

        this.nanobotPrefab   = nanobotPrefab;
        mouseFollowingSprite = new GameObject();
        mouseFollowingSprite.AddComponent <SpriteRenderer>().sprite       = nanobotPrefab.GetComponent <SpriteRenderer>().sprite;
        mouseFollowingSprite.GetComponent <SpriteRenderer>().sortingOrder = 3;
        mouseFollowingSprite.transform.localScale = new Vector3(0.5f, 0.5f, 1);
        Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mouseFollowingSprite.transform.position = new Vector3(position.x, position.y, mouseFollowingSprite.transform.position.z);
        CellHighlighter.triggerHighlights();
    }
Exemplo n.º 2
0
    public IEnumerator moveBotAnimatedCoroutine(GridPosition source, Nanobot nanobot, GridPosition offset, int durationInTicks, bool grow, bool die)
    {
        bool       destroyBot = false;
        GameObject bot;

        if (die)
        {
            bot        = nanobot.gameObject;
            destroyBot = true;
        }
        else
        {
            bot = moveBot(source, nanobot, offset);
            if (bot == null)
            {
                destroyBot = true;
            }
        }

        // make a fake bot to animate, to handle things getting destroyed
        GameObject fakeBot = new GameObject();

        fakeBot.AddComponent <SpriteRenderer>().sprite = nanobot.GetComponent <SpriteRenderer>().sprite;
        fakeBot.transform.localScale = nanobot.transform.localScale;
        if (bot != null)
        {
            bot.GetComponent <SpriteRenderer>().enabled = false;
        }

        Vector2 initialPosition = gridPositionToWorldPosition(source);
        Vector2 finalPosition   = gridPositionToWorldPosition(source + offset);
        Vector2 movement        = finalPosition - initialPosition;

        for (int i = 0; i < durationInTicks; i++)
        {
            fakeBot.transform.position = initialPosition + (((float)i + 1) / durationInTicks) * movement;
            yield return(null);
        }
        fakeBot.transform.position = finalPosition;

        // make the bot shrink to nothing all the time (if it's going to get destroyed) as a first approx
        if (destroyBot || bot == null)
        {
            if (SoundManager.instance != null)
            {
                if (!destroyBot)
                {
                    SoundManager.instance.PlaySingle(GetComponent <AudioSource>(), crashSound);
                }
                else
                {
                    SoundManager.instance.RandomizeSfx(GetComponent <AudioSource>(), fallSound);
                }
            }

            yield return(null);

            Vector3 initialScale = fakeBot.transform.localScale;
            for (int i = 0; i < durationInTicks * 2; i++)
            {
                fakeBot.transform.localScale = initialScale * ((float)(durationInTicks * 2 - i) / (durationInTicks * 2));
                yield return(null);
            }
        }

        Destroy(fakeBot);
        if (bot != null)
        {
            bot.GetComponent <SpriteRenderer>().enabled = true;
        }
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        handler   = GameObject.FindObjectOfType <PlacementMenuHandler>();
        resources = GameObject.FindObjectOfType <Resources>();

        if (nanobot == null)
        {
            // Init empty disabled button
            Destroy(transform.FindChild("Image").gameObject);
            Destroy(transform.FindChild("SchematicGrid").gameObject);
            foreach (Text text in transform.GetComponentsInChildren <Text>())
            {
                text.text = "";
            }
            GetComponent <Button>().interactable = false;
        }
        else
        {
            // Init functioning button
            transform.FindChild("Image").GetComponent <Image>().sprite = nanobot.GetComponent <SpriteRenderer>().sprite;
            foreach (Text text in transform.GetComponentsInChildren <Text>())
            {
                if (text.gameObject.name.Equals("ID"))
                {
                    text.text = nanobot.id;
                    _id       = nanobot.id;
                }
                else if (text.gameObject.name.Equals("Price"))
                {
                    text.text = "" + nanobot.price;
                }
            }

            Transform schematicGrid = transform.FindChild("SchematicGrid");
            for (int x = 0; x < 3; x++)
            {
                Nanobot[] schematicColumn = null;
                switch (x)
                {
                case 0:
                    schematicColumn = nanobot.schematic.transformationColumn1;
                    break;

                case 1:
                    schematicColumn = nanobot.schematic.transformationColumn2;
                    break;

                case 2:
                    schematicColumn = nanobot.schematic.transformationColumn3;
                    break;

                default:
                    break;
                }

                for (int y = 0; y < 3; y++)
                {
                    Text text = schematicGrid.FindChild("Text_" + x + y).gameObject.GetComponent <Text>();

                    text.text = schematicColumn[y] == null ? "" : schematicColumn[y].id;
                }
            }
        }
    }