void Awake() { _armatureComponent = this.target as UnityArmatureComponent; _dragonBoneJSON = _armatureComponent.draggonBonesJSON; if ( !EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.draggonBonesJSON != null && _armatureComponent.armature == null ) { _armatureComponent.ClearChildren(); if (DragonBones.IsAvailableString(_armatureComponent.armatureName)) { var dragonBonesData = _armatureComponent.LoadData(); _changeArmature(_armatureComponent.armatureName, dragonBonesData.name); if (DragonBones.IsAvailableString(_armatureComponent.animationName)) { _armatureComponent.animation.Play(_armatureComponent.animationName); _armatureComponent.animation.Stop(); } } } _update(); }
public override void OnInspectorGUI() { // DragonBones Data GUILayout.BeginHorizontal(); var dragonBonesJSON = EditorGUILayout.ObjectField("DragonBones Data", _dragonBoneJSON, typeof(TextAsset), false) as TextAsset; if (_dragonBoneJSON != dragonBonesJSON) { _dragonBoneJSON = dragonBonesJSON; if (_dragonBoneJSON == null) { } else { } } if (_armatureComponent.draggonBonesJSON != _dragonBoneJSON && GUILayout.Button(_armatureComponent.armature == null ? "Create" : "Change")) { DragonBonesData dragonBonesData = null; _armatureComponent.draggonBonesJSON = _dragonBoneJSON; if (_armatureComponent.draggonBonesJSON != null) { //try //{ _armatureComponent.textureAtlasJSON = new List <string>(); _getTextureAtlasConfigs( _armatureComponent.textureAtlasJSON, AssetDatabase.GetAssetPath(_armatureComponent.draggonBonesJSON.GetInstanceID()) ); dragonBonesData = _armatureComponent.LoadData(); /*} * catch * { * }*/ } if (dragonBonesData == null) { _dragonBoneJSON = null; _armatureComponent.draggonBonesJSON = null; _armatureComponent.textureAtlasJSON = null; EditorUtility.DisplayDialog("Error", "Could not load DragonBones Data.", "OK", null); } else { _armatureComponent.ClearChildren(); _changeArmature(dragonBonesData.armatureNames[0], dragonBonesData.name); _update(); } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_armatureComponent.armature != null) { var dragonBonesData = _armatureComponent.armature.armatureData.parent; if ( _armatureNames != null && UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) ) { // Armature var armatureIndex = EditorGUILayout.Popup("Armature", _armatureIndex, _armatureNames.ToArray()); if (_armatureIndex != armatureIndex) { _armatureIndex = armatureIndex; _armatureComponent.ClearChildren(); _changeArmature(_armatureNames[_armatureIndex], dragonBonesData.name); _update(); } } if (_animationNames != null) { // Animation GUILayout.BeginHorizontal(); var animationIndex = EditorGUILayout.Popup("Animation", _animationIndex, _animationNames.ToArray()); if (_animationIndex >= 0) { if (_armatureComponent.animation.isPlaying) { if (GUILayout.Button("Stop")) { _armatureComponent.animation.Stop(); } } else { if (GUILayout.Button("Play")) { _armatureComponent.animation.Play(); } } } GUILayout.EndHorizontal(); if (animationIndex != _animationIndex) { _animationIndex = animationIndex; _armatureComponent.animationName = _animationNames[animationIndex]; _armatureComponent.animation.Play(_armatureComponent.animationName); } } EditorGUILayout.Space(); // ZSpace GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Z Space", GUILayout.Width(120.0f)); _armatureComponent.zSpace = GUILayout.HorizontalSlider(_armatureComponent.zSpace, 0.0f, 0.2f); GUILayout.EndHorizontal(); // TimeScale GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Time Scale", GUILayout.Width(120.0f)); _armatureComponent.animation.timeScale = GUILayout.HorizontalSlider(_armatureComponent.animation.timeScale, 0.0f, 2.0f); GUILayout.EndHorizontal(); EditorGUILayout.Space(); _selectedOption = EditorGUILayout.Popup("Sorting Layer", _selectedOption, _sortingLayerNames); if (_sortingLayerNames[_selectedOption] != _armatureComponent.sortingLayerName) { Undo.RecordObject(_armatureComponent, "Sorting Layer"); _armatureComponent.sortingLayerName = _sortingLayerNames[_selectedOption]; EditorUtility.SetDirty(_armatureComponent); } int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", _armatureComponent.sortingOrder); if (newSortingLayerOrder != _armatureComponent.sortingOrder) { Undo.RecordObject(_armatureComponent, "Edit Sorting Order"); _armatureComponent.sortingOrder = newSortingLayerOrder; EditorUtility.SetDirty(_armatureComponent); } } if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }