protected override void OnCreate() { base.OnCreate(); _droneMesh = AssetData.Drone.ToRenderMesh(); _droneHighlight = AssetData.Drone.ToHighlightMesh(); _hubHighlight = AssetData.Hub.ToHighlightMesh(); _hubMesh = AssetData.Hub.ToRenderMesh(); _clicked = GetEntityQuery(typeof(PreSelectionTag)); _selected = GetEntityQuery(typeof(SelectionTag)); }
private void CreateEntity(float3 newPosition, RenderMesh renderMesh) { Entity entity = entityManager.CreateEntity(entityArchetype); entityManager.SetComponentData(entity, new Translation { Value = new float3(newPosition) }); entityManager.SetSharedComponentData(entity, renderMesh); }
protected override void OnStartRunning() { base.OnStartRunning(); Entities.ForEach((Entity e, ref CameraFadeParameters cameraFade) => { _renderMesh = _entityManager.GetSharedComponentData<RenderMesh>(e); return; }); }
private void UpdateMaterial(RenderMesh renderMesh, MaterialPass materialPass, MaterialInstance modelMaterialInstance, DecalComponent decalComponent) { renderMesh.MaterialPass = materialPass; renderMesh.IsShadowCaster = false; if (modelMaterialInstance != null) { renderMesh.IsShadowCaster = renderMesh.IsShadowCaster && modelMaterialInstance.IsShadowCaster; } }
protected override void OnCreateManager() { base.OnCreateManager(); m_entityManager = World.Active.GetOrCreateManager <EntityManager>(); RocketRenderData = GetLookFromPrototype("RocketPrototype"); RocketArchetype = m_entityManager.CreateArchetype(typeof(Translation), typeof(Rotation), typeof(ObjectSpeed), typeof(RocketProximityState), typeof(RocketCollision), typeof(RenderMesh)); }
public static void SaveObjFile(string filePath, RenderMesh mesh, MeshType type, ObjExport objExport, string sessionId, bool saveBrushesToTexture = false, bool isCollada = false) { var meshInfos = new List <MeshInfo>(); foreach (var part in mesh.Parts) { meshInfos.Add(new MeshInfo(part, mesh.MorphScale)); } SaveObjFile(filePath, meshInfos, type, objExport, saveBrushesToTexture, isCollada, sessionId); }
protected override void OnUpdate() { Entity player = this.playerQuery.GetSingletonEntity(); PlayerInfo playerInfo = this.EntityManager.GetComponentData <PlayerInfo>(player); DynamicBuffer <InventoryItem> inventoryItemsFromPlayer = this.GetBufferFromEntity <InventoryItem>()[player]; //Prevent this from being null when scene is loaded from another scene (Something about the lifecycle of ECS not behaving well with normal gameobject instantiating -> i can not always guarantee that oncreate receives the gameobject) if (this.hudInjectorProxy == null) { this.hudInjectorProxy = UnityEngine.Object.FindObjectOfType <HUDInjectorProxy>(); } this.hudInjectorProxy.HealthValueText.text = playerInfo.Health.ToString(); this.hudInjectorProxy.ManaValueText.text = playerInfo.Mana.ToString(); this.hudInjectorProxy.LevelValueText.text = playerInfo.Level.ToString(); //Turn on/off inventory/character slots this.hudInjectorProxy.InventorySlotHolderGameObject.SetActive(playerInfo.OpenInventoryFromInputData); this.hudInjectorProxy.CharacterSlotHolderGameObject.SetActive(playerInfo.OpenInventoryFromInputData); //will up item slots (the ones always displayed) for (int inventoryItemIndex = 0; inventoryItemIndex < inventoryItemsFromPlayer.Length; ++inventoryItemIndex) { for (int itemIndex = 0; itemIndex < this.hudInjectorProxy.ItemSlotCollectionDTO.ItemSlotDTOs.Count && !inventoryItemsFromPlayer[inventoryItemIndex].AddedToInventory; ++itemIndex) { ItemSlotDTO itemSlotDTO = this.hudInjectorProxy.ItemSlotCollectionDTO.ItemSlotDTOs[itemIndex]; //Fill up inventory slots left from right if (!itemSlotDTO.HasItem) { InventoryItem inventoryItem = inventoryItemsFromPlayer[inventoryItemIndex]; RenderMesh renderMeshFirstItem = this.EntityManager.GetSharedComponentData <RenderMesh>(inventoryItem.SharedRenderMeshComponentIndex); this.hudInjectorProxy.ItemSlotMeshFilter.mesh = renderMeshFirstItem.mesh; this.hudInjectorProxy.ItemSlotMeshFilter.mesh = ScaleItemMesh(this.hudInjectorProxy.ItemSlotMeshFilter.mesh, this.hudInjectorProxy.ItemSlotMeshRendererRectTransform); //Camera is normaly dsiabled and only enable it to take "screenshots" of the items this.hudInjectorProxy.ItemSlotCamera.enabled = true; this.hudInjectorProxy.ItemSlotCamera.targetTexture = RenderTextureCacheSingleton.Instance.GetOrCreateRenderTexture(itemSlotDTO.GetHashCode(), GameRelatedConstants.ItemSlotSize, GameRelatedConstants.ItemSlotSize, GameRelatedConstants.ItemSlotDepth); this.hudInjectorProxy.ItemSlotMeshRenderer.material = renderMeshFirstItem.material; itemSlotDTO.ItemSlotRawImage.texture = this.RenderCameraToTexture(this.hudInjectorProxy.ItemSlotCamera); this.hudInjectorProxy.ItemSlotCamera.enabled = false; itemSlotDTO.HasItem = true; itemSlotDTO.OriginalInventoryItem = inventoryItemsFromPlayer[inventoryItemIndex]; this.hudInjectorProxy.ItemSlotCollectionDTO.ItemSlotDTOs[itemIndex] = itemSlotDTO; inventoryItem.AddedToInventory = true; inventoryItemsFromPlayer[inventoryItemIndex] = inventoryItem; } } } }
void SelectMaterial(RenderMesh mesh) { switch (mesh.Topology) { case MeshTopology.Triangles: case MeshTopology.Quads: mesh.Material = new Material(SingleSidedMaterial); if (mesh.HasNormals) { mesh.Material.EnableKeyword("WITH_NORMALS"); } if (mesh.HasColours) { mesh.Material.EnableKeyword("WITH_COLOURS_UINT"); } break; case MeshTopology.Points: if (mesh.DrawType == MeshDrawType.Voxels) { mesh.Material = new Material(VoxelsMaterial); } else { mesh.Material = new Material(PointsMaterial); mesh.Material.SetInt("_LeftHanded", ServerInfo.IsLeftHanded ? 1 : 0); if (mesh.HasNormals) { mesh.Material.EnableKeyword("WITH_NORMALS"); } if (mesh.HasColours) { mesh.Material.EnableKeyword("WITH_COLOURS_UINT"); } int pointSize = (Materials != null) ? Materials.DefaultPointSize : 4; mesh.Material.SetInt("_PointSize", pointSize); } break; default: case MeshTopology.Lines: case MeshTopology.LineStrip: mesh.Material = new Material(SingleSidedMaterial); if (mesh.HasColours) { mesh.Material.EnableKeyword("WITH_COLOURS_UINT"); } break; } }
void CreateBlockParent( Vector2 position, Vector2Int size, Flags flags, out Entity block, out DynamicBuffer <Cell> cells, out RenderMesh renderMesh ) { float scale = flags.Has(Flags.IsGrid) ? BlokkyEditor.GridScale : BlokkyEditor.UiScale; bool isDraggable = flags.Has(Flags.IsDraggable); bool isGrid = flags.Has(Flags.IsGrid); int layer = isDraggable ? 2 : 0; float3 position3D = (Vector3)position + Vector3.back * layer; // Create RenderMesh for legos Material material = new Material(legoMaterial) { color = isDraggable ? Color.gray : Color.white }; renderMesh = new RenderMesh { material = material, mesh = legoMesh }; // Create entity EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; block = entityManager.CreateEntity(); #if UNITY_EDITOR entityManager.SetName(block, "Block"); #endif // Add components entityManager.AddComponent <LocalToWorld>(block); entityManager.AddComponentData(block, new Translation { Value = position3D }); entityManager.AddComponentData(block, new Scale { Value = scale }); entityManager.AddComponentData(block, new BlockSize(new int2(size.x, size.y))); cells = entityManager.AddBuffer <Cell>(block); entityManager.AddSharedComponentData(block, renderMesh); // Add Flag components if (isDraggable) { entityManager.AddComponent <IsDraggable>(block); } if (isGrid) { entityManager.AddComponent <IsGrid>(block); } }
public void CreateEntitiesAndGetData( IChartParser parser, out List <RenderMesh> initial, out List <RenderMesh> highlight, out List <RenderMesh> grayout, out List <RenderMesh> head, out List <RenderMesh> height, out RenderMesh shadow, out RenderMesh shadowGrayout, out int arcGroupCount) { //SETUP MATERIALS initial = new List <RenderMesh>(); highlight = new List <RenderMesh>(); grayout = new List <RenderMesh>(); head = new List <RenderMesh>(); height = new List <RenderMesh>(); for (int i = 0; i <= parser.MaxArcColor; i++) { Material arcColorMaterialInstance = Object.Instantiate(arcMaterial); Material heightIndicatorColorMaterialInstance = Object.Instantiate(heightMaterial); arcColorMaterialInstance.SetColor(colorShaderId, Settings.GetArcColor(i)); heightIndicatorColorMaterialInstance.SetColor(colorShaderId, Settings.GetArcColor(i)); Material highlightMat = Object.Instantiate(arcColorMaterialInstance); Material grayoutMat = Object.Instantiate(arcColorMaterialInstance); highlightMat.SetFloat(highlightShaderId, 1); grayoutMat.SetFloat(highlightShaderId, -1); initial.Add(new RenderMesh { mesh = arcMesh, material = arcColorMaterialInstance }); highlight.Add(new RenderMesh { mesh = arcMesh, material = highlightMat }); grayout.Add(new RenderMesh { mesh = arcMesh, material = grayoutMat }); head.Add(new RenderMesh { mesh = headMesh, material = arcColorMaterialInstance }); height.Add(new RenderMesh { mesh = heightMesh, material = heightIndicatorColorMaterialInstance }); } shadow = shadowRenderMesh; shadowGrayout = shadowGrayoutRenderMesh; arcGroupCount = CreateArclike(parser.Arcs); }
public Entity CreateBodyWithoutCollider( RenderMesh displayMesh, float3 position, quaternion orientation, float3 linearVelocity, float3 angularVelocity, float mass) { ComponentType[] componentTypes = new ComponentType[8]; componentTypes[0] = typeof(RenderMesh); componentTypes[1] = typeof(RenderBounds); componentTypes[2] = typeof(Translation); componentTypes[3] = typeof(Rotation); componentTypes[4] = typeof(LocalToWorld); componentTypes[5] = typeof(MoveData); componentTypes[6] = typeof(TrailData); componentTypes[7] = typeof(SensorData); Entity entity = entityManager.CreateEntity(componentTypes); entityManager.SetSharedComponentData(entity, displayMesh); entityManager.SetComponentData(entity, new RenderBounds { Value = displayMesh.mesh.bounds.ToAABB() }); entityManager.SetComponentData(entity, new Translation { Value = position }); entityManager.SetComponentData(entity, new Rotation { Value = orientation }); entityManager.SetComponentData(entity, new TrailData() { lastSpawnedTime = 0f, spawnRate = 0.2f }); entityManager.SetComponentData(entity, new MoveData() { angle = Random.Range(0f, 4 * Mathf.PI), //angle = 0f, rotSpeed = 2f, //speed = 1f speed = Random.Range(15f, 17f) }); entityManager.SetComponentData(entity, new SensorData() { centralSensorAngle = 0f, centralSensorDistance = 2f, centralSensorSize = 1f, leftSensorAngle = 1f, leftSensorDistance = 2f, leftSensorSize = 1f, rightSensorAngle = -1f, rightSensorDistance = 2f, rightSensorSize = 1f }); return(entity); }
protected override void OnCreate() { // renderers modelChunkRenderArchtype = World.EntityManager.CreateArchetype( // important typeof(ChunkMesh), typeof(ChunkMeshAnimation), typeof(ChunkRenderer), typeof(ChunkSides), typeof(ZoxID), // transform typeof(Translation), typeof(Rotation), typeof(NonUniformScale), typeof(LocalToWorld), typeof(Parent), typeof(LocalToParent), typeof(RenderBounds), // renderer //typeof(ChunkRenderer), typeof(RenderMesh), typeof(Static) ); // render prefab modelChunkRenderPrefab = World.EntityManager.CreateEntity(modelChunkRenderArchtype); World.EntityManager.AddComponentData(modelChunkRenderPrefab, new Prefab { }); RenderMesh renderer = World.EntityManager.GetSharedComponentData <RenderMesh>(modelChunkRenderPrefab); //renderer.mesh = new Mesh(); renderer.castShadows = UnityEngine.Rendering.ShadowCastingMode.On; renderer.receiveShadows = true; World.EntityManager.SetSharedComponentData(modelChunkRenderPrefab, renderer); // world chunk prefab worldChunkRenderArchtype = World.EntityManager.CreateArchetype( // important typeof(ZoxID), typeof(ChunkMeshLink), typeof(ChunkMesh), typeof(ChunkRenderer), typeof(ChunkSides), // other stuff typeof(Parent), typeof(Translation) ); worldChunkRenderPrefab = World.EntityManager.CreateEntity(worldChunkRenderArchtype); World.EntityManager.AddComponentData(worldChunkRenderPrefab, new Prefab { }); if (!Bootstrap.instance.isCustomRenderSystem) { worldChunkRenderPrefab = modelChunkRenderPrefab; } }
public static void SaveObjFile(string filePath, RenderMesh mesh, MeshType type, ObjExport objExport) { var meshInfos = new List <MeshInfo>(); foreach (var part in mesh.Parts) { meshInfos.Add(new MeshInfo(part)); } SaveObjFile(filePath, meshInfos, type, objExport, mesh); }
protected override void OnUpdate() { if (!PlayManager.IsUpdatingAndActive) { return; } RenderMesh initialRenderMesh = PlayManager.HoldInitialRenderMesh; RenderMesh highlightRenderMesh = PlayManager.HoldHighlightRenderMesh; RenderMesh grayoutRenderMesh = PlayManager.HoldGrayoutRenderMesh; int currentTime = PlayManager.ReceptorTime; var tracksHeld = PlayManager.InputHandler.tracksHeld; Entities .WithSharedComponentFilter <RenderMesh>(grayoutRenderMesh) .WithAll <Translation, ChartIncrTime>() .WithNone <PastJudgeRange, HoldLocked>() .ForEach( (Entity en, in ChartLane lane) => { if (tracksHeld[lane.lane] > 0) { PlayManager.CommandBuffer.SetSharedComponent <RenderMesh>(en, highlightRenderMesh); } } ).WithoutBurst().Run(); Entities .WithSharedComponentFilter <RenderMesh>(highlightRenderMesh) .WithAll <Translation, ChartIncrTime>() .WithNone <PastJudgeRange, HoldLocked>() .ForEach( (Entity en, in ChartLane lane) => { if (tracksHeld[lane.lane] <= 0) { PlayManager.CommandBuffer.SetSharedComponent <RenderMesh>(en, grayoutRenderMesh); } } ).WithoutBurst().Run(); Entities .WithSharedComponentFilter <RenderMesh>(initialRenderMesh) .WithAll <Translation, ChartIncrTime>().WithNone <PastJudgeRange, HoldLocked>().ForEach( (Entity en, in ChartLane lane, in ChartTime time) => { if (tracksHeld[lane.lane] <= 0 && time.value <= currentTime - Constants.FarWindow) { PlayManager.CommandBuffer.SetSharedComponent(en, grayoutRenderMesh); } else if (tracksHeld[lane.lane] > 0) { PlayManager.CommandBuffer.SetSharedComponent <RenderMesh>(en, highlightRenderMesh); } }
public void FadeBarEntity(Entity entity, Color fadeFrom, float2 alphas, float deltaTime) { RenderMesh render = World.EntityManager.GetSharedComponentData <RenderMesh>(entity); Color newColor = new Color(); newColor.r = fadeFrom.r; newColor.g = fadeFrom.g; newColor.b = fadeFrom.b; newColor.a = math.lerp(alphas.x, alphas.y, deltaTime); SetMaterial(render.material, newColor); }
void SetMeshComponent(Mesh mesh, Entity entity, EntityCommandBuffer commandBuffer) { RenderMesh renderer = new RenderMesh(); renderer.mesh = mesh; bool water = entityManager.HasComponent <Tags.WaterEntity>(entity); renderer.material = water ? waterMaterial : terrainMaterial; commandBuffer.AddSharedComponent(entity, renderer); }
protected override void OnUpdate() { Entity gunEntity = GetSingletonEntity <GunComponent>(); int pos = 1; if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { pos--; } if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { pos++; } if (Input.GetKey(KeyCode.Space) && Time.ElapsedTime >= _cooldownTimer) { GunComponent gunComponent = EntityManager.GetComponentData <GunComponent>(gunEntity); _cooldownTimer = Time.ElapsedTime + gunComponent.Cooldown; EntityQueryDesc query = new EntityQueryDesc { None = new ComponentType[] { ComponentType.ReadOnly <IsMoving>() }, All = new ComponentType[] { typeof(Translation), typeof(MovableComponent), ComponentType.ReadOnly <BulletComponent>() } }; EntityQuery entityQuery = GetEntityQuery(query); if (!entityQuery.IsEmptyIgnoreFilter) { NativeArray <Entity> entities = entityQuery.ToEntityArray(Allocator.Persistent); Entity entity = entities[0]; float3 direction = Quaternion.AngleAxis(60 - 30 * pos, Vector3.back) * Vector3.up; MovableComponent component = EntityManager.GetComponentData <MovableComponent>(entity); component.Direction = direction; PostUpdateCommands.AddComponent(entity, new IsMoving()); PostUpdateCommands.SetComponent(entity, component); entities.Dispose(); GameManager.Instance.ShotFired(); } } var materialReferencesEntity = GetSingletonEntity <MaterialReferences>(); var materialReferences = EntityManager.GetSharedComponentData <MaterialReferences>(materialReferencesEntity); RenderMesh renderMesh = EntityManager.GetSharedComponentData <RenderMesh>(gunEntity); Material newMaterial = materialReferences.GunPositions[pos]; if (newMaterial != renderMesh.material) { renderMesh.material = newMaterial; PostUpdateCommands.SetSharedComponent(gunEntity, renderMesh); } }
public Entity CrearRecurso(int idRecurso, float3 posicion) { if (contenedorRecursos.ContainsKey(idRecurso)) { AdministradorMateriales adminMaterial = AdministradorMateriales.Instanciar(); RecursosPlantilla recursoPlantilla = contenedorRecursos[idRecurso]; LocalToWorld localToWorld = new LocalToWorld(); localToWorld.Value = float4x4.TRS(posicion, Quaternion.Euler(0, recursoPlantilla.angulo, 0), new float3(1, 1, 1)); Translation translation = new Translation { Value = posicion }; RenderMesh renderMesh = new RenderMesh { mesh = recursoPlantilla.mallaMaestra, material = adminMaterial.ObtenerMaterial(recursoPlantilla.idMaterial).material, layer = 1 }; RenderBounds redn = new RenderBounds(); //redn.Value = recursoPlantilla.mallaMaestra.bounds.ToAABB().Extents; /* redn.Value = new AABB * { * Center = posicion * ,Extents = recursoPlantilla.mallaMaestra.bounds.ToAABB().Extents * * };*/ Recurso recurso = new Recurso { idRecurso = recursoPlantilla.idRecurso, cantidadRecurso = recursoPlantilla.cantidadRecurso }; EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; EntityArchetype archetype = entityManager.CreateArchetype( typeof(RenderMesh), typeof(RenderBounds), typeof(LocalToWorld), typeof(Recurso) ); Entity myEntity = entityManager.CreateEntity(archetype); entityManager.AddComponentData(myEntity, localToWorld); // entityManager.AddComponentData(myEntity, translation); // entityManager.AddComponentData(myEntity, redn); entityManager.AddSharedComponentData(myEntity, renderMesh); entityManager.AddComponentData(myEntity, recurso); return(myEntity); } return(default);
protected override void OnStartRunning() { SingleCube = new RenderMesh { mesh = OriginCube, material = MeshComponents.textureAtlas }; base.OnStartRunning(); Entities.ForEach((ref PrefabEntityComponent prefabEntityComponent) => { prefabEntity = prefabEntityComponent.prefabEntity; }); }
public Entity CreateDynamicSphere(EntityManager entityManager, RenderMesh displayMesh, float radius, float3 position, quaternion orientation) { // Sphere with default filter and material. Add to Create() call if you want non default: var spCollider = Unity.Physics.SphereCollider.Create(new SphereGeometry() { Center = new float3() { xyz = 0.0f }, Radius = 0.5f }); return(CreateBody(entityManager, displayMesh, position, orientation, spCollider, float3.zero, float3.zero, 1.0f, true)); }
public static void CreateSpriteComponent(EntityManager entityManager, Entity entity, UnityEngine.SpriteRenderer spriteRenderer) { var sprite = spriteRenderer.sprite; var material = GetMaterial(sprite, spriteRenderer.sharedMaterial); var renderMesh = new RenderMesh { mesh = GetMesh(sprite), material = material }; if (entityManager.HasComponent <RenderMesh>(entity)) { entityManager.SetSharedComponentData(entity, renderMesh); } else { entityManager.AddSharedComponentData(entity, renderMesh); } var tileOffset = default(TileOffsetProperty).Convert(spriteRenderer); entityManager.AddComponentData(entity, new TileOffsetProperty { Value = tileOffset }); var scale = default(ScaleProperty).Convert(spriteRenderer); entityManager.AddComponentData(entity, new ScaleProperty { Value = scale.xyz }); var pivot = default(PivotProperty).Convert(spriteRenderer); entityManager.AddComponentData(entity, new PivotProperty { Value = pivot }); entityManager.AddComponentData(entity, new ColorProperty { Value = default(ColorProperty).Convert(spriteRenderer) }); entityManager.AddComponentData(entity, new FlipProperty { Value = default(FlipProperty).Convert(spriteRenderer) }); entityManager.AddComponentData(entity, new SpriteBounds { Value = renderMesh.mesh.bounds.ToAABB() }); entityManager.AddComponentData(entity, new RenderBounds { Value = renderMesh.mesh.bounds.ToAABB() }); }
/// <summary> /// create materials based on the original object however make sure not to create two material with the same color /// to set up GPU instancing and to optimise performance /// </summary> public void AssignColors() { List <Color> colors = transformObjectToEntity.Colors; Dictionary <Color, Material> materials = transformObjectToEntity.Materials; Material material = transformObjectToEntity.Material; EntityQuery queryForChangingRenderMesh = _entityManager.CreateEntityQuery( ComponentType.ReadWrite <RenderMesh>(), ComponentType.ReadOnly <ObjectConvertedToEntity>()); NativeArray <Entity> entities = queryForChangingRenderMesh.ToEntityArray(Allocator.TempJob); for (int i = 0; i < entities.Length; i++) { RenderMesh renderMesh = _entityManager.GetSharedComponentData <RenderMesh>(entities[i]); RenderMesh newRenderMesh = new RenderMesh(); newRenderMesh.mesh = renderMesh.mesh; //check if a material with this color already exist is so assign this material if (materials.ContainsKey(colors[i])) { if (CheckIfMaterialExist(colors[i], materials, out var materialToAssign)) { newRenderMesh.material = materialToAssign; } else { Debug.LogError($"this key: {colors[i]}, does not exist"); } } //create a new material and add it to the dictionary of materials else { Material newMaterial = new Material(material); newMaterial.name = "material" + materials.Count; newMaterial.SetColor("_BaseColor", colors[i]); newRenderMesh.material = newMaterial; materials.Add(colors[i], newMaterial); } _entityManager.SetSharedComponentData(entities[i], newRenderMesh); } entities.Dispose(); queryForChangingRenderMesh.Dispose(); }
public ProfileSmoothing(RenderMesh mesh, Dictionary <Guid, MeshUndoInfo> undoInfo) { renderMesh = mesh; var newMesh = renderMesh.Parts.ToDictionary(part => part.Guid, part => part.GetUndoInfo()); foreach (var oldMeshInfo in undoInfo) { MeshUndoInfo meshInfo; if (newMesh.TryGetValue(oldMeshInfo.Key, out meshInfo)) { smoothingInfo.Add(oldMeshInfo.Key, new KeyValuePair <MeshUndoInfo, MeshUndoInfo>(oldMeshInfo.Value, meshInfo)); } } }
protected override void OnCreate() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); rm = new RenderMesh { mesh = go.GetComponent <MeshFilter>().sharedMesh, material = go.GetComponent <MeshRenderer>().material, castShadows = UnityEngine.Rendering.ShadowCastingMode.On, receiveShadows = true }; GameObject.Destroy(go); interactionTriggerQuery = GetEntityQuery(typeof(InteractionTrigger), typeof(PlayerInput), typeof(Rotation), typeof(Translation)); }
/// <summary> /// Set the fading material's alpha to the value passed as parameter /// </summary> /// <param name="newAlpha">the new value for the fade material's alpha</param> private void SetFadingMaterialAlpha(float newAlpha) { Entities.ForEach((Entity e, ref CameraFadeParameters cameraFade) => { _renderMesh = _entityManager.GetSharedComponentData <RenderMesh>(e); RenderMesh newRend = _renderMesh; Material newMat = newRend.material; Color color = newMat.color; color.a = newAlpha; newMat.color = color; _renderMesh = newRend; _entityManager.SetSharedComponentData(e, _renderMesh); }); }
// Apply mesh void SetMeshComponent(bool redraw, Mesh mesh, Entity entity, EntityCommandBuffer eCBuffer) { if (redraw) { eCBuffer.RemoveComponent <RenderMesh>(entity); } RenderMesh renderer = new RenderMesh(); renderer.mesh = mesh; renderer.material = material; eCBuffer.AddSharedComponent(entity, renderer); }
public static RenderMesh Transform(this RenderMesh renderMesh, TransformMatrix transform, double tolerance = Tolerance.Distance) { if (!transform.IsRigidTransformation(tolerance)) { BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported."); return(null); } RenderMesh result = renderMesh.DeepClone(); result.Vertices = result.Vertices.Select(x => x.Transform(transform, tolerance)).ToList(); return(result); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //throw new System.NotImplementedException(); NativeArray <Entity> entities = eq.ToEntityArray(Allocator.TempJob); if (entities.Length == 0) { return(inputDeps); } World.Active.EntityManager.AddComponent(entities[0], typeof(completeChunk)); World.Active.EntityManager.RemoveComponent(entities[0], typeof(shouldRender)); //Mesh mesh = new Mesh(); /*SetMesh(mesh, GetBufferFromEntity<filteredVerticesArray>(false)[entities[0]].Reinterpret<Vector3>(), * GetBufferFromEntity<normalArray>(false)[entities[0]].Reinterpret<Vector3>(), * GetBufferFromEntity<indicesArray>(false)[entities[0]].Reinterpret<int>()); * * //World.Active.EntityManager.GetComponentObject<Mesh>(entities[0]) = mesh; * * * /*World.Active.EntityManager.SetSharedComponentData(entities[0], new RenderMesh { * mesh = mesh, * material = material * });*/ //Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 0); //mesh.Clear(); RenderMesh rM = new RenderMesh(); rM.mesh = new Mesh(); SetMesh(rM.mesh, GetBufferFromEntity <filteredVerticesArray>(false)[entities[0]].Reinterpret <Vector3>(), GetBufferFromEntity <normalArray>(false)[entities[0]].Reinterpret <Vector3>(), GetBufferFromEntity <indicesArray>(false)[entities[0]].Reinterpret <int>()); rM.material = material; World.Active.EntityManager.SetSharedComponentData(entities[0], rM); entities.Dispose(); return(inputDeps); }
public static void Start() { EntityManager manager = World.Active.GetOrCreateManager <EntityManager>(); GameObject player = GameObject.FindWithTag("Player"); GameObject enemy = GameObject.FindWithTag("Enemy"); GameObject camera = GameObject.FindWithTag("MainCamera"); Text enemyCount = GameObject.Find("EnemyCountText").GetComponent <Text>(); //获取Player MeshInstanceRenderer RenderMesh playerRenderer = player.GetComponent <RenderMeshProxy>().Value; Object.Destroy(player); //获取Enemy MeshInstanceRenderer RenderMesh enemyRenderer = enemy.GetComponent <RenderMeshProxy>().Value; Object.Destroy(enemy); //初始化玩家实体 Entity entity = manager.CreateEntity(); manager.AddComponentData(entity, new PlayerInput { }); manager.AddComponentData(entity, new Position { Value = new float3(0, 0.5f, 0) }); manager.AddComponentData(entity, new Velocity { Value = 7 }); manager.AddSharedComponentData(entity, playerRenderer); //初始化摄像机实体 GameObjectEntity gameObjectEntity = camera.AddComponent <GameObjectEntity>(); manager.AddComponentData(gameObjectEntity.Entity, new CameraComponent()); //初始化UI系统 UISystem uISystem = World.Active.GetOrCreateManager <UISystem>(); uISystem.Init(enemyCount); //初始化敌人生成系统 EnemySpawnSystem enemySpawnSystem = World.Active.GetOrCreateManager <EnemySpawnSystem>(); enemySpawnSystem.Init(manager, enemyRenderer); //初始化敌人碰撞系统 EnemyCollisionSystem collisionSystem = World.Active.GetOrCreateManager <EnemyCollisionSystem>(); collisionSystem.Init(playerRenderer.mesh.bounds.size.x / 2, enemyRenderer.mesh.bounds.size.x / 2); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (SearchMaterial == null) { var settings = GetSingleton <AntManagerSettings>(); var antSpawner = GetSingleton <AntSpawner>(); var searchColor = settings.SearchColor; var carryColor = settings.CarryColor; Entity antPrefab = antSpawner.AntPrefab; var antPrefabRenderMesh = EntityManager.GetSharedComponentData <RenderMesh>(antPrefab); var antPrefabMaterial = antPrefabRenderMesh.material; SearchMaterial = new Material(antPrefabMaterial); CarryMaterial = new Material(antPrefabMaterial); SearchMaterial.color = searchColor; CarryMaterial.color = carryColor; SearchRenderMesh = antPrefabRenderMesh; CarryRenderMesh = antPrefabRenderMesh; SearchRenderMesh.material = SearchMaterial; CarryRenderMesh.material = CarryMaterial; } Entities.ForEach((Entity e) => { EntityManager.SetSharedComponentData(e, CarryRenderMesh); EntityManager.RemoveComponent <TagAntHasDirtyMesh>(e); }) .WithAll <TagAntHasDirtyMesh>() .WithAll <TagAntHasFood>() .WithStructuralChanges() .Run(); Entities.ForEach((Entity e) => { EntityManager.SetSharedComponentData(e, SearchRenderMesh); EntityManager.RemoveComponent <TagAntHasDirtyMesh>(e); }) .WithAll <TagAntHasDirtyMesh>() .WithNone <TagAntHasFood>() .WithStructuralChanges() .Run(); return(inputDeps); }