Import 2D Level
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor;
|
||||
|
||||
//Checks if we are in a certain template, as some scripts are template-specific.
|
||||
[InitializeOnLoad]
|
||||
public class TemplateEditorDetection : Editor {
|
||||
|
||||
static TemplateEditorDetection() {
|
||||
|
||||
//Get the current definition symbols
|
||||
string currentDefineSymbols = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup));
|
||||
List<string> allDefineSymbols = currentDefineSymbols.Split(';').ToList();
|
||||
|
||||
//Template core namespace classes used for detection
|
||||
var platformer = System.Type.GetType("Platformer.Core.Simulation", false);
|
||||
var kart = System.Type.GetType("KartGame.KartSystems.KartMovement", false);
|
||||
var ballgame = System.Type.GetType("TeamBallGame.Simulation", false);
|
||||
|
||||
//Template definition symbols for use with #if
|
||||
var platformerDefine = "UNITY_TEMPLATE_PLATFORMER";
|
||||
var kartDefine = "UNITY_TEMPLATE_KART";
|
||||
var ballgameDefine = "UNITY_TEMPLATE_BALLGAME";
|
||||
|
||||
//add the define symbols if we are in a specific template, if they don't exist already
|
||||
if (platformer != null && !allDefineSymbols.Contains(platformerDefine)) { allDefineSymbols.Add(platformerDefine); }
|
||||
if (kart != null && !allDefineSymbols.Contains(kartDefine)) { allDefineSymbols.Add(kartDefine); }
|
||||
if (ballgame != null && !allDefineSymbols.Contains(ballgameDefine)) { allDefineSymbols.Add(ballgameDefine); }
|
||||
|
||||
//apply the definition symbols
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup),
|
||||
string.Join(";", allDefineSymbols.ToArray()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
|
||||
[RequireComponent(typeof(ParticleSystem))]
|
||||
public class EmitParticlesOnLand : MonoBehaviour
|
||||
{
|
||||
|
||||
public bool emitOnLand = true;
|
||||
public bool emitOnEnemyDeath = true;
|
||||
|
||||
#if UNITY_TEMPLATE_PLATFORMER
|
||||
|
||||
ParticleSystem p;
|
||||
|
||||
void Start()
|
||||
{
|
||||
p = GetComponent<ParticleSystem>();
|
||||
|
||||
if (emitOnLand) {
|
||||
Platformer.Gameplay.PlayerLanded.OnExecute += PlayerLanded_OnExecute;
|
||||
void PlayerLanded_OnExecute(Platformer.Gameplay.PlayerLanded obj) {
|
||||
p.Play();
|
||||
}
|
||||
}
|
||||
|
||||
if (emitOnEnemyDeath) {
|
||||
Platformer.Gameplay.EnemyDeath.OnExecute += EnemyDeath_OnExecute;
|
||||
void EnemyDeath_OnExecute(Platformer.Gameplay.EnemyDeath obj) {
|
||||
p.Play();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Jiggler : MonoBehaviour
|
||||
{
|
||||
[Range(0, 1)]
|
||||
public float power = .1f;
|
||||
|
||||
[Header("Position Jiggler")]
|
||||
public bool jigPosition = true;
|
||||
public Vector3 positionJigAmount;
|
||||
[Range(0, 120)]
|
||||
public float positionFrequency = 10;
|
||||
float positionTime;
|
||||
|
||||
[Header("Rotation Jiggler")]
|
||||
public bool jigRotation = true;
|
||||
public Vector3 rotationJigAmount;
|
||||
[Range(0, 120)]
|
||||
public float rotationFrequency = 10;
|
||||
float rotationTime;
|
||||
|
||||
[Header("Scale Jiggler")]
|
||||
public bool jigScale = true;
|
||||
public Vector3 scaleJigAmount = new Vector3(.1f, -.1f, .1f);
|
||||
[Range(0, 120)]
|
||||
public float scaleFrequency = 10;
|
||||
float scaleTime;
|
||||
|
||||
Vector3 basePosition;
|
||||
Quaternion baseRotation;
|
||||
Vector3 baseScale;
|
||||
|
||||
void Start(){
|
||||
basePosition = transform.localPosition;
|
||||
baseRotation = transform.localRotation;
|
||||
baseScale = transform.localScale;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
var dt = Time.deltaTime;
|
||||
positionTime += dt * positionFrequency;
|
||||
rotationTime += dt * rotationFrequency;
|
||||
scaleTime += dt * scaleFrequency;
|
||||
|
||||
if (jigPosition)
|
||||
transform.localPosition = basePosition + positionJigAmount * Mathf.Sin(positionTime) * power;
|
||||
|
||||
if (jigRotation)
|
||||
transform.localRotation = baseRotation * Quaternion.Euler(rotationJigAmount * Mathf.Sin(positionTime) * power);
|
||||
|
||||
if (jigScale)
|
||||
transform.localScale = baseScale + scaleJigAmount * Mathf.Sin(scaleTime) * power;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
public class PlatformerJumpPad : MonoBehaviour
|
||||
{
|
||||
public float verticalVelocity;
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
var rb = other.attachedRigidbody;
|
||||
if (rb == null) return;
|
||||
var player = rb.GetComponent<PlayerController>();
|
||||
if (player == null) return;
|
||||
AddVelocity(player);
|
||||
}
|
||||
|
||||
void AddVelocity(PlayerController player)
|
||||
{
|
||||
player.velocity.y = verticalVelocity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
public class PlatformerSpeedPad : MonoBehaviour
|
||||
{
|
||||
public float maxSpeed;
|
||||
|
||||
[Range (0, 5)]
|
||||
public float duration = 1f;
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other){
|
||||
var rb = other.attachedRigidbody;
|
||||
if (rb == null) return;
|
||||
var player = rb.GetComponent<PlayerController>();
|
||||
if (player == null) return;
|
||||
player.StartCoroutine(PlayerModifier(player, duration));
|
||||
}
|
||||
|
||||
IEnumerator PlayerModifier(PlayerController player, float lifetime){
|
||||
var initialSpeed = player.maxSpeed;
|
||||
player.maxSpeed = maxSpeed;
|
||||
yield return new WaitForSeconds(lifetime);
|
||||
player.maxSpeed = initialSpeed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class SimpleTrigger : MonoBehaviour
|
||||
{
|
||||
|
||||
public Rigidbody2D triggerBody;
|
||||
public UnityEvent onTriggerEnter;
|
||||
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other){
|
||||
//do not trigger if there's no trigger target object
|
||||
if (triggerBody == null) return;
|
||||
|
||||
//only trigger if the triggerBody matches
|
||||
var hitRb = other.attachedRigidbody;
|
||||
if (hitRb == triggerBody){
|
||||
onTriggerEnter.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user