2019-05-01 22:53:37 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 STAT = vci.state ASET = vci.assets --Unity駒の名称 CUBE_STR = { "Cube0", "Cube1", "Cube2", "Cube3", "Cube4", "Cube5", "Cube6", "Cube7", "Cube8", "Cube9" } --盤面のどこにどの駒があるか BOARD_NUM = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 } --初期化用 BOARD_NUM_CPY = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 } FIRST_FLG = true --初期化 STAT.Set("FIRST_FLG", FIRST_FLG) TARG_NUM = 0 --駒の掴んだ番号 STAT.Set("TARG_NUM", TARG_NUM) GRIP_FLG = false --グリップ STAT.Set("GRIP_FLG", GRIP_FLG) USE_FLG = false --使用 STAT.Set("USE_FLG", USE_FLG) BORD_NUM = 0 --使用した直下の盤の番号 STAT.Set("BORD_NUM", BORD_NUM) CENTER_NUM = 13 --中央 GAMEEND_FLG = false --ゲーム終了 STAT.Set("GAMEEND_FLG", GAMEEND_FLG) GAMEEND_FLG_FLG = true STAT.Set("GAMEEND_FLG_FLG", GAMEEND_FLG_FLG) ---アイテムを生成したユーザーで毎フレーム呼ばれる function updateAll() GAMEEND_FLG = STAT.Get("GAMEEND_FLG") if FIRST_FLG == nil then FIRST_FLG = true end if GAMEEND_FLG == nil then GAMEEND_FLG = false STAT.Set("GAMEEND_FLG", GAMEEND_FLG) end GAMEEND_FLG_FLG = STAT.Get("GAMEEND_FLG_FLG") if GAMEEND_FLG_FLG == nil then GAMEEND_FLG_FLG = true STAT.Set("GAMEEND_FLG", GAMEEND_FLG) end --配置 if (FIRST_FLG == true) or (STAT.Get("FIRST_FLG") == true) then if GAMEEND_FLG_FLG == true then OBJ = ASET.GetSubItem("Cube99") if OBJ.IsMine == true then --初期化 for i = 1, #BOARD_NUM do BOARD_NUM[i] = BOARD_NUM_CPY[i] end GAMEEND_FLG = false STAT.Set("GAMEEND_FLG", GAMEEND_FLG) GAMEEND_FLG_FLG = false STAT.Set("GAMEEND_FLG_FLG", GAMEEND_FLG_FLG) end end OBJ = ASET.GetSubItem("Cube99") if not(OBJ.IsMine == true) then for i = 1, #BOARD_NUM do BOARD_NUM[i] = STAT.Get(tostring(i)) end STAT.Set("FIRST_FLG", FIRST_FLG) end Move_STROBJ() FIRST_FLG = false end end ---全ユーザーで毎フレーム呼ばれる function update() GRIP_FLG = STAT.Get("GRIP_FLG") TARG_NUM = STAT.Get("TARG_NUM") BORD_NUM = STAT.Get("BORD_NUM") GAMEEND_FLG = STAT.Get("GAMEEND_FLG") if GAMEEND_FLG == nil then GAMEEND_FLG = false end USE_FLG = STAT.Get("USE_FLG") if USE_FLG == nil then USE_FLG = false end --ゲームが続いてる if GAMEEND_FLG == false then --握っている if GRIP_FLG == true then min = 0 --方向保持 min_loc = 0.06 --最近傍の値 --方向決定 for i = 1, 4 do hosei = 0 if i == 1 then if ((BORD_NUM + 1) <= #BOARD_NUM) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM) / 5)) then if BOARD_NUM[BORD_NUM + 1] == 0 then hosei = 1 end end elseif i == 2 then if ((BORD_NUM - 1) > 0) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM - 2) / 5)) then if BOARD_NUM[BORD_NUM - 1] == 0 then hosei = -1 end end elseif i == 3 then if (BORD_NUM + 5) <= #BOARD_NUM then if BOARD_NUM[BORD_NUM + 5] == 0 then hosei = 5 end end elseif i == 4 then if (BORD_NUM - 5) > 0 then if BOARD_NUM[BORD_NUM - 5] == 0 then hosei = -5 end end end --移動可能であるならば、補助マス表示 if not (hosei == 0) then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-2 + math.floor((BORD_NUM + hosei - 1) / 5)) * 0.14 ama = (-2 + (BORD_NUM + hosei - 1) % 5) * 0.14 OBJ = ASET.GetSubItem(CUBE_STR[TARG_NUM]) ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama POS2 = POS POS2.Set( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) POS = OBJ.GetPosition() loc = math.sqrt((POS.x - POS2.x) * (POS.x - POS2.x) + (POS.z - POS2.z) * (POS.z - POS2.z)) if min_loc > loc then min_loc = loc min = i end end end hosei = 0 --方向で補正値決定「 if min > 0 then if min == 1 then hosei = 1 elseif min == 2 then hosei = -1 elseif min == 3 then hosei = 5 elseif min == 4 then hosei = -5 end end --移動したところの値を求める num = BORD_NUM --移動したところの値 for i = 1, 4 do if (hosei == -1) or (hosei == 1) then if ((BORD_NUM + hosei * i) <= #BOARD_NUM) and ((BORD_NUM + hosei * i) > 0) and (BOARD_NUM[(BORD_NUM + hosei * i)] == 0) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM - 1 + hosei * i) / 5)) then num = BORD_NUM + hosei * i else break end else if ((BORD_NUM + hosei * i) <= #BOARD_NUM) and ((BORD_NUM + hosei * i) > 0) and (BOARD_NUM[(BORD_NUM + hosei * i)] == 0) then num = BORD_NUM + hosei * i else break end end end --補助駒移動 --if num > 0 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-2 + math.floor((num - 1) / 5)) * 0.14 ama = (-2 + (num - 1) % 5) * 0.14 OBJ = ASET.GetSubItem("Cube99") ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) --end end --使用した if USE_FLG == true then --移動していれば if num > 0 then --自位置でないならば if not (BORD_NUM == num) then BOARD_NUM[num] = BOARD_NUM[BORD_NUM] BOARD_NUM[BORD_NUM] = 0 end end end USE_FLG = false end --ゲーム終了処理 OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJS = ASET.GetSubItem("MAT") if (BOARD_NUM[CENTER_NUM] == 3) or (BOARD_NUM[CENTER_NUM] == 8) then OBJS.SetPosition(Vector3.__new(POS.x, POS.y + 0.4, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 90)) if BOARD_NUM[CENTER_NUM] > 5 then col = Color.__new(0, 0, 0) else col = Color.__new(1, 1, 1) end ASET._ALL_SetMaterialColorFromName("MAT", col) GAMEEND_FLG = true elseif BOARD_NUM[CENTER_NUM] > 0 then OBJS.SetPosition(Vector3.__new(POS.x, POS.y + 0.4, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 90)) if BOARD_NUM[CENTER_NUM] > 5 then col = Color.__new(1, 1, 1) else col = Color.__new(0, 0, 0) end ASET._ALL_SetMaterialColorFromName("MAT", col) GAMEEND_FLG = true else OBJS.SetPosition(Vector3.__new(POS.x, POS.y, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 0)) end STAT.Set("USE_FLG", USE_FLG) STAT.Set("GAMEEND_FLG", GAMEEND_FLG) for i = 1, #BOARD_NUM do STAT.Set(tostring(i), BOARD_NUM[i]) end end function onUse(use) --初期化 if use == "Capsule" then FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) GAMEEND_FLG = nil STAT.Set("GAMEEND_FLG", GAMEEND_FLG) GAMEEND_FLG_FLG = true STAT.Set("GAMEEND_FLG_FLG", GAMEEND_FLG_FLG) end --グリップ中 if GRIP_FLG == true then for i = 1, #CUBE_STR do --駒ならば if use == CUBE_STR[i] then USE_FLG = true STAT.Set("USE_FLG", USE_FLG) end end end end function onCollisionExit(it, h) Velo_Ang_Zero(it, false) end --掴む ---@param target string @GrabされたSubItem名 function onGrab(tar) --駒を握った for i = 1, #CUBE_STR do if tar == CUBE_STR[i] then TARG_NUM = i GRIP_FLG = true STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) --盤上のどこにあるか for i2 = 1, #BOARD_NUM do if i == BOARD_NUM[i2] then BORD_NUM = i2 STAT.Set("BORD_NUM", BORD_NUM) break end end break end end end function onUngrab(tar) for i = 1, #CUBE_STR do if tar == CUBE_STR[i] then TARG_NUM = 0 GRIP_FLG = false STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) for i2 = 1, #BOARD_NUM do if i == BOARD_NUM[i2] then BORD_NUM = 0 STAT.Set("BORD_NUM", BORD_NUM) break end end break end end Velo_Ang_Zero(tar, true) end --角度と力0 function Velo_Ang_Zero(item, cube_flg) OBJ = ASET.GetSubItem(item) OBJ.SetVelocity(Vector3.__new(0, 0, 0)) OBJ.SetAngularVelocity(Vector3.__new(0, 0, 0)) if item == "Board" then ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end if cube_flg == true then for i = 1, #CUBE_STR do if item == CUBE_STR[i] then end end end FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end --駒をBOARD_NUMに従い配置 function Move_STROBJ() OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end for i = 1, #BOARD_NUM do if BOARD_NUM[i] > 0 then OBJS = ASET.GetSubItem(CUBE_STR[BOARD_NUM[i]]) if OBJS.IsMine == true then sho = (-2 + math.floor((i - 1) / 5)) * 0.14 ama = (-2 + (i - 1) % 5) * 0.14 ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJS.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.06, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJS.SetRotation(Quaternion.Euler(0, ANG, 0)) end end end OBJS = ASET.GetSubItem("Cube99") OBJS.SetPosition(Vector3.__new(POS.x, 0, POS.z)) end