add cellevator stuff

This commit is contained in:
Mister_Nebula 2022-04-25 21:36:17 +01:00
parent b2f62ed24b
commit 768fe36672
8 changed files with 575 additions and 2 deletions

View File

@ -0,0 +1,197 @@
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner;
internal class CustomAutoSlideProjector : MonoBehaviour
{
public float _defaultSlideDuration;
public float _endPauseDuration;
[SerializeField]
public CustomSlideCollectionContainer _slideCollectionItem;
public OWLight2 _light;
[SerializeField]
[Space]
private OWAudioSource _oneShotAudio;
private float _lastSlidePlayTime;
private float _startPausingEndTime;
private bool _isPlaying;
private bool _isPausingEnd;
protected void Awake()
{
DebugLog.DebugWrite($"AWAKE");
if (this._slideCollectionItem != null)
{
this._slideCollectionItem.onSlideTextureUpdated += this.OnSlideTextureUpdated;
this._slideCollectionItem.Initialize();
this._slideCollectionItem.enabled = false;
}
else
{
DebugLog.DebugWrite($"COLLECTION ITEM NULL IN AWAKE", OWML.Common.MessageType.Error);
}
base.enabled = false;
}
protected void OnDestroy()
{
if (this._slideCollectionItem != null)
{
this._slideCollectionItem.onSlideTextureUpdated -= this.OnSlideTextureUpdated;
}
}
public bool IsPlaying()
{
return this._isPlaying;
}
public void Play(bool reset)
{
DebugLog.DebugWrite($"PLAY");
if (this._isPlaying)
{
DebugLog.DebugWrite($"already playing!");
return;
}
this._light.SetActivation(true);
if (reset)
{
this._slideCollectionItem.ResetSlideIndex();
}
this.UpdateSlideTexture();
this._lastSlidePlayTime = Time.time;
this._isPlaying = true;
base.enabled = true;
}
public void Stop()
{
DebugLog.DebugWrite($"Stop");
if (!this._isPlaying)
{
return;
}
this._isPlaying = false;
base.enabled = false;
this._slideCollectionItem.enabled = false;
}
public void TurnOff()
{
DebugLog.DebugWrite($"Turn Off");
this.Stop();
this._oneShotAudio.PlayOneShot(global::AudioType.Lantern_Remove, 1f);
this._light.SetActivation(false);
}
public void SetSlideCollection(CustomSlideCollectionContainer collection)
{
DebugLog.DebugWrite($"SET SLIDE COLLECTION");
if (this._slideCollectionItem != null)
{
if (this._isPlaying)
{
this._slideCollectionItem.enabled = false;
}
this._slideCollectionItem.onSlideTextureUpdated -= this.OnSlideTextureUpdated;
}
this._slideCollectionItem = collection;
this._slideCollectionItem.onSlideTextureUpdated += this.OnSlideTextureUpdated;
this._slideCollectionItem.Initialize();
if (this._isPlaying)
{
this.UpdateSlideTexture();
}
}
protected virtual void Update()
{
if (this._isPlaying)
{
if (this._isPausingEnd)
{
if (Time.time >= this._endPauseDuration + this._startPausingEndTime)
{
this._isPausingEnd = false;
this.FirstSlide();
}
return;
}
if (Time.time >= this.GetCurrentSlidePlayDuration() + this._lastSlidePlayTime)
{
if (!this._slideCollectionItem.isEndOfSlide)
{
this.NextSlide();
return;
}
if (this._endPauseDuration > 0f)
{
this._isPausingEnd = true;
this._startPausingEndTime = Time.time;
return;
}
this.FirstSlide();
}
}
}
private void OnSlideTextureUpdated()
{
DebugLog.DebugWrite($"OnSlideTextureUpdated");
this.UpdateSlideTexture();
}
private void UpdateSlideTexture()
{
DebugLog.DebugWrite($"UpdateSlideTexture");
if (_light == null)
{
DebugLog.DebugWrite($"- Light is null!");
}
if (_slideCollectionItem == null)
{
DebugLog.DebugWrite($"- slide collection item is null!");
}
this._light.GetLight().cookie = this._slideCollectionItem.GetCurrentSlideTexture();
}
private void FirstSlide()
{
this._slideCollectionItem.ResetSlideIndex();
this._lastSlidePlayTime = Time.time;
if (this._oneShotAudio != null)
{
this._oneShotAudio.PlayOneShot(global::AudioType.Projector_Next, 1f);
}
}
private void NextSlide()
{
DebugLog.DebugWrite($"Next Slide");
this._slideCollectionItem.IncreaseSlideIndex();
this._lastSlidePlayTime = Time.time;
if (this._oneShotAudio != null)
{
this._oneShotAudio.PlayOneShot(global::AudioType.Projector_Next, 1f);
}
}
private float GetCurrentSlidePlayDuration()
{
return this._defaultSlideDuration;
}
}

View File

@ -0,0 +1,107 @@
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner;
[Serializable]
public class CustomSlide
{
public Texture2D _image;
private Texture2D _textureOverride;
private CustomSlideCollectionContainer _owningItem;
public bool expanded;
public Texture2D textureOverride
{
get
{
return this._textureOverride;
}
set
{
if (this._textureOverride == value)
{
return;
}
this._textureOverride = value;
this.InvokeTextureUpdate();
}
}
public CustomSlide()
{
this._image = null;
this.expanded = false;
}
public CustomSlide(CustomSlide other)
{
this._image = other._image;
this.expanded = false;
}
public Texture GetTexture()
{
if (this._textureOverride != null)
{
return this._textureOverride;
}
if (_image == null)
{
DebugLog.DebugWrite($"IMAGE IS NULL!", OWML.Common.MessageType.Error);
}
return this._image;
}
public void Display(CustomSlideCollectionContainer owner, bool forward)
{
DebugLog.DebugWrite($"Display");
if (owner == null)
{
DebugLog.DebugWrite($"OWNER IS NULL IN DISPLAY", OWML.Common.MessageType.Error);
}
this._owningItem = owner;
this.InvokeTextureUpdate();
}
public void InvokeTextureUpdate()
{
DebugLog.DebugWrite($"Invoke Texture Update");
if (this._owningItem != null)
{
this._owningItem.onSlideTextureUpdated.Invoke();
}
else
{
DebugLog.DebugWrite($"OWNING ITEM IS NULL!", OWML.Common.MessageType.Error);
}
}
public void SetChangeSlidesAllowed(bool allowed)
{
this._owningItem.SetChangeSlidesAllowed(allowed);
}
public void SetOwner(CustomSlideCollectionContainer owner)
{
this._owningItem = owner;
}
public static CustomSlide CreateSlide(Texture2D texture)
{
CustomSlide slide = new CustomSlide
{
_image = texture
};
return slide;
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner;
public class CustomSlideCollection
{
[SerializeField]
public CustomSlide[] slides;
public CustomSlideCollection(int startArrSize)
{
this.slides = new CustomSlide[startArrSize];
}
public CustomSlide this[int i]
{
get
{
return this.slides[i];
}
}
}

View File

@ -0,0 +1,146 @@
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner;
public class CustomSlideCollectionContainer : MonoBehaviour
{
[SerializeField]
public CustomSlideCollection _slideCollection = new CustomSlideCollection(0);
private bool _changeSlidesAllowed;
private int _currentSlideIndex;
private bool _initialized;
public int slideCount
{
get
{
if (this._slideCollection.slides == null)
{
return 0;
}
return this._slideCollection.slides.Length;
}
}
public bool isEndOfSlide
{
get
{
return this._currentSlideIndex >= this.slideCount - 1;
}
}
public int slideIndex
{
get
{
return this._currentSlideIndex;
}
set
{
if (!this._changeSlidesAllowed)
{
return;
}
if (this._currentSlideIndex == value)
{
DebugLog.DebugWrite($"current slide index is already {value}");
return;
}
bool forward = this._currentSlideIndex < value;
this._currentSlideIndex = value;
if (this._currentSlideIndex > this._slideCollection.slides.Length - 1)
{
this._currentSlideIndex = 0;
}
if (this._currentSlideIndex < 0)
{
this._currentSlideIndex = this._slideCollection.slides.Length - 1;
}
this.GetCurrentSlide().Display(this, forward);
}
}
public OWEvent onSlideTextureUpdated = new OWEvent(1);
public OWEvent onEndOfSlides = new OWEvent(1);
public void Initialize()
{
DebugLog.DebugWrite($"INITIALIZE");
if (this._initialized)
{
return;
}
this._changeSlidesAllowed = true;
this._initialized = true;
}
public CustomSlide GetCurrentSlide()
{
if (this._slideCollection.slides.Length == 0)
{
return null;
}
return this._slideCollection.slides[this._currentSlideIndex];
}
public Texture GetCurrentSlideTexture()
{
if (this._slideCollection.slides.Length == 0)
{
DebugLog.DebugWrite($"NO SLIDES!", OWML.Common.MessageType.Error);
return null;
}
return this.GetCurrentSlide().GetTexture();
}
public void ResetSlideIndex()
{
this.slideIndex = 0;
this.GetCurrentSlide().SetOwner(this);
}
public bool IncreaseSlideIndex()
{
if (!this._changeSlidesAllowed)
{
DebugLog.DebugWrite($"Changing slides is not allowed!");
return false;
}
int slideIndex = this.slideIndex;
this.slideIndex = slideIndex + 1;
if (this.slideIndex == 0)
{
this.onEndOfSlides.Invoke();
}
return true;
}
public bool DecreaseSlideIndex()
{
if (!this._changeSlidesAllowed)
{
return false;
}
int slideIndex = this.slideIndex;
this.slideIndex = slideIndex - 1;
return true;
}
public void SetChangeSlidesAllowed(bool allowed)
{
this._changeSlidesAllowed = allowed;
}
}

View File

@ -37,5 +37,6 @@ internal class PrisonerManager : WorldObjectManager
QSBWorldSync.Init<QSBPrisonerMarker, PrisonerBehaviourCueMarker>();
QSBWorldSync.Init<QSBPrisonerBrain, PrisonerBrain>();
QSBWorldSync.Init<QSBPrisonCellElevator, PrisonCellElevator>();
}
}

View File

@ -0,0 +1,95 @@
using Cysharp.Threading.Tasks;
using QSB.Audio;
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
using QSB.ItemSync.WorldObjects;
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner.WorldObjects;
internal class QSBPrisonCellElevator : WorldObject<PrisonCellElevator>, IQSBDropTarget, IGhostObject
{
public override void SendInitialState(uint to)
{
// todo : implement this
}
private CustomAutoSlideProjector projector;
private OWLight2 light;
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
public override void DisplayLines()
{
Popcron.Gizmos.Sphere(projector.transform.position, 0.5f, Color.white);
Popcron.Gizmos.Line(QSBPlayerManager.LocalPlayer.Body.transform.position, light.transform.position);
Popcron.Gizmos.Cone(light.transform.position, light.transform.rotation, light.range, light.GetLight().spotAngle, Color.yellow);
}
public override async UniTask Init(CancellationToken ct)
{
DebugLog.DebugWrite($"INIT {AttachedObject.name}");
var Interactibles_PrisonCell = AttachedObject.GetAttachedOWRigidbody().GetOrigParent().parent;
DebugLog.DebugWrite(Interactibles_PrisonCell.name);
var AUTO_SLIDE_PROJECTOR = new GameObject("AUTO SLIDE PROJECTOR");
AUTO_SLIDE_PROJECTOR.transform.parent = Interactibles_PrisonCell;
AUTO_SLIDE_PROJECTOR.transform.localPosition = new Vector3(-1.8f, 6.4f, 11.33f);
AUTO_SLIDE_PROJECTOR.transform.localRotation = Quaternion.identity;
AUTO_SLIDE_PROJECTOR.transform.localScale = Vector3.one;
AUTO_SLIDE_PROJECTOR.SetActive(false);
var Light = new GameObject("Light");
Light.transform.parent = AUTO_SLIDE_PROJECTOR.transform;
Light.transform.localPosition = Vector3.zero;
Light.transform.localRotation = Quaternion.Euler(32f, 90f, 0f);
var lightComponent = Light.AddComponent<Light>();
lightComponent.type = LightType.Spot;
lightComponent.range = 10;
lightComponent.spotAngle = 60;
lightComponent.shadows = LightShadows.Soft;
lightComponent.shadowStrength = 1f;
lightComponent.shadowResolution = UnityEngine.Rendering.LightShadowResolution.Low;
lightComponent.shadowBias = 0.05f;
lightComponent.shadowNormalBias = 0.4f;
lightComponent.shadowNearPlane = 0.2f;
light = Light.AddComponent<OWLight2>();
var projectorComponent = AUTO_SLIDE_PROJECTOR.AddComponent<CustomAutoSlideProjector>();
projectorComponent._light = Light.GetComponent<OWLight2>();
var cellevator1 = QSBCore.Helper.Assets.GetTexture("cellevator1.png");
cellevator1.wrapMode = TextureWrapMode.Clamp;
var cellevator2 = QSBCore.Helper.Assets.GetTexture("cellevator2.png");
cellevator2.wrapMode = TextureWrapMode.Clamp;
var cellevator3 = QSBCore.Helper.Assets.GetTexture("cellevator3.png");
cellevator3.wrapMode = TextureWrapMode.Clamp;
var slideCollection = new CustomSlideCollection(3);
slideCollection.slides[0] = new CustomSlide() { _image = cellevator1 };
slideCollection.slides[1] = new CustomSlide() { _image = cellevator2 };
slideCollection.slides[2] = new CustomSlide() { _image = cellevator3 };
var slideContainer = AUTO_SLIDE_PROJECTOR.AddComponent<CustomSlideCollectionContainer>();
slideContainer._slideCollection = slideCollection;
projectorComponent.SetSlideCollection(slideContainer);
projectorComponent._defaultSlideDuration = 1f;
AUTO_SLIDE_PROJECTOR.SetActive(true);
projector = projectorComponent;
projectorComponent.Play(false);
}
}

View File

@ -10,7 +10,7 @@ using UnityEngine;
namespace QSB.EchoesOfTheEye.Prisoner.WorldObjects;
internal class QSBPrisonerBrain : WorldObject<PrisonerBrain>
internal class QSBPrisonerBrain : WorldObject<PrisonerBrain>, IGhostObject
{
public override void SendInitialState(uint to)
{

View File

@ -35,7 +35,7 @@ internal class ItemManager : WorldObjectManager
// other drop targets that don't already have world objects
var listToInitFrom = QSBWorldSync.GetUnityObjects<MonoBehaviour>()
.Where(x => x is IItemDropTarget and not (RaftDock or RaftController))
.Where(x => x is IItemDropTarget and not (RaftDock or RaftController or PrisonCellElevator))
.SortDeterministic();
QSBWorldSync.Init<QSBOtherDropTarget, MonoBehaviour>(listToInitFrom);
}