public override void Draw() { // 動くオブジェクトの描画 GameObjectState.Draw(); // 動かないオブジェクトの描画 mapManager.DrawStaticMapChip(); }
public void SendChangedWorldState(GameObjectState[] worldState) { List <byte> data = new List <byte>(); foreach (var state in worldState) { data.AddRange(GameObjectState.Serialize(state)); } byte[] bytes = data.ToArray(); //Console.WriteLine($"Send {bytes.Length} bytes"); if (bytes.Length == 0) { return; } lock (clientsLocker) { foreach (var c in clients) { lock (c.locker) if (c.isRunning) { c.Send(PacketType.WorldState, bytes); } } } }
public override void Update() { // Zキーでリスタート(Rキーがわからなかったため) if (Input.GetButtonDown(DX.PAD_INPUT_1)) { sceneManager.LoadScene(SceneType.Play, new object[] { mapManager.GetStageFilePath() }); } // Xキーでシーンセレクトへ if (Input.GetButtonDown(DX.PAD_INPUT_2)) { sceneManager.LoadScene(SceneType.Select); } // 全ゲームオブジェクトのアニメーションが終了しているなら通常の更新を再開 if (mapManager.IsAllGameObjectAnimationStop()) { // 全ボックスがゴールに到達しているか if (CheckAllBoxGoal()) { sceneManager.LoadScene(SceneType.Clear); } // ゲームオブジェクトの更新をする GameObjectState.Update(); } else { // ゲームオブジェクトのアニメーション処理 GameObjectState.AnimeUpdate(); } }
public static void Play() { _gameObjectsToRevert = new List <GameObjectState>(); for (int i = 0; i < InternalUiAnimationEditorCanvas.Items.Count; i++) { if (InternalUiAnimationEditorCanvas.Items[i] == null) { continue; } if (InternalUiAnimationEditorCanvas.Items[i].Target == null) { continue; } if (InternalUiAnimationEditorCanvas.Items[i].Target.GameObject == null) { continue; } GameObjectState state = new GameObjectState(); state.Apply(InternalUiAnimationEditorCanvas.Items[i].Target.GameObject); _gameObjectsToRevert.Add(state); } Activated = true; Time = 0; }
private bool ShouldBrake(GameObjectState objectInMyLane, GameObjectState objectInOtherLane, bool shouldChangeLane) { if (objectInMyLane == null) { return(false); } float distance; var distanceToStop = CalculateDistanceToStop(_myCar.VY, _myCar.MaximumDeceleration); if (!shouldChangeLane) { if (objectInOtherLane == null) { return(true); } var closestObjectInMyLaneBottom = objectInMyLane.BoundingBox.Top; var closestObjectInOtherLaneBottom = objectInOtherLane.BoundingBox.Top; if (closestObjectInMyLaneBottom > closestObjectInOtherLaneBottom + _changeLaneDistance) { return(false); } distance = GetDistanceFromObject(_myPositionY, objectInMyLane); return(distance < distanceToStop); } if (objectInOtherLane == null) { return(false); } distance = GetDistanceFromObject(_myPositionY, objectInOtherLane); return(distance < distanceToStop); }
public static void AddToPacket(GameObjectState state, Packet packet) { packet.AddByte((byte)state.Type); foreach (var parameter in state.Parameters) { if (parameter is byte) { packet.AddByte((byte)parameter); } else if (parameter is short) { packet.AddInt16((short)parameter); } else if (parameter is int) { packet.AddInt32((int)parameter); } else if (parameter is ushort) { packet.AddUInt16((ushort)parameter); } else if (parameter is uint) { packet.AddUInt32((uint)parameter); } else if (parameter is string) { packet.AddString((string)parameter); } } }
// Adds a new record of the Player's movement to the State if it doesn't exist. If it does, then it updates the Action's weight public void addAction(double[] stateVals, GameObjectState moveState) { List <NodeDistance <KDTreeNode <PlayerMoveAction> > > foundActions = actionsAvailable.Nearest(stateVals, GameState.voxel_radius); if (foundActions.Count < 1) { PlayerMoveAction newMove = new PlayerMoveAction("Move", 0.05); newMove.stateChange = moveState; actionsAvailable.Add(stateVals, newMove); addAction(newMove); if (numActionsMade < maxActionsMade) { numActionsMade++; newMove.updateProbabilityFromActionStateCount(numActionsMade); } } else { foreach (var action in foundActions) { if (numActionsMade < maxActionsMade) { numActionsMade++; action.Node.Value.updateProbabilityFromActionStateCount(numActionsMade); } } } }
void ToggleGameObject(uint type, GameObjectState state) { GameObject go = GetGameObject(type); if (go) { go.SetGoState(state); } switch (type) { case GDDataTypes.SladRanStatue: SladRanStatueState = state; break; case GDDataTypes.DrakkariColossusStatue: DrakkariColossusStatueState = state; break; case GDDataTypes.MoorabiStatue: MoorabiStatueState = state; break; default: break; } }
private static float GetDistanceFromObject(float myPositionY, GameObjectState closestObject) { if (closestObject != null) { return(closestObject.BoundingBox.Top - myPositionY); } return(100000f); }
private void UpdateTankState() { foreach (TankController t in tankControllers) { GameObjectState s = CreateTankState(t); allObjects.Add(s); } }
public GameObjectExtended(GameObjectState gameObjectState) : base(gameObjectState.Id, gameObjectState.GameObjectType, gameObjectState.BoundingBox, gameObjectState.VX, gameObjectState.VY, gameObjectState.Damage) { }
public void SetState(GameObjectState state) { if (_currentState != null) { _currentState.OnExit(); } _currentState = state; _currentState.OnEnter(); }
public override void OnInspectorGUI() { base.DrawDefaultInspector(); if (GUI.changed) { GameObjectState state = (GameObjectState)target; HierarchyIconViewer.UpdateGameObjectView(state.gameObject.GetInstanceID(), state); } }
public static void Broadcast(this GameObject go, SendEvent eventID) { GameObjectState msg = go.GetComponent <GameObjectState>(); if (msg != null) { msg.Messenger.Broadcast(eventID); } }
public static void Broadcast <T>(this GameObject go, SendEvent eventID, T messageData) { GameObjectState msg = go.GetComponent <GameObjectState>(); if (msg != null) { msg.Messenger.Broadcast <T>(eventID, messageData); } }
public GameObjectState GetClosestObjectInFront(IEnumerable <GameObjectState> gameObjects, GameObjectState self) { var laneBound = new RectangleF(X, self.BoundingBox.Y, self.BoundingBox.Width, self.BoundingBox.Height); return(gameObjects .Where(gameObject => gameObject.BoundingBox.Y > laneBound.Y) .FirstOrDefault(o => IsOverlappingHorizontally(laneBound, o.BoundingBox))); }
private bool ShouldChangeLane(GameObjectState objectInMyLane, GameObjectState objectInOtherLane) { var distanceInMyLane = GetDistanceFromObject(_myPositionY, objectInMyLane); var distanceInOtherLane = GetDistanceFromObject(_myPositionY, objectInOtherLane); if (distanceInMyLane > distanceInOtherLane) { return(false); } var distanceToStop = CalculateDistanceToStop(_myCar.VY, _myCar.MaximumDeceleration); switch (_currentLane) { case Lane.RightRight: if (!CanChangeLane(Lane.Right)) { return(false); } if (objectInOtherLane == null) { _desiredLane = Lane.Right; return(true); } if (objectInOtherLane.GameObjectType == GameObjectType.Roadblock && distanceInOtherLane < distanceToStop) { return(false); } _desiredLane = Lane.Right; return(true); case Lane.LeftLeft: if (!CanChangeLane(Lane.Left)) { return(false); } if (objectInOtherLane == null) { _desiredLane = Lane.Left; return(true); } if (objectInOtherLane.GameObjectType == GameObjectType.Roadblock && distanceInOtherLane < distanceToStop) { return(false); } _desiredLane = Lane.Left; return(true); } return(true); }
// Predicts the next State if this Action was chosen to execute. Used in minimax algorithm. public override GameObjectState predictNextState(GameObjectState currState) { Vector3 rHandPos = currState.rHandPos + (currState.rHandVel * currState.deltaTime); Vector3 rHandVel = currState.rHandVel; Vector3 paddleVel = Vector3.zero; Vector3 paddlePos = currState.paddlePos; return(new GameObjectState(rHandPos, rHandVel, paddlePos, paddleVel, currState.targetPos, currState.targetVel, currState.deltaTime)); }
private bool IsOverlappingHorizontally(GameObjectState self, GameObjectState other) { var r1 = self.BoundingBox; var r2 = other.BoundingBox; return(Between(r1.Left, r1.Right, r2.Left) || Between(r1.Left, r1.Right, r2.Right) || Between(r2.Left, r2.Right, r1.Right) || Between(r2.Left, r2.Right, r1.Left)); }
private void SetMyCarInfo(GameState gameState) { _myCar = gameState.GameObjectStates.First(o => o.Id == _playerId); _currentLane = _myCar.GetLane(); _myPositionX = _myCar.BoundingBox.CenterX; _myPositionY = _myCar.BoundingBox.Bottom; _desiredLane = _currentLane; _changeLaneDistance = CalculateDistanceToChangeLane(_myCar.VY); _objectsNextToMe = GetObjectsNextToMe(gameState); }
public static void UpdateGameObjectView(int instanceID,GameObjectState goState) { if(replicateOnChildren ==null) { replicateOnChildren=new List<int>(); overrideEvent=new List<int>(); EditorApplication.hierarchyWindowChanged(); } CheckForReplicate(instanceID,goState); CheckForOverride(instanceID,goState); }
// Predict the next state if the Player moves in this manner. Used in minimax algorithm public override GameObjectState predictNextState(GameObjectState currState) { Vector3 rHandPos = currState.rHandPos + stateChange.rHandPos; Vector3 rHandVel = currState.rHandVel + stateChange.rHandVel; Vector3 paddlePos = currState.paddlePos + stateChange.paddlePos; Vector3 paddleVel = currState.paddleVel + stateChange.paddleVel; GameObjectState newState = new GameObjectState(rHandPos, rHandVel, paddlePos, paddleVel, currState.targetPos, currState.targetVel, currState.deltaTime); return(newState); }
public static void UpdateGameObjectView(int instanceID, GameObjectState goState) { if (replicateOnChildren == null) { replicateOnChildren = new List <int>(); overrideEvent = new List <int>(); EditorApplication.hierarchyWindowChanged(); } CheckForReplicate(instanceID, goState); CheckForOverride(instanceID, goState); }
private float CalculateDistanceAfterLaneChange(GameObjectState objectInFront) { if (objectInFront == null) { return(10000); } var myPositionAfterLaneChange = _myPositionY + _changeLaneDistance; var objectInfrontPositionAfterLaneChange = objectInFront.BoundingBox.Top + CalculateDistanceToChangeLane(objectInFront.VY); return(objectInfrontPositionAfterLaneChange - myPositionAfterLaneChange); }
public GOTemplate(GOEntry entry, GameObjectState state, MapId mapId, ref Vector3 pos, float orientation, float scale, float[] rotations) { //Id = id; Entry = entry; EntryId = entry.GOId; State = state; MapId = mapId; Pos = pos; Orientation = orientation; Scale = scale; Rotations = rotations; }
public GOSpawnEntry(GOEntry entry, GameObjectState state, MapId mapId, ref Vector3 pos, float orientation, float scale, float[] rotations, int respawnTimeSecs = 600) { this.Entry = entry; this.EntryId = entry.GOId; this.State = state; this.MapId = mapId; this.Position = pos; this.Orientation = orientation; this.Scale = scale; this.Rotations = rotations; this.RespawnSeconds = respawnTimeSecs; }
public GOSpawnEntry(GOEntry entry, GameObjectState state, MapId mapId, ref Vector3 pos, float orientation, float scale, float[] rotations, int respawnTimeSecs = 600) { Entry = entry; EntryId = entry.GOId; State = state; MapId = mapId; Position = pos; Orientation = orientation; Scale = scale; Rotations = rotations; RespawnSeconds = respawnTimeSecs; }
// Get a prediction for the next state if this Action is executed. Used in Minimax calculations public override GameObjectState predictNextState(GameObjectState currState) { Vector3 rHandPos = currState.rHandPos + (currState.rHandVel * currState.deltaTime); Vector3 rHandVel = currState.rHandVel; Vector3 goalPosition = currState.rHandPos + (currState.rHandVel * currState.deltaTime); Vector3 forceVector = (goalPosition - currState.paddlePos).normalized * forcePower; Vector3 paddleVel = currState.paddleVel + (forceVector * currState.deltaTime); Vector3 paddlePos = currState.paddlePos + (paddleVel * currState.deltaTime); return(new GameObjectState(rHandPos, rHandVel, paddlePos, paddleVel, currState.targetPos, currState.targetVel, currState.deltaTime)); }
void TogglePillarCollision(bool enable) { // Toggle visual pillars, pulley, gear, and collision based on previous state for (int i = RingofValorObjectTypes.Pilar1; i <= RingofValorObjectTypes.Gear2; ++i) { if (enable) { DoorOpen(i); } else { DoorClose(i); } } for (byte i = RingofValorObjectTypes.Pilar2; i <= RingofValorObjectTypes.Pulley2; ++i) { if (enable) { DoorClose(i); } else { DoorOpen(i); } } for (byte i = RingofValorObjectTypes.Pilar1; i <= RingofValorObjectTypes.PilarCollision4; ++i) { GameObject go = GetBGObject(i); if (go) { if (i >= RingofValorObjectTypes.PilarCollision1) { GameObjectState state = ((go.GetGoInfo().Door.startOpen != 0) == enable) ? GameObjectState.Active : GameObjectState.Ready; go.SetGoState(state); } foreach (var guid in GetPlayers().Keys) { Player player = Global.ObjAccessor.FindPlayer(guid); if (player) { go.SendUpdateToPlayer(player); } } } } }
private bool ShouldBrake(GameObjectState objectInMyLane, GameObjectState objectInLeftLane, GameObjectState objectInRightLane, bool shouldChangeLane) { if (objectInMyLane == null) { return(false); } var distanceToStop = CalculateDistanceToStop(_myCar.VY, _myCar.MaximumDeceleration); float distance; if (!shouldChangeLane) { distance = GetDistanceFromObject(_myPositionY, objectInMyLane); if (objectInMyLane.VY < _myCar.VY) { return(distance < distanceToStop); } return(false); } var closestObjectInMyLaneBottom = objectInMyLane.BoundingBox.Top; if (_desiredLane == _currentLane + GameConstants.LaneWidth) { if (objectInRightLane == null) { return(false); } distance = GetDistanceFromObject(_myPositionY, objectInRightLane); if (objectInMyLane.VY < _myCar.VY) { return(distance < distanceToStop); } return(false); } if (objectInLeftLane == null) { return(false); } distance = GetDistanceFromObject(_myPositionY, objectInLeftLane); if (objectInMyLane.VY < _myCar.VY) { return(distance < distanceToStop); } return(false); }
public static GameObjectState CreateTankState(TankController t) { GameObjectState s = new GameObjectState(); s.Id = t.gameObject.GetInstanceID(); s.Ammo = t.Ammo; s.Heading = t.Heading; s.Health = t.Health; s.Name = t.Name; s.Type = "Tank"; s.X = t.X; s.Y = t.Y; s.TurretHeading = t.TurretHeading; return(s); }
public void copy(GameObjectState other) { if (other == null) { return; } rHandPos = other.rHandPos; rHandVel = other.rHandVel; paddlePos = other.paddlePos; paddleVel = other.paddleVel; targetPos = other.targetPos; targetVel = other.targetVel; deltaTime = other.deltaTime; }
static void CheckForReplicate(int instanceID,GameObjectState goState) { if(goState.Messenger.replicateEventOnChildren) { if(!replicateOnChildren.Contains(instanceID)) { replicateOnChildren.Add(instanceID); } } else { if(replicateOnChildren.Contains(instanceID)) { replicateOnChildren.Remove(instanceID); } } EditorApplication.RepaintHierarchyWindow(); }
static void CheckForOverride(int instanceID,GameObjectState goState) { if(goState.Messenger.overrideEventForSignal) { if(!overrideEvent.Contains(instanceID)) { overrideEvent.Add(instanceID); } } else { if(overrideEvent.Contains(instanceID)) { overrideEvent.Remove(instanceID); } } EditorApplication.RepaintHierarchyWindow(); }