Re: How to setup 4 Canvas/UIs.
Posted: Sun May 26, 2019 10:02 pm
Yes, like Escape. I think it makes more sense to have the general skip entry function be something like Enter, and the the entire skip conversation be Esc.
Support and discussion forum for Pixel Crushers products
https://www.pixelcrushers.com:443/phpbb/
https://www.pixelcrushers.com:443/phpbb/viewtopic.php?t=2249
Code: Select all
using PixelCrushers.DialogueSystem;
namespace WallsExample
{
/// <summary>
/// This is a version of StandardDialogueUI that adds methods to skip the
/// current dialogue entry (if its custom Skippable field is true) or
/// cancel the conversation (if the conversation's Cancelable field is true).
/// </summary>
public class WallDialogueUI : StandardDialogueUI
{
private Subtitle currentSubtitle;
public override void ShowSubtitle(Subtitle subtitle)
{
currentSubtitle = subtitle;
base.ShowSubtitle(subtitle);
}
public void SkipCurrentDialogueEntry()
{
if (isOpen && currentSubtitle != null)
{
var isSkippable = Field.LookupBool(currentSubtitle.dialogueEntry.fields, "Skippable");
if (isSkippable)
{
OnContinueConversation();
}
}
}
public void CancelCurrentConversation()
{
if (isOpen && currentSubtitle != null)
{
var conversationID = currentSubtitle.dialogueEntry.conversationID;
var isCancelable = DialogueManager.masterDatabase.GetConversation(conversationID).LookupBool("Cancelable");
if (isCancelable)
{
OnClick(null);
}
}
}
}
}
Code: Select all
using PixelCrushers.DialogueSystem;
using UnityEngine;
namespace WallsExample
{
public class Cube : MonoBehaviour
{
public bool allowJump = false;
public bool allowMove = false;
public bool allowLook = false;
public Room room;
private Rigidbody rb;
private float nextTimeAllowedToRotate;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
private void OnCollisionEnter(Collision collision)
{
Sequencer.Message("CubeLanded");
}
// Handles jump, look, and move. Also handles skip and cancel conversation.
private void Update()
{
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
var isArrowKeyPressed = (Mathf.Abs(horizontal) + Mathf.Abs(vertical)) > 0.1;
var isShiftPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
if (allowJump && Input.GetKeyDown(KeyCode.Space))
{
// Jump:
rb.AddForce(Vector3.up * 500);
Sequencer.Message("CubeJumped");
}
if (allowLook && isShiftPressed && isArrowKeyPressed && Time.time >= nextTimeAllowedToRotate)
{
// Look:
var angle = (horizontal < 0.1 || vertical < 0.1) ? -90 : 90;
room.Rotate(angle);
nextTimeAllowedToRotate = Time.time + 1; // Wait 1 second between rotations.
Sequencer.Message("CubeLooked");
}
else if (allowMove && isArrowKeyPressed)
{
// Move:
rb.MovePosition(transform.position - new Vector3(horizontal * Time.deltaTime, 0, vertical * Time.deltaTime));
Sequencer.Message("CubeMoved");
}
else if (Input.GetKeyDown(KeyCode.Return) && DialogueManager.isConversationActive)
{
foreach (var dialogueUI in FindObjectsOfType<WallDialogueUI>())
{
dialogueUI.SkipCurrentDialogueEntry();
}
}
else if (Input.GetKeyDown(KeyCode.Escape) && DialogueManager.isConversationActive)
{
foreach (var dialogueUI in FindObjectsOfType<WallDialogueUI>())
{
dialogueUI.CancelCurrentConversation();
}
}
}
// Show help text:
private void OnGUI()
{
GUILayout.Label("Enter=skip, Escape=cancel");
}
}
}
Code: Select all
using UnityEngine;
namespace WallsExample
{
public class Room : MonoBehaviour
{
public GameObject[] walls;
private void Start()
{
CheckWallVisibility();
}
public void Rotate(float angle)
{
transform.Rotate(new Vector3(0, angle, 0));
CheckWallVisibility();
}
private void CheckWallVisibility()
{
// Use dot product to decide if front of each wall is visible:
foreach (var wall in walls)
{
var forward = wall.transform.forward;
var toCamera = Camera.main.transform.position - wall.transform.position;
var isFrontVisible = Vector3.Dot(forward, toCamera) >= 0;
wall.SetActive(isFrontVisible);
}
}
}
}
Code: Select all
using UnityEngine;
namespace WallsExample
{
public class MrSceneManager : MonoBehaviour
{
private Cube cube;
private void Awake()
{
cube = FindObjectOfType<Cube>();
}
public void CubeDrop()
{
cube.GetComponent<Rigidbody>().useGravity = true;
}
public void CubeCanJump()
{
cube.allowJump = true;
}
public void CubeCanMove()
{
cube.allowMove = true;
}
public void CubeCanLook()
{
cube.allowLook = true;
}
}
}