Ejemplo n.º 1
0
    public void UpdateMesh()
    {
        if (tasks == null)
        {
            tasks = new HashSet <Task>();
        }

        if (tasks.Count > 0 && FUtils.All(tasks, task => task == null || task.IsCompleted || task.IsFaulted || task.IsCanceled))
        {
            tasks.Clear();
            FUtils.Elvis(eventManager, eventManager =>
                         eventManager.DiggingChanged(DiggingMode.NotDigging));

            navMesh = new NavMesh();
            foreach (VoxelSurface surface in GetComponentsInChildren <VoxelSurface>())
            {
                surface.UpdateMesh();
                navMesh.Merge(surface.navMesh, surface.meshCoords, pointDensity, surface.transform);
            }

            Debug.Log("Finished generating mesh positions count=" + navMesh.positions.Count);
            if (navMesh.positions.Count > 0)
            {
                player                = FindObjectOfType <SimpleController>();
                monster               = FindObjectOfType <MonsterController>();
                localPlayerPosition   = transform.InverseTransformPoint(player.transform.position);
                localCreaturePosition = transform.InverseTransformPoint(monster.transform.position);
                playerCell            = navMesh.ClosestCell(localPlayerPosition);
                monsterCell           = navMesh.ClosestCell(localCreaturePosition);
                path = navMesh.FindPath(localPlayerPosition, localCreaturePosition);
            }
        }
    }
Ejemplo n.º 2
0
 public void Build(Vector3 position, float blastRadius)
 {
     if (tasks.Count == 0)
     {
         foreach (VoxelSurface surface in GetComponentsInChildren <VoxelSurface>())
         {
             if (surface.OverlapsSphere(position, buildRadius))
             {
                 tasks.Add(surface.Build(position, buildRadius));
             }
         }
         if (tasks.Count > 0)
         {
             FUtils.Elvis(eventManager, eventManager => eventManager.DiggingChanged(DiggingMode.Digging));
         }
     }
 }
    void OnSceneGUI()
    {
        VoxelSurface voxelSurface = target as VoxelSurface;

        FUtils.Elvis(voxelSurface.GetComponentInParent <GridArray>(), gridArray =>
        {
            gridArray.Update();
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    if (gridArray != null)
                    {
                        gridArray.Hit(hit.point);
                    }
                }
            }
        });
    }