Compare commits

..

1 Commits

Author SHA1 Message Date
Shaun Reed b2283462bf New experience system
Doesn't work, branching for later development
2017-08-26 23:42:00 -04:00
38 changed files with 216 additions and 1134 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,8 @@
fileFormatVersion: 2
guid: 00e22d1ed21d14248801d764a0f6a057
timeCreated: 1504664152
timeCreated: 1478187146
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

View File

@ -1,152 +0,0 @@
fileFormatVersion: 2
guid: 4fe29e11b36d63d4bbddcaa4ef2409cb
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
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
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
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: 2048
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: 2048
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: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
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: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 28a82baf8aadfa844a76fc5dd71094f8
timeCreated: 1504643709
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 10e2d344b53a4c64b854b8b3904b369e
folderAsset: yes
timeCreated: 1504644496
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: e37a904fb373d0244a3345167006b83d
timeCreated: 1504644537
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 4cf0708b040fc2c4aa29a200bec6056f
timeCreated: 1504644516
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: acc04bbf04d68f24fa01177bb3ed86b8
timeCreated: 1504644530
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 3296a1925269b9c4699c0f4de17d0366
timeCreated: 1504644532
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

Binary file not shown.

View File

@ -4,49 +4,53 @@ using UnityEngine.UI;
public class ExperienceBar : MonoBehaviour {
//Playerdata -- Needs saved
public int currentLevel = 1;
public float currentExp = 0;
public float currentRequirement = 100;
// Eventually.. public RectTransform gainedExp
//Array used as expRequired[leveldesired]
[SerializeField]
private GameObject currentLevelText;
private int level = 1;
[SerializeField]
private float expObtained = 0;
[SerializeField]
private float expRequired = 100;
[SerializeField]
private float fillAmount;
[SerializeField]
private GameObject levelText;
[SerializeField]
private Image expBarSprite;
[SerializeField]
private float lerpSpeed;
[SerializeField]
private int clicks;
[SerializeField]
private GameObject eventSystem;
private float clicksNeeded = 10;
private float previousExpRequired;
private float barMovement;
private float barPosition;
[SerializeField]
public float expIncrement = 10.0f;
private string notify;
private float Increment = 10;
private struct levelReqA
{
int levelA;
float expRequiredA;
float clicksRequiredA;
}
private struct levelReqB
{
public int levelB;
public float expRequiredB;
public float clicksRequiredB;
}
// Use this for initialization
void Start () {
eventSystem = GameObject.Find("EventSystem");
fillAmount = currentExp / currentRequirement;
fillAmount = 0;
}
// Update is called once per frame
void Update () {
fillAmount = currentExp / currentRequirement;
this.gameObject.GetComponentInChildren<Text>().text = (int)currentExp + " / " + (int)currentRequirement;
if (currentLevelText.GetComponent<Text>().text != currentLevel.ToString()){
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
}
if (fillAmount != expBarSprite.fillAmount)
{
@ -57,7 +61,7 @@ public class ExperienceBar : MonoBehaviour {
if (expBarSprite.fillAmount >= 1.0f)
{
LevelUp();
clicksNeeded = (currentRequirement - currentExp) / expIncrement;
clicksNeeded = (expRequired - expObtained) / Increment;
fillAmount = 0;
}
}
@ -65,60 +69,50 @@ public class ExperienceBar : MonoBehaviour {
public void ExpMore()
{
++clicks;
currentExp = currentExp + expIncrement;
fillAmount = currentExp / currentRequirement;
notify = "+" + expIncrement + "EXP";
eventSystem.GetComponent<GameManager>().RewardPopup(expIncrement, 1);
//Debug.Log("fillAmount = " + fillAmount);
expObtained = expObtained + Increment;
fillAmount = (expObtained / expRequired);
Debug.Log("fillAmount = " + fillAmount);
}
public void LevelUp()
{
++currentLevel;
expIncrement += 10;
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
previousExpRequired = currentRequirement;
currentExp -= previousExpRequired;
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
GameObject.Find("Main Panel").GetComponent<ToggleMenus>().RaiseRotationSpeed();
notify = "Level " + currentLevel + "!";
eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2);
++level;
levelText.GetComponent<Text>().text = level.ToString();
previousExpRequired = expRequired;
expObtained = 0;
expRequired = Mathf.Pow(expRequired, 1.05f);
}
public void ResetExp()
{
currentLevel = 1;
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
currentExp = 0;
level = 1;
levelText.GetComponent<Text>().text = level.ToString();
fillAmount = 0;
expIncrement = 10.0f;
currentRequirement = 100;
expObtained = 0;
expRequired = 100;
clicksNeeded = 10;
clicks = 0;
notify = "EXP Reset";
eventSystem.GetComponent<GameManager>().MakeStringPopup(notify, 1);
}
public void ExpLess()
{
--clicks;
currentExp = currentExp - expIncrement;
fillAmount = (currentExp / currentRequirement);
expObtained = expObtained - Increment;
fillAmount = (expObtained / expRequired);
Debug.Log("fillAmount = " + fillAmount);
notify = "-" + expIncrement + "EXP";
eventSystem.GetComponent<GameManager>().RewardPopup(-expIncrement, 1);
}
public float GetExperience()
private levelReqB LevelRequirement(int level, levelReqB levelB)
{
float currentExp;
currentExp = this.currentExp;
return currentExp;
}
++level;
levelText.GetComponent<Text>().text = level.ToString();
levelB.expRequiredB = Mathf.Pow(100, 1.05f);
expObtained = 0;
expRequired = Mathf.Pow(expRequired, 1.05f);
}
}

View File

@ -1,167 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public class GameManager : MonoBehaviour {
//Used to save playerdata
//Serializable tells unity it can save to a file
[Serializable]
private class PlayerData
{
public int level;
public float experience;
public float requirement;
public float speed;
public float speedIncrement;
public float expIncrement;
public float rotationsPerSec;
public DateTime currentTime;
}
public float idleExp;
public GameObject popup;
public GameObject popupSpawn;
public string notify;
void OnApplicationFocus(bool pauseStatus)
{
Debug.Log("OnApplicationFocused");
if (pauseStatus)
{
//your app is NO LONGER in the background
Load();
}
else
{
//your app is now in the background
Save();
}
}
void OnApplicationQuit()
{
Save();
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
int currentLevel = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentLevel;
float currentExp = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp;
float currentRequirement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement;
float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec;
float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed;
float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
float currentExpIncrement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().expIncrement;
PlayerData data = new PlayerData();
data.level = currentLevel;
data.experience = currentExp;
data.requirement = currentRequirement;
data.speed = currentSpeed;
data.speedIncrement = currentIncrement;
data.expIncrement = currentExpIncrement;
data.rotationsPerSec = rotationPerSec;
data.currentTime = System.DateTime.Now;
bf.Serialize(file, data);
file.Close();
Debug.Log("Saved");
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec = data.rotationsPerSec;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = data.speed;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement = data.speedIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().expIncrement = data.expIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentLevel = data.level;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement;
DateTime loadTime = System.DateTime.Now;
int secondsPassed = GetIdleTime(data.currentTime, loadTime);
idleExp = (data.rotationsPerSec * secondsPassed) * data.expIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
if (idleExp >= 0.0f)
{
RewardPopup(idleExp, 1);
}
Debug.Log("Loaded");
Debug.Log("idleExp: " + idleExp);
}
}
public int GetIdleTime(DateTime saveTime, DateTime loadTime)
{
int daysPassed = 0;
int hoursPassed = 0;
int minutesPassed = 0;
int secondsPassed = 0;
for (int monthSaved = saveTime.Month; monthSaved < loadTime.Month; ++monthSaved)
{
daysPassed += 30;
}
daysPassed += loadTime.Day - saveTime.Day;
hoursPassed = daysPassed * 24;
hoursPassed += loadTime.Hour - saveTime.Hour;
minutesPassed = hoursPassed * 60;
minutesPassed += loadTime.Minute - saveTime.Minute;
secondsPassed = minutesPassed * 60;
secondsPassed += loadTime.Second - saveTime.Second;
Debug.Log("Seconds Passed: " + secondsPassed);
return secondsPassed;
}
public int notificationType;
public float noteValue;
/*
* type 1 = exp
* type 2 = level
*
*
*
*
*/
public void RewardPopup(float value, int type)
{
notificationType = type;
noteValue = value;
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform );
Debug.Log("Popup Created");
}
public void MakeStringPopup(string content, int type)
{
notify = content;
notificationType = type;
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform);
Debug.Log("Popup Created");
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 2da23f5b35feb9749839423cfa5b61b2
timeCreated: 1503806997
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,151 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PopupNotification : MonoBehaviour {
public bool move = false;
public bool active = false;
public Vector3 origin;
public float timer = 0.0f;
public float maxTimer = 3.0f;
public float speed = 50.0f;
public string localNotify;
public int notificationType;
public float localValue;
// Use this for initialization
void OnEnable ()
{
active = true;
//Get & set random rotation
double randomRotation = GetRandomNumber(-4.0, 4.0);
transform.Rotate(0.0f, 0.0f, (float)randomRotation);
//Debug.Log("Rotation set to :" + randomRotation);
//
notificationType = GameObject.Find("EventSystem").GetComponent<GameManager>().notificationType;
//localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().notify;
localValue = GameObject.Find("EventSystem").GetComponent<GameManager>().noteValue;
CheckNotificationType();
}
// Update is called once per frame
void FixedUpdate()
{
timer += 0.02f;
if (timer >= maxTimer)
{
active = false;
timer = 0.0f;
Destroy(this.gameObject);
}
if(move == true)
{
this.gameObject.transform.Translate(new Vector3(-5.0f, speed * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
else
{
this.gameObject.transform.Translate(new Vector3(0, speed * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.GetComponent<PopupNotification>().notificationType == 1 && notificationType == 1)
{
//if both colliding popus are EXP related
if ((maxTimer - timer) > (col.gameObject.GetComponent<PopupNotification>().maxTimer - col.gameObject.GetComponent<PopupNotification>().timer))
{
//If this Popup has more time left than colliding popup
localValue += col.gameObject.GetComponent<PopupNotification>().localValue;
maxTimer += 0.5f;
CheckNotificationType();
Destroy(col.gameObject);
}//else do nothing, let other popup handle it
}
else if (col.gameObject.GetComponent<PopupNotification>().notificationType == 2 && notificationType == 2)
{
//if both colliding popus are level related
if (localValue > col.gameObject.GetComponent<PopupNotification>().localValue)
{
//If this popup is of higher level
Destroy(col.gameObject);
}//Destroy collider, show most recent level
maxTimer += 1.0f;
CheckNotificationType();
}
else if (col.gameObject.GetComponent<PopupNotification>().notificationType != notificationType)
{
//if both colliding popus are not related
if (notificationType == 2)
{
move = true;
}//else do nothing, let other popup handle it
}
}
public double GetRandomNumber(double min, double max)
{
System.Random random = new System.Random();
return random.NextDouble() * (max - min) + min;
}
public void CheckNotificationType()
{
//If notification is of type EXP
if (notificationType == 1)
{
if (localValue == 0)
{
Debug.Log("Null EXP value, popup discarded :" + localValue);
Destroy(this.gameObject);
}
if (localValue > 0)
{
//If adding EXP
localNotify = "+" + localValue + "EXP";
}
else if (localValue < 0)
{
//If subtracting EXP
localNotify = localValue + "EXP";
}
}
else if (notificationType == 2)
{
//If notification is of type Level Gained
localNotify = "Level " + localValue + "!";
}
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: f65f56ebba8d5fd49ac926af557e92d7
timeCreated: 1504554538
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,80 +1,116 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SpinningCube : MonoBehaviour
{
//Playerdata -- Needs saved
public float currentSpeed = 20f;
public float currentIncrement = 20f;
public float rotationPerSec = 0.0f;
public float m_Speed = 20f;
public float increments = 10f;
public string RotationDirection = "Up";
public Vector3 m_RotationDirection = Vector3.up;
public Vector3 rotationOrigin;
public Vector3 stopRotation = Vector3.zero;
public Vector3 tempRotation;
public float angle2 = 0;
public float angledif, angle1;
public float angleSum = 0;
[SerializeField]
public float secPerRotation = 0.0f;
[SerializeField]
public float lastRPS = 0.0f;
private string RotationDirection = "Up";
private Vector3 m_RotationDirection = Vector3.up;
private Vector3 stopRotation = Vector3.zero;
private Vector3 tempRotation;
[SerializeField]
public float secondsPassed = 0.0f;
[SerializeField]
public int rotations;
public void Start()
public void ToggleRotationDirection()
{
/*
if(GameObject.Find("Rotation Panel").activeSelf)
if (m_RotationDirection == Vector3.up)
{
GameObject.Find("Rotation Direction Button").GetComponent<Button>().onClick.AddListener(() => { ToggleRotationDirection(); });
m_RotationDirection = Vector3.down;
RotationDirection = "Down";
}
*/
}
void FixedUpdate()
else
{
//Set angle1 = eulerAngle of axis being rotated prior to applying rotation
angle1 = this.gameObject.transform.rotation.eulerAngles.y;
transform.Rotate(m_RotationDirection * Time.deltaTime * currentSpeed);
//angle2 = eulerAngle of axis after rotation applied
angle2 = this.gameObject.transform.rotation.eulerAngles.y;
//Difference between angle2 and angle1, how much the object rotated between frames
angledif = angle2 - angle1;
secondsPassed += 0.02f;
//rotations += (int)(m_Speed / 360);
m_RotationDirection = Vector3.up;
RotationDirection = "Up";
}
Debug.Log("Toggled rotation direction: " + RotationDirection);
}
//if object is rotating, and angle difference is less than 0
//If object has rotated 20 degrees (currentSpeed = 20), when angle1 = 350, && angle2 = 10
//angle2(10)-angle1(350) = -340
//Object has rotated past 360
if ((currentSpeed > 0) && (angledif < 0))
public void ToggleRotation()
{
++rotations;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().ExpMore();
Debug.Log("Stopping Rotation. Last known rotation direction: " + RotationDirection);
stopRotation = Vector3.zero;
lastRPS = 1 / secondsPassed;
if(rotationPerSec != lastRPS)
if (m_RotationDirection == stopRotation)
{
rotationPerSec = lastRPS;
secPerRotation = secondsPassed;
Debug.Log("Rotations Per Second: " + rotationPerSec);
}
secondsPassed = 0.0f;
m_RotationDirection = tempRotation;
}
else {
tempRotation = m_RotationDirection;
m_RotationDirection = stopRotation;
}
}
public void RaiseRotationSpeed()
{
m_Speed = m_Speed + increments;
Debug.Log("Rotation Speed: " + m_Speed);
}
public void LowerRotationSpeed()
{
m_Speed = m_Speed - increments;
Debug.Log("Rotation Speed: " + m_Speed);
}
public void ResetRotationSpeed()
{
m_Speed = 20.0f;
Debug.Log("Rotation Speed Reset");
}
public void ChangeColorWhite()
{
GameObject.FindGameObjectsWithTag("Player");
gameObject.GetComponent<Renderer>().material.color = Color.white;
}
public void ChangeColorBlue()
{
gameObject.GetComponent<Renderer>().material.color = Color.blue;
}
public void ChangeColorBlack()
{
gameObject.GetComponent<Renderer>().material.color = Color.black;
}
public void ChangeColorGreen()
{
gameObject.GetComponent<Renderer>().material.color = Color.green;
}
public void ChangeColorRed()
{
gameObject.GetComponent<Renderer>().material.color = Color.red;
}
public void ChangeColorMagenta()
{
gameObject.GetComponent<Renderer>().material.color = Color.magenta;
}
public void ChangeColorYellow()
{
gameObject.GetComponent<Renderer>().material.color = Color.yellow;
}
public void ChangeColorCyan()
{
gameObject.GetComponent<Renderer>().material.color = Color.cyan;
}
void Update()
{
transform.Rotate(m_RotationDirection * Time.deltaTime * m_Speed);
}
}

View File

@ -1,113 +1,87 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class ToggleMenus : MonoBehaviour
{
//Menus
public GameObject rotMenu;
public GameObject colorMenu;
public GameObject shapesMenu;
public GameObject lightingMenu;
public GameObject expMenu;
private bool ActiveMenu = false;
public GameObject RotMenu;
public GameObject ColorMenu;
public GameObject ShapesMenu;
public GameObject LightingMenu;
public GameObject ExpMenu;
//Shapes - Prefabs
public GameObject player;
public GameObject Cube;
public GameObject Square;
public GameObject Sphere;
public GameObject Cylinder;
public GameObject Capsule;
public GameObject Temp;
public GameObject mySpawn;
//Use with lighting menu
//private GameObject lighting = GameObject.FindGameObjectWithTag("Lighting");
public float lightRotX, lightRotY, lightRotZ;
private string Spawn = "Spawn";
private string Active = "Cube";
private bool ActiveMenu = false;
// Use this for initialization
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
mySpawn = GameObject.Find("PlayerSpawn");
InitializeButtonArrays();
Temp = Square;
Temp = Cube;
lightRotX = 0;
lightRotY = 0;
lightRotZ = 0;
//EditLightingRotation();
//EditLightingLocation();
}
public void Update()
{
GameObject.FindGameObjectWithTag("Lighting").transform.Rotate(lightRotX, lightRotY, lightRotZ);
}
public void ToggleRotationMenu()
{
if (rotMenu.gameObject.activeSelf)
if (RotMenu.gameObject.active)
{
rotMenu.gameObject.SetActive(false);
RotMenu.gameObject.SetActive(false);
ActiveMenu = !ActiveMenu;
}
else if (!rotMenu.gameObject.activeSelf && ActiveMenu)
else if (!RotMenu.gameObject.active && ActiveMenu)
{
CloseAll();
rotMenu.gameObject.SetActive(true);
RotMenu.gameObject.SetActive(true);
}
else
{
rotMenu.gameObject.SetActive(true);
RotMenu.gameObject.SetActive(true);
ActiveMenu = !ActiveMenu;
}
}
public void ToggleColorMenu()
{
if (colorMenu.activeSelf)
if (ColorMenu.gameObject.active)
{
colorMenu.gameObject.SetActive(false);
ColorMenu.gameObject.SetActive(false);
ActiveMenu = !ActiveMenu;
}
else if (!colorMenu.activeSelf && ActiveMenu)
else if (!ColorMenu.gameObject.active && ActiveMenu)
{
CloseAll();
colorMenu.SetActive(true);
ColorMenu.gameObject.SetActive(true);
}
else
{
colorMenu.SetActive(true);
ColorMenu.gameObject.SetActive(true);
ActiveMenu = !ActiveMenu;
}
}
public void ToggleShapesMenu()
{
if (shapesMenu.gameObject.activeSelf)
if (ShapesMenu.gameObject.active)
{
shapesMenu.gameObject.SetActive(false);
ShapesMenu.gameObject.SetActive(false);
ActiveMenu = !ActiveMenu;
}
else if (!shapesMenu.gameObject.activeSelf && ActiveMenu)
else if (!ShapesMenu.gameObject.active && ActiveMenu)
{
CloseAll();
shapesMenu.gameObject.SetActive(true);
ShapesMenu.gameObject.SetActive(true);
}
else
{
shapesMenu.gameObject.SetActive(true);
ShapesMenu.gameObject.SetActive(true);
ActiveMenu = !ActiveMenu;
}
@ -115,343 +89,87 @@ public class ToggleMenus : MonoBehaviour
public void ToggleLightingMenu()
{
if (lightingMenu.gameObject.activeSelf)
if (LightingMenu.gameObject.active)
{
lightingMenu.gameObject.SetActive(false);
LightingMenu.gameObject.SetActive(false);
ActiveMenu = !ActiveMenu;
}
else if (!lightingMenu.gameObject.activeSelf && ActiveMenu)
else if (!LightingMenu.gameObject.active && ActiveMenu)
{
CloseAll();
lightingMenu.gameObject.SetActive(true);
LightingMenu.gameObject.SetActive(true);
}
else
{
lightingMenu.gameObject.SetActive(true);
LightingMenu.gameObject.SetActive(true);
ActiveMenu = !ActiveMenu;
}
}
public void ToggleExpMenu()
{
if (expMenu.gameObject.activeSelf)
if (ExpMenu.gameObject.active)
{
expMenu.gameObject.SetActive(false);
ExpMenu.gameObject.SetActive(false);
//check if another menu is open to avoid overlapping
ActiveMenu = !ActiveMenu;
}
else if (!expMenu.gameObject.activeSelf && ActiveMenu)
else if (!ExpMenu.gameObject.active && ActiveMenu)
{
CloseAll();
expMenu.gameObject.SetActive(true);
ExpMenu.gameObject.SetActive(true);
}
else
{
expMenu.gameObject.SetActive(true);
ExpMenu.gameObject.SetActive(true);
ActiveMenu = !ActiveMenu;
}
}
public void CloseAll()
{
shapesMenu.gameObject.SetActive(false);
rotMenu.gameObject.SetActive(false);
colorMenu.gameObject.SetActive(false);
lightingMenu.gameObject.SetActive(false);
expMenu.gameObject.SetActive(false);
ShapesMenu.gameObject.SetActive(false);
RotMenu.gameObject.SetActive(false);
ColorMenu.gameObject.SetActive(false);
LightingMenu.gameObject.SetActive(false);
ExpMenu.gameObject.SetActive(false);
}
public void ChangeShape(string shape)
public void ChangeShapeSquare()
{
switch (shape)
{
case "Cube":
Instantiate(Cube, mySpawn.transform.position, mySpawn.transform.rotation);
Instantiate(Square, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active));
Active = "Cube(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active);
}
break;
case "Sphere":
public void ChangeShapeSphere()
{
Instantiate(Sphere, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active));
Active = "Sphere(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active);
}
break;
case "Capsule":
public void ChangeShapeCapsule()
{
Instantiate(Capsule, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active));
Active = "Capsule(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active);
}
break;
case "Cylinder":
public void ChangeShapeCylinder()
{
Instantiate(Cylinder, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active));
Active = "Cylinder(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active);
break;
default:
Debug.Log("Error - Not a valid shape : " + shape);
break;
}
}
/*
public void EditLightingRotation()
{
buttons = GameObject.FindGameObjectsWithTag("RotationMenuButtons");
foreach (Object button in buttons)
{
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
}
/*
GameObject.Find("X Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationX(); });
GameObject.Find("Y Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationY(); });
GameObject.Find("Z Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationZ(); });
}
public void EditLightingLocation()
{
buttons = GameObject.FindGameObjectsWithTag("RotationMenuButtons");
foreach (Object button in buttons)
{
gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
}
//
//CHANGE THESE TO LOCATION NOT ROTATION
//
GameObject.Find("X Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationX(); });
GameObject.Find("Y Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationY(); });
GameObject.Find("Z Button").GetComponent<Button>().onClick.AddListener(() => { EditLightingRotationZ(); });
}
public void EditLightingLocationX()
{
//lightRotX = 20 * Time.deltaTime;
}
public void EditLightingRotationX()
{
lightRotX = 20 * Time.deltaTime;
}
public void EditLightingRotationY()
{
lightRotY = 20 * Time.deltaTime;
}
public void EditLightingRotationZ()
{
lightRotZ = 20 * Time.deltaTime;
}
*/
public void InitializeButtonArrays()
{
List<Button> mainButtons = new List<Button>();
List<Button> rotationButtons = new List<Button>();
List<Button> colorButtons = new List<Button>();
List<Button> shapesButtons = new List<Button>();
List<Button> lightingButtons = new List<Button>();
List<Button> expButtons = new List<Button>();
//Component spinningCube = player.GetComponent<SpinningCube>();
Button[] allButtons = GameObject.Find("UI Canvas").GetComponentsInChildren<Button>(true);
foreach(Button b in allButtons)
{
if (b.gameObject.transform.parent.name.Contains("Main"))
{
mainButtons.Add(b.gameObject.GetComponent<Button>());
}
if (b.gameObject.transform.parent.name.Contains("Rotation"))
{
rotationButtons.Add(b.gameObject.GetComponent<Button>());
}
if (b.gameObject.transform.parent.name.Contains("Color"))
{
colorButtons.Add(b.gameObject.GetComponent<Button>());
}
if (b.gameObject.transform.parent.name.Contains("Shapes"))
{
shapesButtons.Add(b.gameObject.GetComponent<Button>());
}
if (b.gameObject.transform.parent.name.Contains("Lighting"))
{
lightingButtons.Add(b.gameObject.GetComponent<Button>());
}
if (b.gameObject.transform.parent.name.Contains("Exp"))
{
expButtons.Add(b.gameObject.GetComponent<Button>());
}
}
//5 (0-4)
Debug.Log("mainButtons: " + mainButtons.Count);
//5 (0-4)
Debug.Log("rotationButtons: " + rotationButtons.Count);
//8 (0-7)
Debug.Log("colorButtons: " + colorButtons.Count);
//4 (0-3)
Debug.Log("shapesButtons: " + shapesButtons.Count);
//3 (0-2)
Debug.Log("lightingButtons: " + lightingButtons.Count);
//3 (0-2)
Debug.Log("expButtons: " + expButtons.Count);
mainButtons[0].onClick.AddListener(() => { ToggleRotationMenu(); });
mainButtons[1].onClick.AddListener(() => { ToggleColorMenu(); });
mainButtons[2].onClick.AddListener(() => { ToggleShapesMenu(); });
mainButtons[3].onClick.AddListener(() => { ToggleLightingMenu(); });
mainButtons[4].onClick.AddListener(() => { ToggleExpMenu(); });
rotationButtons[0].onClick.AddListener(() => { RaiseRotationSpeed(); });
rotationButtons[1].onClick.AddListener(() => { LowerRotationSpeed(); });
rotationButtons[2].onClick.AddListener(() => { ToggleRotation(); });
rotationButtons[3].onClick.AddListener(() => { ToggleRotationDirection(); });
rotationButtons[4].onClick.AddListener(() => { ResetRotationSpeed(); });
colorButtons[0].onClick.AddListener(() => { ChangeColor("Black"); });
colorButtons[1].onClick.AddListener(() => { ChangeColor("White"); });
colorButtons[2].onClick.AddListener(() => { ChangeColor("Red"); });
colorButtons[3].onClick.AddListener(() => { ChangeColor("Green"); });
colorButtons[4].onClick.AddListener(() => { ChangeColor("Blue"); });
colorButtons[5].onClick.AddListener(() => { ChangeColor("Yellow"); });
colorButtons[6].onClick.AddListener(() => { ChangeColor("Cyan"); });
colorButtons[7].onClick.AddListener(() => { ChangeColor("Magenta"); });
shapesButtons[0].onClick.AddListener(() => { ChangeShape("Cylinder"); });
shapesButtons[1].onClick.AddListener(() => { ChangeShape("Capsule"); });
shapesButtons[2].onClick.AddListener(() => { ChangeShape("Cube"); });
shapesButtons[3].onClick.AddListener(() => { ChangeShape("Sphere"); });
//Temporary save/load hidden in lighting for debug
lightingButtons[0].onClick.AddListener(() => { GameObject.Find("EventSystem").GetComponent<GameManager>().Save(); });
lightingButtons[1].onClick.AddListener(() => { GameObject.Find("EventSystem").GetComponent<GameManager>().Load(); });
//lightingButtons[2].onClick.AddListener(() => { function(); });
expButtons[0].onClick.AddListener(() => { GameObject.Find("Gained Image").GetComponent<ExperienceBar>().ExpMore(); });
expButtons[1].onClick.AddListener(() => { GameObject.Find("Gained Image").GetComponent<ExperienceBar>().ExpLess(); });
expButtons[2].onClick.AddListener(() => { GameObject.Find("Gained Image").GetComponent<ExperienceBar>().ResetExp(); });
}
public void ToggleRotationDirection()
{
if (GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection == Vector3.up)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = Vector3.down;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection = "Down";
}
else
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = Vector3.up;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection = "Up";
}
Debug.Log("Toggled rotation direction: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection);
}
public void ToggleRotation()
{
Debug.Log("Stopping Rotation. Last known rotation direction: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection);
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation = Vector3.zero;
if (GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection == GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().tempRotation;
}
else
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().tempRotation = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation;
}
}
public void RaiseRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
Debug.Log("Rotation Speed: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed);
}
public void LowerRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed - GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
Debug.Log("Rotation Speed: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed);
}
public void ResetRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = 20.0f;
Debug.Log("Rotation Speed Reset");
}
public void ChangeColor(string color)
{
switch (color)
{
case "White":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.white;
break;
case "Blue":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.blue;
break;
case "Black":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.black;
break;
case "Green":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.green;
break;
case "Red":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.red;
break;
case "Magenta":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.magenta;
break;
case "Yellow":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.yellow;
break;
case "Cyan":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.cyan;
break;
default:
Debug.Log("Error - no color named :" + color);
break;
}
}
}

View File

@ -1,45 +0,0 @@
=== Mon Nov 23 15:21:06 2020
Packages were changed.
Update Mode: resetToDefaultDependencies
The following packages were added:
com.unity.collab-proxy@1.2.16
com.unity.ide.rider@1.1.4
com.unity.ide.vscode@1.2.0
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.test-framework@1.1.13
com.unity.textmeshpro@2.0.1
com.unity.timeline@1.2.14
com.unity.ugui@1.0.0

View File

@ -1,42 +0,0 @@
{
"dependencies": {
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.2.0",
"com.unity.test-framework": "1.1.13",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.14",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1 @@
m_EditorVersion: 2019.3.13f1
m_EditorVersionWithRevision: 2019.3.13f1 (d4ddf0d95db9)
m_EditorVersion: 2017.1.0f3

Binary file not shown.

View File

@ -1,10 +0,0 @@
{
"m_SettingKeys": [
"VR Device Disabled",
"VR Device User Alert"
],
"m_SettingValues": [
"False",
"False"
]
}

View File

@ -1,21 +1,2 @@
# SpinningCube
First Android Unity project
A basic Android Application that can be built and played either on a device as a .apk or within the unity editor.
Not a game, but a demonstration of C# scripting within unity to create an idle-clicker like EXP system.
A learning experience.
The cube spins on the screen at a slow rate initially, as the cube rotates every full rotation grants exp.
Upon leveling up the rotation speed is increased.
Saves player data on exit, loads on start.
If the app is closed, or otherwise suspended, when returning EXP is added for time spent away and awarded to player.
Feel free to use the UI buttons to force your speed to ridiculous amounts.
Other fun debugging options in there, as well as changing the color of the cube.
Have fun, feel free to make a pull request.
![Screenshot of spinningcube](Screenshot.PNG)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB