コード例 #1
0
    public MapItem SpawnItem(string text)
    {
        if (GameManager.CurrentCampaign.GetPageById(MapItemDataConverter.GetId(text)) == null)
        {
            return(null);
        }

        items.Add(Instantiate(mapItemPrefab, mapItemsParent).GetComponent <MapItem>());
        int newItemId = items.Count - 1;

        items[newItemId].SetPage(GameManager.Instance.currentCampaign.GetPageById(MapItemDataConverter.GetId(text)));
        items[newItemId].onEndMove = new UnityEngine.Events.UnityEvent();
        items[newItemId].onEndMove.AddListener(delegate { TextChanged(MapItemDataConverter.GetTextFromItem(items[currentHoverItem].page.id, items[currentHoverItem].rectTransform.anchorMin), currentHoverItem + 1); });

        items[newItemId].rectTransform.anchorMin = MapItemDataConverter.GetPosition(text);
        items[newItemId].rectTransform.anchorMax = MapItemDataConverter.GetPosition(text);
        items[newItemId].rectTransform.offsetMin = Vector2.zero;
        items[newItemId].rectTransform.offsetMax = Vector2.zero;
        items[newItemId].rectTransform.sizeDelta = GetCurrentObjectSize();
        items[newItemId].rectTransform.position  = Vector3.right * items[newItemId].rectTransform.position.x + Vector3.up * items[newItemId].rectTransform.position.y + Vector3.forward * 50;

        for (int i = 0; i < items.Count - 1; i++)
        {
            if (items[newItemId].page.links.Contains(items[i].page.id))
            {
                int foundItem = i;
                linkItems.Add(Instantiate(mapLinkPrefab).GetComponent <MapItemLink>().SetTransforms(items[newItemId].gameObject.transform, items[foundItem].gameObject.transform, sizeSlider));
            }
        }

        return(items[newItemId]);
    }
コード例 #2
0
 public void RemovePage(int id)
 {
     for (int i = 1; i < GameManager.Instance.currentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).texts.Count; i++)
     {
         if (MapItemDataConverter.GetId(GameManager.Instance.currentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).texts[i]) == id)
         {
             GameManager.Instance.currentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).texts.RemoveAt(i);
             break;
         }
     }
     for (int i = 0; i < items.Count; i++)
     {
         if (items[i].page.id == id)
         {
             if (items[i].page.pageType == PageTypes.Map)
             {
                 for (int j = 1; j < items[i].page.texts.Count; j++)
                 {
                     if (MapItemDataConverter.GetId(items[i].page.texts[j]) == GameManager.Instance.mainPanel.currentPageId)
                     {
                         items[i].page.texts.RemoveAt(j);
                     }
                 }
             }
             else
             {
                 items[i].page.links.Remove(GameManager.Instance.mainPanel.currentPageId);
             }
             Destroy(items[i].gameObject);
             items.RemoveAt(i);
         }
     }
 }
コード例 #3
0
 public void CreateLinkedItems()
 {
     if (items[currentHoverItem].page.pageType == PageTypes.Map)
     {
         for (int i = 1; i < items[currentHoverItem].page.texts.Count; i++)
         {
             SpawnItem(MapItemDataConverter.GetId(items[currentHoverItem].page.texts[i]), items[currentHoverItem].rectTransform.anchorMin, (float)i / (float)items[currentHoverItem].page.texts.Count);
         }
     }
     else
     {
         for (int i = 0; i < items[currentHoverItem].page.links.Count; i++)
         {
             SpawnItem(items[currentHoverItem].page.links[i], items[currentHoverItem].rectTransform.anchorMin, (float)i / (float)items[currentHoverItem].page.links.Count);
         }
     }
 }
コード例 #4
0
 private void RemoveItem(PagePanelItem newItem)
 {
     if (newItem.page.pageType == PageTypes.Map)
     {
         for (int i = 1; i < newItem.page.texts.Count; i++)
         {
             if (MapItemDataConverter.GetId(newItem.page.texts[i]) == GameManager.Instance.mainPanel.currentPageId)
             {
                 newItem.page.texts.RemoveAt(i);
                 break;
             }
         }
     }
     else
     {
         GameManager.Instance.currentCampaign.GetPageById(newItem.page.id).links.Remove(GameManager.Instance.mainPanel.currentPageId);
     }
     GameManager.CurrentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).links.Remove(newItem.page.id);
     items.Remove(newItem);
     Destroy(newItem.gameObject);
 }
コード例 #5
0
    public MapItem SpawnItem(int id, Vector2 originPosition, float rotationalOffset)
    {
        if (GetItemById(id) != null || id == GameManager.Instance.mainPanel.currentPageId)
        {
            return(null);
        }

        MapItem newItem = SpawnItem(id);
        float   offsetX = Mathf.Sin(rotationalOffset * Mathf.PI * 2); float offsetY = Mathf.Cos(rotationalOffset * Mathf.PI * 2);

        newItem.rectTransform.anchorMin = originPosition;
        newItem.rectTransform.anchorMin = Utils.NewVector2((((newItem.rectTransform.parent as RectTransform).rect.width * newItem.rectTransform.anchorMin.x) - offsetX * 100)
                                                           / (newItem.rectTransform.parent as RectTransform).rect.width, (((newItem.rectTransform.parent as RectTransform).rect.height *
                                                                                                                           newItem.rectTransform.anchorMin.y) - offsetY * 100) / (newItem.rectTransform.parent as RectTransform).rect.height);
        newItem.rectTransform.anchorMin = Utils.NewVector2(Mathf.Max(0, Mathf.Min(1, newItem.rectTransform.anchorMin.x)), Mathf.Max(0, Mathf.Min(1, newItem.rectTransform.anchorMin.y)));
        newItem.rectTransform.anchorMax = newItem.rectTransform.anchorMin;

        newItem.rectTransform.offsetMax = Vector2.zero;
        newItem.rectTransform.offsetMin = Vector2.zero;

        //newItem.rectTransform.offsetMax = new Vector3(offsetX * 100, offsetY * 100, newItem.rectTransform.localPosition.z);
        //newItem.rectTransform.offsetMin = new Vector3(offsetX * 100, offsetY * 100, newItem.rectTransform.localPosition.z);
        newItem.rectTransform.sizeDelta = Vector2.one * (10 + 150 * sizeSlider.value);
        //newItem.transform.position = Utils.NewVector3(originPosition.x + Mathf.Sin(rotationalOffset * Mathf.PI * 2), originPosition.y + Mathf.Cos(rotationalOffset * Mathf.PI * 2),
        //    originPosition.z);
        //UpdateAnchorsFromLocalposition(items.IndexOf(newItem));

        GameManager.Instance.currentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).texts
        [GameManager.Instance.currentCampaign.GetPageById(GameManager.Instance.mainPanel.currentPageId).texts.Count - 1] = (MapItemDataConverter.GetTextFromItem(id, newItem.rectTransform.anchorMin));

        return(newItem);
    }