Add assets
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cainos.Common;
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
public class BoundingPlatform : MonoBehaviour
|
||||
{
|
||||
public Transform platform;
|
||||
|
||||
public float waitTime = 1.0f;
|
||||
public float retrieveSpeed = 1.0f;
|
||||
public float pushSpeed = 10.0f;
|
||||
|
||||
private float platformYPosDown;
|
||||
private float platformYPosUp;
|
||||
private float platformYPos;
|
||||
private float waitTimer;
|
||||
private State curState = State.Down;
|
||||
|
||||
private Vector3 platformPrevPos;
|
||||
private Vector2 platformVel;
|
||||
|
||||
private SecondOrderDynamics secondOrderDynamics = new SecondOrderDynamics(4.0f, 0.5f, -0.3f);
|
||||
|
||||
private List<Rigidbody2D> onPlatformRigidbodies;
|
||||
|
||||
private void Push()
|
||||
{
|
||||
foreach ( Rigidbody2D rb2d in onPlatformRigidbodies)
|
||||
{
|
||||
rb2d.linearVelocity += pushSpeed * Vector2.up;
|
||||
}
|
||||
onPlatformRigidbodies.Clear();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
platformYPosDown = platform.transform.localPosition.y;
|
||||
platformYPosUp = 0.0f;
|
||||
onPlatformRigidbodies = new List<Rigidbody2D>();
|
||||
|
||||
platformPrevPos = platform.transform.position;
|
||||
|
||||
secondOrderDynamics.Reset(platformYPosDown);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
platformVel = (platform.transform.position - platformPrevPos) / Time.fixedDeltaTime;
|
||||
platformPrevPos = platform.transform.position;
|
||||
|
||||
waitTimer += Time.fixedDeltaTime;
|
||||
if ( waitTimer > waitTime )
|
||||
{
|
||||
//to up
|
||||
if (curState == State.Down)
|
||||
{
|
||||
waitTimer = 0.0f;
|
||||
curState = State.Up;
|
||||
platformYPos = platformYPosUp;
|
||||
|
||||
Push();
|
||||
}
|
||||
//to down
|
||||
else
|
||||
{
|
||||
if (platformYPos > platformYPosDown)
|
||||
{
|
||||
platformYPos -= retrieveSpeed * Time.fixedDeltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
waitTimer = 0.0f;
|
||||
platformYPos = platformYPosDown;
|
||||
curState = State.Down;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
platform.transform.localPosition = Vector3.up * secondOrderDynamics.Update(platformYPos, Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.attachedRigidbody && collision.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic)
|
||||
{
|
||||
if (onPlatformRigidbodies.Contains(collision.attachedRigidbody)) return;
|
||||
|
||||
onPlatformRigidbodies.Add(collision.attachedRigidbody);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if (collision.attachedRigidbody && collision.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic)
|
||||
{
|
||||
if (onPlatformRigidbodies.Contains(collision.attachedRigidbody) == false) return;
|
||||
onPlatformRigidbodies.Remove(collision.attachedRigidbody);
|
||||
}
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3766ef66f3e2cc04c84812bd678acc2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cainos.LucidEditor;
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
public class Chest : MonoBehaviour
|
||||
{
|
||||
[FoldoutGroup("Reference")]
|
||||
public Animator animator;
|
||||
|
||||
[FoldoutGroup("Runtime"), ShowInInspector, DisableInEditMode]
|
||||
public bool IsOpened
|
||||
{
|
||||
get { return isOpened; }
|
||||
set
|
||||
{
|
||||
isOpened = value;
|
||||
animator.SetBool("IsOpened", isOpened);
|
||||
}
|
||||
}
|
||||
private bool isOpened;
|
||||
|
||||
[FoldoutGroup("Runtime"),Button("Open"), HorizontalGroup("Runtime/Button")]
|
||||
public void Open()
|
||||
{
|
||||
IsOpened = true;
|
||||
}
|
||||
|
||||
[FoldoutGroup("Runtime"), Button("Close"), HorizontalGroup("Runtime/Button")]
|
||||
public void Close()
|
||||
{
|
||||
IsOpened = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 564a40ab997e88549a733c999c980526
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaa3b696ddd9d9c4bbb7a5f818178e41
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using Cainos.LucidEditor;
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
[CustomEditor(typeof(Chest))]
|
||||
public class ChestEditor : Cainos.LucidEditor.LucidEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a6ca1c7e69cdc43aa3530067d930e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Cainos.LucidEditor;
|
||||
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
[CustomEditor(typeof(Elevator))]
|
||||
public class ElevatorEditor : LucidEditor.LucidEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6254e17ada0781438d398a8bcda55f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,236 @@
|
||||
using UnityEngine;
|
||||
|
||||
using Cainos.LucidEditor;
|
||||
using Cainos.Common;
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
public class Elevator : MonoBehaviour
|
||||
{
|
||||
[FoldoutGroup("Params")] public Vector2 lengthRange = new Vector2(2, 5);
|
||||
[FoldoutGroup("Params")] public float waitTime = 1.0f;
|
||||
[FoldoutGroup("Params")] public float moveSpeed = 3.0f;
|
||||
[FoldoutGroup("Params")] public State startState = State.Up;
|
||||
|
||||
[FoldoutGroup("Reference")] public Rigidbody2D platform;
|
||||
[FoldoutGroup("Reference")] public SpriteRenderer chainL;
|
||||
[FoldoutGroup("Reference")] public SpriteRenderer chainR;
|
||||
|
||||
[FoldoutGroup("Runtime"), ShowInInspector]
|
||||
public float Length
|
||||
{
|
||||
get { return length; }
|
||||
set
|
||||
{
|
||||
if (value < 0) value = 0.0f;
|
||||
this.length = value;
|
||||
|
||||
platform.transform.localPosition = new Vector3(0.0f, -value, 0.0f);
|
||||
chainL.size = new Vector2(0.09375f, value - 8 * 0.03125f );
|
||||
chainR.size = new Vector2(0.09375f, value - 8 * 0.03125f );
|
||||
}
|
||||
}
|
||||
private float length;
|
||||
|
||||
[FoldoutGroup("Runtime"), ShowInInspector]
|
||||
public State CurState
|
||||
{
|
||||
get { return curState; }
|
||||
set
|
||||
{
|
||||
curState = value;
|
||||
}
|
||||
}
|
||||
private State curState;
|
||||
|
||||
|
||||
[FoldoutGroup("Runtime"), ShowInInspector]
|
||||
public bool IsWaiting
|
||||
{
|
||||
get { return isWaiting; }
|
||||
set
|
||||
{
|
||||
if (isWaiting == value) return;
|
||||
isWaiting = value;
|
||||
waitTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
private bool isWaiting = false;
|
||||
|
||||
|
||||
private float waitTimer;
|
||||
private float curSpeed;
|
||||
private float targetLength;
|
||||
private SecondOrderDynamics secondOrderDynamics = new SecondOrderDynamics(4.0f, 0.3f, -0.3f);
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
curState = startState;
|
||||
Length = curState == State.Up ? lengthRange.y : lengthRange.x;
|
||||
targetLength = Length;
|
||||
|
||||
secondOrderDynamics.Reset(targetLength);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (IsWaiting)
|
||||
{
|
||||
waitTimer += Time.deltaTime;
|
||||
if (waitTimer > waitTime) IsWaiting = false;
|
||||
curSpeed = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curState == State.Up)
|
||||
{
|
||||
curSpeed = -moveSpeed;
|
||||
if (targetLength < lengthRange.x)
|
||||
{
|
||||
curState = State.Down;
|
||||
IsWaiting = true;
|
||||
}
|
||||
}
|
||||
else if (curState == State.Down)
|
||||
{
|
||||
curSpeed = moveSpeed;
|
||||
if (targetLength > lengthRange.y)
|
||||
{
|
||||
curState = State.Up;
|
||||
IsWaiting = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetLength += curSpeed * Time.deltaTime;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Length = secondOrderDynamics.Update(targetLength, Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using UnityEngine;
|
||||
//using Cainos.LucidEditor;
|
||||
|
||||
//namespace Cainos.CustomizablePixelCharacter
|
||||
//{
|
||||
// public class Elevator : MonoBehaviour
|
||||
// {
|
||||
// [FoldoutGroup("Params")] public Vector2 lengthRange = new Vector2(2, 5);
|
||||
// [FoldoutGroup("Params")] public float waitTime = 1.0f;
|
||||
// [FoldoutGroup("Params")] public float moveSpeedMax = 3.0f;
|
||||
// [FoldoutGroup("Params")] public float moveAcc = 10.0f;
|
||||
// [FoldoutGroup("Params")] public State startState = State.Up;
|
||||
|
||||
// [FoldoutGroup("Reference")] public SpriteRenderer platform;
|
||||
// [FoldoutGroup("Reference")] public SpriteRenderer chainL;
|
||||
// [FoldoutGroup("Reference")] public SpriteRenderer chainR;
|
||||
|
||||
// [FoldoutGroup("Runtime"), ShowInInspector]
|
||||
// public float Length
|
||||
// {
|
||||
// get { return length; }
|
||||
// set
|
||||
// {
|
||||
// if (value < 0) value = 0.0f;
|
||||
// this.length = value;
|
||||
|
||||
// platform.transform.localPosition = new Vector3(0.0f, -value, 0.0f);
|
||||
// chainL.size = new Vector2(0.09375f, value - 8 * 0.03125f);
|
||||
// chainR.size = new Vector2(0.09375f, value - 8 * 0.03125f);
|
||||
// }
|
||||
// }
|
||||
// private float length;
|
||||
|
||||
// [FoldoutGroup("Runtime"), ShowInInspector]
|
||||
// public State CurState
|
||||
// {
|
||||
// get { return curState; }
|
||||
// set
|
||||
// {
|
||||
// curState = value;
|
||||
// }
|
||||
// }
|
||||
// private State curState;
|
||||
|
||||
|
||||
// [FoldoutGroup("Runtime"), ShowInInspector]
|
||||
// public bool IsWaiting
|
||||
// {
|
||||
// get { return isWaiting; }
|
||||
// set
|
||||
// {
|
||||
// if (isWaiting == value) return;
|
||||
// isWaiting = value;
|
||||
// waitTimer = 0.0f;
|
||||
// }
|
||||
// }
|
||||
// private bool isWaiting = false;
|
||||
|
||||
|
||||
// private float waitTimer;
|
||||
// private float curSpeed;
|
||||
|
||||
|
||||
// private void Start()
|
||||
// {
|
||||
// curState = startState;
|
||||
// Length = curState == State.Up ? lengthRange.y : lengthRange.x;
|
||||
// }
|
||||
|
||||
// private void Update()
|
||||
// {
|
||||
// Length += curSpeed * Time.deltaTime;
|
||||
|
||||
// if (IsWaiting)
|
||||
// {
|
||||
// waitTimer += Time.deltaTime;
|
||||
// if (waitTimer > waitTime) IsWaiting = false;
|
||||
|
||||
// curSpeed = Mathf.Lerp(curSpeed, 0.0f, 7.5f * Time.deltaTime);
|
||||
// float targetLength = curState == State.Up ? lengthRange.y : lengthRange.x;
|
||||
// Length = Mathf.Lerp(Length, targetLength, 7.5f * Time.deltaTime);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (curState == State.Up)
|
||||
// {
|
||||
// curSpeed = Mathf.MoveTowards(curSpeed, -moveSpeedMax, moveAcc * Time.deltaTime);
|
||||
// if (Length < lengthRange.x)
|
||||
// {
|
||||
// curState = State.Down;
|
||||
// IsWaiting = true;
|
||||
// }
|
||||
// }
|
||||
// else if (curState == State.Down)
|
||||
// {
|
||||
// curSpeed = Mathf.MoveTowards(curSpeed, moveSpeedMax, moveAcc * Time.deltaTime);
|
||||
// if (Length > lengthRange.y)
|
||||
// {
|
||||
// curState = State.Up;
|
||||
// IsWaiting = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public enum State
|
||||
// {
|
||||
// Up,
|
||||
// Down
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: decb355dc5cd8c549ac690cc13f9386e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cainos.PixelArtPlatformer_VillageProps
|
||||
{
|
||||
//moving platform
|
||||
//used on a moving platform so that objects fallen on this platform will perfectly follow to it
|
||||
//otherwise due to physical simulation precision problem object will not follow the moving platform as expected
|
||||
|
||||
public class MovingPlatform : MonoBehaviour
|
||||
{
|
||||
public float velocityInheritPercent = 0.8f;
|
||||
|
||||
private List<Transform> onPlatformObjects;
|
||||
|
||||
private Vector3 prevPos;
|
||||
private Vector2 velocity;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
onPlatformObjects = new List<Transform>();
|
||||
prevPos = transform.position;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
velocity = (transform.position - prevPos) / Time.fixedDeltaTime;
|
||||
prevPos = transform.position;
|
||||
|
||||
foreach (Transform t in onPlatformObjects)
|
||||
{
|
||||
t.Translate(velocity * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.attachedRigidbody && collision.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic)
|
||||
{
|
||||
if (onPlatformObjects.Contains(collision.transform)) return;
|
||||
|
||||
onPlatformObjects.Add(collision.transform);
|
||||
if (collision.attachedRigidbody) collision.attachedRigidbody.linearVelocity -= velocity * velocityInheritPercent;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if (collision.attachedRigidbody && collision.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic)
|
||||
{
|
||||
if (onPlatformObjects.Contains(collision.transform) == false) return;
|
||||
onPlatformObjects.Remove(collision.transform);
|
||||
|
||||
if (collision.attachedRigidbody) collision.attachedRigidbody.linearVelocity += velocity * velocityInheritPercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62f13fc5f387cd24f9b520c8160d7afd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user