Esempio n. 1
0
    void DestroyLevel()
    {
        selectedElement = null;
        duplicatee = null;

        foreach (Transform t in lm.blockList) {
            Destroy(t.gameObject);
        }
        lm.blockList.Clear();

        if (lm.enemyCore != null) {
            Destroy(lm.enemyCore.gameObject);
            lm.enemyCore = null;
        }

        foreach (ShipEnemy se in lm.enemies) {
            Destroy(se.gameObject);
        }
        lm.enemies.Clear();

        if (lm.playerShip != null) {
            Destroy(lm.playerShip.gameObject);
            lm.playerShip = null;
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            if (state != State.Pause) {
                if (state == State.Test) {
                    gm.on = false;
                }

                lastState = state;
                state = State.Pause;
            }
            else {
                state = lastState;

                if (state == State.Test) {
                    gm.on = true;
                }
            }
        }

        if (state == State.Edit) {
            if (!mouseOverGUI) {
                Vector3 wMouse = GameObject.FindWithTag("MainCamera").camera.ScreenToWorldPoint(Input.mousePosition);
                wMouse = new Vector3(Mathf.Round(wMouse.x), Mathf.Round(wMouse.y), 0);

                toolPointer.position = new Vector3(Mathf.Clamp(wMouse.x, 0, lm.size.x - 1),
                                             		Mathf.Clamp(wMouse.y, 0, lm.size.y - 1), wMouse.z);

                if (Input.GetMouseButtonUp(0))
                    drag = false;

                if (selectedTool <= 2) {
                    switch (selectedTool) {
                        case 0:
                            if (Input.GetMouseButtonDown(0)) {
                                SelectElement(toolPointer.position);
                            }
                            else if (Input.GetMouseButton(0)) {
                                if (drag) {
                                    if (!lm.Occupied(toolPointer.position)) {
                                        selectedElement.transf.position = toolPointer.position;

                                        ShipBase ship = selectedElement.transf.GetComponent<ShipBase>();
                                        if (ship != null) {
                                            ship.lastPos = ship.trgtPos = selectedElement.transf.position;
                                        }
                                    }
                                }
                                else if (selectedElement != null) {
                                    LevelManager.LevelElement lastSelectedElement = selectedElement;
                                    SelectElement(toolPointer.position);

                                    if (selectedElement.transf.Equals(lastSelectedElement.transf)) {
                                        drag = true;
                                    }
                                }
                            }
                            break;
                        case 1:
                            if (Input.GetMouseButtonDown(0)) {
                                SelectElement(toolPointer.position);
                                if (selectedElement != null) {
                                    switch (selectedElement.eType) {
                                        case LevelManager.LevelElement.EType.Block:
                                            lm.blockList.Remove(selectedElement.transf);
                                            break;
                                        case LevelManager.LevelElement.EType.Player:
                                            lm.playerShip = null;
                                            break;
                                        case LevelManager.LevelElement.EType.EnemyCore:
                                            lm.enemyCore = null;
                                            break;
                                        case LevelManager.LevelElement.EType.Enemy:
                                            lm.enemies.Remove(selectedElement.transf.GetComponent<ShipEnemy>());
                                            break;
                                    }
                                    Destroy(selectedElement.transf.gameObject);
                                    selectedElement = null;
                                }
                            }
                            break;
                        case 2:
                            if (Input.GetMouseButtonDown(0)) {
                                if (duplicatee != null) {
                                    if (lm.Occupied(toolPointer.position)) {
                                        duplicatee = null;
                                        selectedElement = null;
                                    }
                                    else {
                                        Transform t = Instantiate(toolPointer, toolPointer.position, toolPointer.rotation)
                                            as Transform;
                                        t.parent = lm.holderEnemy;
                                        lm.enemies.Add(t.GetComponent<ShipEnemy>());
                                    }
                                }
                                else {
                                    SelectElement(toolPointer.position);
                                    if (selectedElement != null
                                            && selectedElement.eType == LevelManager.LevelElement.EType.Enemy) {

                                        duplicatee = selectedElement;

                                        Destroy(toolPointer.gameObject);
                                        toolPointer = Instantiate(duplicatee.transf,
                                            duplicatee.transf.position, duplicatee.transf.rotation) as Transform;

                                        selectedElement = new LevelManager.LevelElement();
                                        selectedElement.transf = toolPointer;
                                        selectedElement.eType = LevelManager.LevelElement.EType.Enemy;

                                        editDesc = false;
                                    }
                                }
                            }
                            break;
                    }
                }
                else {
                    if (Input.GetMouseButtonDown(0)) {
                        if (!lm.Occupied(toolPointer.position)) {
                            if (!(selectedTool == 4 && lm.playerShip != null) && !(selectedTool == 5 && lm.enemyCore != null)) {
                                Transform t = Instantiate(toolPointer, toolPointer.position, toolPointer.rotation)
                                    as Transform;

                                editDesc = false;

                                selectedElement = new LevelManager.LevelElement();
                                selectedElement.transf = t;

                                switch (selectedTool) {
                                    case 3:
                                        t.parent = lm.holderBlock;
                                        lm.blockList.Add(t);
                                        selectedElement.eType = LevelManager.LevelElement.EType.Block;
                                        break;
                                    case 4:
                                        t.parent = lm.transform;
                                        lm.playerShip = t.GetComponent<ShipTrianglePlayerMouse>();
                                        selectedElement.eType = LevelManager.LevelElement.EType.Player;
                                        break;
                                    case 5:
                                        t.parent = lm.transform;
                                        lm.enemyCore = t;
                                        selectedElement.eType = LevelManager.LevelElement.EType.EnemyCore;
                                        break;
                                    case 6:
                                        t.parent = lm.holderEnemy;
                                        lm.enemies.Add(t.GetComponent<ShipEnemy>());
                                        selectedElement.eType = LevelManager.LevelElement.EType.Enemy;
                                        break;
                                }
                            }
                        }
                        else {
                            print("occupied");
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
0
    void Start()
    {
        levelToBeRestarted = false;

        selLevInf.levelName = "";

        editDesc = false;

        justStarted = true;

        lastState = state = State.Pause;

        lm = GameObject.FindWithTag("LevelManager").GetComponent<LevelManager>();
        gm = GameObject.FindWithTag("GameManager").GetComponent<GameManager>();

        gm.on = false;

        mainCamera = GameObject.FindWithTag("MainCamera").camera;

        selectedElement = null;

        drag = false;

        defaultToolPrefab.renderer.material = defaultToolMaterial;
        toolPointer = Instantiate(defaultToolPrefab, new Vector3(0, 0), defaultToolPrefab.rotation)
            as Transform;

        selectedTool = 0;
        lastSelectedTool = -1;
    }
Esempio n. 4
0
    void SelectElement(Vector2 pos)
    {
        // block?
        Transform block = lm.blockList.Find(l => HlpVect.EqualInt(l.position, pos));
        if (block != null) {
            selectedElement = new LevelManager.LevelElement();
            selectedElement.transf = block;
            selectedElement.eType = LevelManager.LevelElement.EType.Block;

            editDesc = false;

            return;
        }

        // enemy?
        // using .transform.position as .trgtPos as that doesn't get updated and there's no need for it as it's set to
            // .transform.position on Start() in ShipBase.cs
        ShipEnemy shipEnemy = lm.enemies.Find(l => HlpVect.EqualInt(l.transform.position, pos));
        if (shipEnemy != null) {
            selectedElement = new LevelManager.LevelElement();
            selectedElement.transf = shipEnemy.transform;
            selectedElement.eType = LevelManager.LevelElement.EType.Enemy;

            editDesc = false;

            return;
        }

        // player?
        if (lm.playerShip != null && HlpVect.EqualInt(lm.playerShip.transform.position, pos)) {
            selectedElement = new LevelManager.LevelElement();
            selectedElement.transf = lm.playerShip.transform;
            selectedElement.eType = LevelManager.LevelElement.EType.Player;

            editDesc = false;

            return;
        }

        // enemy core?
        if (lm.enemyCore != null && HlpVect.EqualInt(lm.enemyCore.position, pos)) {
            selectedElement = new LevelManager.LevelElement();
            selectedElement.transf = lm.enemyCore;
            selectedElement.eType = LevelManager.LevelElement.EType.EnemyCore;

            editDesc = false;

            return;
        }

        selectedElement = null;
    }
Esempio n. 5
0
    void GUIStateEdit()
    {
        if (Event.current.type == EventType.Repaint) {
            mouseOverGUI = false;
        }

        Rect r = new Rect(0, trgtRes.y / 2 - guiEdit.leftBoxSize.y / 2,
            guiEdit.leftBoxSize.x, guiEdit.leftBoxSize.y);

        UpdateMouseOverGUI(r);

        GUI.BeginGroup(r, mSkin.GetStyle("box"));
            r = new Rect(0, 0, guiEdit.labelSize.x, guiEdit.labelSize.y);
            GUI.Label(r, "Levelname:");
            r = new Rect(guiEdit.labelSize.x + guiEdit.horizontalSpacing, 0, guiEdit.textFieldSize.x, guiEdit.textFieldSize.y);
            lm.levelName = GUITextField(r, lm.levelName);

            r = new Rect(0, guiEdit.labelSize.y + guiEdit.verticalSpacing, guiEdit.labelSize.x, guiEdit.labelSize.y);
            GUI.Label(r, "Levelsize:");
            r = new Rect(guiEdit.labelSize.x + guiEdit.horizontalSpacing, r.y,
                guiEdit.smallLabelSize.x, guiEdit.smallLabelSize.y);
            GUI.Label(r, "X:");
            r = new Rect(r.x + guiEdit.smallLabelSize.x + guiEdit.horizontalSpacing, r.y,
                guiEdit.smallTextFieldSize.x, guiEdit.smallTextFieldSize.y);
            lm.size.x = GUIFloatField(r, lm.size.x);
            r = new Rect(r.x + guiEdit.smallTextFieldSize.x + guiEdit.horizontalSpacing, r.y,
                guiEdit.smallLabelSize.x, guiEdit.smallLabelSize.y);
            GUI.Label(r, "Y:");
            r = new Rect(r.x + guiEdit.smallLabelSize.x + guiEdit.horizontalSpacing, r.y,
                guiEdit.smallTextFieldSize.x, guiEdit.smallTextFieldSize.y);
            lm.size.y = GUIFloatField(r, lm.size.y);
            if (GUI.changed) {
                lm.SetGrid();
            }

            r = new Rect(0, r.y + guiEdit.labelSize.y + guiEdit.verticalSpacing, guiEdit.btnSize.x, guiEdit.btnSize.y);
            if (GUI.Button(r, "Edit Description")) {
                editDesc = !editDesc;
            }
            if (editDesc)
                selectedElement = null;

            r = new Rect(0, r.y + guiEdit.btnSize.y + guiEdit.verticalSpacing,
                guiEdit.labelSize.x, guiEdit.labelSize.y);
            GUI.Label(r, "Tools:");

            r = new Rect(0, r.y + guiEdit.labelSize.y + guiEdit.verticalSpacing,
                guiEdit.toolBtnSize.x, guiEdit.toolBtnSize.y);

            r.y -= guiEdit.toolBtnSize.y;
            for (int i = 0; i < tools.Length; i++) {
                if ((i % 2) == 0) {
                    r.x = 0;
                    r.y += guiEdit.toolBtnSize.y;
                }
                else {
                    r.x = guiEdit.toolBtnSize.x + guiEdit.horizontalSpacing;
                }

                bool t = (selectedTool == i);
                t = GUI.Toggle(r, t, tools[i], mSkin.GetStyle("button"));
                if (t != (selectedTool == i)) {
                    selectedTool = i;
                }
            }
            SetTool();

        GUI.EndGroup();

        if (selectedElement != null) {
            GUIDisplaySelectedElementInfo();
        }
        else if (editDesc) {
            GUIEditLevelDesc();
        }
    }