Merge branch 'feature/chain-platforms' into 'main'

implement falling platform chain

Closes #116

See merge request kernel-panic/revival!57
This commit is contained in:
Cinder Foster-Smith 2021-03-25 10:47:00 +00:00
commit 4b5124e8ba
17 changed files with 3142 additions and 47 deletions

View File

@ -0,0 +1,51 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1907884617390317472
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 197761351512446430}
- component: {fileID: 600618092916283916}
m_Layer: 0
m_Name: FallawayFloorChain
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &197761351512446430
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1907884617390317472}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &600618092916283916
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1907884617390317472}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59c45615fb0d0ce4fb951b03d885acdf, type: 3}
m_Name:
m_EditorClassIdentifier:
_settings: {fileID: 11400000, guid: 36275776eda5c8249bf45e01721afe36, type: 2}
_spacing: 1.93
_delay: 0.1
_forwards: 1
_prefab: {fileID: 8773676356524340268, guid: d145f0e5906f91a4fad7f384f1b2a6ec, type: 3}
_length: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e72cb2e11c8a50248a284aabf3b87985
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,6 +1,6 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &4449396798674854612 --- !u!1 &1150255153773548759
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -8,49 +8,47 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 4449396798674854634} - component: {fileID: 7672633439318125585}
- component: {fileID: 4449396798674854635} - component: {fileID: 697448341302567644}
- component: {fileID: 4449396798674854632} - component: {fileID: 547292502171110631}
- component: {fileID: 4449396798674854633} - component: {fileID: 7728908912666711682}
- component: {fileID: 4449396798674854614}
- component: {fileID: 4449396798674854615}
m_Layer: 0 m_Layer: 0
m_Name: Safe Zone m_Name: Quad
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!4 &4449396798674854634 --- !u!4 &7672633439318125585
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4449396798674854612} m_GameObject: {fileID: 1150255153773548759}
m_LocalRotation: {x: -0, y: 0.70394546, z: -0, w: 0.7102541} m_LocalRotation: {x: 0.70710677, y: -0, z: -0, w: 0.7071068}
m_LocalPosition: {x: -13.763916, y: -2.875824, z: -3.3844023} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.32437897, y: 1.6604103, z: 1.6020799} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 4449396798674854634}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 89.489, z: 0} m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!33 &4449396798674854635 --- !u!33 &697448341302567644
MeshFilter: MeshFilter:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4449396798674854612} m_GameObject: {fileID: 1150255153773548759}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4449396798674854632 --- !u!23 &547292502171110631
MeshRenderer: MeshRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4449396798674854612} m_GameObject: {fileID: 1150255153773548759}
m_Enabled: 0 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 1
m_ReceiveShadows: 1 m_ReceiveShadows: 1
m_DynamicOccludee: 1 m_DynamicOccludee: 1
@ -84,20 +82,53 @@ MeshRenderer:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0} m_AdditionalVertexStreams: {fileID: 0}
--- !u!64 &4449396798674854633 --- !u!64 &7728908912666711682
MeshCollider: MeshCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4449396798674854612} m_GameObject: {fileID: 1150255153773548759}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 0 m_Enabled: 1
serializedVersion: 4 serializedVersion: 4
m_Convex: 0 m_Convex: 0
m_CookingOptions: 30 m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &4449396798674854612
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4449396798674854634}
- component: {fileID: 4449396798674854614}
- component: {fileID: 4449396798674854615}
m_Layer: 0
m_Name: Safe Zone
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4449396798674854634
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4449396798674854612}
m_LocalRotation: {x: -0, y: 0.70394546, z: -0, w: 0.7102541}
m_LocalPosition: {x: -13.763916, y: -2.875824, z: -3.3844023}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 7672633439318125585}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 89.489, z: 0}
--- !u!65 &4449396798674854614 --- !u!65 &4449396798674854614
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -109,7 +140,7 @@ BoxCollider:
m_IsTrigger: 1 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 10, y: 2.220446e-16, z: 10} m_Size: {x: 1, y: 0.5, z: 1}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &4449396798674854615 --- !u!114 &4449396798674854615
MonoBehaviour: MonoBehaviour:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 79b8b10c70131894eb35fc815dd27679
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f4666c0f84a0ffa4485d1262087cf48a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 629b80fb2362fe948a2482ae209214eb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 112000000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,144 @@
fileFormatVersion: 2
guid: e4eb4b2fe64354d43897141958b0824b
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
seamlessCubemap: 1
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 2
aniso: 0
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 2
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 100
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Windows Store Apps
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,7 +3,6 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DG.Tweening; using DG.Tweening;
using Ktyl.Util;
using UnityEngine; using UnityEngine;
[RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(Rigidbody))]
@ -13,15 +12,14 @@ public class FallawayFloor : MonoBehaviour
public float speed; public float speed;
// Time it takes for ogjecct to begin moving towards the ground. // Time it takes for ogjecct to begin moving towards the ground.
public float fallAwayTime; public float fallAwayTime;
public Material dissolve;
[SerializeField] private Renderer _renderer;
[SerializeField] private SerialFloat objectTimeScale;
[SerializeField] private TrapSettings _settings; [SerializeField] private TrapSettings _settings;
[SerializeField] private GameObject _graphics; [SerializeField] private GameObject _graphics;
private Rigidbody rb; private Rigidbody rb;
private Vector3 initialPosition; private Vector3 initialPosition;
public bool Falling => _triggered;
private bool _triggered = false; private bool _triggered = false;
private void Start() private void Start()
@ -34,7 +32,11 @@ public class FallawayFloor : MonoBehaviour
private void LateUpdate() private void LateUpdate()
{ {
if (!_triggered) return; if (!_triggered)
{
transform.position = initialPosition;
return;
}
if (_settings.FallawayFloor.CanRespawn) if (_settings.FallawayFloor.CanRespawn)
{ {
@ -52,12 +54,7 @@ public class FallawayFloor : MonoBehaviour
{ {
if (!_triggered && other.CompareTag("Player")) if (!_triggered && other.CompareTag("Player"))
{ {
// Start the Destroy floor coroutine and switch to the dissolve material. Fall();
if (objectTimeScale != 0)
{
StartCoroutine(Fall());
_renderer.material = dissolve;
}
} }
} }
@ -67,24 +64,30 @@ public class FallawayFloor : MonoBehaviour
{ {
if (!_triggered && other.CompareTag("Player")) if (!_triggered && other.CompareTag("Player"))
{ {
// Start the Destroy floor coroutine and switch to the dissolve material. Fall();
if (objectTimeScale != 0)
{
StartCoroutine(Fall());
_renderer.material = dissolve;
}
} }
} }
private IEnumerator Fall() public void Fall()
{ {
// already falling
if (_triggered) return;
// time stop
if (_settings.ObjectTimeScale == 0) return;
StartCoroutine(FallCR());
}
private IEnumerator FallCR()
{
_triggered = true;
_graphics.transform.DOShakePosition( _graphics.transform.DOShakePosition(
fallAwayTime, fallAwayTime,
_settings.FallawayFloor.ShakeStrength); _settings.FallawayFloor.ShakeStrength);
FMODUnity.RuntimeManager.PlayOneShot(_settings.FallawayFloor.FMODEvent); FMODUnity.RuntimeManager.PlayOneShot(_settings.FallawayFloor.FMODEvent);
_triggered = true;
// wait a moment // wait a moment
yield return new WaitForSeconds(fallAwayTime); yield return new WaitForSeconds(fallAwayTime);

View File

@ -0,0 +1,158 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public partial class FallawayFloorChain : MonoBehaviour
{
[SerializeField] private float _spacing;
[SerializeField] private float _delay;
[SerializeField] private bool _forwards;
private readonly List<FallawayFloor> _segments = new List<FallawayFloor>();
private bool _triggered;
private void Start()
{
GetComponentsInChildren(_segments);
}
private void LateUpdate()
{
if (_triggered) return;
for (int i = 0; i < _segments.Count; i++)
{
if (_segments[i].Falling)
{
StartCoroutine(FallCR());
break;
}
}
}
private IEnumerator FallCR()
{
_triggered = true;
var wait = new WaitForSeconds(_delay);
if (_forwards)
{
for (int i = 0; i < _segments.Count; i++)
{
_segments[i].Fall();
yield return wait;
}
}
else
{
for (int i = _segments.Count - 1; i >= 0; i--)
{
_segments[i].Fall();
yield return wait;
}
}
yield return new WaitUntil(() =>
{
var idx = _forwards ? _segments.Count - 1 : 0;
foreach (var segment in _segments)
{
if (segment.Falling) return false;
}
_triggered = false;
if (!_segments[idx].Falling)
{
_triggered = false;
return true;
}
return false;
});
}
}
#region Editor
#if UNITY_EDITOR
public partial class FallawayFloorChain
{
[SerializeField] private GameObject _prefab;
[Range(1,16)]
[SerializeField] private int _length;
public float EDITOR_Spacing => _spacing;
public int EDITOR_Length => _length;
public void EDITOR_Refresh()
{
if (_length == transform.childCount) return;
for (int i = transform.childCount - 1; i >= 0; i--)
{
DestroyImmediate(transform.GetChild(i).gameObject);
}
_segments.Clear();
for (int i = 0; i < _length; i++)
{
var platform = Instantiate(_prefab, transform).GetComponent<FallawayFloor>();
_segments.Add(platform);
}
EDITOR_RefreshSpacing();
}
public void EDITOR_RefreshSpacing()
{
for (int i = 0; i < _segments.Count; i++)
{
_segments[i].transform.localPosition = Vector3.forward * _spacing * i;
}
}
}
[CustomEditor(typeof(FallawayFloorChain))]
public class FallawayFloorChainEditor : Editor
{
private FallawayFloorChain _data;
private void OnEnable()
{
_data = target as FallawayFloorChain;
}
public override void OnInspectorGUI()
{
var spacing = _data.EDITOR_Spacing;
base.OnInspectorGUI();
if (_data.transform.childCount != _data.EDITOR_Length)
{
_data.EDITOR_Refresh();
}
if (spacing != _data.EDITOR_Spacing)
{
_data.EDITOR_RefreshSpacing();
}
}
}
#endif
#endregion

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59c45615fb0d0ce4fb951b03d885acdf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,11 +3,15 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DG.Tweening; using DG.Tweening;
using Ktyl.Util; using Ktyl.Util;
using TMPro;
using UnityEngine; using UnityEngine;
[CreateAssetMenu(menuName = "KernelPanic/Traps/Settings")] [CreateAssetMenu(menuName = "KernelPanic/Traps/Settings")]
public class TrapSettings : ScriptableObject public class TrapSettings : ScriptableObject
{ {
public float ObjectTimeScale => _objectTimeScale;
[SerializeField] private SerialFloat _objectTimeScale;
[Serializable] [Serializable]
public struct FallawayFloorSettings public struct FallawayFloorSettings
{ {

View File

@ -12,7 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 93dc605253d04fe45a05492fb3feacc2, type: 3} m_Script: {fileID: 11500000, guid: 93dc605253d04fe45a05492fb3feacc2, type: 3}
m_Name: Trap Settings m_Name: Trap Settings
m_EditorClassIdentifier: m_EditorClassIdentifier:
_objectTimeScale: {fileID: 11400000, guid: 9b68e167db44c0c42837e9a679da964e, type: 2}
_fallawayFloor: _fallawayFloor:
_prefab: {fileID: 8773676356524340268, guid: d145f0e5906f91a4fad7f384f1b2a6ec, type: 3}
_fmodEvent: event:/Environment/Traps/FallingPlatform _fmodEvent: event:/Environment/Traps/FallingPlatform
_respawnTime: {fileID: 11400000, guid: 1d2951ab5083d4d48a319ff00a9eb8bd, type: 2} _respawnTime: {fileID: 11400000, guid: 1d2951ab5083d4d48a319ff00a9eb8bd, type: 2}
_safeTime: {fileID: 11400000, guid: 27c10a061baeec8469e96d4f995c1445, type: 2} _safeTime: {fileID: 11400000, guid: 27c10a061baeec8469e96d4f995c1445, type: 2}