using System.Collections; using System.Collections.Generic; using UnityEngine; using InfallibleCode; public class ItemsInHandsData : MonoBehaviour { public bool CanGetLamp = true; public bool HasLampInHands; public Transform playerLeftHandPOS; public Transform CurrentBulb; public LightBulbEmissionUpdate CurrentLightBulbEmissionUpdate; public SanityActivation CurrentBulbSanityActivation; public float ChangeBulb_LerpItem; public Quaternion _bulbRotationInHands; public LeaveLampInHolder CurrentLeaveLampInHolder; public List CurrentBulbLight; private static ItemsInHandsData _instance; public static ItemsInHandsData GetInstance() { return _instance; } void Awake() { if (!_instance) { _instance = this; } _bulbRotationInHands = new Quaternion(-180f, 0f, 0f, 0f); //Sets the X rotation of the bulb when the player holds it. } private void Start() { playerLeftHandPOS = PlayerManager.GetInstance().playerGameObj.transform.Find("Main Camera/LeftHandItemsPos"); } public IEnumerator GetLamp() { CurrentBulbSanityActivation.DisableSanityTrigger(); #region Emission Disable CurrentLightBulbEmissionUpdate.UpdateEmission = false; CurrentLightBulbEmissionUpdate.EmissionIsDisabled(); #endregion CurrentLeaveLampInHolder = CurrentBulb.GetComponentInParent(); if (CurrentLeaveLampInHolder != null) { CurrentLeaveLampInHolder._hasLampInHolder = false; } CurrentBulb.parent = playerLeftHandPOS; //Set the parent for the bulb. Now the bulb is in the PlayerLeftHandPOS. CurrentBulb.localScale = new Vector3(1, 1, 1); //Set scale to 1. foreach (Light light in CurrentBulbLight) { light.enabled = false; } yield return new WaitForSeconds(0.1f); //After ... seconds: while (ChangeBulb_LerpItem <= 1.0f) { ChangeBulb_LerpItem += 0.8f * Time.deltaTime; CurrentBulb.localPosition = Vector3.Lerp(CurrentBulb.localPosition, Vector3.zero, ChangeBulb_LerpItem); CurrentBulb.localRotation = Quaternion.Lerp(CurrentBulb.localRotation, _bulbRotationInHands, ChangeBulb_LerpItem); HasLampInHands = true; Debug.Log("Is lerping item in hand"); yield return null; } } public IEnumerator LeaveLamp(Transform lampHolder) { CurrentBulb.parent = lampHolder; CurrentBulb.localScale = new Vector3(1, 1, 1); yield return new WaitForSeconds(0.1f); while (ChangeBulb_LerpItem <= 1.0f) { ChangeBulb_LerpItem += 0.8f * Time.deltaTime; CurrentBulb.localPosition = Vector3.Lerp(CurrentBulb.localPosition, Vector3.zero, ChangeBulb_LerpItem); CurrentBulb.localRotation = Quaternion.Lerp(CurrentBulb.localRotation, lampHolder.localRotation, ChangeBulb_LerpItem); HasLampInHands = false; if (CurrentBulb.localPosition == Vector3.zero) { CanGetLamp = true; CurrentBulbSanityActivation.EnableSanityTrigger(); #region Emission Enable CurrentLightBulbEmissionUpdate.UpdateEmission = true; CurrentLightBulbEmissionUpdate.EmissionIsEnabled(); #endregion foreach (Light light in CurrentBulbLight) { light.enabled = true; } if (AllLightsAreEnabled()) { CurrentBulbLight.Clear(); } } Debug.Log("Is lerping item in Holder"); yield return null; } } public bool AllLightsAreEnabled() { for (int i = 0; i < CurrentBulbLight.Count; ++i) { if (CurrentBulbLight[i].enabled == true) { return true; } } return false; } }