예제 #1
0
    void Update()
    {
        distance += Input.GetAxis("Mouse ScrollWheel");
        Vector3 ppp = cameraObj.transform.position + cameraObj.transform.forward * distance;

        position = new Vector3Int((int)ppp.x, (int)ppp.y, (int)ppp.z);
        ghost.transform.position = position;
        ghost.transform.rotation = Quaternion.identity;
        if (Input.GetKeyDown(KeyCode.RightBracket) || Input.GetKeyDown(KeyCode.V))
        {
            partType = (ColPriv)((int)partType & 0xFF);

            partType = (ColPriv)(((int)partType + 1) % (int)ColPriv.COUNT);

            ResetGhost();
        }
        if (Input.GetKeyDown(KeyCode.LeftBracket) || Input.GetKeyDown(KeyCode.C))
        {
            partType = (ColPriv)((int)partType & 0xFF);
            partType = (ColPriv)(((int)partType - 1 + (int)ColPriv.COUNT) % (int)ColPriv.COUNT);
            ResetGhost();
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            position.x++;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            position.x--;
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            position.z++;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            position.z--;
        }
        if (Input.GetKeyDown(KeyCode.Period))
        {
            position.y++;
        }
        if (Input.GetKeyDown(KeyCode.Comma))
        {
            position.y--;
        }
        if (Input.GetKeyDown(KeyCode.Quote))
        {
            buildonly = !buildonly;
            ResetGhost();
        }
        if (Input.GetKeyDown(KeyCode.BackQuote))
        {
            partType = ColPriv.CUBE; ResetGhost();
        }                                                                                            // `: CUBE
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            partType = ColPriv.PX_NY_PRISM; ResetGhost();
        }                                                                                         // 1: PRISM
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            partType = ColPriv.PX_PZ_NY_TETRA; ResetGhost();
        }                                                                                         // 2: TETRA
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            partType = ColPriv.PX_PY_PZ_INNER; ResetGhost();
        }                                                                                         // 3: INNER
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            partType = ColPriv.PX_SLAB; ResetGhost();
        }                                                                                         // 4: HALFSLAB
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            partType = ColPriv.PX_NY_COVER; ResetGhost();
        }                                                                                         // 5: PRISM COVER
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            partType = ColPriv.PX_PZ_NY_COVER; ResetGhost();
        }                                                                                         // 6: TETRA COVER
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            partType = ColPriv.PX_PZ_NY_INCOV; ResetGhost();
        }                                                                                         // 7: INNER COVER
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            partType = ColPriv.X_PILLAR; ResetGhost();
        }                                                                                         // 8: MISC RECTANGLES
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            partType = ColPriv.X_RIDGE_NY; ResetGhost();
        }                                                                                         // 9: CENTERED RIDGE
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            partType = ColPriv.PX_PZ_FACENY_SLOPESIDE; ResetGhost();
        }                                                                                                  // 0: SLOPESIDE

        if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.S))
        {
            Debug.LogError("SAVED MODEL");
            Output();
        }
        if (Input.GetKey(KeyCode.RightCommand) && Input.GetKeyDown(KeyCode.S))
        {
            Debug.LogError("Saving from gameobjects");
            LoadShapesFromGameObjects();
            Output();
        }
        if (Input.GetKeyDown(KeyCode.Insert))
        {
            StartCoroutine(Rotate((byte)UnityEngine.Random.Range(0, 63)));
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            StartCoroutine(Rotate(BlockData.AssembleRotation(Quaternion.Euler(90, 0, 0))));
        }
        if (Input.GetKeyDown(KeyCode.Y))
        {
            StartCoroutine(Rotate(BlockData.AssembleRotation(Quaternion.Euler(0, 270, 0))));
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
            StartCoroutine(Rotate(BlockData.AssembleRotation(Quaternion.Euler(0, 0, 180))));
        }


        if (Input.GetKeyDown(KeyCode.Equals))
        {
            StartCoroutine(Reload());
        }
        if (Input.GetKeyDown(KeyCode.Delete))
        {
            Clear();
        }

        if (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Mouse1))
        {
            for (int i = 0; i < shapes.Count; ++i)
            {
                if (shapes[i].Key.Equals(position))
                {
                    shapes.RemoveAt(i);
                    foreach (var thing in manifest[position])
                    {
                        Destroy(thing);
                    }
                    manifest.Remove(position);
                    break;
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            foreach (var t in shapes)
            {
                if (t.Key == position && !Input.GetKey(KeyCode.LeftControl))
                {
                    return;
                }
            }
            shapes.Add(new KeyValuePair <Vector3Int, ColPriv>(position, partType));
            GameObject g = Instantiate(ghost);
            g.GetComponent <MeshRenderer>().material = whitetrans;
            if (buildonly)
            {
                g.GetComponent <MeshRenderer>().material = lightgreen;
            }
            if (!manifest.ContainsKey(position))
            {
                manifest[position] = new List <GameObject>();
            }
            manifest[position].Add(g);
        }
    }