Esempio n. 1
0
        public virtual void setUnityAPI(MeshStructure meshStructure, Dictionary <AbstractProvince, MeshStructure> neighborBorders)
        {
            //this.meshStructure = meshStructure;

            //spawn object
            GameObject = new GameObject(string.Format("{0}", ID));

            //Add Components
            MeshFilter   = GameObject.AddComponent <MeshFilter>();
            meshRenderer = GameObject.AddComponent <MeshRenderer>();

            // in case you want the new gameobject to be a child
            // of the gameobject that your script is attached to
            GameObject.transform.parent = World.Get.transform;

            var landMesh = MeshFilter.mesh;

            landMesh.Clear();

            landMesh.vertices  = meshStructure.getVertices().ToArray();
            landMesh.triangles = meshStructure.getTriangles().ToArray();
            landMesh.RecalculateNormals();
            landMesh.RecalculateBounds();
            landMesh.name = ID.ToString();

            Position = setProvinceCenter(meshStructure);
            setLabel();
        }
Esempio n. 2
0
        public override void setUnityAPI(MeshStructure meshStructure, Dictionary <AbstractProvince, MeshStructure> neighborBorders)
        {
            base.setUnityAPI(meshStructure, neighborBorders);
            MeshCollider groundMeshCollider = GameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;

            groundMeshCollider.sharedMesh = MeshFilter.mesh;



            meshRenderer.material.shader = Shader.Find("Standard");// Province");

            meshRenderer.material.color = ProvinceColor;

            //var graph = World.Get.GetComponent<AstarPath>();


            // setting neighbors
            //making meshes for border
            foreach (var border in neighborBorders)
            {
                //each color is one neighbor (non repeating)
                var neighbor = border.Key as Province;
                if (neighbor != null)
                {
                    if (!(Terrain == TerrainTypes.Mountains && neighbor.Terrain == TerrainTypes.Mountains))
                    //this.getTerrain() == TerrainTypes.Plains || neighbor.terrain == TerrainTypes.Plains)
                    {
                        neighbors.Add(neighbor);
                        //var newNode = new Pathfinding.PointNode(AstarPath.active);
                        //newNode.gameObject = txtMeshGl;
                        //graph.data.pointGraph.AddNode(newNode, (Pathfinding.Int3)neighbor.getPosition());
                    }

                    GameObject borderObject = new GameObject("Border with " + neighbor);

                    //Add Components
                    MeshFilter = borderObject.AddComponent <MeshFilter>();
                    MeshRenderer meshRenderer = borderObject.AddComponent <MeshRenderer>();

                    borderObject.transform.parent = GameObject.transform;

                    Mesh borderMesh = MeshFilter.mesh;
                    borderMesh.Clear();

                    borderMesh.vertices  = border.Value.getVertices().ToArray();
                    borderMesh.triangles = border.Value.getTriangles().ToArray();
                    borderMesh.uv        = border.Value.getUVmap().ToArray();
                    borderMesh.RecalculateNormals();
                    borderMesh.RecalculateBounds();
                    meshRenderer.material = LinksManager.Get.defaultProvinceBorderMaterial;
                    borderMesh.name       = "Border with " + neighbor;

                    bordersMeshes.Add(neighbor, meshRenderer);
                }
            }
            var node = GameObject.AddComponent <Node>();
        }
Esempio n. 3
0
        public static Vector3 setProvinceCenter(MeshStructure meshStructure)
        {
            Vector3 accu = new Vector3(0, 0, 0);

            foreach (var c in meshStructure.getVertices())
            {
                accu += c;
            }
            accu = accu / meshStructure.verticesCount;
            return(accu);
        }
Esempio n. 4
0
        void setUnityAPI(MeshStructure meshStructure, Dictionary <Province, MeshStructure> neighborBorders)
        {
            //this.meshStructure = meshStructure;

            //spawn object
            rootGameObject = new GameObject(string.Format("{0}", getID()));

            //Add Components
            var meshFilter = rootGameObject.AddComponent <MeshFilter>();

            meshRenderer = rootGameObject.AddComponent <MeshRenderer>();

            // in case you want the new gameobject to be a child
            // of the gameobject that your script is attached to
            rootGameObject.transform.parent = Game.mapObject.transform;

            var landMesh = meshFilter.mesh;

            landMesh.Clear();

            landMesh.vertices  = meshStructure.getVertices().ToArray();
            landMesh.triangles = meshStructure.getTriangles().ToArray();
            landMesh.RecalculateNormals();
            landMesh.RecalculateBounds();
            landMesh.name = getID().ToString();

            meshRenderer.material.shader = Shader.Find("Standard");

            meshRenderer.material.color = color;

            MeshCollider groundMeshCollider = rootGameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;

            groundMeshCollider.sharedMesh = landMesh;

            position = setProvinceCenter(meshStructure);
            setLabel();

            // setting neighbors
            //making meshes for border
            foreach (var border in neighborBorders)
            {
                //each color is one neighbor (non repeating)
                var neighbor = border.Key;
                if (this.getTerrain() == TerrainTypes.Plains || neighbor.terrain == TerrainTypes.Plains)
                {
                    neighbors.Add(neighbor);
                }

                GameObject borderObject = new GameObject("Border with " + neighbor.ToString());

                //Add Components
                meshFilter = borderObject.AddComponent <MeshFilter>();
                MeshRenderer meshRenderer = borderObject.AddComponent <MeshRenderer>();

                borderObject.transform.parent = rootGameObject.transform;

                Mesh borderMesh = meshFilter.mesh;
                borderMesh.Clear();

                borderMesh.vertices  = border.Value.getVertices().ToArray();
                borderMesh.triangles = border.Value.getTriangles().ToArray();
                borderMesh.uv        = border.Value.getUVmap().ToArray();
                borderMesh.RecalculateNormals();
                borderMesh.RecalculateBounds();
                meshRenderer.material = Game.defaultProvinceBorderMaterial;
                borderMesh.name       = "Border with " + neighbor.ToString();

                bordersMeshes.Add(neighbor, meshRenderer);
            }
        }
Esempio n. 5
0
 public override void setUnityAPI(MeshStructure meshStructure, Dictionary <AbstractProvince, MeshStructure> neighborBorders)
 {
     base.setUnityAPI(meshStructure, neighborBorders);
     meshRenderer.material = LinksManager.Get.waterMaterial;
     GameObject.AddComponent <UnityStandardAssets.Water.WaterBasic>();
 }