Beispiel #1
0
    /// <summary>
    /// Fades out and removes all current task objects.
    /// </summary>
    /// <param name="callback">Is called afterwards</param>
    private void FadeOutAndRemoveTaskObjects(TweenCallback callback = null, bool addTeleport = false)
    {
        Sequence mySequence = DOTween.Sequence();

        mySequence.AppendCallback(() => grabEnabled = false);
        mySequence.AppendCallback(RemoveAllInteractableComponents);
        mySequence.AppendCallback(() =>
                                  currentTechnique.BroadcastMessage("FadeOutAndRemoveTaskObjectsStart", SendMessageOptions.DontRequireReceiver));
        mySequence.AppendCallback(() => SetHandsActive(false));
        mySequence.AddMaterialsFade(prefabMaterials, 0, 0.25f);
        mySequence.AddMaterialsFade(transparentPrefabMaterials, 0f, 0.25f, true);
        mySequence.AppendCallback(RemoveAllObjects);
        if (addTeleport)
        {
            AddTeleport(mySequence);
        }
        if (callback != null)
        {
            mySequence.AppendCallback(callback);
        }
        mySequence.AppendCallback(() => SetHandsActive(true));
        mySequence.AppendCallback(() =>
                                  currentTechnique.BroadcastMessage("FadeOutAndRemoveTaskObjectsEnd", SendMessageOptions.DontRequireReceiver));
        mySequence.AppendCallback(() => isMovingOn = false);
        mySequence.Play();
    }
Beispiel #2
0
    /// <summary>
    /// Fades in the next task objects.
    /// </summary>
    private void FadeInNextTaskObjects()
    {
        Sequence mySequence = DOTween.Sequence();

        mySequence.AppendCallback(CreateNextTaskObjects);
        mySequence.AppendCallback(InformNextTaskObjectsCreated);
        mySequence.AddMaterialsFade(prefabMaterials, 1, 0.25f);
        mySequence.AddMaterialsFade(transparentPrefabMaterials, 0.5f, 0.25f, true);
        mySequence.AppendCallback(() => grabEnabled     = true);
        mySequence.AppendCallback(() => taskIsFinishing = false);
        mySequence.Play();
    }
Beispiel #3
0
    /// <summary>
    /// Makes the grid objects completely visible.
    /// </summary>
    private void ResetGridObjectsMaterials()
    {
        Sequence sequence = DOTween.Sequence();

        sequence.AddMaterialsFade(materialMap.Where((e, i) => i % 2 == 1).ToList(), 1f, 0);
        sequence.Play();
    }
Beispiel #4
0
    /// <summary>
    /// Called in TaskController when task objects are started to faded out.
    /// </summary>
    private void FadeOutAndRemoveTaskObjectsStart()
    {
        Sequence sequence = DOTween.Sequence();

        sequence.AddMaterialsFade(materialMap.Where((e, i) => i % 2 == 1).ToList(), 0f, transitionDuration);
        sequence.Play();
        selectionCone.active = false;
        inTransition         = true;
    }
Beispiel #5
0
    /// <summary>
    /// Arranges oll objects in the selection cone in grid.
    /// </summary>
    private void ArrangeObjects()
    {
        // ensure that arranged objects are visible
        ResetGridObjectsMaterials();

        // rotate the grid so is fits the rotation of the head
        grid.rotation = Quaternion.LookRotation(head.forward, Vector3.up);

        // set the position of the grid so it is centered in the view of the user
        int gridSize = (int)Mathf.Ceil(Mathf.Sqrt(selectionCone.interactablesInSelection.Count));

        grid.position = head.position + head.forward * gridDistanceFromUser;
        float moveOffset = (gridSize - 1) *
                           (spaceBetweenObjects + selectionCone.interactablesInSelection[0].transform.localScale.x) / 2;

        grid.position += new Vector3(-moveOffset, moveOffset, 0);

        // move copies of the objects in the selection cone smoothly to there grid position while the originals get transparent
        inTransition = true;
        Sequence sequence = DOTween.Sequence();

        sequence.AddMaterialsFade(materialMap.Where((e, i) => i % 2 == 0).ToList(), 0.25f, transitionDuration);
        objMap = new Dictionary <GameObject, GameObject>();
        List <GameObject> sortedInteractables = SortForGrid(selectionCone.interactablesInSelection);

        for (int i = 0; i < sortedInteractables.Count; i++)
        {
            GameObject clone = Instantiate(sortedInteractables[i].gameObject, grid, true);
            sequence.Join(clone.transform.DOLocalMove(GetGridObjectPosition(i, gridSize, clone.transform.lossyScale.x),
                                                      transitionDuration));
            objMap.Add(sortedInteractables[i], clone);
        }

        // change materials of the grid objects so they stay solid when all other objects are transparent
        foreach (MeshRenderer meshRenderer in grid.GetComponentsInChildren <MeshRenderer>(true))
        {
            for (int i = 0; i < materialMap.Length; i += 2)
            {
                if (meshRenderer.sharedMaterial == materialMap[i])
                {
                    meshRenderer.material = materialMap[i + 1];
                }
            }
        }
        sequence.AppendCallback(() => inTransition = false);
        sequence.Play();

        // change to grid phase
        selectionCone.inGridPhase = true;

        // ensure that only the objects in the grid can be highlighted and selected
        selectionCone.selectableInteractables = objMap.Values.ToList();

        // deselect all objects which are not in the grid
        selectionCone.DeselectAll();
    }
Beispiel #6
0
    /// <summary>
    /// Moves all objects in the grid to there original position and delete them when they reached there target.
    /// </summary>
    private void ReturnObjects()
    {
        inTransition         = true;
        selectionCone.active = false;
        Sequence sequence = DOTween.Sequence();

        foreach (KeyValuePair <GameObject, GameObject> keyValue in objMap)
        {
            sequence.Join(keyValue.Value.transform.DOMove(keyValue.Key.transform.position, transitionDuration));
        }
        sequence.AddMaterialsFade(materialMap.Where((e, i) => i % 2 == 0).ToList(), 1, transitionDuration, true);
        sequence.AppendCallback(delegate
        {
            inTransition = false;
            objMap.Values.ForEach(DestroyImmediate);
            objMap = new Dictionary <GameObject, GameObject>();
            selectionCone.Reset();
            selectionCone.selectableInteractables = TaskController.Instance.currentGameObjects;
        });
        sequence.Play();
    }