2021-01-29 22:56:23 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2021-01-30 22:17:05 +00:00
|
|
|
|
using UnityEngine.UI;
|
2021-01-29 22:56:23 +00:00
|
|
|
|
|
|
|
|
|
public class ObjectManager : MonoBehaviour
|
|
|
|
|
{
|
2021-01-31 01:35:47 +00:00
|
|
|
|
public enum ObjectType {Nothing, PushPull, Sign, Ladder};
|
2021-01-29 22:56:23 +00:00
|
|
|
|
public ObjectType objectType = ObjectType.Nothing;
|
|
|
|
|
private Rigidbody rigidBody;
|
2021-01-30 15:16:42 +00:00
|
|
|
|
private MeshRenderer meshRenderer;
|
|
|
|
|
private PlayerManager playerManager;
|
|
|
|
|
private bool interact = false;
|
2021-01-30 22:17:05 +00:00
|
|
|
|
public GameObject detailSign;
|
2021-01-31 01:35:47 +00:00
|
|
|
|
public List<Transform> MovePoints = new List<Transform>();
|
2021-01-29 22:56:23 +00:00
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2021-01-30 22:17:05 +00:00
|
|
|
|
if (objectType == ObjectType.Sign) {
|
|
|
|
|
MeshRenderer[] meshR = GetComponentsInChildren<MeshRenderer>();
|
|
|
|
|
if (meshR[0].materials[1] != null) {
|
|
|
|
|
meshRenderer = meshR[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meshRenderer = meshR[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-31 01:35:47 +00:00
|
|
|
|
else if (objectType == ObjectType.Ladder)
|
|
|
|
|
{
|
|
|
|
|
meshRenderer = GetComponentInChildren<MeshRenderer>();
|
|
|
|
|
}
|
2021-01-30 22:17:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meshRenderer = GetComponent<MeshRenderer>();
|
|
|
|
|
}
|
2021-01-31 03:06:54 +00:00
|
|
|
|
meshRenderer.materials[0].DisableKeyword("_EMISSION");
|
2021-01-30 15:16:42 +00:00
|
|
|
|
meshRenderer.materials[1].SetFloat ("_Outline", 0.0f);
|
|
|
|
|
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
2021-01-29 22:56:23 +00:00
|
|
|
|
rigidBody = GetComponent<Rigidbody>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2021-01-30 15:16:42 +00:00
|
|
|
|
if (interact)
|
|
|
|
|
{
|
|
|
|
|
if (objectType == ObjectType.PushPull)
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyUp(KeyCode.E))
|
|
|
|
|
{
|
2021-01-30 16:44:13 +00:00
|
|
|
|
if (playerManager.GetPushPullObject() == null && playerManager.activeAbility.Count > 0 && playerManager.activeAbility[0] == 2)
|
2021-01-30 15:16:42 +00:00
|
|
|
|
{
|
|
|
|
|
playerManager.SetPushPullObject(this.gameObject);
|
|
|
|
|
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5568628f, 0.3785397f, 0.1176471f));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
playerManager.RemovePushPullObject();
|
|
|
|
|
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
|
|
|
|
playerManager = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-30 22:17:05 +00:00
|
|
|
|
else if (objectType == ObjectType.Sign)
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyUp(KeyCode.E) && !detailSign.activeSelf)
|
|
|
|
|
{
|
|
|
|
|
detailSign.SetActive(true);
|
|
|
|
|
}
|
2021-01-31 12:06:54 +00:00
|
|
|
|
else if ((Input.GetAxisRaw("Jump") > 0 || Input.GetAxisRaw("Horizontal") != 0 || Input.GetKeyUp(KeyCode.E)) && detailSign.activeSelf)
|
2021-01-30 22:17:05 +00:00
|
|
|
|
{
|
|
|
|
|
detailSign.SetActive(false);
|
2021-01-31 12:06:54 +00:00
|
|
|
|
if (meshRenderer != null)
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.materials[0].DisableKeyword("_EMISSION");
|
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
|
|
|
|
}
|
|
|
|
|
this.GetComponent<ObjectManager>().enabled = false;
|
2021-01-30 22:17:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-30 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (playerManager != null && playerManager.GetPushPullObject() == null)
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.materials[1].SetColor("_OutlineColor", new Color(0.5276349f, 0.5566038f, 0.118147f));
|
|
|
|
|
}
|
2021-01-31 01:35:47 +00:00
|
|
|
|
if (objectType == ObjectType.PushPull)
|
2021-01-30 15:16:42 +00:00
|
|
|
|
{
|
2021-01-31 01:35:47 +00:00
|
|
|
|
if (Input.GetKeyUp(KeyCode.E))
|
2021-01-30 15:16:42 +00:00
|
|
|
|
{
|
2021-01-31 01:35:47 +00:00
|
|
|
|
if (playerManager != null)
|
|
|
|
|
{
|
|
|
|
|
playerManager.RemovePushPullObject();
|
|
|
|
|
playerManager = null;
|
|
|
|
|
}
|
2021-01-30 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-29 22:56:23 +00:00
|
|
|
|
|
2021-01-30 22:17:05 +00:00
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (other.gameObject.tag == "Player")
|
|
|
|
|
{
|
2021-01-31 12:06:54 +00:00
|
|
|
|
if (objectType == ObjectType.Sign && this.GetComponent<ObjectManager>().enabled)
|
2021-01-30 22:17:05 +00:00
|
|
|
|
{
|
|
|
|
|
playerManager = other.gameObject.GetComponent<PlayerManager>();
|
2021-01-31 12:06:54 +00:00
|
|
|
|
meshRenderer.materials[0].EnableKeyword("_EMISSION");
|
|
|
|
|
meshRenderer.materials[0].SetColor("_EmissionColor", new Color(0.2735849f, 0.2018939f, 0.09162514f) * 0.8f);
|
2021-01-30 22:17:05 +00:00
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 2.5f);
|
|
|
|
|
interact = true;
|
|
|
|
|
}
|
2021-01-31 01:35:47 +00:00
|
|
|
|
|
|
|
|
|
if (objectType == ObjectType.Ladder)
|
|
|
|
|
{
|
|
|
|
|
playerManager = other.gameObject.GetComponent<PlayerManager>();
|
|
|
|
|
playerManager.onLadder = true;
|
|
|
|
|
if (playerManager.activeAbility.Count > 0 && playerManager.activeAbility[0] == 4) {
|
|
|
|
|
playerManager.GetComponent<Rigidbody>().useGravity = false;
|
|
|
|
|
}
|
|
|
|
|
interact = true;
|
|
|
|
|
}
|
2021-01-30 22:17:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-31 05:05:43 +00:00
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (other.gameObject.tag == "Player")
|
|
|
|
|
{
|
|
|
|
|
if (objectType == ObjectType.Ladder)
|
|
|
|
|
{
|
|
|
|
|
playerManager = other.gameObject.GetComponent<PlayerManager>();
|
|
|
|
|
if (playerManager.activeAbility.Count > 0 && playerManager.activeAbility[0] == 4)
|
|
|
|
|
{
|
|
|
|
|
playerManager.onLadder = true;
|
|
|
|
|
playerManager.GetComponent<Rigidbody>().useGravity = false;
|
|
|
|
|
interact = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 22:17:05 +00:00
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (other.gameObject.tag == "Player")
|
|
|
|
|
{
|
2021-01-31 01:35:47 +00:00
|
|
|
|
if (objectType == ObjectType.Ladder)
|
|
|
|
|
{
|
|
|
|
|
playerManager.onLadder = false;
|
|
|
|
|
playerManager.GetComponent<Rigidbody>().useGravity = true;
|
|
|
|
|
}
|
|
|
|
|
if (meshRenderer != null) {
|
2021-01-31 12:06:54 +00:00
|
|
|
|
meshRenderer.materials[0].DisableKeyword("_EMISSION");
|
2021-01-31 01:35:47 +00:00
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
|
|
|
|
}
|
2021-01-30 22:17:05 +00:00
|
|
|
|
interact = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 15:16:42 +00:00
|
|
|
|
private void OnCollisionStay(Collision collision)
|
|
|
|
|
{
|
|
|
|
|
if (collision.gameObject.tag == "Player")
|
|
|
|
|
{
|
|
|
|
|
Vector3 hit = collision.contacts[0].normal;
|
|
|
|
|
if (hit.x != 0 && hit.y == 0)
|
|
|
|
|
{
|
|
|
|
|
playerManager = collision.gameObject.GetComponent<PlayerManager>();
|
2021-01-30 16:44:13 +00:00
|
|
|
|
if (playerManager.activeAbility.Count > 0 && playerManager.activeAbility[0] == 2)
|
|
|
|
|
{
|
2021-01-30 18:02:37 +00:00
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 0.1f);
|
2021-01-30 16:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
|
|
|
|
}
|
2021-01-30 15:16:42 +00:00
|
|
|
|
interact = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCollisionExit(Collision collision)
|
|
|
|
|
{
|
|
|
|
|
if (collision.gameObject.tag == "Player")
|
|
|
|
|
{
|
|
|
|
|
meshRenderer.materials[1].SetFloat("_Outline", 0.0f);
|
|
|
|
|
interact = false;
|
|
|
|
|
}
|
2021-01-29 22:56:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|