コード例 #1
0
ファイル: game_uGUI.cs プロジェクト: Bakiet/UnityZombieCross
	void Start () {
		int max_stages_in_a_world = 15;


		GetComponent<AudioSource>().volume = 0.4f;
		n_world = Convert.ToInt32(Application.loadedLevelName.Substring(1,1));
		if(Application.loadedLevelName.Length > 10){
		n_stage = Convert.ToInt32(Application.loadedLevelName.Substring(9,2));
		}else{
			n_stage = Convert.ToInt32(Application.loadedLevelName.Substring(9,1));
		}

		isfinish=false;
		in_pause = false;
		GooglePlayConnection.ActionPlayerConnected +=  OnPlayerConnected;
		GooglePlayConnection.ActionPlayerDisconnected += OnPlayerDisconnected;		
		GooglePlayConnection.ActionConnectionResultReceived += OnConnectionResult;
		GooglePlayManager.ActionScoreSubmited += OnScoreSbumitted;

		GooglePlaySavedGamesManager.ActionNewGameSaveRequest += ActionNewGameSaveRequest;
	//	GooglePlaySavedGamesManager.ActionGameSaveLoaded += ActionGameSaveLoaded;
		GooglePlaySavedGamesManager.ActionConflict += ActionConflict;

		if(GooglePlayConnection.State == GPConnectionState.STATE_CONNECTED) {
			//GooglePlayConnection.Instance.Disconnect ();
			
		} else {
			GooglePlayConnection.Instance.Connect ();
		}
		/*
		if(GooglePlayConnection.State == GPConnectionState.STATE_CONNECTED) {
			//GooglePlayConnection.Instance.Disconnect ();
		} else {
			GooglePlayConnection.Instance.Connect ();
		}*/

		my_options = options_screen.GetComponent<options_menu>();

		//normal_emoticon = perfect_target.sprite;


		if (game_master.game_master_obj)
		{
			my_store_item_manager = game_master.game_master_obj.GetComponent<store_item_manager>();
			my_game_master = (game_master)game_master.game_master_obj.GetComponent("game_master");
			my_game_master.my_ads_master.my_game_uGUI = this;
		}
		funds = my_game_master.current_virtual_money [0];
			//StoreInventory.GetItemBalance("Coins");

		my_game_master = (game_master)game_master.game_master_obj.GetComponent("game_master");

		world_playable = new bool[1][];
		world_purchased = new bool[1][];
		stage_playable = new bool[1][,];
		stage_solved = new bool[1][,];
		all_stages_solved = new bool[1];
		dot_tail_turn_on = new bool[1][,];
		stage_stars_score = new int[1][,];
		star_score_in_this_world = new int[1][];
		stars_total_score = new int[1];
		best_int_score_in_this_stage = new int[1][,];
		best_int_score_for_current_player = new int[1];

		incremental_item_current_level= new int[1][];
	
		consumable_item_current_quantity = new int[1][];

		for (int i = 0; i < 1; i++)
		{
			incremental_item_current_level[i] = new int[my_game_master.my_store_item_manager.incremental_item_list.Length];
			
			consumable_item_current_quantity[i] = new int[my_game_master.my_store_item_manager.consumable_item_list.Length];

			world_playable[i] = new bool[my_game_master.total_stages_in_world_n.Length];
			world_purchased[i] = new bool[my_game_master.total_stages_in_world_n.Length];
			stage_playable[i] = new bool[my_game_master.total_stages_in_world_n.Length,max_stages_in_a_world];
			stage_solved[i] = new bool[my_game_master.total_stages_in_world_n.Length,max_stages_in_a_world];
			stage_stars_score[i] = new int[my_game_master.total_stages_in_world_n.Length,max_stages_in_a_world];
			star_score_in_this_world[i] = new int[my_game_master.total_stages_in_world_n.Length];
			best_int_score_in_this_stage[i] = new int[my_game_master.total_stages_in_world_n.Length,max_stages_in_a_world]; 
			dot_tail_turn_on[i] = new bool[my_game_master.total_stages_in_world_n.Length,max_stages_in_a_world];
			
			//this_profile_have_a_save_state_in_it[i] = Convert.ToBoolean(PlayerPrefs.GetInt("profile_"+i.ToString()+"_have_a_save_state_in_it")) ;
			/*if (my_store_item_manager)
			{
				incremental_item_current_level[i] = new int[my_store_item_manager.incremental_item_list.Length]; 
				consumable_item_current_quantity[i] = new int[my_store_item_manager.consumable_item_list.Length];
			}*/
		}
		Update_virtual_money (funds);

		if (my_game_master)
		{
			//set ads gui
			my_game_master.music_source.Stop();
			my_game_master.my_ads_master.Initiate_ads();
			my_game_master.my_ads_master.my_feedback_window = my_feedback_window;
			my_game_master.my_ads_master.my_gift_manager = my_gift_manager;
			my_gift_manager.my_game_master = my_game_master;
			if(Application.loadedLevelName != "Home"){
			//my_game_master.Start_music(my_game_master.music_menu,false);
				my_game_master.music_source.enabled  = false;
			}
			else{
				my_game_master.music_source.enabled  = true;
				my_game_master.Start_music(my_game_master.music_menu,false);
			}
			//my_game_master.Start_music(my_game_master.music_menu,false);
			//my_game_master.music_menu =null;
			//star score
			if (!ignore_game_master_preferences)
			{
				show_star_score = my_game_master.show_star_score;
				show_progress_bar = my_game_master.show_progres_bar;
				//int score
				show_int_score = my_game_master.show_int_score;
			}
			show_stage_record = my_game_master.show_int_score_stage_record_in_game_stage;
			
			
			if (my_game_master.score_name != "")
				int_score_ico.GetComponent<Text>().text = my_game_master.score_name;
			
			if (!ignore_game_master_preferences)
			{
				show_debug_messages = my_game_master.show_debug_messages;
				show_debug_warnings = my_game_master.show_debug_warnings;
			}
			
			my_game_master.latest_stage_played_world[my_game_master.current_profile_selected] = n_world;
			my_game_master.latest_stage_played_stage[my_game_master.current_profile_selected] = n_stage;
			
			
			my_game_master.current_world[my_game_master.current_profile_selected] = n_world-1;
		}
		else
		{
			temp_score_name = win_screen_int_score_title.text;
			if (show_debug_warnings)
				Debug.LogWarning("In order to allow saves and play music and menu sfx, you must star from Home scene and open this stage using the in game menu");
		}


		//star score
		if (show_star_score)
			star_container.SetActive(true);
		else
		{
			show_star_count = false;
			star_container.SetActive(false);
		}
		if (show_progress_bar)
		{
			my_progress_bar.Start_me(this);
			my_progress_bar.gameObject.SetActive (true);
		}
		else
			my_progress_bar.gameObject.SetActive (false);
		
		//int score
		if (show_int_score)
		{
			int_score_ico.SetActive(true);
		}
		else
			int_score_ico.SetActive(false);
		
		Reset_me();
		if (Application.loadedLevelName == "W1_Stage_1") {
			temptutorial = temptutorial + 1;
			if(temptutorial <= 1){
			Open_tutorial(true);
			}
		}
	}
コード例 #2
0
	// Use this for initialization
	void Awake () {
		GoogleCloudMessageService.ActionCMDRegistrationResult += HandleActionCMDRegistrationResult;
		GoogleCloudMessageService.ActionCouldMessageLoaded += OnMessageLoaded;
		GoogleCloudMessageService.ActionGCMPushLaunched += HandleActionGCMPushLaunched;
		GoogleCloudMessageService.ActionGCMPushReceived += HandleActionGCMPushReceived;
		GoogleCloudMessageService.Instance.Init();


		if ( !game_is_started )
			{
			keep_me = true;
			home_scene_name = Application.loadedLevelName;
			my_store_item_manager = this.gameObject.GetComponent<store_item_manager>();

			my_ads_master = GetComponent<ads_master>();
			if (my_ads_master)
				my_ads_master.Initiate_ads();
			}
		
		if (keep_me)
			{
			game_master_obj = this.gameObject;

			DontDestroyOnLoad(game_master_obj);//this prefab will be used as reference from the others, so don't destry it when load a new scene
			
			//sum the stages in every world to know the total number of stages in the game
				for(int w = 0; w < total_stages_in_world_n.Length; w++)
					{
					total_number_of_stages_in_the_game += total_stages_in_world_n[w];
					if (total_stages_in_world_n[w] > max_stages_in_a_world)
						max_stages_in_a_world = total_stages_in_world_n[w];
					}
				if (show_debug_messages)
					Debug.Log("total_number_of_stages_in_the_game = " + total_number_of_stages_in_the_game + " max_stages_in_a_world = " + max_stages_in_a_world );

			//create multy arrays for multy profile saves
				this_profile_have_a_save_state_in_it = new bool[number_of_save_profile_slot_avaibles];
				profile_name = new string[number_of_save_profile_slot_avaibles];

				music_on = new bool[number_of_save_profile_slot_avaibles];
					music_volume = new float[number_of_save_profile_slot_avaibles];
				sfx_on = new bool[number_of_save_profile_slot_avaibles];
					sfx_volume = new float[number_of_save_profile_slot_avaibles];
				voice_on = new bool[number_of_save_profile_slot_avaibles];
					voice_volume = new float[number_of_save_profile_slot_avaibles];

				if (!infinite_lives)
					{
		
				current_lives = new int[number_of_save_profile_slot_avaibles];
					
					target_time = new DateTime[number_of_save_profile_slot_avaibles];
					recharge_live_countdown_active = new bool[number_of_save_profile_slot_avaibles];
					}
				if(continue_rule_selected == continue_rule.continue_cost_a_continue_token)
					current_continue_tokens = new int[number_of_save_profile_slot_avaibles];

				world_playable = new bool[number_of_save_profile_slot_avaibles][];
				world_purchased = new bool[number_of_save_profile_slot_avaibles][];
					current_world = new int[number_of_save_profile_slot_avaibles];
				stage_playable = new bool[number_of_save_profile_slot_avaibles][,];
					total_number_of_stages_in_the_game_solved = new int[number_of_save_profile_slot_avaibles];
					stage_solved = new bool[number_of_save_profile_slot_avaibles][,];
					all_stages_solved = new bool[number_of_save_profile_slot_avaibles];
					dot_tail_turn_on = new bool[number_of_save_profile_slot_avaibles][,];
				play_this_stage_to_progress_in_the_game_world = new int[number_of_save_profile_slot_avaibles];
				play_this_stage_to_progress_in_the_game_stage = new int[number_of_save_profile_slot_avaibles];
				latest_stage_played_world = new int[number_of_save_profile_slot_avaibles];
				latest_stage_played_stage = new int[number_of_save_profile_slot_avaibles];

				stage_stars_score = new int[number_of_save_profile_slot_avaibles][,];
					star_score_in_this_world = new int[number_of_save_profile_slot_avaibles][];
					stars_total_score = new int[number_of_save_profile_slot_avaibles];

				best_int_score_in_this_stage = new int[number_of_save_profile_slot_avaibles][,];
					best_int_score_for_current_player = new int[number_of_save_profile_slot_avaibles];
					

					//int funds = StoreInventory.GetItemBalance("Coins");
			current_virtual_money = new int[number_of_save_profile_slot_avaibles];
			//current_virtual_money = current_virtual_money +=funds;

				if (my_store_item_manager)
					{
					incremental_item_current_level = new int[number_of_save_profile_slot_avaibles][]; 
					consumable_item_current_quantity = new int[number_of_save_profile_slot_avaibles][]; 
					}
			

				for (int i = 0; i < number_of_save_profile_slot_avaibles; i++)
					{
					world_playable[i] = new bool[total_stages_in_world_n.Length];
					world_purchased[i] = new bool[total_stages_in_world_n.Length];
					stage_playable[i] = new bool[total_stages_in_world_n.Length,max_stages_in_a_world];
					stage_solved[i] = new bool[total_stages_in_world_n.Length,max_stages_in_a_world];
					stage_stars_score[i] = new int[total_stages_in_world_n.Length,max_stages_in_a_world];
					star_score_in_this_world[i] = new int[total_stages_in_world_n.Length];
					best_int_score_in_this_stage[i] = new int[total_stages_in_world_n.Length,max_stages_in_a_world]; 
					dot_tail_turn_on[i] = new bool[total_stages_in_world_n.Length,max_stages_in_a_world];

					this_profile_have_a_save_state_in_it[i] = Convert.ToBoolean(PlayerPrefs.GetInt("profile_"+i.ToString()+"_have_a_save_state_in_it")) ;
					if (my_store_item_manager)
						{
						incremental_item_current_level[i] = new int[my_store_item_manager.incremental_item_list.Length]; 
						consumable_item_current_quantity[i] = new int[my_store_item_manager.consumable_item_list.Length];
						}
					}
					

			exist_a_save_state = Convert.ToBoolean(PlayerPrefs.GetInt("savestate")) ;
			current_profile_selected = PlayerPrefs.GetInt("last_profile_used");

			music_on[current_profile_selected] = true;
				music_volume[current_profile_selected] = 1;
			sfx_on[current_profile_selected] = true;
				sfx_volume[current_profile_selected] = 1;
			voice_on[current_profile_selected] = true;
				voice_volume[current_profile_selected] = 1;

			if (exist_a_save_state)//copy the saves in the arrays
				{
				if (PlayerPrefs.GetInt("total_number_of_stages_in_the_game") == total_number_of_stages_in_the_game) //if the _total_stages number not is the same of last time, erase save data to avoid broken array (the _total_stages don't cange in the game, so the player don't chance to lose his saves. This is useful when you decide to change the total stage number through the making of the game and avoid errors because previous save data refer to a old version)
					{
					if (show_debug_messages)
						{
						Debug.Log("same total_stages from the last time");
						Debug.Log("current_profile_selected "+ current_profile_selected);
						}
					//check if the last profile used have can be load
					if (this_profile_have_a_save_state_in_it[current_profile_selected])
						Load(current_profile_selected);
					else //I can't find the last profile used
						{
						//so ask to select/create a profile
						show_new_profile_window = true;
						}
					}
				else //you have changed the total_stages from the last time, sto the old save data have a different array_length. 
					{
					if (show_debug_messages)
						Debug.Log("different total_stages from the last time");
					if (this_profile_have_a_save_state_in_it[current_profile_selected])
						{
						if (total_number_of_stages_in_the_game > PlayerPrefs.GetInt("total_number_of_stages_in_the_game")) //you have add stages from last time
							{
							if (show_debug_messages)
								Debug.Log("there are more stages that in the previous save data");
							PlayerPrefs.SetInt("total_number_of_stages_in_the_game", total_number_of_stages_in_the_game);
							for (int i = 0; i < number_of_save_profile_slot_avaibles; i++)
								{
								all_stages_solved[i] = false;
								PlayerPrefs.SetInt("all_stages_solved",Convert.ToInt32(all_stages_solved[i]));
								}
							Load(current_profile_selected);
							}
						else //you have remove stages from last time
							{
							if (show_debug_messages)
								Debug.Log("there are less stages that in the previous save data");
							//delete the old data
							Erase_saves();
							for (int i = 0; i < number_of_save_profile_slot_avaibles; i++)
								{
								world_playable[i][0] = true;
								stage_playable[i][0,0] = true;
								Save(i);
								}

							}
						}
					else //I can't find the last profile used
						{
						//so ask to select/create a profile
						show_new_profile_window = true;
						}
					}
					
				}
			else //no save data, so start the game from zero
				{
				current_profile_selected = 0;
				if (number_of_save_profile_slot_avaibles == 1) //if no multiple profiles are allowed, start new game
					{
					if (show_debug_messages)
						Debug.Log("no save data and only one profile slot allowed");
					Create_new_profile("Player");
					}
				//else request to activate a new empty profile
				if (show_debug_messages)
					Debug.Log("no save data and multi profile slot allowed");
				show_new_profile_window = true;
				}

			}
		else
			{
			//this avoid duplication of this istance
			Destroy(this.gameObject);
			}

	}