Forum rules - please read before posting.

Unlock Steam Achievements with Heathen Engineering Steamworks

The Heathen Engineering Steamworks integration is an easy way to get Steamworks.NET working in Unity without code, and so I figured that some people might be using it to set up Steamworks in their project like I am. However, this means that the Achievement Unlock custom action by @Alverik will no longer work correctly. So, I've made a few edits to the script to correctly work with the Heathen Engineering Steamworks, which you can view below.
Hope this helps some people!

using UnityEngine;
using System;
using HeathenEngineering.SteamworksIntegration;
using HeathenEngineering.SteamworksIntegration.API;
using StatsClient = HeathenEngineering.SteamworksIntegration.API.StatsAndAchievements.Client;
using Steamworks;

#if UNITY_EDITOR
using UnityEditor;
#endif
/* By Alvaro Urrutia Luna (Alverik)
* Edited by Ryan Zollinger (Dr. PUZZLER) to work with Heathen Engineering Steamworks
* Custom action to
* Unlock Steam achievements.
*/
namespace AC
{

    [System.Serializable]
    public class ActionUnlockAchievement : Action
    {

        public string AchievementID  = "";

        public override ActionCategory Category { get { return ActionCategory.Custom; }}
        public override string Title { get { return "Unlock Steam Achievement."; }}
        public override string Description { get { return "Unlocks an steam Achievement."; }}

        override public float Run ()

        {
            //your action:
            if (SteamSettings.Initialized) 
            {
                if(AchievementID!=String.Empty || AchievementID!="")
                {
                    try
                    {
                        StatsAndAchievements.Client.SetAchievement(AchievementID);
                        StatsAndAchievements.Client.StoreStats();
                    }
                    catch(Exception e)
                    {
                        Debug.LogError("Error while setting steam achievements... " + e);
                    }

                }
            }
            //end the action
            return 0f;
        }


        #if UNITY_EDITOR

        override public void ShowGUI ()
        {
            // Action-specific Inspector GUI code here
            AchievementID  = EditorGUILayout.TextField("Achievement ID: ", AchievementID , GUILayout.ExpandWidth(true));
        }


        public override string SetLabel ()
        {
            // Return a string used to describe the specific action's job.
            string labelAdd = "Unlocks an steam Achievement.";
            return labelAdd;
        }

        #endif

    }

}

Comments

  • Also, one more thing: If you want to exclude this code from builds that won't be utilising Steamworks, you can do so by adding DISABLESTEAMWORKS as a Scripting Define Symbol in the player settings. (This is required for this to compile on non linux/mac/windows builds.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.