Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class QuestsManager1 : MonoBehaviour
- {
- public Font font;
- public Color fontColor;
- public List<Text> questText;
- public Canvas c;
- public int numberOfQuests;
- public List<string> questsString;// = new string[numberOfTexts];
- public Text parentText;
- public List<int> activeQuests;
- public RectTransform initialTextPos;
- float textPosY;
- float textPosX;
- float textWidth = 300;
- float textHeight;
- void Update ()
- {
- //still buggy, fix. Probs put in the addquests function in the for loop which looks identical. Save on cpu or whatevs, and looks better in code
- float f = 0;
- for(int i = 0; i < numberOfQuests; i++)
- {
- int j = questText.Count;
- f += questText[i].rectTransform.rect.height;
- if (f == 0)
- {
- f = 35.8f;
- }
- Vector2 parentSizeDelta = new Vector2(parentText.GetComponent<RectTransform>().sizeDelta.x, f);
- parentText.GetComponent<RectTransform>().sizeDelta = parentSizeDelta;
- }
- if(Input.GetKeyDown(KeyCode.A))
- {
- AddQuest("Find mister Chocolate Face");
- }
- if(Input.GetKeyDown(KeyCode.D))
- {
- AddQuest("Eat 10 clocks");
- }
- if(Input.GetKeyDown(KeyCode.L))
- {
- AddQuest("gvcdsahbqjkdfghvsjvfgh sbhjhbfbhsde kweydfgeskufygdfufydsfuydvfkbs f7i6g3i734grwfuwei8fgwefisey fiugudsfygdsvfbdzmfgsdyfsdfgd m,ukfhdskfg dsulngdfkjfhdkfg dffkdfjgf");
- }
- //Read the comment above the functions
- AssignQuestTexts();
- }
- //Change this to only be called once every time a quest is added/removed
- public void AssignQuestTexts()
- {
- for(int i = 0; i < numberOfQuests; i++)
- {
- questText[i].text = questsString[i];
- }
- }
- public void AddQuest(string quest)
- {
- numberOfQuests++;
- questsString.Add(quest);
- GameObject g = GameObject.CreatePrimitive(PrimitiveType.Capsule);
- g.AddComponent<RectTransform>();
- g.AddComponent<CanvasRenderer>();
- g.AddComponent<ContentSizeFitter>();
- g.AddComponent<Text>();
- g.GetComponent<Text>().font = font;
- g.GetComponent<Text>().color = fontColor;
- g.GetComponent<Text>().fontSize = 16;
- g.GetComponent<Text>().alignment = TextAnchor.MiddleLeft;
- g.name = "Quest Text";
- g.tag = "QuestText";
- g.transform.SetParent(parentText.transform);
- Destroy(g.GetComponent<CapsuleCollider>());
- Destroy(g.GetComponent<MeshRenderer>());
- ContentSizeFitter cst = g.GetComponent<ContentSizeFitter> ();
- cst.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
- RectTransform rt = g.GetComponent<RectTransform>();
- Vector2 size = new Vector2 (textWidth, 0);
- Vector3 scale = new Vector3(1,1,1);
- Vector2 pos;
- rt.sizeDelta = size;
- rt.localScale = scale;
- Vector2 max = new Vector2(0.5f, 0.5f);
- Vector2 min = new Vector2(0.5f, 0.5f);
- rt.anchorMax = max;
- rt.anchorMin = min;
- questText.Add(g.GetComponent<Text>());
- textPosX = initialTextPos.localPosition.x;
- textPosY = initialTextPos.localPosition.y;
- float finalPosY;// = textPosY;
- for (int i = 0; i < numberOfQuests; i++)
- {
- textPosY -= questText [i].rectTransform.rect.height; // this line changes the y postion of the textwe
- if (numberOfQuests == 1)
- {
- //float finalPosY = textPosY;
- finalPosY = (numberOfQuests + textPosY);
- pos = new Vector2(textPosX, finalPosY);
- rt.localPosition = pos;
- }
- else //if(numberOfQuests > 1)
- {
- Debug.Log(g.GetComponent<Text>().rectTransform.rect.height);
- finalPosY = ((-10 * (numberOfQuests - 1)) + textPosY);
- pos = new Vector2(textPosX, finalPosY);
- rt.localPosition = pos;
- }
- }
- }
- public void RemoveQuest(Text quest)
- {
- numberOfQuests--;
- //questID system should be here, don't use Text ffs
- questText.Remove(quest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement