Implemented steamworks and achievements, v1.3.0
This commit is contained in:
parent
aa56dea657
commit
84e897e147
4
.gitignore
vendored
4
.gitignore
vendored
@ -12,6 +12,10 @@
|
||||
/[Pp]ackages/
|
||||
/[Ss]ave/
|
||||
|
||||
# Asset for Steamworks
|
||||
/[Aa]ssets/com.rlabrecque.steamworks.net/
|
||||
/steam_appid.txt
|
||||
|
||||
# Asset meta data should only be ignored when the corresponding asset is also ignored
|
||||
!/[Aa]ssets/**/*.meta
|
||||
|
||||
|
||||
@ -2895,6 +2895,49 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 352876181}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &356515705
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 356515707}
|
||||
- component: {fileID: 356515706}
|
||||
m_Layer: 0
|
||||
m_Name: SteamManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &356515706
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 356515705}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4716aec506beac44b22821e9b551adc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &356515707
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 356515705}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 509.7981, y: 518.5044, z: -14.710571}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &359361263
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -21,6 +21,7 @@ namespace Assets.Scripts
|
||||
{
|
||||
//maxHealth, maxSecondary, strength, dexterity, intelligence
|
||||
int[] result = new int[5];
|
||||
int[] stats = player.getStats();
|
||||
switch (player.getPlayerName().ToLower())
|
||||
{
|
||||
case "threetimes8":
|
||||
@ -44,9 +45,15 @@ namespace Assets.Scripts
|
||||
result[3] = 47;
|
||||
result[4] = 47;
|
||||
break;
|
||||
case "nicola":
|
||||
result[0] = stats[1];
|
||||
result[1] = stats[3];
|
||||
result[2] = stats[4];
|
||||
result[3] = stats[5];
|
||||
result[4] = stats[6];
|
||||
SteamWorksHandler.getStandardAchievement("GodAchievement");
|
||||
break;
|
||||
default:
|
||||
//health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points
|
||||
int[] stats = player.getStats();
|
||||
result[0] = stats[1];
|
||||
result[1] = stats[3];
|
||||
result[2] = stats[4];
|
||||
|
||||
@ -65,6 +65,10 @@ public class Fight : MonoBehaviour
|
||||
bool isDead = enemy.GetComponent<Enemy>().takeDamage(playerDamage);
|
||||
if (isDead)
|
||||
{
|
||||
if (enemy.GetComponent<Enemy>().getEnemyName() == "Slime (Boss)")
|
||||
{
|
||||
SteamWorksHandler.getStandardAchievement("BossAchievement");
|
||||
}
|
||||
endFight();
|
||||
tile.GetComponent<Tile>().enemyKilled(enemy);
|
||||
player.GetComponent<Player>().enemyKilled();
|
||||
@ -124,6 +128,7 @@ public class Fight : MonoBehaviour
|
||||
|
||||
if (player.GetComponent<Player>().takeDamage(enemyDamage))
|
||||
{
|
||||
SteamWorksHandler.getStandardAchievement("DeathAchievement");
|
||||
uihandler.showDeathScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ namespace Assets.Scripts.Menu
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.openCharacterCreation();
|
||||
SteamWorksHandler.callSteamworks();
|
||||
}
|
||||
|
||||
public void closeCreation()
|
||||
|
||||
@ -20,6 +20,7 @@ namespace Assets.Scripts.Menu
|
||||
options.SetActive(false);
|
||||
characterCreation.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
SteamWorksHandler.getStandardAchievement("StartAchievement");
|
||||
}
|
||||
|
||||
void Update()
|
||||
@ -51,6 +52,7 @@ namespace Assets.Scripts.Menu
|
||||
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
|
||||
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
||||
PlayerPrefs.SetInt("isLoad", 0);
|
||||
SteamWorksHandler.getStandardAchievement("CharAchievement");
|
||||
sceneHandler.openGameScene();
|
||||
}
|
||||
|
||||
|
||||
@ -433,9 +433,22 @@ namespace Assets.Scripts
|
||||
{
|
||||
uihandler.showMessage("SUCCESS;You killed your enemy!");
|
||||
killcount++;
|
||||
SteamWorksHandler.getSlimeAchievement(killcount);
|
||||
if (killcount >= 30 * (difficulty + 1) && GameObject.Find("Worldgenerator").GetComponent<WorldGenerator>().gameWon())
|
||||
{
|
||||
uihandler.showMessage("SUCCESS;You won the game!");
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0:
|
||||
SteamWorksHandler.getStandardAchievement("EasyAchievement");
|
||||
break;
|
||||
case 1:
|
||||
SteamWorksHandler.getStandardAchievement("NormalAchievement");
|
||||
break;
|
||||
case 2:
|
||||
SteamWorksHandler.getStandardAchievement("HardAchievement");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
204
Assets/Scripts/SteamManager.cs
Normal file
204
Assets/Scripts/SteamManager.cs
Normal file
@ -0,0 +1,204 @@
|
||||
// The SteamManager is designed to work with Steamworks.NET
|
||||
// This file is released into the public domain.
|
||||
// Where that dedication is not recognized you are granted a perpetual,
|
||||
// irrevocable license to copy and modify this file as you see fit.
|
||||
//
|
||||
// Version: 1.0.12
|
||||
|
||||
#if !(UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX || STEAMWORKS_WIN || STEAMWORKS_LIN_OSX)
|
||||
#define DISABLESTEAMWORKS
|
||||
#endif
|
||||
|
||||
using UnityEngine;
|
||||
#if !DISABLESTEAMWORKS
|
||||
using System.Collections;
|
||||
using Steamworks;
|
||||
#endif
|
||||
|
||||
//
|
||||
// The SteamManager provides a base implementation of Steamworks.NET on which you can build upon.
|
||||
// It handles the basics of starting up and shutting down the SteamAPI for use.
|
||||
//
|
||||
[DisallowMultipleComponent]
|
||||
public class SteamManager : MonoBehaviour
|
||||
{
|
||||
#if !DISABLESTEAMWORKS
|
||||
protected static bool s_EverInitialized = false;
|
||||
|
||||
protected static SteamManager s_instance;
|
||||
protected static SteamManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_instance == null)
|
||||
{
|
||||
return new GameObject("SteamManager").AddComponent<SteamManager>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected bool m_bInitialized = false;
|
||||
public static bool Initialized
|
||||
{
|
||||
get
|
||||
{
|
||||
return Instance.m_bInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
protected SteamAPIWarningMessageHook_t m_SteamAPIWarningMessageHook;
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(SteamAPIWarningMessageHook_t))]
|
||||
protected static void SteamAPIDebugTextHook(int nSeverity, System.Text.StringBuilder pchDebugText)
|
||||
{
|
||||
Debug.LogWarning(pchDebugText);
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
// In case of disabled Domain Reload, reset static members before entering Play Mode.
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void InitOnPlayMode()
|
||||
{
|
||||
s_EverInitialized = false;
|
||||
s_instance = null;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
// Only one instance of SteamManager at a time!
|
||||
if (s_instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
s_instance = this;
|
||||
|
||||
if (s_EverInitialized)
|
||||
{
|
||||
// This is almost always an error.
|
||||
// The most common case where this happens is when SteamManager gets destroyed because of Application.Quit(),
|
||||
// and then some Steamworks code in some other OnDestroy gets called afterwards, creating a new SteamManager.
|
||||
// You should never call Steamworks functions in OnDestroy, always prefer OnDisable if possible.
|
||||
throw new System.Exception("Tried to Initialize the SteamAPI twice in one session!");
|
||||
}
|
||||
|
||||
// We want our SteamManager Instance to persist across scenes.
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (!Packsize.Test())
|
||||
{
|
||||
Debug.LogError("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.", this);
|
||||
}
|
||||
|
||||
if (!DllCheck.Test())
|
||||
{
|
||||
Debug.LogError("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.", this);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// If Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the
|
||||
// Steam client and also launches this game again if the User owns it. This can act as a rudimentary form of DRM.
|
||||
|
||||
// Once you get a Steam AppID assigned by Valve, you need to replace AppId_t.Invalid with it and
|
||||
// remove steam_appid.txt from the game depot. eg: "(AppId_t)480" or "new AppId_t(480)".
|
||||
// See the Valve documentation for more information: https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
|
||||
if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid))
|
||||
{
|
||||
Application.Quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (System.DllNotFoundException e)
|
||||
{ // We catch this exception here, as it will be the first occurrence of it.
|
||||
Debug.LogError("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + e, this);
|
||||
|
||||
Application.Quit();
|
||||
return;
|
||||
}
|
||||
|
||||
// Initializes the Steamworks API.
|
||||
// If this returns false then this indicates one of the following conditions:
|
||||
// [*] The Steam client isn't running. A running Steam client is required to provide implementations of the various Steamworks interfaces.
|
||||
// [*] The Steam client couldn't determine the App ID of game. If you're running your application from the executable or debugger directly then you must have a [code-inline]steam_appid.txt[/code-inline] in your game directory next to the executable, with your app ID in it and nothing else. Steam will look for this file in the current working directory. If you are running your executable from a different directory you may need to relocate the [code-inline]steam_appid.txt[/code-inline] file.
|
||||
// [*] Your application is not running under the same OS user context as the Steam client, such as a different user or administration access level.
|
||||
// [*] Ensure that you own a license for the App ID on the currently active Steam account. Your game must show up in your Steam library.
|
||||
// [*] Your App ID is not completely set up, i.e. in Release State: Unavailable, or it's missing default packages.
|
||||
// Valve's documentation for this is located here:
|
||||
// https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
|
||||
m_bInitialized = SteamAPI.Init();
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
s_EverInitialized = true;
|
||||
}
|
||||
|
||||
// This should only ever get called on first load and after an Assembly reload, You should never Disable the Steamworks Manager yourself.
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (s_instance == null)
|
||||
{
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_SteamAPIWarningMessageHook == null)
|
||||
{
|
||||
// Set up our callback to receive warning messages from Steam.
|
||||
// You must launch with "-debug_steamapi" in the launch args to receive warnings.
|
||||
m_SteamAPIWarningMessageHook = new SteamAPIWarningMessageHook_t(SteamAPIDebugTextHook);
|
||||
SteamClient.SetWarningMessageHook(m_SteamAPIWarningMessageHook);
|
||||
}
|
||||
}
|
||||
|
||||
// OnApplicationQuit gets called too early to shutdown the SteamAPI.
|
||||
// Because the SteamManager should be persistent and never disabled or destroyed we can shutdown the SteamAPI here.
|
||||
// Thus it is not recommended to perform any Steamworks work in other OnDestroy functions as the order of execution can not be garenteed upon Shutdown. Prefer OnDisable().
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (s_instance != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_instance = null;
|
||||
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SteamAPI.Shutdown();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Run Steam client callbacks
|
||||
SteamAPI.RunCallbacks();
|
||||
}
|
||||
#else
|
||||
public static bool Initialized {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif // !DISABLESTEAMWORKS
|
||||
}
|
||||
11
Assets/Scripts/SteamManager.cs.meta
Normal file
11
Assets/Scripts/SteamManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4716aec506beac44b22821e9b551adc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
81
Assets/Scripts/SteamWorksHandler.cs
Normal file
81
Assets/Scripts/SteamWorksHandler.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Assets.Scripts;
|
||||
|
||||
public class SteamWorksHandler : MonoBehaviour
|
||||
{
|
||||
/* Steam Achievements
|
||||
* FORMAT = Requirement: Message
|
||||
* (Currently dropped) Playing for 5 hours: Got nothing else to do?
|
||||
* (Currently dropped) Playing for 10 hours: Look at THAT sunset!
|
||||
* (Currently dropped) Playing for 20 hours: You want coffee to your bagel?
|
||||
* (Currently dropped) Playing for 40 hours: I guess I have a true fan here
|
||||
* (Currently dropped) Playing for 80 hours: You should consider going outside
|
||||
*/
|
||||
static int counterForest = 0;
|
||||
|
||||
public static void getForestAchievement(string tiletype)
|
||||
{
|
||||
if (counterForest != -1 && !isGodMode())
|
||||
{
|
||||
if (tiletype == "Forest")
|
||||
{
|
||||
counterForest++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counterForest = 0;
|
||||
}
|
||||
if (counterForest >= 5)
|
||||
{
|
||||
SteamUserStats.SetAchievement("ForestAchievement");
|
||||
counterForest = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void getStandardAchievement(string name)
|
||||
{
|
||||
if (!isGodMode())
|
||||
{
|
||||
SteamUserStats.SetAchievement(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void getSlimeAchievement(int killcount)
|
||||
{
|
||||
string name = "";
|
||||
switch (killcount)
|
||||
{
|
||||
case 1:
|
||||
name = "Kill1Slime";
|
||||
break;
|
||||
case 10:
|
||||
name = "Kill10Slime";
|
||||
break;
|
||||
case 50:
|
||||
name = "Kill50Slime";
|
||||
break;
|
||||
case 100:
|
||||
name = "Kill100Slime";
|
||||
break;
|
||||
case 500:
|
||||
name = "Kill500Slime";
|
||||
break;
|
||||
case 1000:
|
||||
name = "Kill1000Slime";
|
||||
break;
|
||||
}
|
||||
if (!isGodMode())
|
||||
{
|
||||
SteamUserStats.SetAchievement(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isGodMode()
|
||||
{
|
||||
return EasterEggHandler.isGodMode(GameObject.Find("Player").GetComponent<Player>());
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SteamWorksHandler.cs.meta
Normal file
11
Assets/Scripts/SteamWorksHandler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d3ed29954b7b9746a1c1331c03220c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -25,6 +25,7 @@ public class Tile : MonoBehaviour
|
||||
{
|
||||
tiletype = type;
|
||||
}
|
||||
SteamWorksHandler.getForestAchievement(type);
|
||||
contentGenerator = GameObject.Find("ContentGenerator");
|
||||
setPosition(pos);
|
||||
setBorders();
|
||||
|
||||
@ -100,6 +100,7 @@ public class WorldGenerator : MonoBehaviour
|
||||
newTile = Instantiate(city, mapPos, Quaternion.identity);
|
||||
name = city.name;
|
||||
cityAmount--;
|
||||
SteamWorksHandler.getStandardAchievement("CityAchievement");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
8
Assets/com.rlabrecque.steamworks.net.meta
Normal file
8
Assets/com.rlabrecque.steamworks.net.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64c2f7c4937560c4e91a13674c1677fe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -581,7 +581,7 @@ PlayerSettings:
|
||||
webGLThreadsSupport: 0
|
||||
webGLDecompressionFallback: 0
|
||||
scriptingDefineSymbols:
|
||||
1: CROSS_PLATFORM_INPUT
|
||||
1: CROSS_PLATFORM_INPUT;STEAMWORKS_NET
|
||||
4: CROSS_PLATFORM_INPUT;MOBILE_INPUT
|
||||
7: CROSS_PLATFORM_INPUT;MOBILE_INPUT
|
||||
14: MOBILE_INPUT
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user