public CharacterJoint3D(IWorld world, IBody3D body1, IBody3D body2, TSVector position, TSVector hingeAxis) : base((World)world) { RigidBody rigid1 = (RigidBody)body1; RigidBody rigid2 = (RigidBody)body2; fixedAngle = new FixedAngle(rigid1, rigid2); pointOnLine = new PointOnLine(rigid1, rigid2, rigid1.position, rigid2.position); firstBody = body1; secondBody = body2; hingeA = hingeAxis; worldPointConstraint = new PointOnPoint[2]; hingeAxis *= FP.Half; TSVector anchor = position; TSVector.Add(ref anchor, ref hingeAxis, out anchor); TSVector anchor2 = position; TSVector.Subtract(ref anchor2, ref hingeAxis, out anchor2); worldPointConstraint[0] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, anchor); worldPointConstraint[1] = new PointOnPoint((RigidBody)body2, (RigidBody)body1, anchor2); StateTracker.AddTracking(worldPointConstraint[0]); StateTracker.AddTracking(worldPointConstraint[1]); //UnityEngine.CharacterJoint; Activate(); }
/** * @brief Initial setup when game is started. **/ public override void OnSyncedStart() { StateTracker.AddTracking(this); paddleCountText = (Instantiate(paddleCountPrefab) as GameObject).GetComponent <Text>(); paddleCountText.transform.SetParent(GameObject.Find("Canvas").transform, false); tsRigidBody = GetComponent <TSRigidBody2D>(); // If paddle's owner is the first player then place it on top side if (owner.Id == 1) { Material redMatter = Resources.Load("RedMatter", typeof(Material)) as Material; GetComponent <MeshRenderer>().material = redMatter; tsRigidBody.position = new TSVector2(0, 8); // Adds this PaddleController in the {@link #paddlesBySide} dictionary with key being true (top size) paddlesBySide[true] = this; } else { tsRigidBody.position = new TSVector2(0, -8); // Adds this PaddleController in the {@link #paddlesBySide} dictionary with key being false (bottom size) paddlesBySide[false] = this; } }
public BasicJoint3D(IWorld world, IBody3D body1, IBody3D body2, TSVector anchorPosition, TSVector anchorPosition2) : base((World)world) { firstBody = body1; secondBody = body2; //hingeA = hingeAxis; worldPointConstraint = new FixedPoint[2]; ///hingeAxis *= FP.Half; TSVector anchor = anchorPosition; //TSVector.Add(ref anchor, ref hingeAxis, out anchor); TSVector anchor2 = anchorPosition2; //TSVector.Subtract(ref anchor2, ref hingeAxis, out anchor2); //pointLock = new PointPointDistance((RigidBody)body1, (RigidBody)body2, position, position); //pointLock.Distance = 0; //pointLock.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance; worldPointConstraint[0] = new FixedPoint((RigidBody)body1, (RigidBody)body2, anchor, anchor); worldPointConstraint[1] = new FixedPoint((RigidBody)body2, (RigidBody)body1, anchor, anchor); StateTracker.AddTracking(worldPointConstraint[0]); //StateTracker.AddTracking(worldPointConstraint[1]); Activate(); }
/** * @brief Initial setup when game is started. **/ public override void OnSyncedStart() { TSPlayerInfoToPlayerDict.Add(owner, this); //_tapLocationSphereCheckRB = _tapLocationSphereCheckGO.GetComponent<TSRigidBody>(); // Adds {@link #lastJumpState} to the tracking system StateTracker.AddTracking(this); // if is first player then changes ball's color to black if (owner != null && owner.Id == 1) { //GetComponent<Renderer>().material.color = Color.black; } }
// Use this for initialization public override void OnSyncedStart() { // Store a direction so we can make the local player always play on the same side and create the second player on the other side if (owner.Id == localOwner.Id) { direction = 1; } else { direction = -1; } textMesh = GetComponentInChildren <TextMesh>(); GetComponentInChildren <Transform> ().localPosition = new Vector3(-2.3f, 0f, direction); StateTracker.AddTracking(boxData); }
private HingeJoint3D(IWorld world, IBody3D body1, IBody3D body2, TSVector position, TSVector hingeAxis) : base((World)world) { worldPointConstraint = new PointOnPoint[2]; hingeAxis *= FP.Half; TSVector pos1 = position; TSVector.Add(pos1, hingeAxis, out pos1); TSVector pos2 = position; TSVector.Subtract(pos2, hingeAxis, out pos2); worldPointConstraint[0] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, pos1); worldPointConstraint[1] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, pos2); StateTracker.AddTracking(worldPointConstraint[0]); StateTracker.AddTracking(worldPointConstraint[1]); Activate(); }
public MyHingeJoint(IWorld world, IBody3D body1, IBody3D body2, TSVector position, TSVector hingeAxis) : base((World)world) { firstBody = body1; secondBody = body2; hingeA = hingeAxis; worldPointConstraint = new PointOnPoint[2]; hingeAxis *= FP.Half; TSVector anchor = position; TSVector.Add(ref anchor, ref hingeAxis, out anchor); TSVector anchor2 = position; TSVector.Subtract(ref anchor2, ref hingeAxis, out anchor2); worldPointConstraint[0] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, anchor); worldPointConstraint[1] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, anchor2); StateTracker.AddTracking(worldPointConstraint[0]); StateTracker.AddTracking(worldPointConstraint[1]); }
public override void OnSyncedStart() { Debug.Log("Started UnitBehavior Script for a unit (ID = " + gameObject.GetInstanceID() + ") owned by Player " + owner.Id); // Store a direction so we can make the local player always play on the same side and create the second player on the other side if (owner.Id != localOwner.Id) { direction = -1; } else { direction = 1; } // Hardcode some speed factor because this is just an experiement translation = (new TSVector(0, 0, 0.05f * direction)); textMesh = GetComponentInChildren <TextMesh>(); StateTracker.AddTracking(unitData); unitState = UnitState.Summoning; // Initialize in a summoning state (to avoid a problem, please talk to MIK to discuss) }
public PrismaticJoint3D(IWorld world, IBody3D body1, IBody3D body2, FP minimumDistance, FP maximumDistance) : base((World)world) { //fixedAngle = new FixedAngle((RigidBody)body1, (RigidBody)body2); pointOnLine = new PointOnLine((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position); //minDistance = new PointPointDistance((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position); //minDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMinimumDistance; //minDistance.Distance = minimumDistance; //maxDistance = new PointPointDistance((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position); //maxDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance; //maxDistance.Distance = maximumDistance; //StateTracker.AddTracking(fixedAngle); StateTracker.AddTracking(pointOnLine); //StateTracker.AddTracking(minDistance); //StateTracker.AddTracking(maxDistance); Activate(); }
public override void OnSyncedStart() { nickLabel = (Instantiate(nickPrefab) as GameObject).GetComponent <Text>(); nickLabel.transform.SetParent(GameObject.Find("Canvas").transform, false); nickLabel.text = owner.Name; rb = GetComponent <TSRigidBody> (); ss = (SphereShape)GetComponent <TSSphereCollider> ().Shape; rb.position += new TSVector(owner.Id * 2, 0, 0); originalRadius = ss.Radius; originalGraphicsScale = graphics.localScale; // needed for rollbacks StateTracker.AddTracking(this, "currentScale"); if (owner.Id == localOwner.Id) { Camera.main.GetComponent <TopDownCamera> ().target = transform; } }
public LimitHingeJoint3D(IWorld world, IBody3D body1, IBody3D body2, TSVector position, TSVector hingeAxis, FP minLimit, FP maxLimit) : base(world, body1, body2, position, hingeAxis) { TSVector perpDir = TSVector.up; if (TSVector.Dot(perpDir, hingeAxis) > 0.1f) { perpDir = TSVector.right; } TSVector sideAxis = TSVector.Cross(hingeAxis, perpDir); perpDir = TSVector.Cross(sideAxis, hingeAxis); perpDir.Normalize(); FP len = 15; TSVector hingeRelAnchorPos0 = perpDir * len; FP angleToMiddle = FP.Half * (minLimit - maxLimit); TSMatrix outMatrix; TSMatrix.CreateFromAxisAngle(ref hingeAxis, -angleToMiddle * FP.Deg2Rad, out outMatrix); TSVector hingeRelAnchorPos1 = TSVector.Transform(hingeRelAnchorPos0, outMatrix); FP hingeHalfAngle = FP.Half * (minLimit + maxLimit); FP allowedDistance = len * 2 * FP.Sin(hingeHalfAngle * FP.Half * FP.Deg2Rad); TSVector hingePos = body1.TSPosition; TSVector relPos0c = hingePos + hingeRelAnchorPos0; TSVector relPos1c = hingePos + hingeRelAnchorPos1; distance = new PointPointDistance((RigidBody)body1, (RigidBody)body2, relPos0c, relPos1c); distance.Distance = allowedDistance; distance.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance; StateTracker.AddTracking(distance); }
/** * @brief Initial setup when game is started. **/ public override void OnSyncedStart() { StateTracker.AddTracking(this); tsRigidBody = GetComponent <TSRigidBody2D>(); }
private void SpawnCharacter(int i_TeamIndex, int i_TeamSize, int i_SpawnIndex, int i_PhotonPlayerId, tnCharacterDescription i_CharacterDescription) { if (m_CharacterPrefab == null || i_CharacterDescription == null) { return; } int descriptorCharacterId = i_CharacterDescription.characterId; int descriptorOnlinePlayerIndex = i_CharacterDescription.onlinePlayerIndex; int descriptorPlayerId = i_CharacterDescription.playerId; string[] spawnPointsNames = SpawnPoints.GetSpawnPoints(i_TeamIndex, i_TeamSize); if (spawnPointsNames == null) { return; } if (i_SpawnIndex < 0 || i_SpawnIndex >= spawnPointsNames.Length) { return; } string spawnPointName = spawnPointsNames[i_SpawnIndex]; GameObject spawnPointGo = GameObject.Find(spawnPointName); if (spawnPointGo == null) { return; } TSTransform2D spawnPoint = spawnPointGo.GetComponent <TSTransform2D>(); if (spawnPoint == null) { return; } tnCharacterData characterData = tnGameData.GetCharacterDataMain(descriptorCharacterId); if (characterData == null) { return; } tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamsModule == null) { return; } tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex); if (teamDescription == null) { return; } int teamId = teamDescription.teamId; Color teamColor = teamDescription.teamColor; tnTeamData teamData = tnGameData.GetTeamDataMain(teamId); if (teamData == null) { return; } bool isLocal = (PhotonNetwork.offlineMode) ? true : tnGameModulesUtils.IsLocalPlayer(descriptorOnlinePlayerIndex); bool isHuman = (PhotonNetwork.offlineMode) ? (descriptorPlayerId != Hash.s_NULL) : (descriptorOnlinePlayerIndex >= 0); Vector3 spawnPosition = spawnPoint.position.ToVector(); Quaternion spawnRotation = Quaternion.Euler(0f, 0f, spawnPoint.rotation.AsFloat()); // Spawn character. GameObject characterInstance = Instantiate <GameObject>(m_CharacterPrefab); characterInstance.name = characterData.displayName; characterInstance.transform.position = spawnPosition; characterInstance.transform.rotation = spawnRotation; // Configure TSTransform TSTransform2D tsTransform = characterInstance.GetComponent <TSTransform2D>(); if (tsTransform != null) { tsTransform.position = spawnPoint.position; tsTransform.rotation = spawnPoint.rotation; } // Configure depth2d. tnDepth2d depth2d = characterInstance.GetComponent <tnDepth2d>(); if (depth2d != null) { depth2d.SetOffset(spawnPointGo.transform.position.z); } // Configure character stats database. tnStatsDatabase teamStats = teamData.teamStats; tnStatsContainer statsContainer = characterInstance.GetComponent <tnStatsContainer>(); if (statsContainer != null) { statsContainer.SetStatsDatabase(teamStats); } // Configure character view. tnCharacterViewController characterViewController = characterInstance.GetComponent <tnCharacterViewController>(); if (characterViewController != null) { // Base color. characterViewController.SetBaseColor(teamColor); // Charging force bar. characterViewController.SetChargingForceBarColor(teamColor); // Energy bar. characterViewController.SetEnergyBarColor(teamColor); // Flag. characterViewController.SetFlagSprite(teamData.baseSprite); // Animator characterViewController.SetAnimatorController(characterData.animatorController); // Set facing right. characterViewController.SetFacingRight((spawnPoint.position.x < 0f)); // Player color. characterViewController.TurnOffColor(); characterViewController.SetArrowVisible(false); characterViewController.SetArrowColor(Color.white); if (isLocal) { if (PhotonNetwork.offlineMode) { if (isHuman) { tnPlayerData playerData = tnGameData.GetPlayerDataMain(descriptorPlayerId); if (playerData != null) { Color playerColor = playerData.color; characterViewController.SetPlayerColor(playerColor); characterViewController.SetArrowVisible(true); characterViewController.SetArrowColor(playerColor); } } } else { List <int> onlinePlayersKeys = tnGameData.GetOnlinePlayersKeysMain(); if (onlinePlayersKeys != null) { if (descriptorOnlinePlayerIndex >= 0 && descriptorOnlinePlayerIndex < onlinePlayersKeys.Count) { int onlinePlayerKey = onlinePlayersKeys[descriptorOnlinePlayerIndex]; tnOnlinePlayerData onlinePlayerData = tnGameData.GetOnlinePlayerDataMain(onlinePlayerKey); if (onlinePlayerData != null) { Color playerColor = onlinePlayerData.color; characterViewController.SetPlayerColor(playerColor); characterViewController.SetArrowVisible(true); characterViewController.SetArrowColor(playerColor); } } } } } } // Input: NOTE that current aiFacotry assumes that all AI are handled by the same client. // If you want to support AI in multiplayer you should change the ai factory implementation. // Now multiplayer isn't implemented, so now, if you're using AI, you are playing offline --> All AIs are yours. if (isLocal) { tnInputFiller inputFiller = null; tnRumbleController rumbleController = null; int localPlayerIndex; bool localPlayerIndexFound = tnGameModulesUtils.OnlineToLocalPlayerIndex(descriptorOnlinePlayerIndex, out localPlayerIndex); if (localPlayerIndexFound || PhotonNetwork.offlineMode) { tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>(); int playerId = (PhotonNetwork.offlineMode) ? descriptorPlayerId : ((localPartyModule != null) ? localPartyModule.GetPlayerId(localPlayerIndex) : Hash.s_NULL); tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData != null) { string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; PlayerInput playerInput = InputSystem.GetPlayerByNameMain(playerInputName); WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName); if (playerInput != null) { inputFiller = new tnPlayerInputFiller(playerInput); rumbleController = new tnRumbleController(playerInput); m_LocalPlayersInput.Add(playerInput); } else { if (wifiPlayerInput != null) { inputFiller = new tnWiFiPlayerInputFiller(wifiPlayerInput); m_LocalWifiPlayersInput.Add(wifiPlayerInput); } } } else { tnAIInputFiller aiInputFiller = CreateAIInputFiller(i_TeamIndex, i_SpawnIndex, characterInstance); inputFiller = aiInputFiller; List <tnAIInputFiller> aiList = m_LocalAI[i_TeamIndex]; aiList.Add(aiInputFiller); } } // Bind input filler to character instance. if (inputFiller != null) { tnInputController inputController = new tnInputController(inputFiller); inputController.SetRumbleController(rumbleController); AddInputController(inputController); tnCharacterInput characterInput = characterInstance.GetComponent <tnCharacterInput>(); if (characterInput != null) { characterInput.Bind(inputController); } } // Add rumble component. if (isHuman) { tnRumbleParams rumbleParams = Resources.Load <tnRumbleParams>(s_RumbleParams_ResourcePath); if (rumbleParams != null) { tnRumble rumbleComponent = characterInstance.GetComponent <tnRumble>(); if (rumbleComponent == null) { rumbleComponent = characterInstance.AddComponent <tnRumble>(); } rumbleComponent.SetParams(rumbleParams); } } // Input Delay. int delay = (TrueSyncManager.isOfflineMain) ? m_OfflinePlayerInputDelay : 0; if (!isHuman) { tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>(); int aiLevelIndex = (matchSettingsModule != null) ? matchSettingsModule.aiLevelIndex : (tnGameData.aiLevelCountMain / 2); tnAILevel aiLevel = tnGameData.GetAILevelMain(aiLevelIndex); if (aiLevel != null) { delay = aiLevel.inputDelay; } } // Register on player input collector. RegisterObjectOnInputCollector(characterInstance, delay); } // Configure character info. tnCharacterInfo characterInfo = characterInstance.GetComponent <tnCharacterInfo>(); if (characterInfo == null) { characterInfo = characterInstance.AddComponent <tnCharacterInfo>(); } int characterIndex = m_Characters.Count; characterInfo.SetCharacterIndex(characterIndex); characterInfo.SetCharacterId(descriptorCharacterId); characterInfo.SetTeamIndex(i_TeamIndex); characterInfo.SetTeamId(teamId); characterInfo.SetTeamColor(teamColor); // Callback. OnCharacterSpawned(i_TeamIndex, characterIndex, characterInstance); // Add characters to lists. m_Characters.Add(characterInstance); if (isLocal) { m_LocalCharacters.Add(characterInstance); } List <GameObject> team = m_Teams[i_TeamIndex]; team.Add(characterInstance); // Create character result. tnCharacterResults characterResults = CreateCharacterResults(descriptorCharacterId); characterResults.isHuman = isHuman; tnTeamResults teamResults = GetTeamResultsByIndex(i_TeamIndex); if (teamResults != null) { teamResults.AddCharacterResults(characterResults); } m_CharactersResults.Add(characterResults); // Track character result. StateTracker.AddTracking(characterResults); // Configure TrueSyncObject. TrueSyncObject trueSyncObject = characterInstance.GetComponent <TrueSyncObject>(); if (trueSyncObject != null) { trueSyncObject.SetOwnerId(i_PhotonPlayerId); TrueSyncManager.RegisterTrueSyncObjectMain(trueSyncObject); } }
private void ProceesTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription) { if (i_TeamDescription == null) { return; } int teamId = i_TeamDescription.teamId; tnTeamData teamData = tnGameData.GetTeamDataMain(teamId); if (teamData == null) { return; } m_TeamsIds.Add(teamId); // Get team size. int teamSize = i_TeamDescription.charactersCount; // Create team results. tnTeamResults teamResults = CreateTeamResults(teamId); m_TeamsResults.Add(teamResults); StateTracker.AddTracking(teamResults); // Callback. OnCreateTeam(i_TeamIndex, i_TeamDescription); for (int characterIndex = 0; characterIndex < teamSize; ++characterIndex) { tnCharacterDescription characterDescription = (PhotonNetwork.offlineMode) ? i_TeamDescription.GetCharacterDescriptionBySpawnOrder(characterIndex) : i_TeamDescription.GetCharacterDescription(characterIndex); if (characterDescription == null) { continue; } int disconnectedPlayerPhotonId = -1; int photonPlayerId; if (PhotonNetwork.offlineMode) { photonPlayerId = 0; // 0 is the default value related to a fake "Local_Player". See TrueSyncController::Initialize. } else { int onlinePlayerIndex = characterDescription.onlinePlayerIndex; tnGameModulesUtils.GetPhotonPlayerOwnerId(onlinePlayerIndex, out photonPlayerId); // Check if the owner of this character is still connected. If not, reset photon player id. PhotonPlayer owner = PhotonUtils.GetPhotonPlayer(photonPlayerId); disconnectedPlayerPhotonId = (owner == null) ? photonPlayerId : -1; photonPlayerId = (owner != null) ? photonPlayerId : -1; } // If photon player id is valid, spawn character. if (photonPlayerId >= 0) { SpawnCharacter(i_TeamIndex, teamSize, characterIndex, photonPlayerId, characterDescription); } else { Debug.LogWarning("[tnMatchController] Character skipped for photon player id " + disconnectedPlayerPhotonId + "."); } } }
// Enable a behaviour to enable tracking on the class' fields public void SetStateTracking() { StateTracker.AddTracking(this); }
public override void OnSyncedStart() { // Adds to TrueSync's tracking system StateTracker.AddTracking(this); }