NOW YOU HAVE LEVEL LOADING BUT YOU NEED TO BUILD FIRST FUCK IT - DOOOOOOOOOOOOOOOOOOOOON
This commit is contained in:
parent
e60bb80dc4
commit
e79e8de926
@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CharacterMovement : MonoBehaviour {
|
||||
|
||||
@ -63,24 +64,33 @@ public class CharacterMovement : MonoBehaviour {
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.T))
|
||||
{
|
||||
print("Got teleport key.");
|
||||
powerTeleport();
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.F))
|
||||
{
|
||||
print("got shit");
|
||||
if (canPass == true)
|
||||
canPass = false;
|
||||
else
|
||||
canPass = true;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
{
|
||||
if(SceneManager.GetActiveScene().name == "GMLevel1")
|
||||
{
|
||||
StartCoroutine(GameManager.gManager.SetGameStateAndLoad("GMLevel2"));
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(GameManager.gManager.SetGameStateAndLoad("GMLevel1"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.G))
|
||||
{
|
||||
print("got nodda");
|
||||
if (changeBox == true)
|
||||
changeBox = false;
|
||||
else
|
||||
@ -92,7 +102,6 @@ public class CharacterMovement : MonoBehaviour {
|
||||
public void powerTransfer()
|
||||
{
|
||||
//Transfer (enabling the player to "transfer" thier "hit" box behind them)
|
||||
print("got transfer");
|
||||
if (changeBox == true && timeRemainingTransfer >= 0.0 )
|
||||
{
|
||||
GetComponent<BoxCollider2D>().offset = new Vector2(secondBoxX, secondBoxY);
|
||||
@ -112,7 +121,6 @@ public class CharacterMovement : MonoBehaviour {
|
||||
public void powerTransparency()
|
||||
{
|
||||
//Transparency (enabling the player to "glitch" through certain boundaries.)
|
||||
print("got transparency");
|
||||
if (canPass == true && timeRemainingTransparency >= 0.0)
|
||||
{
|
||||
Physics2D.IgnoreLayerCollision(8, 10, true); //Make sure that the "barriers" that the player needs to "phase" through are part of the barrier layer.
|
||||
|
Binary file not shown.
@ -19,6 +19,7 @@ namespace UnityStandardAssets._2D
|
||||
// Use this for initialization
|
||||
private void Start()
|
||||
{
|
||||
target = GameManager.m_Character.gameObject.transform;
|
||||
m_LastTargetPosition = target.position;
|
||||
m_OffsetZ = (transform.position - target.position).z;
|
||||
transform.parent = null;
|
||||
|
@ -1,24 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityStandardAssets.CrossPlatformInput;
|
||||
using GameUtils;
|
||||
|
||||
namespace UnityStandardAssets._2D
|
||||
{
|
||||
[RequireComponent(typeof (PlatformerCharacter2D))]
|
||||
public class Platformer2DUserControl : CharacterMovement
|
||||
public class Platformer2DUserControl : CharacterMovement, ISceneObject
|
||||
{
|
||||
private PlatformerCharacter2D m_Character;
|
||||
private bool m_Jump;
|
||||
|
||||
public bool canMove;
|
||||
|
||||
private void Awake()
|
||||
public void Initialize()
|
||||
{
|
||||
m_Character = GetComponent<PlatformerCharacter2D>();
|
||||
// Put any needed initialization script here.
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
public void ObjectUpdate()
|
||||
{
|
||||
// calling stuff in from the Character Movement class
|
||||
Movement();
|
||||
@ -33,14 +33,13 @@ namespace UnityStandardAssets._2D
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Read the inputs.
|
||||
bool crouch = Input.GetKey(KeyCode.LeftControl);
|
||||
float h = CrossPlatformInputManager.GetAxis("Horizontal");
|
||||
// Pass all parameters to the character control script.
|
||||
m_Character.Move(h, crouch, m_Jump);
|
||||
GameManager.m_Character.Move(h, crouch, m_Jump);
|
||||
m_Jump = false;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using GameUtils;
|
||||
|
||||
namespace UnityStandardAssets._2D
|
||||
{
|
||||
|
@ -6,12 +6,11 @@ namespace UnityStandardAssets._2D
|
||||
{
|
||||
public class Restarter : MonoBehaviour
|
||||
{
|
||||
public string mapName; // does not need extension. will error if provided
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.tag == "Player")
|
||||
{
|
||||
SceneManager.LoadScene(mapName);
|
||||
SceneManager.LoadScene(SceneManager.GetSceneAt(0).path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
Assets/Resources/Scenes/GameManagerTest.meta
Normal file
9
Assets/Resources/Scenes/GameManagerTest.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10bdeb02a569ee74697a560aeed379bf
|
||||
folderAsset: yes
|
||||
timeCreated: 1454218606
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Resources/Scenes/GameManagerTest/GMLevel1.unity
Normal file
BIN
Assets/Resources/Scenes/GameManagerTest/GMLevel1.unity
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df7043776028eda4588369674933f682
|
||||
timeCreated: 1454199405
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Resources/Scenes/GameManagerTest/GMLevel2.unity
Normal file
BIN
Assets/Resources/Scenes/GameManagerTest/GMLevel2.unity
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f4034ffc15b1544cb93d5c3ea99cb0a
|
||||
timeCreated: 1454203428
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/Resources/Scripts/GManagerTestScripts.meta
Normal file
9
Assets/Resources/Scripts/GManagerTestScripts.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7852d1fb45334546801538ecd10fcc6
|
||||
folderAsset: yes
|
||||
timeCreated: 1454218607
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CameraManager : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c15eaae1cece194f942a577aaf35afe
|
||||
timeCreated: 1454200762
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a3983c59ebf804b4abba687bd7c9e92f, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
89
Assets/Resources/Scripts/GManagerTestScripts/GameManager.cs
Normal file
89
Assets/Resources/Scripts/GManagerTestScripts/GameManager.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using GameUtils;
|
||||
using UnityStandardAssets._2D;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static GameManager gManager; // gManager for GameManager, iManager for InputManager, etc...
|
||||
public static InputManager iManager;
|
||||
public static PlatformerCharacter2D m_Character;
|
||||
public static Camera m_Camera;
|
||||
public static GameState gState;
|
||||
|
||||
public Dictionary<GameState, string> levelDictionary;
|
||||
|
||||
private GameObject[] tagged_objects;
|
||||
private ISceneObject[] scene_objects;
|
||||
private string _testLevelPrefix, _regularLevelPrefix;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (gManager == this)
|
||||
{
|
||||
iManager = new InputManager(0.1f, 0.2f); // It could be helpful, I guess.
|
||||
tagged_objects = GameObject.FindGameObjectsWithTag("Scene_Object");
|
||||
scene_objects = new ISceneObject[tagged_objects.Length];
|
||||
iManager.Initialize();
|
||||
// Initialize the list of scene objects, all of which have ONE ISceneObject component.
|
||||
for (int i = 0; i < tagged_objects.Length; i++)
|
||||
{
|
||||
scene_objects[i] = tagged_objects[i].GetComponent<ISceneObject>(); // Grab all of those scene objects!
|
||||
}
|
||||
|
||||
// Initialize all scene objects.
|
||||
for (int j = 0; j < scene_objects.Length; j++)
|
||||
{
|
||||
scene_objects[j].Initialize();
|
||||
}
|
||||
levelDictionary = new Dictionary<GameState, string>() { { GameState.TLEVELONE, "GMLevel1" },
|
||||
{ GameState.TLEVELTWO, "GMLevel2" } };
|
||||
// This will break on regular levels, handle regular levels separately.
|
||||
GameManager.gState = levelDictionary.FirstOrDefault(x => x.Value == _testLevelPrefix + SceneManager.GetActiveScene().name).Key;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator SetGameStateAndLoad(string levelName)
|
||||
{
|
||||
GameManager.gState = levelDictionary.FirstOrDefault(x => x.Value == levelName).Key;
|
||||
// Trigger Loading Screen
|
||||
transform.Find("LoadingScreen").gameObject.SetActive(true);
|
||||
AsyncOperation aSyncOp = SceneManager.LoadSceneAsync(levelDictionary[GameManager.gState]);
|
||||
aSyncOp.allowSceneActivation = true;
|
||||
float progress = 0.0f;
|
||||
while (progress < 0.9f) // whatever "100" is
|
||||
{
|
||||
progress = aSyncOp.progress * 100.0f;
|
||||
print("Loading: " + progress);
|
||||
yield return null;
|
||||
}
|
||||
transform.Find("LoadingScreen").gameObject.SetActive(false);
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all scene objects in one update loop.
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
iManager.ObjectUpdate();
|
||||
for (int j = 0; j < scene_objects.Length; j++)
|
||||
{
|
||||
scene_objects[j].ObjectUpdate();
|
||||
}
|
||||
if (GameManager.gManager != null && GameManager.iManager != null && GameManager.m_Camera != null)
|
||||
return;
|
||||
if (GameManager.gManager == null)
|
||||
throw new Exception("We did not assign the game manager.");
|
||||
if (GameManager.iManager == null)
|
||||
throw new Exception("We did not assign an input manager.");
|
||||
if (GameManager.m_Camera == null)
|
||||
throw new Exception("We did not assign a main camera.");
|
||||
// It can be the case that there is no character in the scene (i.e. main menu) so we won't check for that.
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9f83bb10cb22ff4d98a2ce12f695f16
|
||||
timeCreated: 1454121212
|
||||
timeCreated: 1454200751
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
icon: {fileID: 2800000, guid: f588d850485d0ae479d73cf3bd0b7b00, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,12 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df3fc0ea74484414d8eab988c8ea33f6
|
||||
timeCreated: 1454122161
|
||||
timeCreated: 1454200715
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
icon: {fileID: 2800000, guid: 9866a92691696b346901281f2b329034, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Resources/Scripts/GManagerTestScripts/Singleton.cs
Normal file
37
Assets/Resources/Scripts/GManagerTestScripts/Singleton.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityStandardAssets._2D;
|
||||
using System.Collections;
|
||||
|
||||
public class Singleton : MonoBehaviour {
|
||||
|
||||
private GameManager gManager;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
gManager = GameObject.FindGameObjectWithTag("Game_Manager").GetComponent<GameManager>();
|
||||
if(GameManager.gManager == null && gameObject.tag == "Game_Manager")
|
||||
{
|
||||
print("Assigning game manager.");
|
||||
GameManager.gManager = gameObject.GetComponent<GameManager>();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else if(GameManager.m_Character == null && gameObject.layer == LayerMask.NameToLayer("player"))
|
||||
{
|
||||
print("Assigning main character");
|
||||
GameManager.m_Character = gameObject.GetComponent<PlatformerCharacter2D>();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else if(GameManager.m_Camera == null && gameObject.tag == "MainCamera")
|
||||
{
|
||||
print("Assigning main camera.");
|
||||
GameManager.m_Camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
print("FOUND ANOTHER INSTANCE OF SINGLETON");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f8b471ac1371a34e910fe1e3be2a54f
|
||||
timeCreated: 1454200775
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a94c9a7eb94ceec4a8d67a1890e22e51, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -46,7 +46,9 @@ namespace GameUtils
|
||||
public enum GameState
|
||||
{
|
||||
TITLE, // index 0
|
||||
MAINMENU // index 1
|
||||
MAINMENU, // index 1
|
||||
TLEVELONE,
|
||||
TLEVELTWO
|
||||
// ... this goes on to define levels, most useful if kept in the same loading order that is to be used during build.
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cba653c7df71b3141bd84232c2d61186
|
||||
timeCreated: 1454120355
|
||||
timeCreated: 1454200817
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
icon: {fileID: 2800000, guid: 20b408984aa19d74097eb6ed5b7f6dec, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,53 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using GameUtils;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static GameManager gManager; // gManager for GameManager, iManager for InputManager, etc...
|
||||
public static InputManager iManager;
|
||||
|
||||
private GameObject[] tagged_objects;
|
||||
private ISceneObject[] scene_objects;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (gManager == null)
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
gManager = this;
|
||||
iManager = new InputManager(0.1f, 0.2f);
|
||||
tagged_objects = GameObject.FindGameObjectsWithTag("Scene_Object");
|
||||
scene_objects = new ISceneObject[tagged_objects.Length];
|
||||
iManager.Initialize();
|
||||
// Initialize the list of scene objects, all of which have ONE ISceneObject component.
|
||||
for (int i = 0; i < tagged_objects.Length; i++)
|
||||
{
|
||||
scene_objects[i] = tagged_objects[i].GetComponent<ISceneObject>(); // Grab all of those scene objects!
|
||||
}
|
||||
|
||||
// Initialize all scene objects.
|
||||
for (int j = 0; j < scene_objects.Length; j++)
|
||||
{
|
||||
scene_objects[j].Initialize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all scene objects in one update loop.
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
iManager.ObjectUpdate();
|
||||
for (int j = 0; j < scene_objects.Length; j++)
|
||||
{
|
||||
scene_objects[j].ObjectUpdate();
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 5.3.2f1
|
||||
m_EditorVersion: 5.3.1f1
|
||||
m_StandardAssetsVersion: 0
|
||||
|
Reference in New Issue
Block a user