//
// Copyright (C) 2014 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if (UNITY_ANDROID || (UNITY_IPHONE && !NO_GPGS))
namespace GooglePlayGames.BasicApi
{
using System;
/// Data interface for retrieving achievement information.
///
/// There are 3 states an achievement can be in:
///
/// Hidden - indicating the name and description of the achievement is
/// not visible to the player.
///
/// Revealed - indicating the name and description of the achievement is
/// visible to the player.
/// Unlocked - indicating the player has unlocked, or achieved, the achievment.
///
/// Achievements has two types, standard which is unlocked in one step,
/// and incremental, which require multiple steps to unlock.
///
///
public class Achievement
{
static readonly DateTime UnixEpoch =
new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
private string mId = string.Empty;
private bool mIsIncremental = false;
private bool mIsRevealed = false;
private bool mIsUnlocked = false;
private int mCurrentSteps = 0;
private int mTotalSteps = 0;
private string mDescription = string.Empty;
private string mName = string.Empty;
private long mLastModifiedTime = 0;
private ulong mPoints;
private string mRevealedImageUrl;
private string mUnlockedImageUrl;
///
/// Returns a that represents the current .
///
/// A that represents the current .
public override string ToString()
{
return string.Format(
"[Achievement] id={0}, name={1}, desc={2}, type={3}, revealed={4}, unlocked={5}, steps={6}/{7}",
mId, mName, mDescription, mIsIncremental ? "INCREMENTAL" : "STANDARD",
mIsRevealed, mIsUnlocked, mCurrentSteps, mTotalSteps);
}
public Achievement()
{
}
///
/// Indicates whether this achievement is incremental.
///
public bool IsIncremental
{
get
{
return mIsIncremental;
}
set
{
mIsIncremental = value;
}
}
///
/// The number of steps the user has gone towards unlocking this achievement.
///
public int CurrentSteps
{
get
{
return mCurrentSteps;
}
set
{
mCurrentSteps = value;
}
}
///
/// The total number of steps needed to unlock this achievement.
///
public int TotalSteps
{
get
{
return mTotalSteps;
}
set
{
mTotalSteps = value;
}
}
///
/// Indicates whether the achievement is unlocked or not.
///
public bool IsUnlocked
{
get
{
return mIsUnlocked;
}
set
{
mIsUnlocked = value;
}
}
///
/// Indicates whether the achievement is revealed or not (hidden).
///
public bool IsRevealed
{
get
{
return mIsRevealed;
}
set
{
mIsRevealed = value;
}
}
///
/// The ID string of this achievement.
///
public string Id
{
get
{
return mId;
}
set
{
mId = value;
}
}
///
/// The description of this achievement.
///
public string Description
{
get
{
return this.mDescription;
}
set
{
mDescription = value;
}
}
///
/// The name of this achievement.
///
public string Name
{
get
{
return this.mName;
}
set
{
mName = value;
}
}
///
/// The date and time the state of the achievement was modified.
///
///
/// The value is invalid (-1 long) if the achievement state has
/// never been updated.
///
public DateTime LastModifiedTime
{
get
{
return UnixEpoch.AddMilliseconds(mLastModifiedTime);
}
set
{
TimeSpan ts = value - UnixEpoch;
mLastModifiedTime = (long)ts.TotalMilliseconds;
}
}
///
/// The number of experience points earned for unlocking this Achievement.
///
public ulong Points
{
get
{
return mPoints;
}
set
{
mPoints = value;
}
}
///
/// The URL to the image to display when the achievement is revealed.
///
public string RevealedImageUrl
{
get
{
return mRevealedImageUrl;
}
set
{
mRevealedImageUrl = value;
}
}
///
/// The URL to the image to display when the achievement is unlocked.
///
public string UnlockedImageUrl
{
get
{
return mUnlockedImageUrl;
}
set
{
mUnlockedImageUrl = value;
}
}
}
}
#endif