コード例 #1
0
ファイル: ObjImage.cs プロジェクト: chengyimingvb/CYMUni
        /// <summary>
        /// Call this method if you've updated your target object (e.g. a model in your scene)
        /// and you want UIObject3D's copy to be updated to match.
        /// Performs a small cleanup and then updates and schedules a render.
        /// (Has less of a performance hit than HardUpdateDisplay())
        /// </summary>
        public void RefreshTarget()
        {
            if (_target != null)
            {
                Cleanup();
            }

            FrameTimer.AtEndOfFrame(() => UpdateDisplay(), this);
        }
コード例 #2
0
ファイル: ObjImage.cs プロジェクト: chengyimingvb/CYMUni
        void InEditorCleanup()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
            {
                Cleanup();

                FrameTimer.AtEndOfFrame(() =>
                {
                    Cleanup();
                }, this, true);
            }
        }
コード例 #3
0
ファイル: ObjImage.cs プロジェクト: chengyimingvb/CYMUni
        /// <summary>
        /// Unity's 'OnEnable' method. Handles some initialization.
        /// </summary>
        protected override void OnEnable()
        {
            base.OnEnable();
            // If Start hasn't been called yet, then this has been called too early.
            // Start() will call this when it is time
            if (!started)
            {
                return;
            }
            FrameTimer.AtEndOfFrame(() => UpdateDisplay(true), this);
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += InEditorCleanup;
#endif
        }
コード例 #4
0
ファイル: ObjImage.cs プロジェクト: chengyimingvb/CYMUni
        /// <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 = this.color;

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

            DestroyResources();

            Cleanup();

            //UpdateDisplay();
            FrameTimer.AtEndOfFrame(() => UpdateDisplay(), this);
            FrameTimer.DelayedCall(0.05f, () => { this.color = color; }, this, true);
        }
コード例 #5
0
        public override void OnInspectorGUI()
        {
            ObjImage objecImage = target as ObjImage;
            Dictionary <ObjImage, Transform> targetPrefabs = new Dictionary <ObjImage, Transform>();

            targetPrefabs = targets.ToDictionary(k => k as ObjImage, v => (v as ObjImage).ObjectPrefab);
            Dictionary <ObjImage, float> renderScales = targets.ToDictionary(k => k as ObjImage, v => (v as ObjImage).RenderScale);

            EditorGUI.BeginChangeCheck();

            if (GUILayout.Button("Force Render"))
            {
                foreach (var t in targetPrefabs)
                {
                    t.Key.HardUpdateDisplay();
                }
            }

            EditorGUILayout.Space();


            base.OnInspectorGUI();

            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }


            foreach (var t in targetPrefabs)
            {
                if (t.Key.ObjectPrefab != t.Value ||
                    renderScales[t.Key] != t.Key.RenderScale)
                {
                    t.Key.SetStarted();
                    t.Key.HardUpdateDisplay();
                    FrameTimer.AtEndOfFrame(() => t.Key.UpdateDisplay(), t.Key);
                }
                else
                {
                    t.Key.UpdateDisplay(true);
                }
            }
        }
コード例 #6
0
ファイル: ObjImage.cs プロジェクト: chengyimingvb/CYMUni
        /// <summary>
        /// Unity's Start() method. Used for initialization.
        /// </summary>
        protected override void Start()
        {
            base.Start();
            var color = this.color;

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

            FrameTimer.AtEndOfFrame(() => SetStarted(), this, true);
            FrameTimer.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
            FrameTimer.DelayedCall(0.01f, () =>
            {
                Cleanup();
                UpdateDisplay();

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