Ejemplo n.º 1
0
 protected override void OnUpdate()
 {
     Entities.WithAll <SpawnMapCommand>().ForEach((Entity e, ref SpawnMapCommand command) =>
     {
         SpawnWorld(command.spawnID, command.spawnPosition, mapsMeta[command.mapID], command.game);
         World.EntityManager.DestroyEntity(e);
     });
     Entities.WithAll <RemoveMap>().ForEach((Entity e, ref RemoveMap command) =>
     {
         DestroyWorld(command.map);
         World.EntityManager.DestroyEntity(e);
     });
     Entities.WithAll <UpdateModelCommand>().ForEach((Entity e, ref UpdateModelCommand command) =>
     {
         SkeletonDatam skeletonDatam = null;
         if (skeletonsMeta.ContainsKey(command.skeletonID))
         {
             skeletonDatam = skeletonsMeta[command.skeletonID];
         }
         UpdateModel(command.entity, command.model, skeletonDatam, command.spawnID);
         World.EntityManager.DestroyEntity(e);
     });
 }
Ejemplo n.º 2
0
        private void NewWay()
        {
            GUILayout.Space(15);
            GUILayout.Label("Chose a Monster:");
            VoxDatam newMonster = EditorGUILayout.ObjectField(monster, typeof(VoxDatam), false) as VoxDatam;

            if (newMonster != monster)
            {
                monster    = newMonster;
                vox        = monster;
                outputPath = Path.GetDirectoryName(Path.GetFullPath(AssetDatabase.GetAssetPath(vox))) + "\\";
            }
            GUILayout.Label("Chose a Skeleton:");
            SkeletonDatam newSkeleton = EditorGUILayout.ObjectField(skeleton, typeof(SkeletonDatam), false) as SkeletonDatam;

            if (newSkeleton != skeleton)
            {
                skeleton = newSkeleton;
            }
            if (vox == null)
            {
                return;
            }
            //GUILayout.Space(10);
            //GUILayout.Label("   Located at: " + outputPath);
            // chose a vox

            /*GUILayout.Space(15);
             * GUILayout.Label("Chose a Vox Model:");
             * VoxDatam newVox = EditorGUILayout.ObjectField(vox, typeof(VoxDatam)) as VoxDatam;
             * if (newVox != vox)
             * {
             *  vox = newVox;
             *  outputPath = Path.GetDirectoryName(Path.GetFullPath(AssetDatabase.GetAssetPath(vox))) + "\\";
             * }*/
            // Grab is mesh!
            //GUILayout.Space(15);
            //GUILayout.Label("Chose a Skeleton:");
            //skeleton = EditorGUILayout.ObjectField(skeleton, typeof(SkeletonDatam)) as SkeletonDatam;
            // chose animations
            if (animations.Count > 0)
            {
                if (GUILayout.Button("Bake Animator"))
                {
                    BakeVox();
                }
            }
            GUILayout.Label("Add Animation:");
            newAnim = EditorGUILayout.ObjectField(newAnim, typeof(AnimationClip), true) as AnimationClip;
            // if (GUILayout.Button("Clear Animations"))
            {
                //    animations.Clear();
            }
            for (int i = 0; i < animations.Count; i++)
            {
                if (GUILayout.Button(animations[i].name + " [-]"))
                {
                    animations.RemoveAt(i);
                    break;
                }
            }
            if (newAnim != null)
            {
                animations.Add(newAnim);
                newAnim = null;
            }
            //isPlaceUpwards = GUILayout.Toggle(isPlaceUpwards, "Place Half Height Upwards?");

            /* if (GUILayout.Button("Create Instance"))
             * {
             *   CreateSkinny();
             * }
             * GUILayout.Space(5);
             * if (GUILayout.Button("Bake Weighted Mesh"))
             * {
             *   BakeWeightedMesh();
             * }*/
            GUILayout.Space(5);

            if (newSkinny)
            {
                GUILayout.Space(5);
                if (GUILayout.Button("Kill Dude Instance"))
                {
                    DestroyImmediate(newSkinny);
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateModel(Entity world, VoxData model, SkeletonDatam skeleton, int id)
        {
            if (worlds.ContainsKey(id) == false)
            {
                //Debug.LogError("Updating Model: " + id);
                worlds.Add(id, world);
                worldLookups.Add(id, new WorldChunkMap {
                    chunks = new Dictionary <int3, Entity>()
                });
            }
            else
            {
                //Debug.LogError("Removing previous world: " + id);
                DestroyWorldWeakly(id);
                worlds.Add(id, world);
                worldLookups.Add(id, new WorldChunkMap {
                    chunks = new Dictionary <int3, Entity>()
                });
            }
            if (models.ContainsKey(id))
            {
                models[id] = model;
            }
            else
            {
                models.Add(id, model);
            }
            float3 scale = new float3(model.scale.x / 16f, model.scale.y / 16f, model.scale.z / 16f);

            World.EntityManager.SetComponentData(world, new ZoxID {
                id = id
            });
            World worldComponent = new World
            {
                //chunkIDs = new BlitableArray<int>(0, Unity.Collections.Allocator.Persistent),
                //chunkPositions = new BlitableArray<int3>(0, Unity.Collections.Allocator.Persistent),
                scale           = scale,
                voxelDimensions = model.size,
                modelID         = model.id
            };

            if (skeleton != null)
            {
                //worldComponent.skeletonID = skeleton.data.id;
            }
            float renderDistance = 0;

            if (World.EntityManager.HasComponent <World>(world) == false)
            {
                World.EntityManager.AddComponentData(world, worldComponent);
            }
            else
            {
                World.EntityManager.SetComponentData(world, worldComponent);
            }
            WorldStreamSystem.StreamChunksIn(
                World.EntityManager,
                chunkSpawnSystem,
                true,
                world,
                ref worldComponent,
                int3.Zero(),
                renderDistance,
                renderDistance,
                false);
            World.EntityManager.SetComponentData(world, worldComponent);
        }