void SyncTransform(Vector3 pos, Vector3 euler, Vector3 scale) { if (agent == null) { return; } // 更新玩家位置:玩家id|localPosition|localRotation|localScale string data = string.Format( "{0}|{1}|{2}|{3}", playerId, agent.ParseVectorToString(pos), agent.ParseVectorToString(euler), agent.ParseVectorToString(scale) ); agent.SendCmd(Cmd.player_transform, data); }
void UpdateAutoPlayingState() { bool isStateChanged = false; if (autoPlayingState != autoPlayingStateLast) { isStateChanged = true; autoPlayingStateLast = autoPlayingState; } switch (autoPlayingState) { case AuotPlayingState.Init: { //botPosition = Vector3.zero; //botEuler = Vector3.zero; //botScale = Vector3.one; botIdleTimer = 0f; botIdleToMoveWaitSeconds = 0f; botMoveVector = Vector3.forward; botMoveSpeed = 0f; botMoveTimer = 0f; botMoveToIdleWaitSeconds = 0f; autoPlayingState = AuotPlayingState.Idle; } break; case AuotPlayingState.Idle: { if (isStateChanged) { botIdleTimer = 0f; botIdleToMoveWaitSeconds = Random.Range(3f, 6f); break; } botIdleTimer += Time.deltaTime; if (botIdleTimer >= botIdleToMoveWaitSeconds) { autoPlayingState = AuotPlayingState.Move; } } break; case AuotPlayingState.Move: { if (isStateChanged) { botMoveVector = new Vector3(Random.Range(-1, 1), 0f, Random.Range(-1, 1)); botMoveVector.Normalize(); botMoveSpeed = 2f; botMoveTimer = 0f; botMoveToIdleWaitSeconds = Random.Range(3f, 6f); botMoveVector = botMoveVector * botMoveSpeed * Time.deltaTime; break; } botMoveTimer += Time.deltaTime; botPosition += botMoveVector; // # (both) 更新玩家位置:玩家id|localPosition|localRotation|localScale string data = string.Format( "{0}|{1}|{2}|{3}", myPlayerId, connectionAgent.ParseVectorToString(botPosition), connectionAgent.ParseVectorToString(botEuler), connectionAgent.ParseVectorToString(botScale) ); connectionAgent.SendCmd(Cmd.player_transform, data); if (botMoveTimer >= botMoveToIdleWaitSeconds) { autoPlayingState = AuotPlayingState.Idle; } } break; } }