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);
            }
        }
    }
    public SerialiableNavMesh AsSerialiableNavMesh()
    {
        SerialiableNavMesh ret = new SerialiableNavMesh();

        if (connections != null)
        {
            ret.connections = FUtils.FlatMap(connections.Keys, from =>
                                             FUtils.Map(connections[from], to => new CellConnection(from, to)));
        }
        else
        {
            ret.connections = new List <CellConnection>();
        }

        if (positions != null)
        {
            ret.positions = FUtils.Map(positions.Keys, from =>
                                       new CellPosition(from, positions[from]));
        }
        else
        {
            ret.positions = new List <CellPosition>();
        }

        return(ret);
    }
Beispiel #3
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     FUtils.InvokeOnMainThread(200, () =>
     {
         DisplayAlert("Pepe", "Pepep", "Cancelar");
     });
 }
Beispiel #4
0
 protected override void OnParentSet()
 {
     base.OnParentSet();
     if (Parent != null)
     {
         FUtils.InvokeOnMainThread(100, () => OnAppearing());
     }
     else
     {
         OnDisappearing();
     }
 }
Beispiel #5
0
        void TxtField_Unfocused(object sender, FocusEventArgs e)
        {
            FUtils.InvokeOnMainThread(TimeSpan.FromMilliseconds(100), () =>
            {
                if (Entry.IsFocused)
                {
                    return;
                }

                var result = Field.Validate();
                ShowError(result);
            });
        }
Beispiel #6
0
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();
            if (ViewModel != null)
            {
                ViewModel.NavigateToDelegate      = NavigateTo;
                ViewModel.NavigateModalToDelegate = NavigateModalTo;
                ViewModel.NavigateCloseDelegate   = NavigateClose;
                ViewModel.NavigateBackDelegate    = NavigateBack;
                ViewModel.AskAsyncDelegate        = AskAsync;

                FUtils.InvokeOnMainThread(100, () =>
                {
                    ViewModel.InvokeLoaded();
                });
            }
        }
 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);
                    }
                }
            }
        });
    }
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var text       = File.ReadAllText(ctx.assetPath);
        var rjObj      = JsonUtility.FromJson <RJObj>(text);
        var rjMesh     = rjObj.mesh;
        var rjVertices = rjMesh.vertices;

        List <Material> materialList = new List <Material>();
        var             mesh         = new Mesh();

        mesh.name         = rjObj.name + "Mesh";
        mesh.subMeshCount = rjMesh.materials.Count;

        int rootIndex        = getGroupIndex(rjObj.groups, "Root");
        int attachPointIndex = getGroupIndex(rjObj.groups, "AttachPoint");

        var mV   = new List <Vector3>();
        var mN   = new List <Vector3>();
        var mUVA = new List <List <Vector2> >();
        var mEA  = new List <List <int> >();

        for (int layerIndex = 0; layerIndex < rjMesh.uvLayers.Count; ++layerIndex)
        {
            mUVA.Add(new List <Vector2>());
        }

        Vector3 rootVector        = Vector3.zero;
        Vector3 attachPointVector = Vector3.zero;

        foreach (RJVector vector in rjMesh.vertices)
        {
            if (vector.groups.Contains(rootIndex))
            {
                rootVector = toVector3(vector.p);
                Debug.Log("Root Vector: " + rootVector);
            }
            if (vector.groups.Contains(attachPointIndex))
            {
                attachPointVector = toVector3(vector.p);
                Debug.Log("Attach Point: " + attachPointVector);
            }
        }

        for (int materialIndex = 0; materialIndex < rjMesh.materials.Count; ++materialIndex)
        {
            RJMaterial rjMaterial   = rjMesh.materials[materialIndex];
            string     materialPath = "Assets/" + rjMaterial.name + ".mat";
            Material   material     = AssetDatabase.LoadAssetAtPath("Assets/Space/Materials/" + rjMaterial.name + ".mat", typeof(Material)) as Material;
            if (material == null)
            {
                throw new Exception("Cannot load material " + materialPath);
            }
            materialList.Add(material);

            var mE = new List <int>();

            foreach (int faceIndex in Enumerable.Range(0, rjMesh.faces.Count))
            {
                RJFace face = rjMesh.faces[faceIndex];

                if (face.materialIndex != materialIndex)
                {
                    continue;
                }

                List <int> vs        = face.vertexIndexes;
                int        baseIndex = mV.Count;
                foreach (int vIndex in face.vertexIndexes)
                {
                    mV.Add(toVector3(rjVertices[vIndex]));
                    mN.Add(toVector3(face.normal));
                }

                if (vs.Count == 3)
                {
                    mE.Add(baseIndex + 0);
                    mE.Add(baseIndex + 1);
                    mE.Add(baseIndex + 2);
                }
                else if (vs.Count == 4)
                {
                    mE.Add(baseIndex + 0);
                    mE.Add(baseIndex + 1);
                    mE.Add(baseIndex + 2);

                    mE.Add(baseIndex + 0);
                    mE.Add(baseIndex + 2);
                    mE.Add(baseIndex + 3);
                }
                else
                {
                    throw new Exception("Unexpected number of verticies in face count=" + vs.Count);
                }

                for (int layerIndex = 0; layerIndex < rjMesh.uvLayers.Count; ++layerIndex)
                {
                    RJUVLayer uvLayer = rjMesh.uvLayers[layerIndex];
                    var       uvList  = uvLayer.faces[faceIndex].uvList;

                    if (uvList.Count != vs.Count)
                    {
                        throw new Exception("Diffing verticies and uvLists vCount=" + vs.Count + " uvList.Count=" + uvList.Count);
                    }
                    foreach (RJVector rjVector in uvList)
                    {
                        mUVA[layerIndex].Add(toVector2(rjVector));
                    }
                }
            }
            mEA.Add(mE);
        }

        mV = FUtils.Map(mV, v => v - rootVector);
        mesh.SetVertices(mV);
        mesh.SetNormals(mN);

        for (int layerIndex = 0; layerIndex < rjMesh.uvLayers.Count; ++layerIndex)
        {
            mesh.SetUVs(layerIndex, mUVA[layerIndex]);
        }

        for (int materialIndex = 0; materialIndex < rjMesh.materials.Count; ++materialIndex)
        {
            mesh.SetTriangles(mEA[materialIndex], materialIndex);
        }

        GameObject gameObject = new GameObject(rjObj.name);

        GameObject attachPoint = new GameObject("AttachPoint");

        attachPoint.transform.parent        = gameObject.transform;
        attachPoint.transform.localPosition = attachPointVector;

        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = mesh;

        var meshRenderer = gameObject.AddComponent <MeshRenderer>();

        meshRenderer.materials = materialList.ToArray();

        ctx.AddObjectToAsset("mesh", mesh);
        ctx.AddObjectToAsset("main", gameObject);

        ctx.SetMainObject(gameObject);
    }
Beispiel #10
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            foreach (var key in Fields.Keys)
            {
                var field   = Fields[key].Field;
                var control = Fields[key].Control;

                field.ValueChanged += Field_ValueChanged;
                field.Validated    += Field_Validated;

                if (control is WEntry)
                {
                    var entry = control as WEntry;
                    entry.TextChanged += Entry_TextChanged;
                    entry.Text         = (string)field.Value;
                    entry.Placeholder  = field.Placeholder;
                    entry.IsEnabled    = field.IsEnabled;

                    if (field.Rules != null)
                    {
                        if (field.Rules != null)
                        {
                            var rule = field.Rules.FindRule <LengthRule>();
                            if (rule != null)
                            {
                                entry.MaxLength = rule.Max;
                            }
                        }
                    }

                    Entry_TextChanged(entry, null);
                }

                else if (control is Picker)
                {
                    var picker = control as WPicker;
                    picker.ItemsSource = field.Options.Select(p => p.Text).ToList();

                    if (field.Value == null)
                    {
                        picker.SelectedIndex = -1;
                    }
                    else
                    {
                        if (field.Value is string)
                        {
                            if (picker.SelectedItem != field.Value)
                            {
                                picker.SelectedItem = field.Value;
                            }
                        }
                        else
                        {
                            var option = field.Options.Where(p => p.Source == field.Value).FirstOrDefault();
                            if ((string)picker.SelectedItem != option.Text)
                            {
                                picker.SelectedItem = option.Text;
                            }
                        }
                    }

                    picker.IsEnabled   = field.IsEnabled;
                    picker.Placeholder = "picker";
                    FUtils.InvokeOnMainThread(TimeSpan.FromMilliseconds(100), () =>
                    {
                        picker.Placeholder = field.Placeholder;
                    });
                    picker.SelectedIndexChanged += Picker_SelectedIndexChanged;
                    Picker_SelectedIndexChanged(picker, null);
                }

                if (Fields[key].LblTitle != null)
                {
                    Fields[key].LblTitle.Text = field.Title;
                }
            }
        }
 public CellIndex ClosestBoundaryCell(IEnumerable <CellIndex> lst, Vector3 p, Dictionary <CellIndex, float> distanceFromStart)
 {
     return(FUtils.ArgMinStruct(lst, cellIndex => TotalDistance(cellIndex, p, distanceFromStart)).Value);
 }
 public CellIndex ClosestCell(IEnumerable <CellIndex> lst, Vector3 p)
 {
     return(FUtils.ArgMinStruct(lst, cellIndex => (p - positions[cellIndex]).magnitude).Value);
 }