/** Unity-Editor Functions **/ /// <summary> /// Increases the number of times the given <c>Mission</c> has been /// completed if the given <c>up</c> is <c>true</c>; otherwise decreases /// the number of times completed. /// </summary> /// <param name="mission"><c>Mission</c> to set as completed.</param> /// <param name="up">If set to <c>true</c> add 1 to the number of times /// completed, otherwise subtract 1.</param> /// <param name="notify">If set to <c>true</c> trigger the relevant /// event according to the value of <c>up</c>.</param> protected virtual void _setCompleted(Mission mission, bool up, bool notify) { int total = _getTimesCompleted(mission) + (up ? 1 : -1); if (total < 0) { total = 0; } string key = keyMissionTimesCompleted(mission.ID); KeyValueStorage.SetValue(key, total.ToString()); if (notify) { if (up) { LevelUpEvents.OnMissionCompleted(mission); } else { LevelUpEvents.OnMissionCompletionRevoked(mission); } } }
/** Unity-Editor Functions **/ /// <summary> /// Increases the number of times the given <c>Mission</c> has been /// completed if the given <c>up</c> is <c>true</c>; otherwise decreases /// the number of times completed. /// </summary> /// <param name="mission"><c>Mission</c> to set as completed.</param> /// <param name="up">If set to <c>true</c> add 1 to the number of times /// completed, otherwise subtract 1.</param> /// <param name="notify">If set to <c>true</c> trigger the relevant /// event according to the value of <c>up</c>.</param> protected virtual void _setCompleted(Mission mission, bool up, bool notify) { #if UNITY_EDITOR int total = _getTimesCompleted(mission) + (up ? 1 : -1); if (total < 0) { total = 0; } string key = keyMissionTimesCompleted(mission.ID); PlayerPrefs.SetString(key, total.ToString()); if (notify) { if (up) { LevelUpEvents.OnMissionCompleted(mission); } else { LevelUpEvents.OnMissionCompletionRevoked(mission); } } #endif }
public void onMissionCompletionRevoked(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMissionCompletionRevoked with message: " + message); Mission mission = SoomlaLevelUp.GetMission(message); LevelUpEvents.OnMissionCompletionRevoked(mission); }
public void onScoreRecordChanged(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onScoreRecordChanged with message: " + message); Score score = SoomlaLevelUp.GetScore(message); LevelUpEvents.OnScoreRecordChanged(score); }
public void onWorldAssignedReward(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onWorldAssignedReward with message: " + message); World world = SoomlaLevelUp.GetWorld(message); LevelUpEvents.OnWorldAssignedReward(world); }
public void onLevelEnded(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLevelEnded with message: " + message); Level level = (Level)SoomlaLevelUp.GetWorld(message); LevelUpEvents.OnLevelEnded(level); }
public void onGateClosed(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGateClosed with message: " + message); Gate gate = SoomlaLevelUp.GetGate(message); LevelUpEvents.OnGateClosed(gate); }
/// <summary> /// Initializes the specified <c>InitialWorld</c> and rewards. /// </summary> /// <param name="initialWorld">Initial world.</param> public static void Initialize(World initialWorld) { LevelUpEvents.Initialize(); InitialWorld = initialWorld; save(); WorldStorage.InitLevelUp(); }
/** Unity-Editor Functions **/ /// <summary> /// Sets the given <c>Score</c> to the given value. /// </summary> /// <param name="score"><c>Score</c> to set.</param> /// <param name="latest">The value to set for the <c>Score</c>.</param> protected virtual void _setLatestScore(Score score, double latest) { string key = keyLatestScore(score.ID); string val = latest.ToString(); KeyValueStorage.SetValue(key, val); LevelUpEvents.OnLatestScoreChanged(score); }
/// <summary> /// Sets the given record for the given <c>Score</c>. /// </summary> /// <param name="score"><c>Score</c> whose record is to change.</param> /// <param name="record">The new record.</param> protected virtual void _setRecordScore(Score score, double record) { string key = keyRecordScore(score.ID); string val = record.ToString(); KeyValueStorage.SetValue(key, val); LevelUpEvents.OnScoreRecordChanged(score); }
/// <summary> /// Initializes game state before the game starts. /// </summary> void Awake(){ if(instance == null){ // making sure we only initialize one instance. instance = this; gameObject.name = "LevelUpEvents"; GameObject.DontDestroyOnLoad(this.gameObject); Initialize(); } else { // Destroying unused instances. GameObject.Destroy(this.gameObject); } }
/** Unity-Editor Functions **/ /// <summary> /// Sets the given <c>Score</c> to the given value. /// </summary> /// <param name="score"><c>Score</c> to set.</param> /// <param name="latest">The value to set for the <c>Score</c>.</param> protected virtual void _setLatestScore(Score score, double latest) { #if UNITY_EDITOR string key = keyLatestScore(score.ID); string val = latest.ToString(); PlayerPrefs.SetString(key, val); LevelUpEvents.OnLatestScoreChanged(score); #endif }
/// <summary> /// Sets the given record for the given <c>Score</c>. /// </summary> /// <param name="score"><c>Score</c> whose record is to change.</param> /// <param name="record">The new record.</param> protected virtual void _setRecordScore(Score score, double record) { #if UNITY_EDITOR string key = keyRecordScore(score.ID); string val = record.ToString(); PlayerPrefs.SetString(key, val); LevelUpEvents.OnScoreRecordChanged(score); #endif }
public void onLastCompletedInnerWorldChanged(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLastCompletedInnerWorldChanged with message: " + message); JSONObject eventJSON = new JSONObject(message); string worldId = eventJSON["worldId"].str; string innerWorldId = eventJSON["innerWorldId"].str; World world = SoomlaLevelUp.GetWorld(worldId); LevelUpEvents.OnLastCompletedInnerWorldChanged(world, innerWorldId); }
/// <summary> /// Initializes game state before the game starts. /// </summary> void Awake() { if (instance == null) // making sure we only initialize one instance. { instance = this; GameObject.DontDestroyOnLoad(this.gameObject); Initialize(); } else // Destroying unused instances. { GameObject.Destroy(this.gameObject); } }
public virtual void SetTempScore(double score, bool onlyIfBetter) { if (onlyIfBetter && !HasScoreReached(score, _tempScore)) { return; } if (!_scoreRecordReachedSent && HasScoreReached(score, _tempScore)) { LevelUpEvents.OnScoreRecordReached(this); _scoreRecordReachedSent = true; } _tempScore = score; }
/// <summary> /// Assigns the reward with the given reward ID to the given <c>World</c>. /// </summary> /// <param name="world"><c>World</c> to assign a reward to.</param> /// <param name="rewardId">ID of reward to assign.</param> protected virtual void _setReward(World world, string rewardId) { string key = keyReward(world.ID); if (!string.IsNullOrEmpty(rewardId)) { KeyValueStorage.SetValue(key, rewardId); } else { KeyValueStorage.DeleteKeyValue(key); } // Notify world was assigned a reward LevelUpEvents.OnWorldAssignedReward(world); }
protected virtual void _setLastCompletedInnerWorld(World world, string innerWorldId) { string key = keyLastCompletedInnerWorld(world.ID); if (!string.IsNullOrEmpty(innerWorldId)) { KeyValueStorage.SetValue(key, innerWorldId); } else { KeyValueStorage.DeleteKeyValue(key); } // Notify world had inner level complete LevelUpEvents.OnLastCompletedInnerWorldChanged(world, innerWorldId); }
/// <summary> /// Initializes this instance. /// </summary> public static void Initialize() { if (Instance == null) { CoreEvents.Initialize(); Instance = GetSynchronousCodeGeneratedInstance<LevelUpEvents>(); SoomlaUtils.LogDebug (TAG, "Initialize"); #if UNITY_ANDROID && !UNITY_EDITOR AndroidJNI.PushLocalFrame(100); using(AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.unity.LevelUpEventHandler")) { jniEventHandler.CallStatic("initialize"); } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS && !UNITY_EDITOR soomlaLevelup_Init(); #endif } }
protected virtual void _setLastCompletedInnerWorld(World world, string innerWorldId) { #if UNITY_EDITOR string key = keyLastCompletedInnerWorld(world.ID); if (!string.IsNullOrEmpty(innerWorldId)) { PlayerPrefs.SetString(key, innerWorldId); } else { PlayerPrefs.DeleteKey(key); } // Notify world had inner level complete LevelUpEvents.OnLastCompletedInnerWorldChanged(world, innerWorldId); #endif }
/// <summary> /// Assigns the reward with the given reward ID to the given <c>World</c>. /// </summary> /// <param name="world"><c>World</c> to assign a reward to.</param> /// <param name="rewardId">ID of reward to assign.</param> protected virtual void _setReward(World world, string rewardId) { #if UNITY_EDITOR string key = keyReward(world.ID); if (!string.IsNullOrEmpty(rewardId)) { PlayerPrefs.SetString(key, rewardId); } else { PlayerPrefs.DeleteKey(key); } // Notify world was assigned a reward LevelUpEvents.OnWorldAssignedReward(world); #endif }
/// <summary> /// Increases by 1 the number of times the given <c>Level</c> has been started. /// </summary> /// <returns>The number of times started after increasing.</returns> /// <param name="level"><c>Level</c> to increase its times started.</param> protected virtual int _incTimesStarted(Level level) { int started = _getTimesStarted(level); if (started < 0) /* can't be negative */ { started = 0; } string startedStr = (started + 1).ToString(); string key = keyTimesStarted(level.ID); KeyValueStorage.SetValue(key, startedStr); // Notify level has started LevelUpEvents.OnLevelStarted(level); return(started + 1); }
/// <summary> /// Increases by 1 the number of times the given <c>Level</c> has been played. /// </summary> /// <returns>The number of times played after increasing.</returns> /// <param name="level"><c>Level</c> to increase its times played.</param> protected virtual int _incTimesPlayed(Level level) { int played = _getTimesPlayed(level); if (played < 0) /* can't be negative */ { played = 0; } string playedStr = (played + 1).ToString(); string key = keyTimesPlayed(level.ID); KeyValueStorage.SetValue(key, playedStr); // Notify level has ended LevelUpEvents.OnLevelEnded(level); return(played + 1); }
/// <summary> /// Sets the given <c>World</c> as completed if <c>completed</c> is <c>true</c>. /// </summary> /// <param name="world"><c>World</c> to set as completed.</param> /// <param name="completed">If set to <c>true</c> the <c>World</c> will be set /// as completed.</param> /// <param name="notify">If set to <c>true</c> trigger events.</param> protected virtual void _setCompleted(World world, bool completed, bool notify) { string key = keyWorldCompleted(world.ID); if (completed) { KeyValueStorage.SetValue(key, "yes"); if (notify) { LevelUpEvents.OnWorldCompleted(world); } } else { KeyValueStorage.DeleteKeyValue(key); } }
/// <summary> /// Initializes this instance. /// </summary> public static void Initialize() { if (Instance == null) { CoreEvents.Initialize(); Instance = GetSynchronousCodeGeneratedInstance <LevelUpEvents>(); SoomlaUtils.LogDebug(TAG, "Initialize"); #if UNITY_ANDROID && !UNITY_EDITOR AndroidJNI.PushLocalFrame(100); using (AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.unity.LevelUpEventHandler")) { jniEventHandler.CallStatic("initialize"); } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS && !UNITY_EDITOR soomlaLevelup_Init(); #endif } }
/** Unity-Editor Functions **/ /// <summary> /// Sets the given <c>Gate</c> as open if <c>open</c> is <c>true.</c> /// Otherwise sets as closed. /// </summary> /// <param name="gate">The <c>Gate</c> to open/close.</param> /// <param name="open">If set to <c>true</c> set the <c>Gate</c> to open; /// <param name="notify">If set to <c>true</c> trigger event.</param> protected virtual void _setOpen(Gate gate, bool open, bool notify) { string key = keyGateOpen(gate.ID); if (open) { KeyValueStorage.SetValue(key, "yes"); if (notify) { LevelUpEvents.OnGateOpened(gate); } } else { KeyValueStorage.DeleteKeyValue(key); } }
/// <summary> /// Sets the given <c>World</c> as completed if <c>completed</c> is <c>true</c>. /// </summary> /// <param name="world"><c>World</c> to set as completed.</param> /// <param name="completed">If set to <c>true</c> the <c>World</c> will be set /// as completed.</param> /// <param name="notify">If set to <c>true</c> trigger events.</param> protected virtual void _setCompleted(World world, bool completed, bool notify) { #if UNITY_EDITOR string key = keyWorldCompleted(world.ID); if (completed) { PlayerPrefs.SetString(key, "yes"); if (notify) { LevelUpEvents.OnWorldCompleted(world); } } else { PlayerPrefs.DeleteKey(key); } #endif }
/// <summary> /// Increases by 1 the number of times the given <c>Level</c> has been played. /// </summary> /// <returns>The number of times played after increasing.</returns> /// <param name="level"><c>Level</c> to increase its times played.</param> protected virtual int _incTimesPlayed(Level level) { #if UNITY_EDITOR int played = _getTimesPlayed(level); if (played < 0) /* can't be negative */ { played = 0; } string playedStr = (played + 1).ToString(); string key = keyTimesPlayed(level.ID); PlayerPrefs.SetString(key, playedStr); // Notify level has ended LevelUpEvents.OnLevelEnded(level); return(played + 1); #else return(0); #endif }
/** Unity-Editor Functions **/ /// <summary> /// Sets the given <c>Gate</c> as open if <c>open</c> is <c>true.</c> /// Otherwise sets as closed. /// </summary> /// <param name="gate">The <c>Gate</c> to open/close.</param> /// <param name="open">If set to <c>true</c> set the <c>Gate</c> to open;</param> /// <param name="notify">If set to <c>true</c> trigger event.</param> protected virtual void _setOpen(Gate gate, bool open, bool notify) { #if UNITY_EDITOR string key = keyGateOpen(gate.ID); if (open) { PlayerPrefs.SetString(key, "yes"); if (notify) { LevelUpEvents.OnGateOpened(gate); } } else { PlayerPrefs.DeleteKey(key); } #endif }
/** Unity-Editor Functions **/ /// <summary> /// Initializes <c>SoomlaLevelUp</c> /// </summary> protected virtual void _initLevelUp() { LevelUpEvents.OnLevelUpInitialized(); }
/** Unity-Editor Functions **/ /// <summary> /// Initializes <c>SoomlaLevelUp</c> /// </summary> protected virtual void _initLevelUp() { #if UNITY_EDITOR LevelUpEvents.OnLevelUpInitialized(); #endif }
public void onLevelUpInitialized(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLevelStarted"); LevelUpEvents.OnLevelUpInitialized(); }