Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //hideCursor();

        configureStamp();

        mouse0click += Time.deltaTime;

        if (nextState != currentState)
        {
            currentState = nextState;
            // Set the states and reset this bitch
            //return;
        }

        // Global key swtiches for the state machine.
        if (Input.GetKeyDown(KeyCode.P))
        {
            sceneManager.Save();
            this.Save();
        }

        if (Input.GetKeyDown(KeyCode.L))
        {
            if (currentState == State.StartSceneLoader)
            {
                cleanSceneLoaderWindow();
                setNextState(State.FreeMove);
            }
            else
            {
                setNextState(State.StartSceneLoader);
            }
            return;
        }

        // Create room
        if (Input.GetKeyDown(KeyCode.C))
        {
            if (currentState == State.StartCreateRoom)
            {
                setNextState(State.FreeMove);
            }
            else
            {
                setNextState(State.StartCreateRoom);
            }
        }

        // Global key swtiches for the state machine.
        if (Input.GetKeyDown(KeyCode.R))
        {
            if (currentState == State.StartManageRooms || currentState == State.StartCreateRoom)
            {
                setNextState(State.FreeMove);
            }
            else
            {
                setNextState(State.StartManageRooms);
            }
        }

        // Setup state machine...
        switch (currentState)
        {
        case State.StartSceneLoader:
            if (sceneLoaderWindow != null)
            {
                sceneLoaderWindow.Update();
            }
            break;

        case State.FreeMove:
            // if we are removing all windows, delete them bitches. ...
            cleanBuilderWindow1();
            cleanBuilderWindow2();
            break;

        //case State.EditObjectTexture:
        //	showCursor();
        //	break;
        case State.StartManageRooms:
            if (sceneManager.getRoomCount() == 0)
            {
                setNextState(State.StartCreateRoom);
                break;
            }
            if (builderWindow != null)
            {
                builderWindow.Update();
            }
            if (builderWindow2 != null)
            {
                builderWindow2.Update();
            }
            break;

        case State.StartCreateRoom:
            break;

        case State.EndCreateRoom:
            // Cleanup after room window is success
            cleanBuilderWindow1();
            if (sceneManager.getRoomCount() == 0)
            {
                setNextState(State.FreeMove);
            }
            else
            {
                setNextState(State.StartManageRooms);
            }
            break;

        case State.ObjectSelection:
            break;
        }

        onWindow = false;

        if (builderWindow != null)
        {
            onWindow = builderWindow.isMouseOver();
        }
        if (!onWindow && builderWindow2 != null)
        {
            onWindow = builderWindow2.isMouseOver();
        }

        if (!onWindow && sceneLoaderWindow != null)
        {
            onWindow = sceneLoaderWindow.isMouseOver();
        }

        // If we are not currently over a menu, we will allow the user to click
        // and do shit on the screen...
        if (!onWindow)
        {
            registerZoom();
            doZoom();
            UpdateStamp();
            doDrag();

            // If there are no rooms, we can't have a stamp now can we.. fuckk.
            if (sceneManager.getRoomCount() == 0)
            {
                //stampGO.SetActive(false);
                return;
            }

            // If right click, we are going to disable the stamp from following..
            if (Input.GetMouseButtonDown(1))
            {
                canControlStamp = !canControlStamp;
            }
            // If left click, add current object.
            if (Input.GetMouseButton(0))
            {
                // If tile
                if (stampType == 0)
                {
                    if (!mouse0click.Equals(stampSprite.getPosition().x + "_" + stampSprite.getPosition().y))
                    {
                        mouse0click = stampSprite.getPosition().x + "_" + stampSprite.getPosition().y;
                        ItemData item = new ItemData(stampSprite, Constants.ITEM_TYPES.TILE);
                        sceneManager.AddItemToRoom(item);
                        sceneManager.processCurrentRoom();
                    }
                }
                // if collider
                if (stampType == 2)
                {
                    if (!mouse0click.Equals(stampSprite.getPosition().x + "_" + stampSprite.getPosition().y))
                    {
                        mouse0click = stampSprite.getPosition().x + "_" + stampSprite.getPosition().y;
                        if (colliderType == 0)
                        {
                            ItemData item = new ItemData(stampSprite, Constants.ITEM_TYPES.COLLIDER_SQUARE);
                            sceneManager.AddItemToRoom(item);
                            sceneManager.processCurrentRoom();
                        }
                        else if (colliderType == 1)
                        {
                            ItemData item = new ItemData(stampSprite, Constants.ITEM_TYPES.COLLIDER_RAMP);
                            sceneManager.AddItemToRoom(item);
                            sceneManager.processCurrentRoom();
                        }
                        else
                        {
                            // it is nothing...
                        }
                    }
                }
                // Delete
                if (stampType == 3)
                {
                    sceneManager.RemoveItemFromRoom(stampSprite.getPosition().x, stampSprite.getPosition().y);
                    sceneManager.processCurrentRoom();
                }
            }
            // If right click, delete object. if (Input.GetMouseButton(1)){}
        }
        else
        {
        }
    }