Example #1
0
 public static RectTransform CreateRectTransform(RectTransform prefab,Vector2 size)
 {
     var rect = Instantiate(prefab);
     rect.SetParent(prefab.parent);
     rect.localPosition = prefab.localPosition;
     rect.localScale = Vector3.one;
     rect.SetSiblingIndex(prefab.GetSiblingIndex() + 1);
     rect.sizeDelta = size;
     return rect;
 }
Example #2
0
	public static PaintingDetector2D CreateDetector(RectTransform prefab)
    {
        var detectRect = Instantiate(prefab);
        detectRect.name = "detect";
        detectRect.SetParent(prefab.parent);
        detectRect.localPosition = prefab.localPosition;
        detectRect.localScale = Vector3.one;
        detectRect.SetSiblingIndex(prefab.GetSiblingIndex() + 1);
        //detectRect.localPosition = new Vector3(indicator.rect.width, indicator.rect.height,0);
        detectRect.sizeDelta = new Vector2(Screen.width, Screen.height);
        detectRect.GetComponent<RawImage>().color = Color.clear;
        var detector = detectRect.gameObject.AddComponent<PaintingDetector2D>();
        return detector;
    }
Example #3
0
        public void Setup(RippleData data, Vector2 positon, IRippleCreator creator, bool oscillate = false)
        {
            m_RippleData = data;
            m_RippleParent = (RectTransform)data.RippleParent;
            rectTransform.SetParent(m_RippleParent);
            rectTransform.SetSiblingIndex(0);
            m_Oscillate = oscillate;
            rectTransform.sizeDelta = Vector2.zero;

            switch (GetComponentInParent<Canvas>().renderMode)
            {
                case RenderMode.ScreenSpaceOverlay:
                    rectTransform.position = new Vector3(positon.x, positon.y, m_RippleParent.position.z);
                    break;
                case RenderMode.ScreenSpaceCamera:
                    rectTransform.position = new Ray(Camera.main.transform.position, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_RippleParent.position.z))).GetPoint(Vector3.Distance(Camera.main.transform.position, m_RippleParent.position));
                    break;
                case RenderMode.WorldSpace:
                    rectTransform.position = new Ray(Camera.main.transform.position, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_RippleParent.position.z))).GetPoint(Vector3.Distance(Camera.main.transform.position, m_RippleParent.position));
                    break;
            }

            rectTransform.localEulerAngles = Vector3.zero;
            image.color = data.Color;
            canvasGroup.alpha = data.StartAlpha;
            m_AnimationDuration = 4f / data.Speed;
            m_RippleCreator = creator;
            if (data.PlaceRippleBehind)
            {
                int index = m_RippleParent.GetSiblingIndex();
                rectTransform.SetParent(m_RippleParent.parent);
                rectTransform.SetSiblingIndex(index);
            }

        }
Example #4
0
    private void RefreshCPURectangleType(List<RectTransform> existingTransforms, RectTransform prototype, int numOfCores)
    {
        for (int i = 0; i < numOfCores + existingTransforms.Count; i++)
        {
            bool cpuStateIsOn = i < numOfCores;
            bool transformExists = i < existingTransforms.Count;

            if (transformExists)
            {
                existingTransforms[i].gameObject.SetActive(cpuStateIsOn);
            }
            else if (cpuStateIsOn)
            {
                existingTransforms.Add(GameObject.Instantiate<RectTransform>(prototype));
                existingTransforms[i].SetParent(this.transform);
                existingTransforms[i].localScale = Vector3.one;
                existingTransforms[i].localRotation = Quaternion.identity;
                existingTransforms[i].localPosition = Vector3.zero;
                existingTransforms[i].gameObject.SetActive(true);
                existingTransforms[i].SetSiblingIndex(prototype.GetSiblingIndex() + 1);
            }
        }
    }