[unity] 2018.3 prefab handling for scene components and inspectors.

This commit is contained in:
pharan 2018-11-28 20:53:16 +08:00
parent 7175cf98e7
commit 80272fb719
4 changed files with 39 additions and 1 deletions

View File

@ -30,6 +30,12 @@
// With contributions from: Mitch Thompson
#if UNITY_2018_3 || UNITY_2019
#define NEW_PREFAB_SYSTEM
#else
#define NO_PREFAB_MESH
#endif
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
@ -122,7 +128,11 @@ namespace Spine.Unity.Editor {
skeletonRenderer.Initialize(false);
skeletonRenderer.LateUpdate();
skeleton = skeletonRenderer.skeleton;
#if NEW_PREFAB_SYSTEM
isPrefab = false;
#else
isPrefab |= PrefabUtility.GetPrefabType(selectedObject) == PrefabType.Prefab;
#endif
UpdateAttachments();
}
}

View File

@ -28,7 +28,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#if UNITY_2018_3 || UNITY_2019
#define NEW_PREFAB_SYSTEM
#else
#define NO_PREFAB_MESH
#endif
using UnityEditor;
using System.Collections.Generic;
@ -81,7 +85,11 @@ namespace Spine.Unity.Editor {
}
protected virtual void OnEnable () {
#if NEW_PREFAB_SYSTEM
isInspectingPrefab = false;
#else
isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
#endif
SpineEditorUtilities.ConfirmInitialization();

View File

@ -28,6 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#if UNITY_2018_3 || UNITY_2019
#define NEW_PREFAB_SYSTEM
#endif
using UnityEngine;
using UnityEditor;
@ -61,7 +65,11 @@ namespace Spine.Unity.Editor {
}
public override void OnInspectorGUI () {
#if !NEW_PREFAB_SYSTEM
bool isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
#else
bool isInspectingPrefab = false;
#endif
// Try to auto-assign SkeletonRenderer field.
if (skeletonRenderer.objectReferenceValue == null) {
@ -94,8 +102,10 @@ namespace Spine.Unity.Editor {
EditorGUILayout.PropertyField(slotName, new GUIContent("Slot"));
if (EditorGUI.EndChangeCheck()) {
serializedObject.ApplyModifiedProperties();
#if !NEW_PREFAB_SYSTEM
if (!isInspectingPrefab)
rebuildRequired = true;
#endif
}
using (new SpineInspectorUtility.LabelWidthScope(150f)) {

View File

@ -28,7 +28,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
// Contributed by: Mitch Thompson
#if UNITY_2018_3 || UNITY_2019
#define NEW_PREFAB_SYSTEM
#endif
using UnityEngine;
using UnityEditor;
@ -46,7 +48,11 @@ namespace Spine.Unity.Editor {
SkeletonUtility skeletonUtility;
Skeleton skeleton;
SkeletonRenderer skeletonRenderer;
#if !NEW_PREFAB_SYSTEM
bool isPrefab;
#endif
readonly GUIContent SpawnHierarchyButtonLabel = new GUIContent("Spawn Hierarchy", Icons.skeleton);
void OnEnable () {
@ -62,14 +68,18 @@ namespace Spine.Unity.Editor {
if (!skeletonRenderer.valid) return;
#if !NEW_PREFAB_SYSTEM
isPrefab |= PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab;
#endif
}
public override void OnInspectorGUI () {
#if !NEW_PREFAB_SYSTEM
if (isPrefab) {
GUILayout.Label(new GUIContent("Cannot edit Prefabs", Icons.warning));
return;
}
#endif
if (!skeletonRenderer.valid) {
GUILayout.Label(new GUIContent("Spine Component invalid. Check Skeleton Data Asset.", Icons.warning));