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