示例#1
0
    public static void LoadMap(string path)
    {
        if (File.Exists(path))
        {
            try
            {
                var bf     = new BinaryFormatter();
                var file   = File.Open(path, FileMode.Open);
                var blocks = (SerBlock[])bf.Deserialize(file);
                file.Close();

                //SceneManager.sceneLoaded += (x, y) => { FinishLoad(x, y, blocks); };
                //SceneManager.LoadScene("levelEditor", LoadSceneMode.Single);

                BlockManipulator.DestroyAll();

                for (int i = 0; i < blocks.Length; i++)
                {
                    TileSpawner.SpawnFull(blocks[i].info, (Vector3)blocks[i].pos, blocks[i].Blendshapes, (Vector3)blocks[i].rot, false);
                }
            }
            catch (System.Exception ex)
            {
                Debug.Log("Uh oh error while loading.");
                Debug.Log(ex.Message);
            }
        }
    }
 void SetBlendshape(int id, float amount)
 {
     try {
         var allInfos = BlockManipulator.GetSelectedInfos();
         for (int i = 0; i < allInfos.Length; i++)
         {
             var rends = allInfos [i].GetComponentsInChildren <SkinnedMeshRenderer> ();
             if (rends.Length == 0)
             {
                 continue;
             }
             if (allInfos [i].Blendshapes == null)
             {
                 allInfos [i].Blendshapes = new float[currRend.sharedMesh.blendShapeCount];
             }
             allInfos [i].Blendshapes [id] = amount;
             for (int j = 0; j < rends.Length; j++)
             {
                 rends [j].SetBlendShapeWeight(id, amount);
             }
         }
     } catch (System.Exception ex) {
         Debug.Log("Error while setting blendshapes, probably models with different Blendshape counts");
         Debug.Log(ex);
     }
 }
示例#3
0
        public void Setup()
        {
            _data     = Encoding.UTF8.GetBytes("Quod Erat Dimanstrandum");
            _password = Encoding.UTF8.GetBytes(
                "If you immediately know the dimalight is fire, then the security was cooked a long time ago.");

            var bitConverter     = new FastBitConverter();
            var keyGenerator     = new KeyGenerator(bitConverter);
            var blockManipulator = new BlockManipulator();

            _tea    = new BlackTeaCryptoServiceProvider(blockManipulator, keyGenerator, bitConverter);
            _cipher = _tea.EncryptRaw(_data, _password);
        }
示例#4
0
 public void SpawnNormal()
 {
     if (variations != null && variations.Length > 0)
     {
         var go  = Instantiate(variations [info.Variation]);
         var pos = GridPlaneControl.LookIntersect();
         pos = new Vector3(Round.ToFour(pos.x), Round.ToThreePointSix(pos.y), Round.ToFour(pos.z));
         go.transform.position = pos;
         var iOnBlock = go.AddComponent <InfoOnBlock> ();
         var newInfo  = info;
         newInfo.MyTileKind = TileKind.Normal;
         iOnBlock.Info      = newInfo;
         BlockManipulator.SelectItem(go);
     }
 }
示例#5
0
        public void TestEncryptDecrypt()
        {
            var bitConverter     = new FastBitConverter();
            var keyGenerator     = new KeyGenerator(bitConverter);
            var blockManipulator = new BlockManipulator();
            var tea = new BlackTeaCryptoServiceProvider(blockManipulator, keyGenerator, bitConverter);

            var password = Encoding.UTF8.GetBytes("Quod Erat Dimanstrandum");
            var data     = Encoding.UTF8.GetBytes(
                "If you immediately know the dimalight is fire, then the security was cooked a long time ago.");

            var cipher = tea.EncryptRaw(data, password);
            var plain  = tea.DecryptRaw(cipher, password);

            Assert.IsTrue(plain.SequenceEqual(data));
        }
示例#6
0
        public void TestDeterministicOutput()
        {
            var bitConverter     = new FastBitConverter();
            var keyGenerator     = new KeyGenerator(bitConverter);
            var blockManipulator = new BlockManipulator();
            var tea = new BlackTeaCryptoServiceProvider(blockManipulator, keyGenerator, bitConverter);

            var passwordBytes = new byte[16];
            var dataBytes     = new byte[16];

            for (var i = 0; i < 10000; i++)
            {
                Guid.NewGuid().TryWriteBytes(passwordBytes);
                Guid.NewGuid().TryWriteBytes(dataBytes);

                var cipher = tea.EncryptRaw(dataBytes, passwordBytes);
                var plain  = tea.DecryptRaw(cipher, passwordBytes);

                Assert.IsTrue(plain.SequenceEqual(dataBytes));
            }
        }
示例#7
0
    void Update()
    {
        if (SaveAndLoad.GetInputField().isFocused)
        {
            return;
        }
        var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //Shortcuts
        if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown(KeyCode.Plus))
        {
            manip.NextVariation();
        }
        if (Input.GetKeyDown(KeyCode.KeypadMinus) || Input.GetKeyDown(KeyCode.Minus))
        {
            manip.PrevVariation();
        }
        if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.back * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Keypad8))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.forward * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Keypad4))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.left * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Keypad6))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.right * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Keypad7))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.down * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Keypad9))
        {
            var infos = BlockManipulator.GetSelectedInfos();
            BlockManipulator.DeselectAll();

            for (int i = 0; i < infos.Length; i++)
            {
                TileSpawner.SpawnFull(infos [i].Info, infos [i].transform.position + Vector3.up * 4f, infos[i].Blendshapes, infos[i].transform.rotation.eulerAngles);
            }
        }
        if (Input.GetKeyDown(KeyCode.Delete))
        {
            manip.DestroySelected();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                manip.MoveSelectedBy(Vector3.left * 4f);
            }
            else
            {
                manip.MoveSelectedBy(Vector3.right * 4f);
            }
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                manip.MoveSelectedBy(Vector3.down * 4f);
            }
            else
            {
                manip.MoveSelectedBy(Vector3.up * 4f);
            }
        }
        if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Y))
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                manip.MoveSelectedBy(Vector3.back * 4f);
            }
            else
            {
                manip.MoveSelectedBy(Vector3.forward * 4f);
            }
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            manip.SetMoveInGrid(!BlockManipulator.moveInGrid);
            snapToggle.isOn = !snapToggle.isOn;
        }
        if (BlockManipulator.moveInGrid)
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                manip.RotateSelectedBy(new Vector3(0, -90, 0));
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                manip.RotateSelectedBy(new Vector3(0, 90, 0));
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.Q))
            {
                manip.RotateSelectedBy(new Vector3(0, 30 * Time.deltaTime, 0));
            }
            else if (Input.GetKey(KeyCode.E))
            {
                manip.RotateSelectedBy(new Vector3(0, -30 * Time.deltaTime, 0));
            }
        }
        if (Input.GetMouseButton(0))
        {
            if (moving != null)
            {
                moving.Move();
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (moving != null)
            {
                moving.EndMove();
            }
            moving = null;
        }

        if (EventSystem.current.IsPointerOverGameObject())          //is mouse over UI
        {
            return;
        }

        if (Physics.Raycast(ray, out hit, 100f, controlsMask))
        {
            if (Input.GetMouseButton(0))
            {
                manip.SetManipulating(true);
            }
            if (Input.GetMouseButtonDown(0))
            {
                var m = hit.collider.GetComponent <MoveSelected> ();
                if (m != null)
                {
                    m.StartMove();
                }
                moving = m;
            }
        }

        if (!BlockManipulator.IsManipulating && Physics.Raycast(ray, out hit, 100f, objectMask))
        {
            if (grid != null)
            {
                grid.Move(hit.point);
            }
        }
        if (!BlockManipulator.IsManipulating && Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(ray, out hit, 100f, objectMask))
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    BlockManipulator.AddSelectItem(hit.collider.gameObject);
                }
                else
                {
                    BlockManipulator.SelectItem(hit.collider.gameObject.transform.root.gameObject);
                }
            }
        }
    }
示例#8
0
    public static void SpawnFull(BlockInfo info, Vector3 pos, float[] Blendshapes, Vector3 rot, bool addSelect = true)
    {
        var block = ListBlockTypes.AllBlocks.types [info.BlockId];

        GameObject[] tile = null;
        switch (info.TileTypeId)
        {
        case 0:
            switch (info.MyTileKind)
            {
            case TileKind.Normal:
                tile = block.wallTiles [info.UpperVariation].variations;
                break;

            case TileKind.InnerCorner:
                tile = block.wallTiles [info.UpperVariation].innerCorners;
                break;

            case TileKind.OuterCorner:
                tile = block.wallTiles [info.UpperVariation].outerCorners;
                break;

            default:
                break;
            }
            break;

        case 1:
            switch (info.MyTileKind)
            {
            case TileKind.Normal:
                tile = block.floorTiles [info.UpperVariation].variations;
                break;

            case TileKind.InnerCorner:
                tile = block.floorTiles [info.UpperVariation].innerCorners;
                break;

            case TileKind.OuterCorner:
                tile = block.floorTiles [info.UpperVariation].outerCorners;
                break;

            default:
                break;
            }
            break;

        case 2:
            switch (info.MyTileKind)
            {
            case TileKind.Normal:
                tile = block.ceilingTiles [info.UpperVariation].variations;
                break;

            case TileKind.InnerCorner:
                tile = block.ceilingTiles [info.UpperVariation].innerCorners;
                break;

            case TileKind.OuterCorner:
                tile = block.ceilingTiles [info.UpperVariation].outerCorners;
                break;

            default:
                break;
            }
            break;

        case 3:
            tile = block.traps;
            break;

        case 4:
            tile = block.puzzles;
            break;

        case 5:
            tile = block.other;
            break;

        default:
            break;
        }

        if (tile.Length == 0)
        {
            return;
        }

        info.Variation += 10 * tile.Length;
        info.Variation %= tile.Length;

        var go = Instantiate(tile [info.Variation]);

        go.transform.position = pos;
        if (rot != Vector3.zero)
        {
            go.transform.rotation = Quaternion.Euler(rot);
        }
        var iOb = go.AddComponent <InfoOnBlock> ();

        iOb.Info        = info;
        iOb.Blendshapes = Blendshapes;
        if (iOb.Blendshapes != null)
        {
            BlendshapeEditor.ApplyAll(iOb.GetComponent <SkinnedMeshRenderer> (), iOb);
        }

        if (addSelect)
        {
            BlockManipulator.AddSelectItem(go);
        }
    }
 private void Start()
 {
     instance   = this;
     moveInGrid = true;
     ShowHandles();
 }