public void AddInlineGraphicsChild()
        {
            if (m_inlineGraphic != null)
            {
                //Debug.LogWarning("A child Inline Graphics object already exists.");
                return;
            }

            GameObject inlineGraphicObj = new GameObject("Inline Graphic");

            m_inlineGraphic = inlineGraphicObj.AddComponent<InlineGraphic>();

            m_inlineGraphicRectTransform = inlineGraphicObj.GetComponent<RectTransform>();
            m_inlineGraphicCanvasRenderer = inlineGraphicObj.GetComponent<CanvasRenderer>();

            m_inlineGraphicRectTransform.SetParent(transform, false);
            m_inlineGraphicRectTransform.localPosition = Vector3.zero;
            m_inlineGraphicRectTransform.anchoredPosition3D = Vector3.zero;
            m_inlineGraphicRectTransform.sizeDelta = Vector2.zero;
            m_inlineGraphicRectTransform.anchorMin = Vector2.zero;
            m_inlineGraphicRectTransform.anchorMax = Vector2.one;

            m_TextMeshPro = gameObject.GetComponent<TextMeshPro>();
            m_TextMeshProUI = gameObject.GetComponent<TextMeshProUGUI>();
        }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        //general setup
        menu = GetComponentInParent<Menu>();
        options = new List<MenuViewOptionBasic>();
        GetComponentsInChildren<MenuViewOptionBasic>(options);
        toDraw = true;
        if(options == null) options = new List<MenuViewOptionBasic>();
        //Setup view
        viewObject = new GameObject("MenuViewBasic");
        viewObject.transform.SetParent(transform);
        canvas = viewObject.AddComponent<Canvas>();
        canvas.renderMode = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = drawCamera;
        canvas.planeDistance = 1f;
        viewObject.AddComponent<CanvasScaler>();
        viewObject.AddComponent<GraphicRaycaster>();
        //Setup textbox
        textbox = new GameObject("TextBox");
        textPosition = textbox.AddComponent<RectTransform>();
        textPosition.SetParent(viewObject.transform);
        textPosition.localPosition = new Vector3(position.x,position.y, 0);
        textbox.AddComponent<CanvasRenderer>();

        text = textbox.AddComponent<Text>();
        text.font = textFont;
        text.alignment = TextAnchor.MiddleCenter;
        text.color = new Color(color.r, color.g, color.b);
        if(options.Count > 0) text.text = options[menu.CurOption].optionText;
    }
        public void AddItem(RectTransform item)
        {
            item.SetParent(contentsNode, false);

            if (this.gameObject.activeInHierarchy)
            {
                StartCoroutine(SetPosition(item));
            }
        }
Beispiel #4
0
 public void addChild(RectTransform rt ,RectTransform parent = null)
 {
     if(parent == null)
     {
         parent = UIRoot;
     }
     rt.SetParent(parent);
     rt.localPosition = Vector3.zero;
     rt.localScale = Vector3.one;
 }
Beispiel #5
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        GameObject go = new GameObject();
        placeholder = go.AddComponent<RectTransform>();
        placeholder.SetParent(parentToReturn);
        placeholder.transform.SetSiblingIndex(myTransform.GetSiblingIndex());
        placeholder.transform.localScale = new Vector3(10, 10, 0);

        myTransform.SetParent(parentDragging);
        tooltip.DestroyTooltip();
        tooltip.enabled = false;
    }
Beispiel #6
0
	public void PlaceUI(RectTransform prefabZone, RectTransform prefabLetter)
	{
		Assert.Check (prefabZone, "Zone UI prefab is null");
		Assert.Check (prefabLetter, "Letter prefab is null");

		GameObject gCanvas = GameObject.Find ("CanvasZone");
		Assert.Check (gCanvas, "CanvasZone gameObject is not found");

		GameObject zoneG = GameObject.Instantiate (prefabZone.gameObject) as GameObject;
		Assert.Check (zoneG, "Couldn't instantiate zone UI");

		ZoneUI = zoneG.transform as RectTransform;
		Assert.Check (ZoneUI, "Zone has no RectTransform");

		RectTransform imgT = zoneG.transform.FindChild("Picto") as RectTransform;
		Assert.Check (imgT, "Zone has no Picto RectTransform");

		this.Picto = imgT.GetComponent<Image>();
		Assert.Check(this.Picto, "Picto has no image");

		this.Picto.sprite = this.Effect.Picto;

		Canvas canvas = gCanvas.GetComponent<Canvas> ();
		Assert.Check (canvas, "CanvasZone's 'Canvas' component is not found");

		ZoneUI.SetParent(canvas.transform, false);

		Vector2 local;
		Vector2 screen = RectTransformUtility.WorldToScreenPoint (Camera.main, this.transform.position);
		RectTransformUtility.ScreenPointToLocalPointInRectangle (canvas.transform as RectTransform, screen, Camera.main, out local);
		ZoneUI.anchoredPosition = local;

		for (int i = 0; i < Combinaison.Count; i++) 
		{
			GameObject letterG = GameObject.Instantiate (prefabLetter.gameObject) as GameObject;
			Assert.Check (zoneG, "Couldn't instantiate letter");

			RectTransform letter = letterG.transform as RectTransform;
			Assert.Check (ZoneUI, "Letter has no RectTransform");

			letter.SetParent (ZoneUI, false);
			Letters.Add (letter);

			RectTransform txtT = letter.FindChild ("Text") as RectTransform;
			Assert.Check (txtT, "Letter Text child not found or has no RectTransform");

			Text txt = txtT.GetComponent<Text> ();
			Assert.Check (txtT, "Letter Text child's 'Text' component not found");

			txt.text = Combinaison [i].ToString();
		}
	}
Beispiel #7
0
    void Start()
    {
        healthBarCanvas = GameObject.Find("Health Bar Canvas").transform;
        hpSource = this.GetComponent<IHealth>();

        _healthBarInstance = GameObject.Instantiate(healthBarPrefab);
        _healthBarInstance.SetParent(healthBarCanvas, false);
        healthBarSlider = _healthBarInstance.GetComponentInChildren<Slider>();

        healthBarPos = this.transform.position;
        healthBarPos.y += healthBarHeight;
        _healthBarInstance.anchoredPosition = Camera.main.WorldToScreenPoint(healthBarPos);
    }
Beispiel #8
0
 // Use this for initialization
 void Init()
 {
     //		Debug.Log("apply");
     us=gameObject.GetComponent<RectTransform>();
     //from=us.parent as RectTransform;
     us.SetParent(us.RootCanvasTransform());
     us.SetInternalAnchors (new Vector4 (0, 0, 1, 1));
     //start=us.rect;
     //reference=from.rect;
     Rect rr = to.RootCanvasRect ();
     //	Debug.Log(rr);
     tovec = (us.parent as RectTransform).getAnchorsFromCanvasRect (rr);
     //	Debug.Log(tovec);
     stvec = new Vector4 (us.anchorMin.x,us.anchorMin.y,us.anchorMax.x,us.anchorMax.y);
 }
Beispiel #9
0
    public RichEditLine(Transform parent, float width)
    {
        gameObject = new GameObject("RichEditLine");
        transform = gameObject.AddComponent<RectTransform>();
        transform.SetParent(parent, false);
        transform.SetAsLastSibling();

        layoutElement = gameObject.AddComponent<LayoutElement>();
        layoutElement.preferredWidth = width;
        layoutElement.preferredHeight = 0;

        layoutGroup = gameObject.AddComponent<HorizontalLayoutGroup>();
        layoutGroup.childForceExpandWidth = false;
        layoutGroup.childForceExpandHeight = false;
        layoutGroup.childAlignment = TextAnchor.LowerLeft;
    }
Beispiel #10
0
    public RichEditBlock(Transform parent, float width, float lineSpacing)
    {
        gameObject = new GameObject("RichEditBlock");
        transform = gameObject.AddComponent<RectTransform>();
        transform.SetParent(parent, false);
        transform.SetAsLastSibling();

        layoutElement = gameObject.AddComponent<LayoutElement>();
        layoutElement.preferredWidth = width;
        layoutElement.preferredHeight = 0;

        layoutGroup = gameObject.AddComponent<VerticalLayoutGroup>();
        layoutGroup.childForceExpandWidth = false;
        layoutGroup.childForceExpandHeight = false;
        layoutGroup.childAlignment = TextAnchor.LowerLeft;
        layoutGroup.spacing = lineSpacing;

        currentLine = AddNewLine();
    }
Beispiel #11
0
        void Awake()
        {
            m_TextMeshPro = gameObject.GetComponent<TextMeshProUGUI>();


            m_Canvas = gameObject.GetComponentInParent<Canvas>();

            // Get a reference to the camera if Canvas Render Mode is not ScreenSpace Overlay.
            if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                m_Camera = null;
            else
                m_Camera = m_Canvas.worldCamera;

            // Create pop-up text object which is used to show the link information.
            m_TextPopup_RectTransform = Instantiate(TextPopup_Prefab_01) as RectTransform;
            m_TextPopup_RectTransform.SetParent(m_Canvas.transform, false);
            m_TextPopup_TMPComponent = m_TextPopup_RectTransform.GetComponentInChildren<TextMeshProUGUI>();
            m_TextPopup_RectTransform.gameObject.SetActive(false);
        }
Beispiel #12
0
		public virtual void Init()
		{
			// set attributes of scrollrect
			scrollRect = GetComponent<ScrollRect> ();
			scrollRect.onValueChanged.AddListener (OnValueChanged);

			// set the scroll direction
			switch (layout) 
			{
			case Layout.Horizontal:
				scrollRect.horizontal = true;
				scrollRect.vertical = false;
				break;
			case Layout.Vertical:
				scrollRect.horizontal = false;
				scrollRect.vertical = true;
				break;
			}

			// add a scrollrect content
			GameObject go = new GameObject ();
			go.name = "content";
			content = go.AddComponent (typeof(RectTransform)) as RectTransform;
			content.SetParent (transform);
			content.pivot = new Vector2 (0, 1);
			content.anchorMin = content.anchorMax = content.pivot;
			content.anchoredPosition = Vector2.zero;
			content.localScale = Vector3.one;
			scrollRect.content = content;

			// record some sizes
			RectTransform scrollRectTransform = scrollRect.transform as RectTransform;
			scrollRectSize = scrollRectTransform.rect.size;

			// add mask
			if (needMask) 
			{
				Image image = gameObject.AddComponent(typeof(Image)) as Image;
				image.color = new Color32(0, 0, 0, 5);
				gameObject.AddComponent(typeof(Mask));
			}
		}
Beispiel #13
0
    /// <summary>
    /// Add an option to the dialogue box
    /// </summary>
    /// <param name="option_text">Text to display for the option</param>
    /// <param name="option_action">Function to run when this option is selected</param>
    public void AddOption(string option_text, UnityAction option_action)
    {
        if (options.Count % 3 == 0)
        {
            current_option_panel = Instantiate(OptionPanelPrefab).GetComponent<RectTransform>();
            current_option_panel.SetParent(transform, false);
            current_option_panel.gameObject.SetActive(true);
            panels.Add(current_option_panel);
        }

        Button new_button = Instantiate(OptionButtonPrefab).GetComponent<Button>();
        new_button.transform.SetParent(current_option_panel.transform, false);

        new_button.GetComponentInChildren<Text>().text = option_text;
        new_button.onClick.AddListener(option_action);

        new_button.gameObject.SetActive(true);

        options.Add(new_button);
    }
Beispiel #14
0
    public virtual void ApplyTo(GameObject ApplyingTo, Image UIicon, RectTransform UIdurationPanel, Transform parent)
    {
        affecting = ApplyingTo;

        UIIcon = UIicon;

        UIDurationPanel = UIdurationPanel;

        BuffIndex = affecting.GetComponent<IBuffable>().GetNumberOfBuffs();
        affecting.GetComponent<IBuffable>().AddNumberOfBuffs(1);

        UIIcon.transform.SetParent(parent, false);
        UIIcon.rectTransform.anchorMin = new Vector2(0.04f * BuffIndex, 0);
        UIIcon.rectTransform.anchorMax = new Vector2(0.04f * (BuffIndex + 1), 1);

        UIDurationPanel.SetParent(UIIcon.rectTransform, false);
        UIDurationPanel.anchorMin = new Vector2(0, 0);
        UIDurationPanel.anchorMax = new Vector2(1, 1);

        UIIcon.sprite = Icon;
    }
        void Awake()
        {
            if (!enabled)
                return;

            Application.targetFrameRate = -1;

            GameObject frameCounter = new GameObject("Frame Counter");
            m_frameCounter_transform = frameCounter.AddComponent<RectTransform>();

            m_frameCounter_transform.SetParent(this.transform, false);

            m_TextMeshPro = frameCounter.AddComponent<TextMeshProUGUI>();
            m_TextMeshPro.font = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
            m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Overlay", typeof(Material)) as Material;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize = 36;

            m_TextMeshPro.isOverlay = true;

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
Beispiel #16
0
        public void Initialize()
        {
            if (panel == null)
            {
                try
                {
                    panel = GameObject.Find("/Canvas/EventPanel").GetComponent<RectTransform>();
                }
                catch
                {
                    GameObject g = Resources.Load<GameObject>("Prefabs/UIPrefabs/EventPanel");
                    panel = Instantiate(g).GetComponent<RectTransform>();
                    panel.name = panel.name.Replace("(Clone)", "");
                    panel.SetParent(GameObject.Find("/Canvas").GetComponent<RectTransform>(), false);
                    panel.sizeDelta = new Vector2();
                    panel.position = new Vector3(panel.rect.width / 2, panel.rect.height / 2, 0);
                }
            }

            if (nameBox == null) nameBox = panel.FindChild("TextPanel/NameBox").GetComponent<RectTransform>();
            if (contentBox == null) contentBox = panel.FindChild("TextPanel/ContentBox").GetComponent<RectTransform>();

            panel.gameObject.SetActive(false);
        }
		public virtual void Init()
		{
			if (initialized)
				return;

			if (null == item) 
			{
				Debug.LogError("set an listitem first");
				return;
			}

			// set attributes of scrollrect
			scrollRect = GetComponent<ScrollRect> ();
			scrollRect.onValueChanged.AddListener (OnValueChanged);

			// add a scrollrect content
			GameObject go = new GameObject ();
			go.name = "content";
			content = go.AddComponent (typeof(RectTransform)) as RectTransform;
			content.SetParent (transform);
			content.pivot = new Vector2 (0, 1);
			content.anchorMin = content.anchorMax = content.pivot;
			content.anchoredPosition = Vector2.zero;
			scrollRect.content = content;

			// record some sizes
			RectTransform scrollRectTransform = scrollRect.transform as RectTransform;
			scrollRectSize = scrollRectTransform.sizeDelta;
			RectTransform itemRectTransform = item.transform as RectTransform;
			itemSize = itemRectTransform.sizeDelta;

			// record the max shown item num
			maxShowNum = GetMaxShowItemNum();

			initialized = true;
		}
Beispiel #18
0
    public void AddChild(RectTransform child)
    {
        var parentTransform = GetComponent<RectTransform>();
        //这样会把孙结点也包含进来
        //        var childrenTransforms = GetComponentsInChildren<RectTransform>();
        var childrenTransforms = new List<RectTransform>();
        var transform = this.transform;
        for (int i = 0; i < transform.childCount; i++) {
            var achild = transform.GetChild(i);
            if (achild.gameObject.activeSelf) {
                childrenTransforms.Add(achild.GetComponent<RectTransform>());
            }
        }

        var childrenLength = 0f;
        var expectLen = 0f;

        //设置居中或不居中时的锚点
        var anchor = .5f;
        if (!Center) {
            anchor = 0f;
        }

        if (align == Alignment.Horizontal) {
            for (int i = 0; i < childrenTransforms.Count; i++) {
                childrenLength += childrenTransforms[i].sizeDelta.x;
            }

            //加入新子节点后的总宽度
            expectLen = (childrenTransforms.Count + 2) * padding
                              + childrenLength + child.sizeDelta.x;

            resize(expectLen);

            if (reverse) {
                child.anchorMin = new Vector2(1, anchor);
                child.anchorMax = new Vector2(1, anchor);
                child.anchoredPosition = new Vector2(
                    - (expectLen - padding - child.sizeDelta.x / 2),
                    parentTransform.sizeDelta.y);
            } else {
                child.anchorMin = new Vector2(0, anchor);
                child.anchorMax = new Vector2(0, anchor);
                child.anchoredPosition = new Vector2(
                    expectLen - padding - child.sizeDelta.x / 2,
                    parentTransform.sizeDelta.y);
            }
        } else {
            // 第一项为Content本身 所以去除
            for (int i = 0; i < childrenTransforms.Count; i++) {
                childrenLength += childrenTransforms[i].sizeDelta.y;
            }

            //加入新子节点后的总宽度
            expectLen = (childrenTransforms.Count + 2) * padding
                              + childrenLength + child.sizeDelta.y;

            resize(expectLen);

            if (reverse) {
                child.anchorMin = new Vector2(anchor, 1);
                child.anchorMax = new Vector2(anchor, 1);
                child.anchoredPosition = new Vector2(
                    parentTransform.sizeDelta.x,
                    - (expectLen - padding - child.sizeDelta.y / 2));
            } else {
                child.anchorMin = new Vector2(anchor, 0);
                child.anchorMax = new Vector2(anchor, 0);
                child.anchoredPosition = new Vector2(
                    parentTransform.sizeDelta.x,
                    expectLen - padding - child.sizeDelta.y / 2);
            }
        }

        child.SetParent(GetComponent<Transform>(), false);
    }
    //build the popup from the given list of descriptors
    //also receives the component that this popup will edit and the type of component used to find the descriptors
    public void buildPopup(GameRuleDesignComponent cr, List<GameRuleDesignComponentDescriptor> pd, System.Type describedType)
    {
        //instead of Start(), this is the place where stuff will get initialized
        //store a bunch of size information for positioning things
        RectTransform iconArea = (RectTransform)(transform.GetChild(1));
        iconAreaBottomLeft = iconArea.offsetMin;
        iconAreaTopRight = iconArea.offsetMax; //x and y are both negative for an inset corner
        iconAreaTotalBounds = iconAreaBottomLeft - iconAreaTopRight;
        iconContainer = (RectTransform)(transform.GetChild(2));
        //throw the container out to under the canvas so that it renders over the whole rule
        iconContainer.SetParent(GameRuleDesigner.instance.uiCanvas);
        RectTransform iconContainerSpacing = (RectTransform)(iconContainer.GetChild(0));
        iconContainerSpacingSize = iconContainerSpacing.sizeDelta;
        //we only needed these to get their size, we can get rid of them now
        Destroy(iconArea.gameObject);
        Destroy(iconContainerSpacing.gameObject);

        //now we can build the popup
        transform.SetParent(GameRuleDesigner.instance.iconContainerTransform);
        //setting the parent screwed up the scale so fix it
        transform.localScale = new Vector3(1.0f, 1.0f);
        componentRepresented = cr;
        popupDescriptors = pd;
        //go through all the descriptors and add their icon to this popup
        foreach (GameRuleDesignComponentDescriptor descriptor in popupDescriptors) {
            RectTransform popupIcon;
            //int descriptors don't have icon prefabs, so we have to construct the icons
            if (descriptor is GameRuleDesignComponentIntDescriptor) {
                List<GameObject> iconList = new List<GameObject>();
                int i = ((GameRuleDesignComponentIntDescriptor)descriptor).intDescribed;
                if (i >= 0) {
                    if (describedType == typeof(GameRulePointsPlayerEffect))
                        iconList.Add(GameRuleIconStorage.instance.charPlusIcon);
                    GameRuleIconStorage.instance.addDigitIcons(i, iconList);
                } else {
                    iconList.Add(GameRuleIconStorage.instance.charMinusIcon);
                    GameRuleIconStorage.instance.addDigitIcons(-i, iconList);
                }
                //make a gameobject to hold all of the icons
                popupIcon = groupIcons(iconList);
            //almost all other descriptors we can construct normally
            //if it doesn't have an icon then it's a special case we know about
            } else if (descriptor.displayIcon == null) {
                if (descriptor is GameRuleDesignComponentClassDescriptor) {
                    System.Type otherType = ((GameRuleDesignComponentClassDescriptor)descriptor).typeDescribed;
                    //a points effect shows up as "+?"
                    if (otherType == typeof(GameRulePointsPlayerEffect))
                        popupIcon = groupIcons(new List<GameObject>(new GameObject[] {
                            GameRuleIconStorage.instance.charPlusIcon,
                            GameRuleIconStorage.instance.charQmarkIcon
                        }));
                    else
                        throw new System.Exception("Bug: no special popup icon cases for type " + otherType);
                } else
                    throw new System.Exception("Bug: no special popup icon cases for " + descriptor);
            //it has an icon, it's probably normal
            } else
                popupIcon = componentRepresented.getIconMaybeOpponent(descriptor);
            popupIcon.SetParent(iconContainer);
            popupIcons.Add(popupIcon);
        }
        //we add a "cancel" icon at the end to ensure there's room to cancel out of the popup
        RectTransform cancelIcon = instantiateIcon(GameRuleDesigner.instance.cancelIconPopupPrefab);
        cancelIcon.SetParent(iconContainer);
        popupIcons.Add(cancelIcon);

        //if we're doing a points effect, default to the "+1" choice
        if (describedType == typeof(GameRulePointsPlayerEffect))
            cr.assignDescriptor(popupDescriptors[
                GameRulePointsPlayerEffect.POINTS_SERIALIZATION_MASK - GameRulePointsPlayerEffect.POINTS_SERIALIZATION_MAX_VALUE + 1]);
        //if we're doing a fixed duration, default to the rule generator min value
        else if (describedType == typeof(GameRuleActionFixedDuration))
            cr.assignDescriptor(popupDescriptors[GameRuleGenerator.ACTION_DURATION_SECONDS_SHORTEST]);
        else
            cr.assignDescriptor(popupDescriptors[0]);
    }
 //display the icon as the selected option for this popup
 public void placeIcon(RectTransform displayIcon)
 {
     RectTransform t = (RectTransform)transform;
     t.sizeDelta = displayIcon.sizeDelta + iconAreaTotalBounds;
     displayIcon.SetParent(transform);
     displayIcon.localPosition = new Vector3(iconAreaBottomLeft.x, 0.0f);
     displayIcon.localScale = new Vector3(1.0f, 1.0f);
 }
    private IEnumerator LoadCoroutine()
    {
        int i = 0;
        foreach (FileInfo f in info)
        {
            item = Instantiate(prefab) as RectTransform;
            item.SetParent(transform, false);
            Text titleText = item.GetComponentInChildren<Text>();
            titleText.text = f.Name.Substring(0, f.Name.Length - 5);

            item.gameObject.GetComponent<LoadButtonParam>().Number = i++;
            _loadButtonParam = item.gameObject.GetComponent<LoadButtonParam>();

            string folderPath = "";
            try
            {

                if (Application.platform != RuntimePlatform.WindowsEditor)
                {
                    folderPath = Application.persistentDataPath + "/" + titleText.text + ".png";
                }
                else if(Application.platform == RuntimePlatform.OSXEditor)
                {
                    folderPath = Application.dataPath + "/../" + titleText.text + ".png";
                }else
                {
                    folderPath = Application.dataPath + "/../" + titleText.text + ".png";
                }
                byte[] by = File.ReadAllBytes(folderPath);

                Texture2D tex = new Texture2D(0, 0);
                tex.LoadImage(by);

                GameObject sun = item.transform.FindChild("ScreenShot").gameObject;
                Image image = sun.GetComponent<Image>();
                image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height),Vector2.zero);
            }
            catch (Exception e)
            {
                print(e.Message);
            }

            yield return null;
        }
    }
Beispiel #22
0
        /// <summary>
        /// Read the data into the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="reader">Reader.</param>
        public override void ReadInto(object value, ISaveGameReader reader)
        {
            UnityEngine.RectTransform rectTransform = (UnityEngine.RectTransform)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "anchorMin":
                    rectTransform.anchorMin = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "anchorMax":
                    rectTransform.anchorMax = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "anchoredPosition3D":
                    rectTransform.anchoredPosition3D = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "anchoredPosition":
                    rectTransform.anchoredPosition = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "sizeDelta":
                    rectTransform.sizeDelta = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "pivot":
                    rectTransform.pivot = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "offsetMin":
                    rectTransform.offsetMin = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "offsetMax":
                    rectTransform.offsetMax = reader.ReadProperty <UnityEngine.Vector2>();
                    break;

                case "position":
                    rectTransform.position = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "localPosition":
                    rectTransform.localPosition = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "eulerAngles":
                    rectTransform.eulerAngles = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "localEulerAngles":
                    rectTransform.localEulerAngles = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "right":
                    rectTransform.right = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "up":
                    rectTransform.up = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "forward":
                    rectTransform.forward = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "rotation":
                    rectTransform.rotation = reader.ReadProperty <UnityEngine.Quaternion>();
                    break;

                case "localRotation":
                    rectTransform.localRotation = reader.ReadProperty <UnityEngine.Quaternion>();
                    break;

                case "localScale":
                    rectTransform.localScale = reader.ReadProperty <UnityEngine.Vector3>();
                    break;

                case "parent":
                    if (rectTransform.parent == null)
                    {
                        rectTransform.SetParent(reader.ReadProperty <UnityEngine.Transform>(), false);
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Transform>(rectTransform.parent);
                    }
                    break;

                case "hasChanged":
                    rectTransform.hasChanged = reader.ReadProperty <System.Boolean>();
                    break;

                case "hierarchyCapacity":
                    rectTransform.hierarchyCapacity = reader.ReadProperty <System.Int32>();
                    break;

                case "tag":
                    rectTransform.tag = reader.ReadProperty <System.String>();
                    break;

                case "name":
                    rectTransform.name = reader.ReadProperty <System.String>();
                    break;

                case "hideFlags":
                    rectTransform.hideFlags = reader.ReadProperty <UnityEngine.HideFlags>();
                    break;
                }
            }
        }
 // Use this for initialization
 void Start()
 {
     itsTransform = this.GetComponent<RectTransform> ();
     itsTransform.SetParent(GameObject.Find("EnemiesAll").transform, false);
     StartPosition = Field.StartPosition;
     Step = Field.Step;
     Movings = Field.MoveInstructions;
     MaxHealthPoints = HealthPoints;
     StandartColor = GetComponent<Image>().color;
     Init ();
     StartCoroutine (Moving ());
 }
Beispiel #24
0
    //in canvas coords?
    public void drawArrow(Vector2 pt0,Vector2 pt1)
    {
        if(trans==null) Init ();
        //		Debug.Log(pt0);	Debug.Log(pt1);
        float distance= Vector2.Distance(pt0,pt1);
        if(distance<0.01f) return;
        float bodydist=distance-taillen-headlen;
        Rect rct=new Rect((pt0+pt1)/2-(new Vector2(distance,height)/2),new Vector2(distance,height));
        Vector4 vs=canv.getAnchorsFromCanvasRect(rct);
        //		Debug.Log(rct);
        trans.assignRectAnchors(vs);
        trans.pivot=new Vector2(0.5f,0.5f);
        //Debug.Log(trans.rect);
        float tailoff=taillen/distance;
        float headoff=headlen/distance;
        float bodyoff=bodylen/distance;

        if(headItem==null)
        {
            GameObject go=new GameObject("head");
            go.AddComponent(typeof(RawImage));
            RawImage img=go.GetComponent<UnityEngine.UI.RawImage>();
            img.texture=head;
            headItem=go.GetComponent<RectTransform>();
            headItem.SetParent(trans,false);
        }

        if(tailItem==null)
        {
            GameObject go=new GameObject("tail");
            go.AddComponent(typeof(RawImage));
            RawImage img=go.GetComponent<UnityEngine.UI.RawImage>();
            img.texture=tail;
            tailItem=go.GetComponent<RectTransform>();
            tailItem.SetParent(trans,false);
        }
        headItem.assignRectAnchors(new Vector4(1.0f-headoff,0,1,1f));
        tailItem.assignRectAnchors(new Vector4(0,0,tailoff,1f));
        float ang=Mathf.Atan2(pt1.y-pt0.y,pt1.x-pt0.x);
        Quaternion rot=Quaternion.identity;
        rot.eulerAngles=new Vector3(0,0,ang*180.0f/Mathf.PI);
        trans.rotation=rot;
        if(bodydist<bodylen) return;
        int maxnecessarybodies=Mathf.CeilToInt((bodydist-(bodylengaps*bodylen))/(bodylen+bodylengaps*bodylen));
        while(maxnecessarybodies>bodyItems.Count)
        {
            RectTransform bi;
            GameObject go=new GameObject("body"+bid);
            go.AddComponent(typeof(RawImage));
            RawImage img=go.GetComponent<UnityEngine.UI.RawImage>();
            img.texture=body;
            bi=go.GetComponent<RectTransform>();
            bi.SetParent(trans,false);
            bid++;
            bodyItems.Add(bi);
        }
        foreach(RectTransform r in bodyItems)
            r.gameObject.SetActive(false);
        float gapsize=(bodydist-(float)maxnecessarybodies*bodylen)/((float)maxnecessarybodies+1.0f);
        float gapoff=gapsize/distance;
        float stp=gapoff+tailoff;
        for(int i=0;i<maxnecessarybodies;i++)
        {
            RectTransform bi=bodyItems[i];
            bi.assignRectAnchors(new Vector4(stp,0,stp+bodyoff,1f));
            bi.gameObject.SetActive(true);
            stp=stp+bodyoff+gapoff;
        }
    }
Beispiel #25
0
 public void Start()
 {
     panel = Instantiate(Resources.Load<GameObject>("Prefabs/UIPrefabs/ButtlePanel")).GetComponent<RectTransform>();
     panel.SetParent(GameObject.Find("/Canvas").transform);
     panel.sizeDelta = new Vector2();
     panel.SetSiblingIndex(0);
     panel.position = new Vector3(panel.rect.width / 2, panel.rect.height / 2, 0);
     player = GameObject.Find("/Player").GetComponent<PlayerController>();
     maxHP = player.MaxHP;
     hpbar = panel.FindChild("HPPanel/HPBar").GetComponent<Slider>();
     hptext = panel.FindChild("HPPanel/HPText").GetComponent<Text>();
     hpbar.maxValue = maxHP;
     enemyPoint = Resources.Load<GameObject>("Prefabs/UIPrefabs/EnemyPoint");
     radarPanel = panel.FindChild("RadarPanel").gameObject;
     playerPoint = panel.FindChild("RadarPanel/PlayerPoint").gameObject;
     prtf = playerPoint.GetComponent<RectTransform>();
     ptf = player.transform;
     rrtf = radarPanel.GetComponent<RectTransform>();
     marker = panel.FindChild("MarkerPanel").GetComponent<MarkerScript>();
     maincamera = GameObject.Find("/Player/Main Camera").GetComponent<Camera>();
     remainingEnemyPanel = panel.FindChild("RemainingEnemyPanel").GetComponent<RectTransform>();
     remainingEnemyNumText = remainingEnemyPanel.FindChild("Text").GetComponent<Text>();
     remainingEnemyPanel.localScale = Vector3.zero;
     timeLimitPanel = panel.FindChild("TimeLimitPanel").GetComponent<RectTransform>();
     timeLimitText = timeLimitPanel.FindChild("Text").GetComponent<Text>();
     timeLimitPanel.localScale = Vector3.zero;
 }
Beispiel #26
0
        public override void Init(ObjectInfo infoo)
        {
            ImageInfo info = (ImageInfo)infoo;
            //load image
            GameObject go = Resources.Load<GameObject>(Settings.Instance.PREFAB_PATH + "Image");
            go = GameObject.Instantiate(go);

            //set tag

            go.layer = Settings.Instance.ACTOR_LAYER;

            //set name
            go.name = info.ObjName;

            //add Image
            _image = go.GetComponent<Image>();
            Sprite sp = Resources.Load<Sprite>(info.Path + info.Name);

            if (sp)
            {
                _image.sprite = sp;
                _image.SetNativeSize();
            }
            else
            {
                Debug.LogFormat("Actor: {0} not found", info.Path + info.Name);
            }

            _transform = go.GetComponent<RectTransform>();

            //set local position
            _transform.anchorMin = Vector2.zero;
            _transform.anchorMax = Vector2.zero;

            //set parent
            _transform.SetParent(Settings.ActorRoot, true);

            //set position and scale
            _transform.anchoredPosition = info.Position;

            _transform.localScale = new Vector3(info.Scale, info.Scale, info.Scale);

            go.SetActive(false);
            this.Go = go;

            IsEnterScene = false;
        }
 private void CreateContextMenuRT()
 {
     GameObject contextMenuGO = new GameObject();
     contextMenuGO.name = "DynamicContextMenu";
     contextMenuRT = contextMenuGO.AddComponent<RectTransform>();
     Transform thisObjectTransform = this.gameObject.GetComponent<Transform>();
     if (thisObjectTransform != null)
     {
         contextMenuRT.SetParent(thisObjectTransform);
         contextMenuRT.anchorMin = new Vector2(0.0f,0.0f);
         contextMenuRT.anchorMax = new Vector2(1.0f,1.0f);
         contextMenuRT.offsetMin = new Vector2(0.0f,0.0f);
         contextMenuRT.offsetMax = new Vector2(0.0f,0.0f);
     }
     else
     {
         Debug.LogError("CreateContextMenu must be attached at element with Transform component!");
     }
     contextMenuRT.localScale = new Vector3(1.0f,1.0f,1.0f);
 }
    void Start()
    {
        if (!HealthbarPrefab)
        {
            Debug.LogWarning("wub");
            return;
        }

        thisT = this.transform;
        if (canvas.transform.FindChild("HealthbarRoot") != null)
            healthbarRoot = canvas.transform.FindChild("HealthbarRoot").gameObject;
        else
            healthbarRoot = new GameObject("HealthbarRoot", typeof(RectTransform), typeof(HealthbarRoot));
        healthbarRoot.transform.SetParent(canvas.transform, false);
        HealthbarPrefab = (RectTransform)Instantiate(HealthbarPrefab, new Vector2(-1000, -1000), Quaternion.identity);
        HealthbarPrefab.name = "HealthBar";
        HealthbarPrefab.SetParent(healthbarRoot.transform, false);
        canvasGroup = HealthbarPrefab.GetComponent<CanvasGroup>();

        healthVolume = HealthbarPrefab.transform.Find("Health").GetComponent<Image>();
        backGround = HealthbarPrefab.transform.Find("Background").GetComponent<Image>();
        healthInfo = HealthbarPrefab.transform.Find("HealthInfo").GetComponent<Text>();
        healthInfo.resizeTextForBestFit = true;
        healthInfo.rectTransform.anchoredPosition = Vector2.zero;
        healthInfoPosition = healthInfo.rectTransform.anchoredPosition;
        healthInfo.resizeTextMinSize = 1;
        healthInfo.resizeTextMaxSize = 500;

        healthbarSize = HealthbarPrefab.sizeDelta;
        canvasGroup.alpha = alphaSettings.fullAplpha;
        canvasGroup.interactable = false;
        canvasGroup.blocksRaycasts = false;
        cam = Camera.main;
    }
        void SetPosition(RectTransform trans, int index)
        {
            if (trans.parent != this.transform) trans.SetParent(this.transform);
            Vector2 pos = trans.anchoredPosition;
            if (this.columns == 0)
            {
                pos.x = rect.width * index + rect.width * .5f + this.padding.x;
            }
            else
            {
                int y = index / columns;
                int x = index % columns;
                if (this.direction == Direction.Down)
                    pos.y = -(rect.height * y + this.padding.y + rect.height * .5f);
                else
                    pos.y = rect.height * y + this.padding.y + rect.height * .5f;

                pos.x = rect.width * x + rect.width * .5f + this.padding.x;
            }
            trans.anchoredPosition = pos;
        }
Beispiel #30
0
    public bool Add(RectTransform child, bool forceAdd = false)
    {
        bool canAdd = child.rect.width <= AvailableWidth;

        if (!canAdd && !forceAdd)
        {
            return false;
        }

        UpdateHeightForChild(child);

        if (canAdd)
        {
            child.SetParent(transform, false);
            child.SetAsLastSibling();

            CurrentWidth += child.rect.width;
        }
        else
        {
            GameObject containerObject = new GameObject("LineForceContainer");
            RectTransform containerTransformRect = containerObject.AddComponent<RectTransform>();
            containerTransformRect.SetParent(transform, false);
            containerTransformRect.SetAsLastSibling();

            LayoutElement containerLayoutElement = containerObject.AddComponent<LayoutElement>();
            containerLayoutElement.preferredWidth = AvailableWidth;
            containerLayoutElement.preferredHeight = child.rect.height;

            CurrentWidth += containerLayoutElement.preferredWidth;
        }
        return true;
    }
Beispiel #31
0
 private void AddRectTransform(RectTransform rect)
 {
     rect.SetParent(mOwnTransform, false);
     mElements.Enqueue(rect);
 }