/// <summary> /// 横マイナス方向の回転処理 /// </summary> /// <param name="center_obj"></param> private void Minus_Side_Rotate() { //取得した子オブジェクトの個数分繰り返す for (int child_pointer = 0; child_pointer < g_work_children.Length; child_pointer++) { //子オブジェクトのスクリプト取得 g_child_Script = g_work_children[child_pointer].GetComponent <Dice_Squares>(); //子オブジェクトの指標を取得 (g_child_Ver, g_child_Side, g_child_High) = g_child_Script.Get_Dice_Pointer(); //配列に子オブジェクトを格納 Storage_Work_Array(child_pointer); //回転量計算 (g_next_side, g_next_high) = Minus_Rotate(g_next_side, g_next_high); //回転先の指標計算 Rotate_Pointer_Calc(); //移動前の位置を配列に格納して保持 g_check_Script.Retention_Before_Pointer(g_child_Ver, g_child_Side, g_child_High); //移動後の位置を配列に格納して保持 g_check_Script.Retention_After_Pointer(g_child_Ver, g_next_side - 1, g_next_high); //移動先が埋まっていないか調べる g_is_rotate = g_check_Script.Check(g_child_Ver, g_next_side - 1, g_next_high); if (!g_is_ground) { g_is_ground = g_check_Script.Obj_Ground_Check(g_child_Ver, g_next_side - 1, g_next_high, g_work_children[child_pointer]); } //移動先が埋まっていないか調べる if (!g_is_rotate) { //処理中断 break; } } }
/// <summary> /// 移動前を空にして移動先にオブジェクトとタイプを格納する処理 /// </summary> /// <param name="ver">縦</param> /// <param name="side">横</param> /// <param name="high">高さ</param> /// <param name="pointer">子オブジェクト配列の指標</param> public void Reset_And_Storage_Obj() { //動かすダイスの個数分繰り返す for (int child_pointer = g_zero_Count; child_pointer < g_work_children.Length; child_pointer++) { //ダイスのスクリプト取得 g_child_Script = g_work_children[child_pointer].GetComponent <Dice_Squares>(); //移動前の位置を取得 (g_child_Ver, g_child_Side, g_child_High) = g_check_Script.Get_Before_Pointer(); //移動先の位置を取得 (g_next_ver, g_next_side, g_next_high) = g_check_Script.Get_After_Pointer(); //元々格納されていたオブジェクトを空にする g_game_Con_Script.Storage_Reset(g_child_Ver, g_child_Side, g_child_High); //子オブジェクトを回転に格納 g_game_Con_Script.Storage_Obj(g_next_ver, g_next_side, g_next_high, g_work_children[child_pointer]); //タイプを回転先に格納 g_game_Con_Script.Storage_Obj_Type(g_next_ver, g_next_side, g_next_high, 100); //移動先のポジション取得 Vector3 pos = g_game_Con_Script.Get_Pos(g_next_ver, g_next_side, g_next_high); //ポジション移動 g_work_children[child_pointer].transform.position = pos; //子オブジェクトが保持している指標を更新する g_child_Script.Storage_This_Index(g_next_ver, g_next_side, g_next_high); //サイコロのマス目を変更 g_child_Script.Change_Squares(g_now_para); //ダイスの全方向を調べて、くっつくダイスがあるか調べる g_child_Script.All_Check(); } //ダイス落下処理 g_dice_fall_Script.All_Dice_Fall(g_work_children, g_center_Dice); }
/// <summary> /// 操作中のダイスを移動先に格納する /// </summary> private void Dice_Storage() { //ダイスの個数分だけ処理を繰り返す for (int dice_count = g_zero_Count; dice_count < g_work_dices.Length; dice_count++) { //ダイスのスクリプト取得 g_child_Script = g_work_dices[dice_count].GetComponent <Dice_Squares>(); //ダイスの現在位置取得 (g_dice_ver, g_dice_side, g_dice_high) = g_child_Script.Get_Dice_Pointer(); //現在の位置―移動回数をして移動先の高さを計算 int fall_high = g_dice_high - g_min_counter; //ダイス格納 g_game_Con_Script.Storage_Obj(g_dice_ver, g_dice_side, fall_high, g_work_dices[dice_count]); //ダイスのタイプ格納 g_game_Con_Script.Storage_Obj_Type(g_dice_ver, g_dice_side, fall_high, 100); //格納先のポジション取得 Vector3 dice_pos = g_game_Con_Script.Get_Pos(g_dice_ver, g_dice_side, fall_high); //ダイス移動 g_work_dices[dice_count].transform.position = dice_pos; //子オブジェクトが保持している指標を更新する g_child_Script.Storage_This_Index(g_dice_ver, g_dice_side, fall_high); //全方位を調べて、くっつくダイスがあるか調べる g_child_Script.All_Check(); } }
/// <summary> /// 軸にするダイスを中心にダイスを回転させる /// </summary> /// <param name="storage_obj">軸にするダイス</param> /// <param name="para">移動方向パラメータ</param> public void Storage_Control_Obj(GameObject storage_obj, int para) { //自分が保持しているプレイヤーのポインターを更新する (g_player_ver, g_player_side, g_player_high) = g_player_con_Script.Get_Player_Pointer(); g_con_Obj = storage_obj; g_dice_Script = g_con_Obj.GetComponent <Dice_Squares>(); g_rotate_Script = g_con_Obj.GetComponent <Dice_Rotate>(); Move(para); }
/// <summary> /// ダイスをゆっくり落下させる処理 /// </summary> /// <returns></returns> private IEnumerator Move() { //移動中状態にする g_player_con_Script.MoveFlag_True(); //速度初期化 g_move_speed = g_zero_count; //速度加算変数初期化 g_plus_speed = g_zero_count; //中心のダイスのスクリプト取得 g_child_Script = g_center_dice.GetComponent <Dice_Squares>(); //中心のダイスの現在位置取得 (g_dice_ver, g_dice_side, g_dice_high) = g_child_Script.Get_Dice_Pointer(); //現在の位置―移動回数をして移動先の高さを計算 int fall_high = g_dice_high - g_min_counter; //中心のダイスの現在のポジション取得 Vector3 center_Pos = g_game_Con_Script.Get_Pos(g_dice_ver, g_dice_side, g_dice_high); //中心のダイスの移動後のポジション取得 Vector3 end_Pos = g_game_Con_Script.Get_Pos(g_dice_ver, g_dice_side, fall_high); //動かしたい親を取得 Get_Parent(); //動かしたい親オブジェクトの移動先を計算して格納 //移動前から移動先の移動量を計算し、親の移動先を計算する Vector3 parent_end_Pos = g_parent_Obj.transform.position - (center_Pos - end_Pos); //親オブジェクトの位置が移動先につくまで繰り返す while (g_center_dice.transform.position != end_Pos) { //移動速度上げる if (g_move_speed < g_max_speed) { //移動速度加算 g_move_speed = g_move_speed + g_plus_speed; //加算量増加 g_plus_speed = g_plus_speed + 2.5f; } //親オブジェクトを移動先に向かって移動 g_parent_Obj.transform.position = Vector3.MoveTowards(g_parent_Obj.transform.position, parent_end_Pos, g_move_speed * Time.deltaTime); yield return(null); } //移動中状態を解除する g_player_con_Script.MoveFlag_False(); //移動先への移動終了 g_center_dice.transform.position = end_Pos; //移動SE再生 g_se_source_Script.Se_Play(0); //ダイスを配列から削除 Dice_Storage_Reset(); //ダイスを配列の移動先に格納 Dice_Storage(); //処理終了 yield break; }
/// <summary> /// ダイスをどれだけ落下させるか調べる処理 /// </summary> private void Fall_Check() { //最小値初期化 g_min_counter = g_min_Start; //ダイスの個数分だけ処理を繰り返す for (int dice_count = g_zero_Count; dice_count < g_work_dices.Length; dice_count++) { g_fall_counter = g_zero_Count; //ダイスのスクリプト取得 g_child_Script = g_work_dices[dice_count].GetComponent <Dice_Squares>(); //ダイスの現在位置取得 (g_dice_ver, g_dice_side, g_dice_high) = g_child_Script.Get_Dice_Pointer(); //落下先が埋まるか、配列の範囲外になるまで繰り返す for (int pointer = g_dice_high - 1; pointer >= g_zero_Count; pointer--) { //同じ親フラグ初期化 g_same_parent_flag = false; //検索先に埋まっているオブジェクトのタイプ取得 int type = g_game_Con_Script.Get_Obj_Type(g_dice_ver, g_dice_side, pointer); //検索先がダイスの時、ダイスが検索用ダイスと同じ階層にあるか調べる if (type >= 100) { //検索用ダイスの親オブジェクトを取得 GameObject dice_parent = g_work_dices[dice_count].transform.parent.gameObject; //検索先のダイス取得 GameObject next_dice = g_game_Con_Script.Get_Obj(g_dice_ver, g_dice_side, pointer); //検索先のダイスの親オブジェクトを取得 GameObject next_parent = next_dice.transform.parent.gameObject; //ダイスが検索用ダイスと同じ階層にあるか調べる if (dice_parent == next_parent) { //同じならフラグON g_same_parent_flag = true; } } //移動先オブジェクトが空白ではないなら(床があるなら) if (type != 0 && !g_same_parent_flag) { //処理終了 break; } //検索先の移動回数+1 g_fall_counter++; } //移動回数が最小値より小さいなら if (g_fall_counter < g_min_counter) { //最小値上書き g_min_counter = g_fall_counter; } } }
/// <summary> /// 現在格納されているダイスを配列から削除する /// </summary> private void Dice_Storage_Reset() { //ダイスの個数分だけ処理を繰り返す for (int dice_count = g_zero_Count; dice_count < g_work_dices.Length; dice_count++) { //ダイスのスクリプト取得 g_child_Script = g_work_dices[dice_count].GetComponent <Dice_Squares>(); //ダイスの現在位置取得 (g_dice_ver, g_dice_side, g_dice_high) = g_child_Script.Get_Dice_Pointer(); //元の位置を空にする g_game_Con_Script.Storage_Reset(g_dice_ver, g_dice_side, g_dice_high); } }
void Start() { g_player_con_Script = GameObject.Find("Player_Controller").GetComponent <Playercontroller>(); g_parent_rotate_Script = GameObject.Find("Dice_Controller").GetComponent <Parent_All_Rotation>(); g_trouble_script = GameObject.Find("TroubleObj").GetComponent <TroubleScr>(); g_dice_Script = this.GetComponent <Dice_Squares>(); g_se_source_Script = GameObject.Find("SEList").GetComponent <Se_Source>(); //操作オブジェクト取得 g_dice_Obj = this.gameObject; //サイズを求める g_dice_Size = g_dice_Obj.transform.localScale.x / g_size_change; //回転速度の初期化 g_rotation_Speed = g_start_rotation_Speed; }
/// <summary> /// 指定した位置に格納されているオブジェクトのタイプを取得する /// </summary> /// <param name="this_ver">縦</param> /// <param name="this_side">横</param> /// <param name="this_high">高さ</param> private void Check_Type(int this_ver, int this_side, int this_high, int change_para) { //タイプ取得 int type = g_game_Con_Script.Get_Obj_Type(this_ver, this_side, this_high); //取得したタイプがサイコロだった時 if (type >= 100) { //接触された側のオブジェクトを取得 g_next_dice_Obj = g_game_Con_Script.Get_Obj(this_ver, this_side, this_high); //接触された側のスクリプトを取得 g_next_dice_Script = g_next_dice_Obj.GetComponent <Dice_Squares>(); //移動側の接触面のパラメータを保持 g_adhesive_para = change_para; //接触面を調べてくっつくか調べる Docking_Check(); } }
/// <summary> /// サイコロを回転移動させる処理 /// </summary> /// <param name="para"></param> private void Move(int para) { //回転中の間は回転させない if (g_player_con_Script.Get_MoveFlag()) { return; } //回転の中心にしているサイコロの親を取得 g_con_Obj_Parent = g_con_Obj.transform.parent.gameObject; //親のスクリプトを取得 g_parent_Script = g_con_Obj_Parent.GetComponent <Parent_Dice>(); //与えられたパラメータに応じて、回転の軸にするダイスを取得 switch (para) { //縦プラス方向 case g_ver_plus_Para: g_next_con_Obj = g_parent_Script.Get_Center_Ver_Plus(g_player_ver, g_player_side, g_player_high); break; //縦マイナス方向 case g_ver_minus_Para: g_next_con_Obj = g_parent_Script.Get_Center_Ver_Minus(g_player_ver, g_player_side, g_player_high); break; //横プラス方向 case g_side_plus_Para: g_next_con_Obj = g_parent_Script.Get_Center_Side_Plus(g_player_ver, g_player_side, g_player_high); break; //横マイナス方向 case g_side_minus_Para: g_next_con_Obj = g_parent_Script.Get_Center_Side_Minus(g_player_ver, g_player_side, g_player_high); break; } //回転の中心にするサイコロを変更 g_con_Obj = g_next_con_Obj; //サイコロのスクリプト取得 g_dice_Script = g_con_Obj.GetComponent <Dice_Squares>(); //サイコロのスクリプト取得 g_rotate_Script = g_con_Obj.GetComponent <Dice_Rotate>(); //サイコロを親オブジェクトごと回転させる処理 g_parent_rotate_Script.All_Rotation(g_con_Obj, para); }
/// <summary> /// ダイスを配列に格納する処理 /// </summary> /// <param name="_storage_dice">格納するダイス</param> private void Storage_Dices() { //現在保持している子オブジェクトの数分繰り返す for (int i = 0; i < g_work_children.Length; i++) { //ダイスを格納する配列のサイズを増やす Array.Resize(ref g_undo_dices, g_undo_dices.Length + 1); //保持中のダイスを配列に格納 g_undo_dices[g_dice_pointer] = g_work_children[i]; //ダイスのスクリプトを取得 g_squares_Script = g_undo_dices[g_dice_pointer].GetComponent <Dice_Squares>(); //指標を進める g_dice_pointer++; //取得したスクリプトから・縦・横・高さの3つの指標を取得 (g_work_ver, g_work_side, g_work_high) = g_squares_Script.Get_Dice_Pointer(); //取得した指標を配列に格納 Storage_Dice_Pointer(g_work_ver, g_work_side, g_work_high); //ダイスの現在のマス目を取得 g_work_before_squares = g_squares_Script.Get_Dice_Squares(); //ダイスのマス目を保持 Storage_Dice_Squares(g_work_before_squares); } }
/// <summary> /// 保持している情報をもとに一手前の状態に戻す /// </summary> public void Undo_Play() { if (!g_is_undo) { return; } if (g_player_con_Script.Get_MoveFlag()) { return; } g_is_undo = false; //プレイヤーの移動先取得 Vector3 _player_pos = g_game_con_Script.Get_Pos(g_player_ver, g_player_side, g_player_high); //プレイヤー移動 g_player_obj.transform.position = _player_pos; //プレイヤーの保持する指標変更 g_player_con_Script.Storage_Player_Pointer(g_player_ver, g_player_side, g_player_high); //プレイヤーの向きを変更 g_direction_Script.Player_Direction_Change(g_player_direction); //ダイス配列用の指標 int _dice_pointer = 0; //縦・横・高さ配列用の指標 int _point_pointer = 0; //保持している親の数分繰り返す for (int i = 0; i < g_undo_parents.Length; i++) { //親オブジェクト取得 GameObject _work_parent = g_undo_parents[i]; //親の子オブジェクトの数取得 int _work_count = g_undo_dice_counters[i]; //子オブジェクトの数分繰り返す for (int j = 0; j < _work_count; j++) { //子オブジェクト取得 GameObject _work_dice = g_undo_dices[j + _dice_pointer]; //子オブジェクトの親を今保持している親に変更 _work_dice.transform.parent = _work_parent.transform; //縦の指標取得 g_work_ver = g_dice_pointers[_point_pointer]; //横の指標取得 g_work_side = g_dice_pointers[_point_pointer + 1]; //高さの指標取得 g_work_high = g_dice_pointers[_point_pointer + 2]; //元に戻す位置を取得 Vector3 _undo_pos = g_game_con_Script.Get_Pos(g_work_ver, g_work_side, g_work_high); //子オブジェクトを移動 _work_dice.transform.position = _undo_pos; //ダイスのスクリプト取得 g_squares_Script = _work_dice.GetComponent <Dice_Squares>(); //ダイスの移動前の指標取得 (g_before_ver, g_before_side, g_before_high) = g_squares_Script.Get_Dice_Pointer(); //オブジェクトの種類を取得 int _type = g_game_con_Script.Get_Obj_Type(g_before_ver, g_before_side, g_before_high); //大元の配列からダイスを除去 g_game_con_Script.Storage_Reset(g_before_ver, g_before_side, g_before_high); //移動後の縦・横・高さの指標に変更 g_squares_Script.Storage_This_Index(g_work_ver, g_work_side, g_work_high); //大元の配列にダイス格納 g_game_con_Script.Storage_Obj(g_work_ver, g_work_side, g_work_high, _work_dice); //大元の配列に種類格納 g_game_con_Script.Storage_Obj_Type(g_work_ver, g_work_side, g_work_high, _type); //ダイスの移動後のマス目を取得 g_work_after_squares = g_squares_Script.Get_Dice_Squares(); //配列に保持しているマス目を取得する g_work_before_squares = Get_Dice_Squares(); //ダイスが保持しているマス目を保持していたマス目に変更する g_squares_Script.Storage_Squares(g_work_before_squares); //変更後のマス目に応じてダイスを回転させる g_dice_create_Script.Undo_Squares_Change(_work_dice, g_work_before_squares, g_work_after_squares); //縦・横・高さ配列の指標を3つ進める _point_pointer += 3; } //ダイス用の配列の指標を取り出した個数分進める _dice_pointer += _work_count; } //手数を戻す g_trouble_Script.Trouble_Plus(); //保持する変数を全て初期化 Array_Reset(); }