[Unity] Added Basic Platformer scripts and Hero character

This commit is contained in:
Fenrisul 2014-09-30 01:13:35 -07:00
parent 55896be38f
commit 131e4babe0
33 changed files with 660 additions and 0 deletions

View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 2a88cb6ea6a9bd94e8513bd8b866934b
folderAsset: yes
DefaultImporter:
userData:

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: c0218f9f0a3cc144698dca06a3f59668
DefaultImporter:
userData:

View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: fadfb38fe9b3ecc4db70956f425e4720
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 1
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 3
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 1
compressionQuality: 100
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 6
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: 6be9cbac7529e734ab3d6093239f6bec
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 1
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 3
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 1
compressionQuality: 100
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 6
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

View File

@ -0,0 +1,222 @@
/******************************************************************************
* Spine Runtimes Software License
* Version 2.1
*
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable and
* non-transferable license to install, execute and perform the Spine Runtimes
* Software (the "Software") solely for internal use. Without the written
* permission of Esoteric Software (typically granted by licensing Spine), you
* may not (a) modify, translate, adapt or otherwise create derivative works,
* improvements of the Software or develop new applications using the Software
* or (b) remove, delete, alter or obscure any trademarks or any copyright,
* trademark, patent or other intellectual property or proprietary rights
* notices on or in the Software, including any copy thereof. Redistributions
* in binary or source form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
/*****************************************************************************
* Basic Platformer Controller created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class BasicPlatformerController : MonoBehaviour {
[Header("Controls")]
public string XAxis = "Horizontal";
public string YAxis = "Vertical";
public string JumpButton = "Jump";
[Header("Moving")]
public float walkSpeed = 4;
public float runSpeed = 10;
public float gravity = 65;
[Header("Jumping")]
public float jumpSpeed = 25;
public float jumpDuration = 0.5f;
public float jumpInterruptFactor = 100;
public float forceCrouchVelocity = 25;
public float forceCrouchDuration = 0.5f;
[Header("Graphics")]
public Transform graphicsRoot;
public SkeletonAnimation skeletonAnimation;
[Header("Animation")]
public string walkName = "Walk";
public string runName = "Run";
public string idleName = "Idle";
public string jumpName = "Jump";
public string fallName = "Fall";
public string crouchName = "Crouch";
[Header("Audio")]
public AudioSource jumpAudioSource;
public AudioSource hardfallAudioSource;
public AudioSource footstepAudioSource;
public string footstepEventName = "Footstep";
CharacterController controller;
Vector2 velocity = Vector2.zero;
Vector2 lastVelocity = Vector2.zero;
bool lastGrounded = false;
float jumpEndTime = 0;
bool jumpInterrupt = false;
float forceCrouchEndTime;
Quaternion flippedRotation = Quaternion.Euler(0, 180, 0);
void Awake()
{
controller = GetComponent<CharacterController>();
}
void Start(){
//register a callback for Spine Events (in this case, Footstep)
skeletonAnimation.state.Event += HandleEvent;
}
void HandleEvent (Spine.AnimationState state, int trackIndex, Spine.Event e)
{
//play some sound if footstep event fired
if(e.Data.Name == footstepEventName){
footstepAudioSource.Stop();
footstepAudioSource.Play();
}
}
void Update()
{
//control inputs
float x = Input.GetAxis(XAxis);
float y = Input.GetAxis(YAxis);
//check for force crouch
bool crouching = (controller.isGrounded && y < -0.5f) || (forceCrouchEndTime > Time.time);
velocity.x = 0;
//Calculate control velocity
if (!crouching) {
if (Input.GetButtonDown(JumpButton) && controller.isGrounded)
{
//jump
jumpAudioSource.Stop();
jumpAudioSource.Play();
velocity.y = jumpSpeed;
jumpEndTime = Time.time + jumpDuration;
}
else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton))
{
jumpInterrupt = true;
}
if (x != 0)
{
//walk or run
velocity.x = Mathf.Abs(x) > 0.6f ? runSpeed : walkSpeed;
velocity.x *= Mathf.Sign(x);
}
if (jumpInterrupt)
{
//interrupt jump and smoothly cut Y velocity
if (velocity.y > 0)
{
velocity.y = Mathf.MoveTowards(velocity.y, 0, Time.deltaTime * 100);
}
else
{
jumpInterrupt = false;
}
}
}
//apply gravity F = mA (Learn it, love it, live it)
velocity.y -= gravity * Time.deltaTime;
//move
controller.Move(new Vector3(velocity.x, velocity.y, 0) * Time.deltaTime);
if (controller.isGrounded)
{
//cancel out Y velocity if on ground
velocity.y = -gravity * Time.deltaTime;
jumpInterrupt = false;
}
Vector2 deltaVelocity = lastVelocity - velocity;
if (!lastGrounded && controller.isGrounded)
{
//detect hard fall
if ((gravity*Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity)
{
forceCrouchEndTime = Time.time + forceCrouchDuration;
hardfallAudioSource.Play();
}
else{
//play footstep audio if light fall because why not
footstepAudioSource.Play();
}
}
//graphics updates
if (controller.isGrounded)
{
if (crouching) //crouch
{
skeletonAnimation.AnimationName = crouchName;
}
else
{
if (x == 0) //idle
skeletonAnimation.AnimationName = idleName;
else //move
skeletonAnimation.AnimationName = Mathf.Abs(x) > 0.6f ? runName : walkName;
}
}
else
{
if (velocity.y > 0) //jump
skeletonAnimation.AnimationName = jumpName;
else //fall
skeletonAnimation.AnimationName = fallName;
}
//flip left or right
if (x > 0)
graphicsRoot.localRotation = Quaternion.identity;
else if (x < 0)
graphicsRoot.localRotation = flippedRotation;
//store previous state
lastVelocity = velocity;
lastGrounded = controller.isGrounded;
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27b3e3370f55c0a438ef0a10c2eba510
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -0,0 +1,62 @@
/******************************************************************************
* Spine Runtimes Software License
* Version 2.1
*
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable and
* non-transferable license to install, execute and perform the Spine Runtimes
* Software (the "Software") solely for internal use. Without the written
* permission of Esoteric Software (typically granted by licensing Spine), you
* may not (a) modify, translate, adapt or otherwise create derivative works,
* improvements of the Software or develop new applications using the Software
* or (b) remove, delete, alter or obscure any trademarks or any copyright,
* trademark, patent or other intellectual property or proprietary rights
* notices on or in the Software, including any copy thereof. Redistributions
* in binary or source form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
/*****************************************************************************
* Constrained Camera created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using System.Collections;
public class ConstrainedCamera : MonoBehaviour {
public Transform target;
public Vector3 offset;
public Vector3 min;
public Vector3 max;
public float smoothing = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void LateUpdate () {
Vector3 goalPoint = target.position + offset;
goalPoint.x = Mathf.Clamp(goalPoint.x, min.x, max.x);
goalPoint.y = Mathf.Clamp(goalPoint.y, min.y, max.y);
goalPoint.z = Mathf.Clamp(goalPoint.z, min.z, max.z);
transform.position = Vector3.Lerp(transform.position, goalPoint, smoothing * Time.deltaTime);
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6df2d8b571e22504284108b691b4a3cd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: ab51e7c76aeecdb4cab94e4cad31b50f
folderAsset: yes
DefaultImporter:
userData:

Binary file not shown.

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c34d92bb58dd1a14db9e89d6188087ea
AudioImporter:
serializedVersion: 4
format: -1
quality: .5
stream: 1
3D: 0
forceToMono: 0
useHardware: 0
loopable: 0
userData:

Binary file not shown.

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf832d4a857c27545bff51681de106c0
AudioImporter:
serializedVersion: 4
format: -1
quality: .5
stream: 1
3D: 0
forceToMono: 0
useHardware: 0
loopable: 0
userData:

Binary file not shown.

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9afdb740ae0deb74a8906a353b597a03
AudioImporter:
serializedVersion: 4
format: -1
quality: .5
stream: 1
3D: 0
forceToMono: 0
useHardware: 0
loopable: 0
userData:

View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 2c9c8caf9ef4a2d44a6978ea8bdcb3f6
folderAsset: yes
DefaultImporter:
userData:

Binary file not shown.

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 095df186000aff741a2407fe13d65e42
NativeFormatImporter:
userData:

View File

@ -0,0 +1,139 @@
Hero.png
size: 512,256
format: RGBA8888
filter: Linear,Linear
repeat: none
White/body
rotate: true
xy: 172, 0
size: 97, 95
orig: 97, 95
offset: 0, 0
index: -1
White/cape
rotate: false
xy: 172, 97
size: 146, 159
orig: 146, 159
offset: 0, 0
index: -1
White/eyes
rotate: true
xy: 267, 15
size: 82, 31
orig: 82, 31
offset: 0, 0
index: -1
White/fingers
rotate: true
xy: 371, 85
size: 31, 33
orig: 31, 33
offset: 0, 0
index: -1
White/foot1
rotate: true
xy: 426, 151
size: 50, 42
orig: 50, 42
offset: 0, 0
index: -1
White/foot2
rotate: false
xy: 318, 99
size: 53, 38
orig: 53, 38
offset: 0, 0
index: -1
White/forearm1
rotate: false
xy: 468, 154
size: 41, 49
orig: 41, 49
offset: 0, 0
index: -1
White/forearm2
rotate: false
xy: 412, 115
size: 31, 32
orig: 31, 32
offset: 0, 0
index: -1
White/hand1
rotate: true
xy: 110, 7
size: 37, 48
orig: 37, 48
offset: 0, 0
index: -1
White/hand2
rotate: true
xy: 375, 116
size: 31, 37
orig: 31, 37
offset: 0, 0
index: -1
White/head
rotate: false
xy: 0, 83
size: 172, 173
orig: 172, 173
offset: 0, 0
index: -1
White/mantles
rotate: false
xy: 318, 201
size: 136, 55
orig: 136, 55
offset: 0, 0
index: -1
White/mouth
rotate: true
xy: 298, 36
size: 61, 13
orig: 61, 13
offset: 0, 0
index: -1
White/shin1
rotate: true
xy: 454, 203
size: 53, 57
orig: 53, 57
offset: 0, 0
index: -1
White/shin2
rotate: false
xy: 375, 147
size: 51, 54
orig: 51, 54
offset: 0, 0
index: -1
White/thigh1
rotate: false
xy: 0, 20
size: 60, 63
orig: 60, 63
offset: 0, 0
index: -1
White/thigh2
rotate: false
xy: 318, 137
size: 57, 64
orig: 57, 64
offset: 0, 0
index: -1
White/upperarm1
rotate: false
xy: 60, 27
size: 50, 56
orig: 50, 56
offset: 0, 0
index: -1
White/upperarm2
rotate: true
xy: 110, 44
size: 39, 59
orig: 39, 59
offset: 0, 0
index: -1

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 51b2d149fb5a7f7449fdafb65d240843
TextScriptImporter:
userData:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 4d269c9fcaaba024fb93b58c75bcafdd
TextScriptImporter:
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: a34fffda3f6321b4288a172798648ba3
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 0
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: a071d9faa273ab047939cccdcacddc55
NativeFormatImporter:
userData:

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 380672bd303e2764eb47728ead477b19
NativeFormatImporter:
userData:

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 6ba8c33ba732ee34290c79f1d69e0d55
NativeFormatImporter:
userData: