Пример #1
0
        public void RenderPaths(beMobileMaze maze, Vector3 drawingOffset)
        {
            var pathController = maze.GetComponent <PathController>();

            if (pathController == null)
            {
                return;
            }

            foreach (var path in pathController.Paths)
            {
                float localDrawingOffset = path.ID * 0.1f;

                if (localDrawingOffset > 1)
                {
                    localDrawingOffset = 1 - localDrawingOffset;
                }

                Color drawingColor;

                if (path.ID % 2 == 0)
                {
                    drawingColor = new Color(localDrawingOffset, (localDrawingOffset * 0.5f) + 0.5f, 1 - localDrawingOffset);
                }
                else
                {
                    drawingColor = new Color(localDrawingOffset, 1 - localDrawingOffset, (localDrawingOffset * 0.5f) + 0.5f);
                }

                var offset = drawingOffset + new Vector3(localDrawingOffset, 0, localDrawingOffset);

                PathEditorUtils.RenderPathElements(maze, path, offset, drawingColor);
            }
        }
Пример #2
0
        /// <summary>
        /// Export as a textfield which could be read as a matlab expression and evals to an matrix containing zeros and ones on unit positions
        /// </summary>
        /// <param name="maze"></param>
        /// <param name="targetFile"></param>
        public void Export(beMobileMaze maze, FileInfo targetFile)
        {
            using (var fs = new FileStream(targetFile.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                var builders = new List <StringBuilder>();

                if (maze.Rows == 0 || maze.Columns == 0)
                {
                    OnUnexpectedValuesFound("Maze has no Grid to use during Export process");

                    if (abortExport)
                    {
                        return;
                    }
                }


                builders.Add(AppendMazeMatrix(maze));

                var pathController = maze.GetComponent <PathController>();

                if (pathController.Paths.Count == 0)
                {
                    OnUnexpectedValuesFound("No Paths found during Export process");

                    if (abortExport)
                    {
                        return;
                    }
                }

                foreach (var path in pathController.Paths)
                {
                    builders.Add(AppendPathWithMatrix(maze, path));
                }

                StringBuilder finalBuilder  = new StringBuilder();
                int           appedingIndex = 0;

                do
                {
                    finalBuilder.Append(builders[appedingIndex]).AppendLine();
                    appedingIndex++;
                } while (appedingIndex < builders.Count);

                byte[] info = new UTF8Encoding(true).GetBytes(finalBuilder.ToString());
                fs.Write(info, 0, info.Length);
            }
        }
Пример #3
0
        public static bool DoesNotContainPaths(this beMobileMaze maze)
        {
            var controller = maze.GetComponent <PathController>();

            if (controller == null)
            {
                return(false);
            }

            if (!controller.Paths.Any() || controller.Paths.Any((p) => p == null))
            {
                controller.ForcePathLookup();
            }

            var hasPaths = controller.Paths.Any(p => p.PathAsLinkedList.Any());

            return(!hasPaths);
        }
Пример #4
0
        public beMobileMaze Bake(beMobileMaze originalMaze)
        {
            beMobileMaze mazeToUse = null;

            if (!replaceOriginalMaze)
            {
                mazeToUse = GameObject.Instantiate(originalMaze);
                originalMaze.gameObject.SetActive(false);
            }

            Debug.Assert(mazeToUse.GetComponent <MeshFilter>() == null, "Component has already a MeshFilter");

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

            Debug.Assert(mazeToUse.GetComponent <MeshRenderer>() == null, "Component has already a MeshRenderer");

            meshFilter.mesh            = new Mesh();
            meshFilter.sharedMesh.name = mazeToUse.name;

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

            var plane = GameObject.CreatePrimitive(PrimitiveType.Plane);

            meshRenderer.material = plane.GetComponent <MeshRenderer>().sharedMaterial;

            GameObject.DestroyImmediate(plane);

            var combineInstances = new List <CombineInstance>();

            var allMeshFilter = new List <MeshFilter>();
            var allRenderer   = new List <MeshRenderer>();

            traverseAndCollectAll(new Stack <MazeUnit>(mazeToUse.Units), allMeshFilter, allRenderer);

            List <MeshFilter> selectedMeshFilter = allMeshFilter;

            selectedMeshFilter.RemoveAll(filter => !filter.gameObject.activeInHierarchy);

            if (ignoreFloor)
            {
                selectedMeshFilter.RemoveAll(filter => filter.name.Equals("Floor") || filter.transform.parent.name.Equals("Floor"));
            }

            foreach (var filter in selectedMeshFilter)
            {
                var combined = new CombineInstance();
                combined.mesh      = filter.sharedMesh;
                combined.transform = filter.transform.localToWorldMatrix;
                combineInstances.Add(combined);

                Component.DestroyImmediate(filter);
            }

            foreach (var renderer in allRenderer)
            {
                Component.DestroyImmediate(renderer);
            }


            meshFilter.sharedMesh.CombineMeshes(combineInstances.ToArray(), MERGE_SUBMESHES, USE_MATRICES);

            ;

            meshFilter.sharedMesh.RecalculateNormals();

            AssetDatabase.CreateAsset(meshFilter.sharedMesh, EditorEnvironmentConstants.Get_PACKAGE_MODEL_SUBFOLDER() + "/" + mazeToUse.name + "_combinedMesh.asset");

            return(mazeToUse);
        }