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);
     }
 }
예제 #2
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);
                }
            }
        }
    }