protected override void OnCreateManager() { CoreDataQuery = GetEntityQuery(typeof(CoreData)); GameObject a = Resources.Load("Core/Debug/LiveEntityDebugging") as GameObject; EntityDebug = GameObject.Instantiate(a); if (EntityDebug != null) { GameObject[] debugs = CoreFunctionsClass.FindGameObjectsWithLayer(8); if (debugs != null) { GameObject parent = CoreFunctionsClass.FindGameObjectWithName(debugs, "GameSettings"); if (parent != null) { EntityDebug.transform.SetParent(parent.transform); } else { Debug.LogWarning("Failed to set parent of the LiveENtityComponent, failed to find GameSettings thing"); } } else { Debug.LogWarning("Failed to set parent of the LiveEntityComponent"); } DebugComponent = EntityDebug.GetComponent <LiveEntityDebugComponent>(); } else { Debug.LogError("EntityDenig is invalid!"); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //handle the gameobject display and changes if (EntityDebug != null) { if (DebugComponent != null) { if (DebugComponent.active) { if (desiredEntity.Equals(new Entity { }) || EntityManager.GetName(desiredEntity) != DebugComponent.EntityName) { if (DebugComponent.EntityName == "") { Debug.LogWarning("Cannot display or change entity with a blank Entity name"); } else { if (CoreDataQuery.CalculateEntityCount() > 0) { string[] a = DebugComponent.EntityName.Split(':'); if (!CoreFunctionsClass.FindEntity(EntityManager, ref desiredEntity, a[0], a.Length > 1 ? a[1] : "")) { Debug.LogWarning("Failed to find Entity that matches \"" + DebugComponent.EntityName + "\""); } } else { Debug.LogError("Cannot use LiveEntityDebugging with no Entity with a CoreData Component"); } } } else { DebugComponent.Display.Update(EntityManager, desiredEntity); } //Handle Global Settings if (DebugComponent.GlobalSettings.applyChange) { DebugComponent.GlobalSettings.ApplyChanges(); DebugComponent.GlobalSettings.Update(); DebugComponent.GlobalSettings.applyChange = false; DebugComponent.GlobalSettings.editMode = false; } else if (!DebugComponent.GlobalSettings.IsUpdated() && !DebugComponent.GlobalSettings.editMode) { DebugComponent.GlobalSettings.Update(); } } } } return(inputDeps); }
public static void GenerateEnviroment(string region, string enviroment, EntityManager entityManager, float3 bounds, float3 position, quaternion rotation, float3 scale, float bevelRadius = 0) { EntityArchetype defaultArchtype = entityManager.CreateArchetype( typeof(Translation), typeof(Rotation), typeof(Scale), typeof(LocalToWorld), // typeof(PhysicsCollider), typeof(AudioSharedData), typeof(AudioData), typeof(CoreData) ); Entity entity = entityManager.CreateEntity(defaultArchtype); Translation trans = new Translation { Value = position }; entityManager.SetComponentData(entity, trans); entityManager.SetComponentData(entity, new Scale { Value = scale.x }); CoreData _cd = new CoreData(new ByteString30(enviroment), new ByteString30(region), bounds, new float3(1f, 1f, 1f)); entityManager.SetComponentData(entity, _cd); /* entityManager.SetComponentData(entity, new PhysicsCollider * { * Value = Unity.Physics.BoxCollider.Create(new BoxGeometry * { * Center = position+(bounds/2), * Size = bounds, * Orientation = rotation, * BevelRadius = bevelRadius * }) * });*/ entityManager.SetSharedComponentData(entity, GetEnviromentSoundInfo(region, "Forest")); switch (enviroment) { case "Forest": //populate forest entities //we gonna need some trees, and bushes GameObject ForestTreeGO = Resources.Load("Enviroment/Kanto/Forest/Landscapes/Tree/Tree") as GameObject; ForestTreeGO = GameObject.Instantiate(ForestTreeGO); if (ForestTreeGO != null) { //create the exclude list NativeArray <CoreData> excludes = new NativeArray <CoreData>(1, Allocator.TempJob); excludes[0] = _cd; //get all the entities position/size within an area // NativeArray<Bounds> cubes = CoreFunctionsClass.GetEntitiesWIthinArea(entityManager, position, bounds, excludes, true); // Debug.Log("bounds = "+ ForestTreeGO.GetComponent<MeshFilter>().mesh.bounds.size); // NativeArray<Entity> trees = new NativeArray<Entity>(30, Allocator.Temp); // entityManager.CreateEntity(GetEnviromentArchtype(entityManager, "Tree"), trees); //calculate size // float3 size = ForestTreeGO.GetComponent<MeshFilter>().mesh.bounds.size; //set the values // SetEnviromentEntityData(entityManager, ForestTreeGO, trees,cubes,true, region, "Tree", // size, position, bounds); // trees.Dispose(); excludes.Dispose(); Entity e = new Entity { }; bool a = CoreFunctionsClass.FindEntity(entityManager, ref e, "Tree", "Kanto/Landscapes/Tree"); if (a) { NativeArray <Entity> generatedEntities = CoreFunctionsClass.SpawnEntitiesWithinBounds(entityManager, e, new Bounds(trans.Value, _cd.size), 30, excludes, new float[0, 0], true); entityManager.AddComponentData(e, new DestroyMe { }); generatedEntities.Dispose(); } else { Debug.LogError("Failed to find Tree entity"); } } else { Debug.LogError("Failed to successfully load ForestTree"); } GameObject.Destroy(ForestTreeGO); break; default: Debug.LogError("cannot create enviroment with name \"" + enviroment + "\""); break; } }
public static void GenerateEntityUIGameObject(EntityManager entityManager, Entity entity, ref GameObject PlayerCanvas, ref GameObject WorldCanvas, UIComponentRequest uicr) { GameObject bob = Resources.Load("Core/UI/InGameUI/PlayerBarContainers") as GameObject; GameObject go = GameObject.Instantiate(bob) as GameObject; UIComponent uic = new UIComponent { }; if (go != null) { GameObject[] containers = CoreFunctionsClass.GetGameObjectChildren(go); for (int i = 0; i < containers.Length; i++) { GameObject[] containerChildren = CoreFunctionsClass.GetGameObjectChildren(containers[i]); for (int j = 0; j < containerChildren.Length; j++) { // Debug.Log("Children: name = \"" + containerChildren[j].name + "\""); if (containerChildren[j].name.Contains("BarBorder")) { uic.BarBorder = containerChildren[j].GetComponent <Image>(); } else if (containerChildren[j].name == "HealthBar") { uic.HealthBarImage = containerChildren[j].GetComponent <Image>(); } else if (containerChildren[j].name == "EnergyBar") { uic.EnergyBarImage = containerChildren[j].GetComponent <Image>(); } else if (containerChildren[j].name == "HealthBarValue") { uic.HealthBarValue = containerChildren[j].GetComponent <TextMeshProUGUI>(); } else if (containerChildren[j].name == "EnergyBarValue") { uic.EnergyBarValue = containerChildren[j].GetComponent <TextMeshProUGUI>(); } } } uic.onWorld = uicr.addToWorld; uic.toggleVisibility = !uicr.visible; uic.followPlayer = uicr.followPlayer; if (uic.BarBorder != null && uic.HealthBarImage != null && uic.EnergyBarImage != null && uic.HealthBarValue != null && uic.EnergyBarValue != null) { uic.isValid = true; } if (uic.isValid) { uic.UIGameObject = go; //assumes that the entity has CoreData SetEntityWorldCanvasUIOffset(entityManager.GetComponentData <CoreData>(entity).BaseName.ToString(), ref uic); //add world canvas height/2 // uic.positionOffset.y += WorldCanvas.GetComponent<RectTransform>().rect.height/ 2; //set the new scale offeset if (uicr.addToWorld) { uic.UIGameObject.GetComponent <RectTransform>().localScale = uic.scaleOffset; } if (entityManager.HasComponent <UIComponent>(entity)) { entityManager.SetSharedComponentData <UIComponent>(entity, uic); } else { entityManager.AddSharedComponentData(entity, uic); } if (!entityManager.HasComponent <UIComponentFilter>(entity)) { entityManager.AddComponentData <UIComponentFilter>(entity, new UIComponentFilter { }); } } else { Debug.LogError("Failed to add UIComponent due to an invalid UIComponent: " + uic.BarBorder + "," + uic.EnergyBarImage + "," + uic.EnergyBarValue + "," + uic.HealthBarImage + "," + uic.HealthBarValue); return; } AddToCanvas(go, ref PlayerCanvas, ref WorldCanvas, uicr.addToWorld); entityManager.RemoveComponent <UIComponentRequest>(entity); } else { Debug.LogError("Failed to load UI COmponent because go is null"); return; } }