예제 #1
0
        public static void CreateLocationLabel(GUI.GUIMapTile mapTile, WorldMapLocation wml)
        {
            //Debug.Log ("Creating location label for " + wml.Name);

            bool createIcon  = true;
            bool createLabel = true;

            switch (wml.LabelStyle)
            {
            case MapLabelStyle.AlwaysVisible:
            default:
                createLabel = true;
                break;

            case MapLabelStyle.None:
                createLabel = false;
                break;

            case MapLabelStyle.Descriptive:
                createIcon  = false;
                createLabel = true;
                break;
            }

            if (createIcon)
            {
                //sort it into the right list based on icon
                switch (wml.IconStyle)
                {
                case MapIconStyle.Small:
                    mapTile.SmallLocations.Add(wml);
                    break;

                case MapIconStyle.Medium:
                    mapTile.MediumLocations.Add(wml);
                    break;

                case MapIconStyle.Large:
                    mapTile.LargeLocations.Add(wml);
                    break;

                case MapIconStyle.AlwaysVisible:
                    mapTile.ConstantLocations.Add(wml);
                    break;

                case MapIconStyle.None:
                default:
                    //Debug.Log("Icon style was none in " + wml.IconName);
                    //NONE
                    createIcon = false;
                    //does it have a label?
                    if (createLabel)
                    {
                        //if so, keep it in the constant list
                        mapTile.ConstantLocations.Add(wml);
                    }
                    else
                    {
                        //otherwise, just ignore it
                        //dont bother to create labels
                        //return;
                    }
                    break;
                }
            }
            else
            {
                mapTile.ConstantLocations.Add(wml);
            }

            Vector3 mapTilePosition = new Vector3(wml.ChunkPosition.x, wml.ChunkPosition.z, 0f);             //-(wml.ChunkPosition.y));

            wml.LocationTransform = mapTile.TileBackground.gameObject.CreateChild(wml.Name).transform;
            mapTilePosition.z     = NGUIWorldMap.GetWorldMapAtChunkPosition(mapTilePosition, mapTile.ChunkToDisplay.MiniHeightmap, 0f);
            wml.LocationTransform.localPosition = mapTilePosition;

            if (createLabel)
            {
                float      mapTileScale = 1f;           //Mathf.Clamp (location.Radius * gLocationRadiusMult, 1f, 5f);
                GameObject newWMLabelGo = NGUITools.AddChild(NGUIWorldMap.Get.LabelsPanel.gameObject, mapTile.WMLabelPrefab);
                UILabel    label        = newWMLabelGo.GetComponent <UILabel> ();
                label.name = wml.Name;
                label.text = wml.Name;
                if (wml.LabelStyle == MapLabelStyle.Descriptive)
                {
                    label.font = Mats.Get.CleanHandwriting42Font;
                }
                else
                {
                    label.font = Mats.Get.CleanHandwriting42Font;                    //PrintingPress40Font;
                }
                wml.Label = label;
                if (!createIcon)
                {
                    wml.LabelPosition = Vector3.zero;
                }
                wml.LabelTransform = label.cachedTransform;
                wml.LabelTransform.localPosition = mapTilePosition + wml.LabelPosition + wml.IconOffset;
                wml.LabelTransform.localScale    = Vector3.one;
                label.alpha   = 0f;
                label.enabled = true;
            }

            if (createIcon)
            {
                GameObject newWMIconGo = NGUITools.AddChild(NGUIWorldMap.Get.IconsPanel.gameObject, mapTile.WMIconPrefab);
                UISprite   icon        = newWMIconGo.GetComponent <UISprite> ();
                WMIcon     wmIcon      = newWMIconGo.GetComponent <WMIcon> ();
                wmIcon.OnClick   += wml.OnClick;
                wmIcon.Reference  = wml.Reference;
                icon.name         = wml.Name;
                icon.spriteName   = wml.IconName;
                wml.Icon          = icon;
                wml.IconTransform = wml.Icon.cachedTransform;
                wml.IconTransform.localPosition = mapTilePosition + wml.IconOffset;
                wml.IconTransform.localScale    = Vector3.one * wml.IconScale;
                icon.alpha   = 0f;
                icon.enabled = true;
                wml.Collider = newWMIconGo.AddComponent <SphereCollider> ();                //for mouseovers

                if (wml.IsMarked || wml.IsNew)
                {
                    NGUIWorldMap.Get.CreateMarkedLocationSprite(wml);
                }
            }
            else
            {
                //Debug.Log ("No create icon with icon name " + wml.IconName + " and icon style " + wml.IconStyle.ToString ());
            }
        }
예제 #2
0
        public void BlendEdges(List <GUIMapTile> chunksDisplayed)
        {
            if (ChunkToDisplay.IsEmpty)
            {
                //Debug.Log("We're empty");
                return;
            }

            //Debug.Log("Blending " + ChunkToDisplay.ChunkID.ToString () + " with " + ChunkToDisplay.BlendIDTop.ToString() + ", " + ChunkToDisplay.BlendIDBottom.ToString() + ", " + ChunkToDisplay.BlendIDLeft.ToString() + ", " + ChunkToDisplay.BlendIDRight.ToString());
            for (int i = 0; i < chunksDisplayed.Count; i++)
            {
                GUIMapTile chunkDisplayed = chunksDisplayed[i];

                if (chunkDisplayed == this)
                {
                    //Debug.Log("Whoops, not blending with this");
                    continue;
                }

                if (BlendedWith.Contains(chunkDisplayed.ChunkToDisplay.ChunkID))
                {
                    //Debug.Log("Already blended " + ChunkToDisplay.ChunkID.ToString() + " with " + chunkDisplayed.ChunkToDisplay.ChunkID.ToString());
                    continue;
                }

                if ((ChunkToDisplay.BlendIDTop > 0 && chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDTop) ||
                    (ChunkToDisplay.BlendIDBottom > 0 && chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDBottom) ||
                    (ChunkToDisplay.BlendIDLeft > 0 && chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDLeft) ||
                    (ChunkToDisplay.BlendIDRight > 0 && chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDRight))
                {
                    //Debug.Log("Blending " + chunkDisplayed.ChunkToDisplay.ChunkID.ToString() + " with " + ChunkToDisplay.ChunkID.ToString());
                    chunkDisplayed.BlendedWith.Add(ChunkToDisplay.ChunkID);

                    Mesh mesh1 = HeightMeshFilter.sharedMesh;
                    Mesh mesh2 = chunkDisplayed.HeightMeshFilter.sharedMesh;

                    Vector3[]  verts1 = mesh1.vertices;
                    Vector3[]  verts2 = mesh2.vertices;
                    Vector3    vert1;
                    Vector3    vert2;
                    float      blendedHeight;
                    List <int> indices1 = null;
                    List <int> indices2 = null;
                    int        index1   = 0;
                    int        index2   = 0;

                    if (chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDTop)
                    {
                        indices1 = TopVertices;
                        indices2 = BotVertices;
                    }
                    else if (chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDBottom)
                    {
                        indices1 = BotVertices;
                        indices2 = TopVertices;
                    }
                    else if (chunkDisplayed.ChunkToDisplay.ChunkID == ChunkToDisplay.BlendIDLeft)
                    {
                        indices1 = LeftVertices;
                        indices2 = RightVertices;
                    }
                    else
                    {
                        indices1 = RightVertices;
                        indices2 = LeftVertices;
                    }

                    for (int v = 0; v < indices1.Count; v++)
                    {
                        index1         = indices1[v];
                        index2         = indices2[v];
                        vert1          = verts1[index1];
                        vert2          = verts2[index2];
                        blendedHeight  = (vert1.y + vert2.y) / 2;
                        vert1.y        = blendedHeight;
                        vert2.y        = blendedHeight;
                        verts1[index1] = vert1;
                        verts2[index2] = vert2;
                    }

                    mesh1.vertices = verts1;
                    mesh2.vertices = verts2;

                    mesh1.RecalculateBounds();
                    mesh2.RecalculateBounds();

                    System.Array.Clear(verts1, 0, verts1.Length);
                    System.Array.Clear(verts2, 0, verts2.Length);

                    verts1 = null;
                    verts2 = null;
                }
            }
        }