Пример #1
0
        /// <summary>
        /// Clear all textures/etc. destroy the current target objects, and then start from scratch.
        /// Necessary, if, for example, the RectTransform size has changed.
        /// Fairly performance-intensive - only call this if strictly necessary.
        /// </summary>
        public void HardUpdateDisplay()
        {
            var color = imageComponent.color;

            if (Application.isPlaying)
            {
                imageComponent.color = new Color(0, 0, 0, 0);
                //imageComponent.sprite = null;
            }

            DestroyResources();

            Cleanup();

            //UpdateDisplay();
            UIObject3DTimer.AtEndOfFrame(() => UpdateDisplay(), this);
            UIObject3DTimer.DelayedCall(0.05f, () => { imageComponent.color = color; }, this, true);
        }
Пример #2
0
        private static void NewUIObject3D()
        {
            Transform parent = UnityEditor.Selection.activeTransform;

            if (parent == null || !(parent is RectTransform))
            {
                parent = GetCanvasTransform();
            }

            var prefabGUID = AssetDatabase.FindAssets("UIObject3D t:GameObject").FirstOrDefault();

            if (prefabGUID != null)
            {
                var prefab = (GameObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(prefabGUID), typeof(GameObject));

                var newUIObject3D = GameObject.Instantiate(prefab);

                newUIObject3D.name = "UIObject3D";
                newUIObject3D.transform.SetParent(parent);

                var transform = newUIObject3D.transform as RectTransform;

                transform.localPosition      = Vector3.zero;
                transform.anchoredPosition3D = Vector3.zero;
                transform.localScale         = Vector3.one;
                transform.localRotation      = Quaternion.identity;

                transform.SetParent(parent);

                transform.anchorMin = Vector2.zero;
                transform.anchorMax = Vector2.one;
                transform.offsetMin = Vector2.zero;
                transform.offsetMax = Vector2.zero;

                var uiObject3D = newUIObject3D.GetComponent <UIObject3D>();

                UIObject3DTimer.DelayedCall(0.01f, () => uiObject3D.HardUpdateDisplay(), uiObject3D);
            }
        }
Пример #3
0
        /// <summary>
        /// Unity's Start() method. Used for initialization.
        /// </summary>
        void Start()
        {
            var color = imageComponent.color;

            if (Application.isPlaying)
            {
                imageComponent.color = new Color(0, 0, 0, 0);
                //imageComponent.sprite = null;
            }

            UIObject3DTimer.AtEndOfFrame(() => SetStarted(), this, true);
            UIObject3DTimer.AtEndOfFrame(() => OnEnable(), this);

            // Some models (particularly, models with rigs) can cause Unity to crash if they are instantiated this early (for some reason)
            // as such, we must delay very briefly to avoid this before rendering
            UIObject3DTimer.DelayedCall(0.01f, () =>
            {
                Cleanup();
                UpdateDisplay();

                UIObject3DTimer.DelayedCall(0.05f, () => { imageComponent.color = color; }, this, true);
            }, this, true);
        }