コード例 #1
0
        /// <summary>
        /// Called when a list of assets including the target(s) GameObject(s) is displayed.
        /// NOTE: This override is necessary in order to load the asset preview correctly when displayed in the project
        /// browser. See UnityEditor.GameObjectInspector class from Unity CS reference for more informations:
        /// https://github.com/Unity-Technologies/UnityCsReference
        /// </summary>
        public override Texture2D RenderStaticPreview(string _AssetPath, Object[] _SubAssets, int _Width, int _Height)
        {
            if (NativeEditor == null)
            {
                return(null);
            }

            return(ReflectionUtility.CallMethod <Texture2D>("RenderStaticPreview", NativeEditor, new object[] { _AssetPath, _SubAssets, _Width, _Height }));
        }
コード例 #2
0
        /// <summary>
        /// Called when the GameObject is dragged to the scene view.
        /// NOTE: This override is necessary in order to load the object correctly when it's dragged into the scene.
        /// Without this, the object cannot be dragged from the Project browser to the Scene View (dragging it to the
        /// Hierarchy works though). See UnityEditor.GameObjectInspector class from Unity CS reference for more
        /// informations: https://github.com/Unity-Technologies/UnityCsReference
        /// </summary>
        /// <param name="_SceneView">The SceneView where this GameObject is dragged to.</param>
        public void OnSceneDrag(SceneView _SceneView)
        {
            if (NativeEditor == null)
            {
                return;
            }

            ReflectionUtility.CallMethod("OnSceneDrag", NativeEditor, new object[] { _SceneView });
        }
コード例 #3
0
        /// <summary>
        /// Draws the preview of the GameObject.
        /// NOTE: This override is necessary in order to load the asset preview correctly when displayed in the
        /// inspector. See UnityEditor.GameObjectInspector class from Unity CS reference for more informations:
        /// https://github.com/Unity-Technologies/UnityCsReference
        /// </summary>
        public override void OnPreviewGUI(Rect _Rect, GUIStyle _Background)
        {
            if (NativeEditor == null)
            {
                return;
            }

            ReflectionUtility.CallMethod("OnPreviewGUI", NativeEditor, new object[] { _Rect, _Background });
        }
コード例 #4
0
        /// <summary>
        /// Called when this editor is disabled.
        /// Destroys the created native editor properly in order to avoid memory leaks.
        /// Enables the GameObject (ensuring its preview cache has been initialized, and so avoiding errors), then destroys it properly
        /// using Editor.DestroyImmediate().
        /// </summary>
        /// <param name="_NativeEditor">The native editor instance to destroy.</param>
        protected override void DestroyNativeEditor(Editor _NativeEditor)
        {
            // Check if the preview cache is set or not
            object previewCache = ReflectionUtility.GetFieldValue <object>("m_PreviewCache", _NativeEditor);

            // If the preview cache is not defined, call OnEnable() method to initialize the GameObject editor
            if (previewCache == null)
            {
                ReflectionUtility.CallMethod("OnEnable", _NativeEditor);
            }

            DestroyImmediate(_NativeEditor);
        }