| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Interface; |
| | 5 | | using DCL.Models; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using Google.Protobuf; |
| | 8 | | using UnityEngine; |
| | 9 | | using DCL.Configuration; |
| | 10 | | using Random = UnityEngine.Random; |
| | 11 | |
|
| | 12 | | namespace DCL.Bots |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Bots Tool: BotsController |
| | 16 | | /// |
| | 17 | | /// Used to spawn bots/avatarShapes for debugging and profiling purposes. |
| | 18 | | /// </summary> |
| | 19 | | public class BotsController : IBotsController |
| | 20 | | { |
| | 21 | | private ParcelScene globalScene; |
| 666 | 22 | | private List<string> randomizedCollections = new List<string>(); |
| 666 | 23 | | private List<string> instantiatedBots = new List<string>(); |
| 666 | 24 | | private List<string> eyesWearableIds = new List<string>(); |
| 666 | 25 | | private List<string> eyebrowsWearableIds = new List<string>(); |
| 666 | 26 | | private List<string> mouthWearableIds = new List<string>(); |
| 666 | 27 | | private List<string> hairWearableIds = new List<string>(); |
| 666 | 28 | | private List<string> facialWearableIds = new List<string>(); |
| 666 | 29 | | private List<string> upperBodyWearableIds = new List<string>(); |
| 666 | 30 | | private List<string> lowerBodyWearableIds = new List<string>(); |
| 666 | 31 | | private List<string> feetWearableIds = new List<string>(); |
| 666 | 32 | | private List<string> bodyshapeWearableIds = new List<string>(); |
| | 33 | |
|
| | 34 | | private Coroutine movementRoutine = null; |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Makes sure the Catalogue with all the wearables has already been loaded, otherwise it loads it |
| | 38 | | /// </summary> |
| | 39 | | private IEnumerator EnsureGlobalSceneAndCatalog() |
| | 40 | | { |
| 0 | 41 | | if (globalScene != null) |
| 0 | 42 | | yield break; |
| | 43 | |
|
| 0 | 44 | | globalScene = Environment.i.world.state.loadedScenes[Environment.i.world.state.globalSceneIds[0]] as ParcelS |
| | 45 | |
|
| 0 | 46 | | CatalogController.wearableCatalog.Clear(); |
| | 47 | |
|
| 0 | 48 | | yield return WearablesFetchingHelper.GetRandomCollections(20, true, randomizedCollections); |
| | 49 | |
|
| 0 | 50 | | List<WearableItem> wearableItems = new List<WearableItem>(); |
| 0 | 51 | | yield return WearablesFetchingHelper.GetWearableItems(BuildRandomizedCollectionsURL(), wearableItems); |
| | 52 | |
|
| 0 | 53 | | PopulateCatalog(wearableItems); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | string BuildRandomizedCollectionsURL() |
| | 57 | | { |
| 0 | 58 | | if (randomizedCollections.Count == 0) |
| 0 | 59 | | return null; |
| | 60 | |
|
| 0 | 61 | | string finalUrl = WearablesFetchingHelper.WEARABLES_FETCH_URL; |
| | 62 | |
|
| 0 | 63 | | finalUrl += "collectionId=" + randomizedCollections[0]; |
| 0 | 64 | | for (int i = 1; i < randomizedCollections.Count; i++) |
| | 65 | | { |
| 0 | 66 | | finalUrl += "&collectionId=" + randomizedCollections[i]; |
| | 67 | | } |
| | 68 | |
|
| 0 | 69 | | return finalUrl; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Populates the catalogue and internal avatar-part divided collections for optimized randomization |
| | 74 | | /// </summary> |
| | 75 | | /// <param name="newWearables">The list of WearableItem objects to be added to the catalog</param> |
| | 76 | | private void PopulateCatalog(List<WearableItem> newWearables) |
| | 77 | | { |
| 0 | 78 | | foreach (var wearableItem in newWearables) |
| | 79 | | { |
| 0 | 80 | | switch (wearableItem.data.category) |
| | 81 | | { |
| | 82 | | case WearableLiterals.Categories.EYES: |
| 0 | 83 | | eyesWearableIds.Add(wearableItem.id); |
| 0 | 84 | | break; |
| | 85 | | case WearableLiterals.Categories.EYEBROWS: |
| 0 | 86 | | eyebrowsWearableIds.Add(wearableItem.id); |
| 0 | 87 | | break; |
| | 88 | | case WearableLiterals.Categories.MOUTH: |
| 0 | 89 | | mouthWearableIds.Add(wearableItem.id); |
| 0 | 90 | | break; |
| | 91 | | case WearableLiterals.Categories.FEET: |
| 0 | 92 | | feetWearableIds.Add(wearableItem.id); |
| 0 | 93 | | break; |
| | 94 | | case WearableLiterals.Categories.HAIR: |
| 0 | 95 | | hairWearableIds.Add(wearableItem.id); |
| 0 | 96 | | break; |
| | 97 | | case WearableLiterals.Categories.FACIAL: |
| 0 | 98 | | facialWearableIds.Add(wearableItem.id); |
| 0 | 99 | | break; |
| | 100 | | case WearableLiterals.Categories.LOWER_BODY: |
| 0 | 101 | | lowerBodyWearableIds.Add(wearableItem.id); |
| 0 | 102 | | break; |
| | 103 | | case WearableLiterals.Categories.UPPER_BODY: |
| 0 | 104 | | upperBodyWearableIds.Add(wearableItem.id); |
| 0 | 105 | | break; |
| | 106 | | case WearableLiterals.Categories.BODY_SHAPE: |
| 0 | 107 | | bodyshapeWearableIds.Add(wearableItem.id); |
| | 108 | | break; |
| | 109 | | } |
| | 110 | | } |
| | 111 | |
|
| 0 | 112 | | CatalogController.i.AddWearablesToCatalog(newWearables); |
| 0 | 113 | | } |
| | 114 | |
|
| 0 | 115 | | private Vector3 playerUnityPosition => CommonScriptableObjects.playerUnityPosition.Get(); |
| 0 | 116 | | private Vector3 playerWorldPosition => CommonScriptableObjects.playerWorldPosition.Get(); |
| | 117 | | private WorldPosInstantiationConfig lastConfigUsed; |
| | 118 | | /// <summary> |
| | 119 | | /// Instantiates bots using the config file param values. It defaults some uninitialized values using the player |
| | 120 | | /// </summary> |
| | 121 | | /// <param name="config">The config file to be used</param> |
| | 122 | | public IEnumerator InstantiateBotsAtWorldPos(WorldPosInstantiationConfig config) |
| | 123 | | { |
| 0 | 124 | | yield return EnsureGlobalSceneAndCatalog(); |
| | 125 | |
|
| 0 | 126 | | PatchWorldPosInstantiationConfig(config); |
| | 127 | |
|
| 0 | 128 | | Log($"Instantiating {config.amount} randomized avatars inside a {config.areaWidth}x{config.areaDepth} area p |
| | 129 | |
|
| 0 | 130 | | Vector3 randomizedAreaPosition = new Vector3(); |
| 0 | 131 | | for (int i = 0; i < config.amount; i++) |
| | 132 | | { |
| 0 | 133 | | randomizedAreaPosition.Set(Random.Range(config.xPos, config.xPos + config.areaWidth), config.yPos, Rando |
| 0 | 134 | | InstantiateBot(randomizedAreaPosition); |
| | 135 | | } |
| | 136 | |
|
| 0 | 137 | | Log($"Finished instantiating {config.amount} avatars. They may take some time to appear while their wearable |
| | 138 | |
|
| 0 | 139 | | lastConfigUsed = config; |
| | 140 | |
|
| | 141 | | // TODO: Remove this and add to new entrypoint call in DebugController... |
| | 142 | | // StartRandomMovement(0.5f); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | private void PatchWorldPosInstantiationConfig(WorldPosInstantiationConfig config) |
| | 146 | | { |
| | 147 | | // TODO(Brian): Use nullable types here, this may fail. |
| 0 | 148 | | if (config.xPos == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 149 | | { |
| 0 | 150 | | Log($"X Position value wasn't provided... using player's current X Position."); |
| 0 | 151 | | config.xPos = playerUnityPosition.x; |
| | 152 | | } |
| | 153 | |
|
| 0 | 154 | | if (config.yPos == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 155 | | { |
| 0 | 156 | | Log($"Y Position value wasn't provided... using player's current Y Position."); |
| 0 | 157 | | config.yPos = playerUnityPosition.y; |
| | 158 | | } |
| | 159 | |
|
| 0 | 160 | | if (config.zPos == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 161 | | { |
| 0 | 162 | | Log($"Z Position value wasn't provided... using player's current Z Position."); |
| 0 | 163 | | config.zPos = playerUnityPosition.z; |
| | 164 | | } |
| 0 | 165 | | } |
| | 166 | |
|
| | 167 | | /// <summary> |
| | 168 | | /// Instantiates bots using the config file param values. It defaults some uninitialized values using the player |
| | 169 | | /// </summary> |
| | 170 | | /// <param name="config">The config file to be used</param> |
| | 171 | | public IEnumerator InstantiateBotsAtCoords(CoordsInstantiationConfig config) |
| | 172 | | { |
| 0 | 173 | | PatchCoordsInstantiationConfig(config); |
| | 174 | |
|
| 0 | 175 | | var worldPosConfig = new WorldPosInstantiationConfig() |
| | 176 | | { |
| | 177 | | amount = config.amount, |
| | 178 | | xPos = config.xCoord * ParcelSettings.PARCEL_SIZE, |
| | 179 | | yPos = playerUnityPosition.y - DCLCharacterController.i.characterController.height / 2, |
| | 180 | | zPos = config.yCoord * ParcelSettings.PARCEL_SIZE, |
| | 181 | | areaWidth = config.areaWidth, |
| | 182 | | areaDepth = config.areaDepth |
| | 183 | | }; |
| | 184 | |
|
| 0 | 185 | | Log($"Instantiating {config.amount} randomized avatars inside a {config.areaWidth}x{config.areaDepth} area p |
| | 186 | |
|
| 0 | 187 | | yield return InstantiateBotsAtWorldPos(worldPosConfig); |
| 0 | 188 | | } |
| | 189 | |
|
| | 190 | | private void PatchCoordsInstantiationConfig(CoordsInstantiationConfig config) |
| | 191 | | { |
| | 192 | | // TODO(Brian): Use nullable types here, this may fail. |
| 0 | 193 | | if (config.xCoord == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 194 | | { |
| 0 | 195 | | Log($"X Coordinate value wasn't provided... using player's current scene base X coordinate."); |
| 0 | 196 | | config.xCoord = Mathf.Floor(playerWorldPosition.x / ParcelSettings.PARCEL_SIZE); |
| | 197 | | } |
| | 198 | |
|
| 0 | 199 | | if (config.yCoord == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 200 | | { |
| 0 | 201 | | Log($"Y Coordinate value wasn't provided... using player's current scene base Y coordinate."); |
| 0 | 202 | | config.yCoord = Mathf.Floor(playerWorldPosition.z / ParcelSettings.PARCEL_SIZE); |
| | 203 | | } |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | /// <summary> |
| | 207 | | /// Instantiates an entity with an AvatarShape component, with randomized wearables, at the given position |
| | 208 | | /// </summary> |
| | 209 | | /// <param name="position">The world position of the randomized bot</param> |
| | 210 | | void InstantiateBot(Vector3 position) |
| | 211 | | { |
| 0 | 212 | | string entityId = "BOT-" + instantiatedBots.Count; |
| | 213 | |
|
| 0 | 214 | | AvatarModel avatarModel = new AvatarModel() |
| | 215 | | { |
| | 216 | | id = entityId, |
| | 217 | | name = entityId, |
| | 218 | | hairColor = Random.ColorHSV(0, 1, 0, 1, 0.25f, 0.9f), |
| | 219 | | eyeColor = Random.ColorHSV(0, 1, 0, 1, 0f, 0.2f), |
| | 220 | | skinColor = Random.ColorHSV(0, 1, 0.3f, 1, 0.4f, 0.9f), |
| | 221 | | bodyShape = Random.Range(0, 2) == 0 ? WearableLiterals.BodyShapes.FEMALE : WearableLiterals.BodyShapes.M |
| | 222 | | wearables = GetRandomizedWearablesSet() |
| | 223 | | }; |
| | 224 | |
|
| 0 | 225 | | globalScene.CreateEntity(entityId); |
| 0 | 226 | | globalScene.EntityComponentCreateOrUpdateWithModel(entityId, CLASS_ID_COMPONENT.AVATAR_SHAPE, avatarModel); |
| 0 | 227 | | UpdateEntityTransform(globalScene, entityId, position, Quaternion.identity, Vector3.one); |
| | 228 | |
|
| 0 | 229 | | instantiatedBots.Add(entityId); |
| 0 | 230 | | } |
| | 231 | |
|
| | 232 | | /// <summary> |
| | 233 | | ///Removes an instantiated bot. Every bot has its ID as its avatar name. |
| | 234 | | /// </summary> |
| | 235 | | /// <param name="targetEntityId">The target bot ID. Every bot has its ID as its avatar name.</param> |
| | 236 | | public void RemoveBot(string targetEntityId) |
| | 237 | | { |
| 0 | 238 | | if (!instantiatedBots.Contains(targetEntityId)) |
| 0 | 239 | | return; |
| | 240 | |
|
| 0 | 241 | | globalScene.RemoveEntity(targetEntityId); |
| 0 | 242 | | instantiatedBots.Remove(targetEntityId); |
| 0 | 243 | | } |
| | 244 | |
|
| | 245 | | /// <summary> |
| | 246 | | /// Removes all instantiated bots. |
| | 247 | | /// </summary> |
| | 248 | | public void ClearBots() |
| | 249 | | { |
| 0 | 250 | | while (instantiatedBots.Count > 0) |
| | 251 | | { |
| 0 | 252 | | RemoveBot(instantiatedBots[0]); |
| | 253 | | } |
| 0 | 254 | | Log("Removed all bots."); |
| 0 | 255 | | } |
| | 256 | |
|
| | 257 | | /// <summary> |
| | 258 | | /// Randomizes a whole avatar set of wearables and returns a list with all the wearable IDs |
| | 259 | | /// </summary> |
| | 260 | | List<string> GetRandomizedWearablesSet() |
| | 261 | | { |
| 0 | 262 | | var wearablesSet = new List<string>(); |
| | 263 | |
|
| 0 | 264 | | if (eyesWearableIds.Count > 0) |
| 0 | 265 | | wearablesSet.Add(eyesWearableIds[Random.Range(0, eyesWearableIds.Count)]); |
| | 266 | |
|
| 0 | 267 | | if (eyebrowsWearableIds.Count > 0) |
| 0 | 268 | | wearablesSet.Add(eyebrowsWearableIds[Random.Range(0, eyebrowsWearableIds.Count)]); |
| | 269 | |
|
| 0 | 270 | | if (mouthWearableIds.Count > 0) |
| 0 | 271 | | wearablesSet.Add(mouthWearableIds[Random.Range(0, mouthWearableIds.Count)]); |
| | 272 | |
|
| 0 | 273 | | if (hairWearableIds.Count > 0) |
| 0 | 274 | | wearablesSet.Add(hairWearableIds[Random.Range(0, hairWearableIds.Count)]); |
| | 275 | |
|
| 0 | 276 | | if (facialWearableIds.Count > 0) |
| 0 | 277 | | wearablesSet.Add(facialWearableIds[Random.Range(0, facialWearableIds.Count)]); |
| | 278 | |
|
| 0 | 279 | | if (upperBodyWearableIds.Count > 0) |
| 0 | 280 | | wearablesSet.Add(upperBodyWearableIds[Random.Range(0, upperBodyWearableIds.Count)]); |
| | 281 | |
|
| 0 | 282 | | if (lowerBodyWearableIds.Count > 0) |
| 0 | 283 | | wearablesSet.Add(lowerBodyWearableIds[Random.Range(0, lowerBodyWearableIds.Count)]); |
| | 284 | |
|
| 0 | 285 | | if (feetWearableIds.Count > 0) |
| 0 | 286 | | wearablesSet.Add(feetWearableIds[Random.Range(0, feetWearableIds.Count)]); |
| | 287 | |
|
| 0 | 288 | | if (bodyshapeWearableIds.Count > 0) |
| 0 | 289 | | wearablesSet.Add(bodyshapeWearableIds[Random.Range(0, bodyshapeWearableIds.Count)]); |
| | 290 | |
|
| 0 | 291 | | return wearablesSet; |
| | 292 | | } |
| | 293 | |
|
| | 294 | | /// <summary> |
| | 295 | | /// Starts a coroutine that traverses a % of the instantiated population at that moment and updates their waypoi |
| | 296 | | /// </summary> |
| | 297 | | /// <param name="populationNormalizedPercentage">The population % that will start moving, expressed normalized e |
| | 298 | | /// <param name="waypointsUpdateTime">The time wait in seconds for each waypoints update</param> |
| | 299 | | public void StartRandomMovement(CoordsRandomMovementConfig config) |
| | 300 | | { |
| 0 | 301 | | if (instantiatedBots.Count == 0) |
| | 302 | | { |
| 0 | 303 | | Log($"Can't start randomized movement if there are no bots instantiated. Please first instantiate some b |
| 0 | 304 | | return; |
| | 305 | | } |
| | 306 | |
|
| 0 | 307 | | PatchCoordsRandomMovementConfig(config); |
| | 308 | |
|
| 0 | 309 | | Log($"Starting randomized movement on {(config.populationNormalizedPercentage * 100)}% of the current popula |
| | 310 | |
|
| 0 | 311 | | StopRandomMovement(); |
| | 312 | |
|
| 0 | 313 | | int instantiatedCount = instantiatedBots.Count; |
| 0 | 314 | | int botsAmount = Mathf.Min(Mathf.FloorToInt(instantiatedCount * config.populationNormalizedPercentage), inst |
| | 315 | |
|
| 0 | 316 | | List<int> randomBotIndices = new List<int>(); |
| 0 | 317 | | for (int i = 0; i < botsAmount; i++) |
| | 318 | | { |
| 0 | 319 | | int randomIndex = Random.Range(0, instantiatedCount); |
| | 320 | |
|
| 0 | 321 | | if (botsAmount == instantiatedCount) |
| | 322 | | { |
| 0 | 323 | | randomIndex = i; |
| 0 | 324 | | } |
| | 325 | | else |
| | 326 | | { |
| 0 | 327 | | while (randomBotIndices.Contains(randomIndex)) |
| | 328 | | { |
| 0 | 329 | | randomIndex = Random.Range(0, instantiatedCount); |
| | 330 | | } |
| | 331 | | } |
| | 332 | |
|
| 0 | 333 | | randomBotIndices.Add(randomIndex); |
| | 334 | | } |
| | 335 | |
|
| 0 | 336 | | movementRoutine = CoroutineStarter.Start(RandomMovementRoutine(randomBotIndices, config)); |
| 0 | 337 | | } |
| | 338 | |
|
| | 339 | | private const float WAYPOINTS_UPDATE_DEFAULT_TIME = 5f; |
| | 340 | | private void PatchCoordsRandomMovementConfig(CoordsRandomMovementConfig config) |
| | 341 | | { |
| 0 | 342 | | config.populationNormalizedPercentage = Mathf.Clamp(config.populationNormalizedPercentage, 0f, 1f); |
| | 343 | |
|
| | 344 | | // TODO(Brian): Use nullable types here, this may fail. |
| 0 | 345 | | if (config.waypointsUpdateTime == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 346 | | { |
| 0 | 347 | | config.waypointsUpdateTime = WAYPOINTS_UPDATE_DEFAULT_TIME; |
| 0 | 348 | | Log($"waypointsUpdateTime value wasn't provided... using default time: {config.waypointsUpdateTime}"); |
| | 349 | | } |
| | 350 | |
|
| 0 | 351 | | if (config.xCoord == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 352 | | { |
| 0 | 353 | | config.xCoord = Mathf.Floor(lastConfigUsed.xPos / ParcelSettings.PARCEL_SIZE); |
| 0 | 354 | | Log($"X Coordinate value wasn't provided... using last bots spawning X coordinate: {config.xCoord}"); |
| | 355 | | } |
| | 356 | |
|
| 0 | 357 | | if (config.yCoord == EnvironmentSettings.UNINITIALIZED_FLOAT) |
| | 358 | | { |
| 0 | 359 | | config.yCoord = Mathf.Floor(lastConfigUsed.zPos / ParcelSettings.PARCEL_SIZE); |
| 0 | 360 | | Log($"Y Coordinate value wasn't provided... using last bots spawning Y coordinate: {config.yCoord}"); |
| | 361 | | } |
| | 362 | |
|
| 0 | 363 | | if (config.areaWidth == 0) |
| | 364 | | { |
| 0 | 365 | | config.areaWidth = lastConfigUsed.areaWidth; |
| 0 | 366 | | Log($"Area width provided is 0... using last bots spawning area config width: {config.areaWidth}"); |
| | 367 | | } |
| | 368 | |
|
| 0 | 369 | | if (config.areaDepth == 0) |
| | 370 | | { |
| 0 | 371 | | config.areaWidth = lastConfigUsed.areaDepth; |
| 0 | 372 | | Log($"Area depth provided is 0... using last bots spawning area config depth: {config.areaWidth}"); |
| | 373 | | } |
| 0 | 374 | | } |
| | 375 | |
|
| | 376 | | public void StopRandomMovement() |
| | 377 | | { |
| 0 | 378 | | if (movementRoutine == null) |
| 0 | 379 | | return; |
| | 380 | |
|
| 0 | 381 | | CoroutineStarter.Stop(movementRoutine); |
| 0 | 382 | | Log("Stopped bots movement."); |
| 0 | 383 | | } |
| | 384 | |
|
| | 385 | | private float lastMovementUpdateTime; |
| | 386 | | IEnumerator RandomMovementRoutine(List<int> targetBots, CoordsRandomMovementConfig config) |
| | 387 | | { |
| 0 | 388 | | lastMovementUpdateTime = Time.timeSinceLevelLoad; |
| 0 | 389 | | while (true) |
| | 390 | | { |
| 0 | 391 | | float currentTime = Time.timeSinceLevelLoad; |
| 0 | 392 | | if (currentTime - lastMovementUpdateTime >= config.waypointsUpdateTime) |
| | 393 | | { |
| 0 | 394 | | lastMovementUpdateTime = currentTime; |
| 0 | 395 | | foreach (int targetBotIndex in targetBots) |
| | 396 | | { |
| | 397 | | // Thanks to the avatars movement interpolation, we can just update their entity position to the |
| | 398 | |
|
| 0 | 399 | | Vector3 position = new Vector3(config.xCoord * ParcelSettings.PARCEL_SIZE, lastConfigUsed.yPos, |
| 0 | 400 | | Vector3 randomizedAreaPosition = new Vector3(Random.Range(position.x, position.x + config.areaWi |
| | 401 | | position.y, Random.Range(position.z, position.z + config.areaDepth)); |
| | 402 | |
|
| | 403 | |
|
| 0 | 404 | | UpdateEntityTransform(globalScene, instantiatedBots[targetBotIndex], randomizedAreaPosition, Qua |
| | 405 | | } |
| | 406 | | } |
| | 407 | |
|
| 0 | 408 | | yield return null; |
| | 409 | | } |
| | 410 | | } |
| | 411 | |
|
| | 412 | | void UpdateEntityTransform(ParcelScene scene, string entityId, Vector3 position, Quaternion rotation, Vector3 sc |
| | 413 | | { |
| 0 | 414 | | PB_Transform pB_Transform = GetPBTransform(position, rotation, scale); |
| 0 | 415 | | scene.EntityComponentCreateOrUpdate( |
| | 416 | | entityId, |
| | 417 | | CLASS_ID_COMPONENT.TRANSFORM, |
| | 418 | | System.Convert.ToBase64String(pB_Transform.ToByteArray()) |
| | 419 | | ); |
| 0 | 420 | | } |
| | 421 | |
|
| | 422 | | public PB_Transform GetPBTransform(Vector3 position, Quaternion rotation, Vector3 scale) |
| | 423 | | { |
| 0 | 424 | | PB_Transform pbTranf = new PB_Transform(); |
| 0 | 425 | | pbTranf.Position = new PB_Vector3(); |
| 0 | 426 | | pbTranf.Position.X = position.x; |
| 0 | 427 | | pbTranf.Position.Y = position.y; |
| 0 | 428 | | pbTranf.Position.Z = position.z; |
| 0 | 429 | | pbTranf.Rotation = new PB_Quaternion(); |
| 0 | 430 | | pbTranf.Rotation.X = rotation.x; |
| 0 | 431 | | pbTranf.Rotation.Y = rotation.y; |
| 0 | 432 | | pbTranf.Rotation.Z = rotation.z; |
| 0 | 433 | | pbTranf.Rotation.W = rotation.w; |
| 0 | 434 | | pbTranf.Scale = new PB_Vector3(); |
| 0 | 435 | | pbTranf.Scale.X = scale.x; |
| 0 | 436 | | pbTranf.Scale.Y = scale.y; |
| 0 | 437 | | pbTranf.Scale.Z = scale.z; |
| 0 | 438 | | return pbTranf; |
| | 439 | | } |
| | 440 | |
|
| | 441 | | /// <summary> |
| | 442 | | /// Logs the tool messages in console regardless of the "Debug.unityLogger.logEnabled" value. |
| | 443 | | /// </summary> |
| | 444 | | private void Log(string message) |
| | 445 | | { |
| 0 | 446 | | bool originalLogEnabled = Debug.unityLogger.logEnabled; |
| 0 | 447 | | Debug.unityLogger.logEnabled = true; |
| | 448 | |
|
| 0 | 449 | | Debug.Log("BotsController - " + message); |
| | 450 | |
|
| 0 | 451 | | Debug.unityLogger.logEnabled = originalLogEnabled; |
| 0 | 452 | | } |
| | 453 | | } |
| | 454 | | } |