void OnEnable() { skeletonRenderer = serializedObject.FindProperty("skeletonRenderer"); slotName = serializedObject.FindProperty("slotName"); pointAttachmentName = serializedObject.FindProperty("pointAttachmentName"); targetPointFollower = (PointFollower)target; if (targetPointFollower.skeletonRenderer != null) { targetPointFollower.skeletonRenderer.Initialize(false); } if (!targetPointFollower.IsValid || needsReset) { targetPointFollower.Initialize(); targetPointFollower.LateUpdate(); needsReset = false; SceneView.RepaintAll(); } }
override public void OnInspectorGUI() { if (serializedObject.isEditingMultipleObjects) { if (needsReset) { needsReset = false; foreach (var o in targets) { var bf = (BoneFollower)o; bf.Initialize(); bf.LateUpdate(); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); needsReset |= EditorGUI.EndChangeCheck(); return; } if (needsReset && Event.current.type == EventType.Layout) { targetPointFollower.Initialize(); targetPointFollower.LateUpdate(); needsReset = false; SceneView.RepaintAll(); } serializedObject.Update(); DrawDefaultInspector(); // Find Renderer if (skeletonRenderer.objectReferenceValue == null) { SkeletonRenderer parentRenderer = targetPointFollower.GetComponentInParent <SkeletonRenderer>(); if (parentRenderer != null && parentRenderer.gameObject != targetPointFollower.gameObject) { skeletonRenderer.objectReferenceValue = parentRenderer; Debug.Log("Inspector automatically assigned PointFollower.SkeletonRenderer"); } } var skeletonRendererReference = skeletonRenderer.objectReferenceValue as SkeletonRenderer; if (skeletonRendererReference != null) { if (skeletonRendererReference.gameObject == targetPointFollower.gameObject) { skeletonRenderer.objectReferenceValue = null; EditorUtility.DisplayDialog("Invalid assignment.", "PointFollower can only follow a skeleton on a separate GameObject.\n\nCreate a new GameObject for your PointFollower, or choose a SkeletonRenderer from a different GameObject.", "Ok"); } } if (!targetPointFollower.IsValid) { needsReset = true; } var current = Event.current; bool wasUndo = (current.type == EventType.ValidateCommand && current.commandName == "UndoRedoPerformed"); if (wasUndo) { targetPointFollower.Initialize(); } serializedObject.ApplyModifiedProperties(); }