private void UpdateDragon() { if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature == null && _armatureComponent.unityData != null && !string.IsNullOrEmpty(_armatureComponent.armatureName)) { // Clear cache UnityFactory.factory.Clear(true); // Unload EditorUtility.UnloadUnusedAssetsImmediate(); System.GC.Collect(); // Load data. var dragonBonesData = UnityFactory.factory.LoadData(_armatureComponent.unityData); // Refresh texture atlas. UnityFactory.factory.RefreshAllTextureAtlas(_armatureComponent); // Refresh armature. UnityEditor.ChangeArmatureData(_armatureComponent, _armatureComponent.armatureName, dragonBonesData.name); // Refresh texture. _armatureComponent.armature.InvalidUpdate(null, true); // Play animation. if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); } _armatureComponent.CollectBones(); } }
private void UpdateBaseAnimation() { if (_armatureBaseIndex > 0) { var baseArmatureName = _armatureBaseNames[_armatureBaseIndex]; UnityEditor.ReplaceAnimation(_armatureComponent, baseArmatureName); } }
void OnEnable() { _armatureComponent = target as UnityArmatureComponent; if (_isPrefab()) { return; } // _nowTime = System.DateTime.Now.Ticks; _sortingLayerNames = _getSortingLayerNames(); _sortingLayerIndex = _sortingLayerNames.IndexOf(_armatureComponent.sortingLayerName); // Update armature. if ( !EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature == null && _armatureComponent.unityData != null && !string.IsNullOrEmpty(_armatureComponent.armatureName) ) { //clear cache UnityFactory.factory.Clear(true); // Load data. var dragonBonesData = UnityFactory.factory.LoadData(_armatureComponent.unityData); // Refresh texture atlas. UnityFactory.factory.RefreshAllTextureAtlas(_armatureComponent); // Refresh armature. UnityEditor.ChangeArmatureData(_armatureComponent, _armatureComponent.armatureName, dragonBonesData.name); // Refresh texture. _armatureComponent.armature.InvalidUpdate(null, true); // Play animation. if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { _armatureComponent.animation.Play(_armatureComponent.animationName); } _armatureComponent.CollectBones(); } // Update hideFlags. if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature != null && _armatureComponent.armature.parent != null ) { _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable; } else { _armatureComponent.gameObject.hideFlags = HideFlags.None; } _updateParameters(); }
private void SetUnityDragonBonesData() { List <string> textureAtlasJSONs = new List <string>(); UnityEditor.GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(_dragonBoneJSONData.GetInstanceID())); UnityDragonBonesData.TextureAtlas[] textureAtlas = UnityEditor.GetTextureAtlasByJSONs(textureAtlasJSONs); UnityDragonBonesData data = UnityEditor.CreateUnityDragonBonesData(_dragonBoneJSONData, textureAtlas); _armatureComp.unityData = data; }
public static bool ChangeDragonBonesData(UnityArmatureComponent _armatureComponent, TextAsset dragonBoneJSON) { if (dragonBoneJSON != null) { var textureAtlasJSONs = new List <string>(); UnityEditor.GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBoneJSON.GetInstanceID())); UnityDragonBonesData.TextureAtlas[] textureAtlas = UnityEditor.GetTextureAtlasByJSONs(textureAtlasJSONs); UnityDragonBonesData data = UnityEditor.CreateUnityDragonBonesData(dragonBoneJSON, textureAtlas); _armatureComponent.unityData = data; var dragonBonesData = UnityFactory.factory.LoadData(data, _armatureComponent.isUGUI); if (dragonBonesData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.unityData = data; var armatureName = dragonBonesData.armatureNames[0]; ChangeArmatureData(_armatureComponent, armatureName, _armatureComponent.unityData.dataName); _armatureComponent.gameObject.name = armatureName; EditorUtility.SetDirty(_armatureComponent); return(true); } else { EditorUtility.DisplayDialog("Error", "Could not load dragonBones data.", "OK", null); return(false); } } else if (_armatureComponent.unityData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.unityData = null; if (_armatureComponent.armature != null) { _armatureComponent.Dispose(false); } EditorUtility.SetDirty(_armatureComponent); return(true); } return(false); }
void DrawAnimations() { if (_animationNames != null && _animationNames.Count > 0) { if (GUILayout.Button("Setup Pose", GUILayout.Width(105), GUILayout.Height(18))) { if (_previewUnityArmatureComp != null) { var armatureName = _armatureNames[_armatureIndex]; _previewUnityArmatureComp.unityData = _unityDragonbonesData; UnityEditor.ChangeArmatureData(_previewUnityArmatureComp, armatureName, _unityDragonbonesData.dataName); UpdateParameters(); SetEnabledRecursive(_previewUnityArmatureComp.gameObject, false); } } idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton); if (activePlayButtonStyle == null) { activePlayButtonStyle = new GUIStyle(idlePlayButtonStyle); activePlayButtonStyle.normal.textColor = Color.red; } if (activePlayButtonStyle == null) { activePlayButtonStyle = new GUIStyle(idlePlayButtonStyle); activePlayButtonStyle.normal.textColor = Color.red; } _foldAnimation = EditorGUILayout.Foldout(_foldAnimation, "Animations"); if (_foldAnimation) { EditorGUILayout.LabelField("Name", " Duration"); foreach (string animation in _animationNames) { using (new GUILayout.HorizontalScope()) { AnimationData animData = _previewUnityArmatureComp.armature.armatureData.GetAnimation(animation); bool active = _previewUnityArmatureComp.animationName == animation; if (GUILayout.Button("\u25BA", active ? activePlayButtonStyle : idlePlayButtonStyle, GUILayout.Width(24))) { this._animData = animData; _previewUnityArmatureComp.animationName = animation; _previewUnityArmatureComp.animation.Play(animation); } string frameCountString = (_frameRate > 0) ? ("(" + (Mathf.RoundToInt(animData.duration / _frameRate)) + ")").PadLeft(12, ' ') : string.Empty; EditorGUILayout.LabelField(new GUIContent(animation), new GUIContent(animData.duration.ToString("f3") + "s" + frameCountString)); } } } } }
void DrawArmatures() { if (_armatureNames != null && _armatureNames.Count > 0) { var armatureIndex = EditorGUILayout.Popup("Armature", _armatureIndex, _armatureNames.ToArray()); if (_armatureIndex != armatureIndex) { _armatureIndex = armatureIndex; var armatureName = _armatureNames[_armatureIndex]; _previewUnityArmatureComp.unityData = _unityDragonbonesData; UnityEditor.ChangeArmatureData(_previewUnityArmatureComp, armatureName, _unityDragonbonesData.dataName); UpdateParameters(); SetEnabledRecursive(_previewUnityArmatureComp.gameObject, false); } } }
void OnEnable() { this._armatureComponent = target as UnityArmatureComponent; if (_IsPrefab()) { return; } // this._nowTime = System.DateTime.Now.Ticks; this._sortingModeIndex = (int)this._armatureComponent.sortingMode; this._sortingLayerNames = _GetSortingLayerNames(); this._sortingLayerIndex = this._sortingLayerNames.IndexOf(this._armatureComponent.sortingLayerName); this._playTimesPro = serializedObject.FindProperty("_playTimes"); this._timeScalePro = serializedObject.FindProperty("_timeScale"); this._flipXPro = serializedObject.FindProperty("_flipX"); this._flipYPro = serializedObject.FindProperty("_flipY"); this._closeCombineMeshsPro = serializedObject.FindProperty("_closeCombineMeshs"); // Update armature. if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature == null && _armatureComponent.unityData != null && !string.IsNullOrEmpty(_armatureComponent.armatureName)) { // Clear cache UnityFactory.factory.Clear(true); // Unload EditorUtility.UnloadUnusedAssetsImmediate(); System.GC.Collect(); // Load data. var dragonBonesData = UnityFactory.factory.LoadData(_armatureComponent.unityData); // Refresh texture atlas. UnityFactory.factory.RefreshAllTextureAtlas(_armatureComponent); // Refresh armature. UnityEditor.ChangeArmatureData(_armatureComponent, _armatureComponent.armatureName, dragonBonesData.name); // Refresh texture. _armatureComponent.armature.InvalidUpdate(null, true); // Play animation. if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); } } // Update hideFlags. if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature != null && _armatureComponent.armature.parent != null) { _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable; } else { _armatureComponent.gameObject.hideFlags = HideFlags.None; } _UpdateParameters(); }
public override void OnInspectorGUI() { if (_IsPrefab()) { return; } serializedObject.Update(); if (_armatureIndex == -1) { _UpdateParameters(); } // DragonBones Data EditorGUILayout.BeginHorizontal(); _armatureComponent.unityData = EditorGUILayout.ObjectField("DragonBones Data", _armatureComponent.unityData, typeof(UnityDragonBonesData), false) as UnityDragonBonesData; var created = false; if (_armatureComponent.unityData != null) { if (_armatureComponent.armature == null) { if (GUILayout.Button("Create")) { created = true; } } else { if (GUILayout.Button("Reload")) { if (EditorUtility.DisplayDialog("DragonBones Alert", "Are you sure you want to reload data", "Yes", "No")) { created = true; } } } } else { //create UnityDragonBonesData by a json data if (GUILayout.Button("JSON")) { PickJsonDataWindow.OpenWindow(_armatureComponent); } } if (created) { //clear cache UnityFactory.factory.Clear(true); ClearUp(); _armatureComponent.animationName = null; if (UnityEditor.ChangeDragonBonesData(_armatureComponent, _armatureComponent.unityData.dragonBonesJSON)) { _UpdateParameters(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_armatureComponent.armature != null) { var dragonBonesData = _armatureComponent.armature.armatureData.parent; // Armature if (UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) && _armatureNames != null) { var armatureIndex = EditorGUILayout.Popup("Armature", _armatureIndex, _armatureNames.ToArray()); if (_armatureIndex != armatureIndex) { _armatureIndex = armatureIndex; var armatureName = _armatureNames[_armatureIndex]; UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); UpdateBaseAnimation(); UpdateAnimation(); _UpdateParameters(); _armatureComponent.gameObject.name = armatureName; MarkSceneDirty(); } } // Armature Base Animation if (UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) && _armatureNames != null && _armatureBaseNames != null) { var armatureIndex = EditorGUILayout.Popup("Base animation", _armatureBaseIndex, _armatureBaseNames.ToArray()); if (_armatureBaseIndex != armatureIndex && _armatureIndex != -1) { _armatureBaseIndex = armatureIndex; if (_armatureBaseIndex == 0) { var armatureName = _armatureNames[_armatureIndex]; UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); _armatureComponent.gameObject.name = armatureName; UnityEditor.ReplaceAnimation(_armatureComponent, null); } else { UpdateBaseAnimation(); } UpdateAnimation(); _UpdateParameters(); MarkSceneDirty(); } } // Animation if (_animationNames != null && _animationNames.Count > 0) { EditorGUILayout.BeginHorizontal(); List <string> anims = new List <string>(_animationNames); anims.Insert(0, "<None>"); var animationIndex = EditorGUILayout.Popup("Animation", _animationIndex + 1, anims.ToArray()) - 1; if (animationIndex != _animationIndex) { _animationIndex = animationIndex; UpdateAnimation(); MarkSceneDirty(); } if (_animationIndex >= 0) { if (_armatureComponent.animation.isPlaying) { if (GUILayout.Button("Stop")) { _armatureComponent.animation.Stop(); } } else { if (GUILayout.Button("Play")) { _armatureComponent.animation.Play(null, _playTimesPro.intValue); } } } EditorGUILayout.EndHorizontal(); //playTimes EditorGUILayout.BeginHorizontal(); var playTimes = _playTimesPro.intValue; EditorGUILayout.PropertyField(_playTimesPro, false); if (playTimes != _playTimesPro.intValue) { if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { _armatureComponent.animation.Reset(); _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); } } EditorGUILayout.EndHorizontal(); // TimeScale var timeScale = _timeScalePro.floatValue; EditorGUILayout.PropertyField(_timeScalePro, false); if (timeScale != _timeScalePro.floatValue) { _armatureComponent.animation.timeScale = _timeScalePro.floatValue; } } // EditorGUILayout.Space(); if (!_armatureComponent.isUGUI) { //Sorting Mode _sortingModeIndex = EditorGUILayout.Popup("Sorting Mode", (int)_armatureComponent.sortingMode, _sortingMode); if (_sortingModeIndex != (int)_armatureComponent.sortingMode) { Undo.RecordObject(_armatureComponent, "Sorting Mode"); _armatureComponent.sortingMode = (SortingMode)_sortingModeIndex; // 里面return了,没有赋值成功 if (_armatureComponent.sortingMode != (SortingMode)_sortingModeIndex) { _sortingModeIndex = (int)_armatureComponent.sortingMode; } MarkSceneDirty(); } // Sorting Layer _sortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", _sortingLayerIndex, _sortingLayerNames.ToArray()); if (_sortingLayerNames[_sortingLayerIndex] != _armatureComponent.sortingLayerName) { Undo.RecordObject(_armatureComponent, "Sorting Layer"); _armatureComponent.sortingLayerName = _sortingLayerNames[_sortingLayerIndex]; MarkSceneDirty(); } // Sorting Order var sortingOrder = EditorGUILayout.IntField("Order in Layer", _armatureComponent.sortingOrder); if (sortingOrder != _armatureComponent.sortingOrder) { Undo.RecordObject(_armatureComponent, "Edit Sorting Order"); _armatureComponent.sortingOrder = sortingOrder; MarkSceneDirty(); } // ZSpace EditorGUILayout.BeginHorizontal(); _armatureComponent.zSpace = EditorGUILayout.Slider("Z Space", _armatureComponent.zSpace, 0.0f, 0.5f); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); // Flip EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Flip"); var flipX = _flipXPro.boolValue; var flipY = _flipYPro.boolValue; _flipXPro.boolValue = GUILayout.Toggle(_flipXPro.boolValue, "X", GUILayout.Width(30)); _flipYPro.boolValue = GUILayout.Toggle(_flipYPro.boolValue, "Y", GUILayout.Width(30)); if (flipX != _flipXPro.boolValue || flipY != _flipYPro.boolValue) { _armatureComponent.armature.flipX = _flipXPro.boolValue; _armatureComponent.armature.flipY = _flipYPro.boolValue; MarkSceneDirty(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } if (_armatureComponent.armature != null && _armatureComponent.armature.parent == null) { if (!Application.isPlaying && !this._armatureComponent.isUGUI) { // var oldValue = this._closeCombineMeshsPro.boolValue; if (!this._closeCombineMeshsPro.boolValue) { this._closeCombineMeshsPro.boolValue = EditorGUILayout.Toggle("CloseCombineMeshs", this._closeCombineMeshsPro.boolValue); if (GUILayout.Button("Show Slots")) { ShowSlotsWindow.OpenWindow(this._armatureComponent); } } if (oldValue != this._closeCombineMeshsPro.boolValue) { if (this._closeCombineMeshsPro.boolValue) { this._armatureComponent.CloseCombineMeshs(); } } } } serializedObject.ApplyModifiedProperties(); if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }
public override void OnInspectorGUI() { if (_armatureIndex == -1) { _updateParameters(); } // DragonBones Data EditorGUILayout.BeginHorizontal(); _armatureComponent.unityData = EditorGUILayout.ObjectField("DragonBones Data", _armatureComponent.unityData, typeof(UnityDragonBonesData), false) as UnityDragonBonesData; var created = false; if (_armatureComponent.unityData != null) { if (_armatureComponent.armature == null) { if (GUILayout.Button("Create")) { created = true; } } else { if (GUILayout.Button("Reload")) { if (EditorUtility.DisplayDialog("DragonBones Alert", "Are you sure you want to reload data", "Yes", "No")) { created = true; } } } } if (created) { //clear cache UnityFactory.factory.Clear(true); _armatureNames = null; _animationNames = null; _armatureIndex = -1; _animationIndex = -1; _armatureComponent.animationName = null; if (UnityEditor.ChangeDragonBonesData(_armatureComponent, _armatureComponent.unityData.dragonBonesJSON)) { _armatureComponent.CollectBones(); _updateParameters(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_armatureComponent.armature != null) { var dragonBonesData = _armatureComponent.armature.armatureData.parent; // Armature if (UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) && _armatureNames != null) { var armatureIndex = EditorGUILayout.Popup("Armature", _armatureIndex, _armatureNames.ToArray()); if (_armatureIndex != armatureIndex) { _armatureIndex = armatureIndex; var armatureName = _armatureNames[_armatureIndex]; UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); _updateParameters(); if (_armatureComponent.bonesRoot != null && _armatureComponent.unityBones != null) { _armatureComponent.ShowBones(); } _armatureComponent.gameObject.name = armatureName; _armatureComponent.zorderIsDirty = true; EditorUtility.SetDirty(_armatureComponent); if (!Application.isPlaying && !_isPrefab()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } // Animation if (_animationNames != null && _animationNames.Count > 0) { EditorGUILayout.BeginHorizontal(); List <string> anims = new List <string>(_animationNames); anims.Insert(0, "<None>"); var animationIndex = EditorGUILayout.Popup("Animation", _animationIndex + 1, anims.ToArray()) - 1; if (animationIndex != _animationIndex) { _animationIndex = animationIndex; if (animationIndex >= 0) { _armatureComponent.animationName = _animationNames[animationIndex]; _armatureComponent.animation.Play(_armatureComponent.animationName); _updateParameters(); } else { _armatureComponent.animationName = null; _armatureComponent.animation.Stop(); } EditorUtility.SetDirty(_armatureComponent); if (!Application.isPlaying && !_isPrefab()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } if (_animationIndex >= 0) { if (_armatureComponent.animation.isPlaying) { if (GUILayout.Button("Stop")) { _armatureComponent.animation.Stop(); } } else { if (GUILayout.Button("Play")) { _armatureComponent.animation.Play(); } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (!_armatureComponent.isUGUI) { bool haveSpriteGorup = false; #if UNITY_5_6_OR_NEWER haveSpriteGorup = _armatureComponent.GetComponent <UnityEngine.Rendering.SortingGroup>() != null; #endif if (!haveSpriteGorup) { //sort mode serializedObject.Update(); EditorGUILayout.PropertyField(serializedObject.FindProperty("sortingMode"), true); serializedObject.ApplyModifiedProperties(); // Sorting Layer _sortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", _sortingLayerIndex, _sortingLayerNames.ToArray()); if (_sortingLayerNames[_sortingLayerIndex] != _armatureComponent.sortingLayerName) { Undo.RecordObject(_armatureComponent, "Sorting Layer"); _armatureComponent.sortingLayerName = _sortingLayerNames[_sortingLayerIndex]; EditorUtility.SetDirty(_armatureComponent); if (!Application.isPlaying && !_isPrefab()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } if (_armatureComponent.sortingMode == SortingMode.SortByZ) { // Sorting Order var sortingOrder = EditorGUILayout.IntField("Order in Layer", _armatureComponent.sortingOrder); if (sortingOrder != _armatureComponent.sortingOrder) { Undo.RecordObject(_armatureComponent, "Edit Sorting Order"); _armatureComponent.sortingOrder = sortingOrder; EditorUtility.SetDirty(_armatureComponent); if (!Application.isPlaying && !_isPrefab()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } } // ZSpace EditorGUILayout.BeginHorizontal(); _armatureComponent.zSpace = EditorGUILayout.Slider("Z Space", _armatureComponent.zSpace, 0.0f, 0.2f); EditorGUILayout.EndHorizontal(); } // TimeScale EditorGUILayout.BeginHorizontal(); _armatureComponent.animation.timeScale = EditorGUILayout.Slider("Time Scale", _armatureComponent.animation.timeScale, 0.0f, 2.0f); EditorGUILayout.EndHorizontal(); // Flip EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Flip"); bool flipX = _armatureComponent.flipX; bool flipY = _armatureComponent.flipY; _armatureComponent.flipX = GUILayout.Toggle(_armatureComponent.flipX, "X", GUILayout.Width(30)); _armatureComponent.flipY = GUILayout.Toggle(_armatureComponent.flipY, "Y", GUILayout.Width(30)); _armatureComponent.armature.flipX = _armatureComponent.flipX; _armatureComponent.armature.flipY = _armatureComponent.flipY; if (_armatureComponent.flipX != flipX || _armatureComponent.flipY != flipY) { EditorUtility.SetDirty(_armatureComponent); if (!Application.isPlaying && !_isPrefab()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } EditorGUILayout.EndHorizontal(); //normals EditorGUILayout.BeginHorizontal(); _armatureComponent.addNormal = EditorGUILayout.Toggle("Normals", _armatureComponent.addNormal); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } if (_armatureComponent.armature != null && _armatureComponent.armature.parent == null) { if (_armatureComponent.unityBones != null && _armatureComponent.bonesRoot != null) { _armatureComponent.boneHierarchy = EditorGUILayout.Toggle("Bone Hierarchy", _armatureComponent.boneHierarchy); } EditorGUILayout.BeginHorizontal(); if (!Application.isPlaying) { if (_armatureComponent.unityBones != null && _armatureComponent.bonesRoot != null) { if (GUILayout.Button("Remove Bones", GUILayout.Height(20))) { if (EditorUtility.DisplayDialog("DragonBones Alert", "Are you sure you want to remove bones", "Yes", "No")) { _armatureComponent.RemoveBones(); } } } else { if (GUILayout.Button("Show Bones", GUILayout.Height(20))) { _armatureComponent.ShowBones(); } } } if (!Application.isPlaying && !_armatureComponent.isUGUI) { UnityCombineMesh ucm = _armatureComponent.gameObject.GetComponent <UnityCombineMesh>(); if (!ucm) { if (GUILayout.Button("Add Mesh Combine", GUILayout.Height(20))) { ucm = _armatureComponent.gameObject.AddComponent <UnityCombineMesh>(); } } } EditorGUILayout.EndHorizontal(); } if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }
public override void OnInspectorGUI() { if (_IsPrefab()) { return; } serializedObject.Update(); if (_armatureIndex == -1) { _UpdateParameters(); } // DragonBones Data EditorGUILayout.BeginHorizontal(); _armatureComponent.unityData = EditorGUILayout.ObjectField("DragonBones Data", _armatureComponent.unityData, typeof(UnityDragonBonesData), false) as UnityDragonBonesData; var created = false; if (FindObjectsOfType <UnityArmatureComponent>().Length <= 1) { if (_armatureComponent.unityData != null) { if (_armatureComponent.armature == null) { if (GUILayout.Button("Create")) { created = true; } } /*else * { * if (GUILayout.Button("Reload")) * { * if (EditorUtility.DisplayDialog("DragonBones Alert", "Are you sure you want to reload data", "Yes", "No")) * { * created = true; * } * } * }*/ } else { //create UnityDragonBonesData by a json data if (GUILayout.Button("JSON")) { PickJsonDataWindow.OpenWindow(_armatureComponent); } } } else { if (GUILayout.Button("Info")) { EditorUtility.DisplayDialog("DragonBones Alert", "У вас на сцене 2 или больше Game Object-ов с UnityArmatureComponent, " + "если вы хотите инициализировать новую модель, то нужно, чтобы на сцене был только " + "один Game Object c UnityArmatureComponent! ", "Понял!"); } } if (created) { //clear cache UnityFactory.factory.Clear(true); ClearUp(); _armatureComponent.animationName = null; if (UnityEditor.ChangeDragonBonesData(_armatureComponent, _armatureComponent.unityData.dragonBonesJSON)) { _armatureComponent.CollectBones(); _UpdateParameters(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_armatureComponent.armature != null) { var dragonBonesData = _armatureComponent.armature.armatureData.parent; // Armature if (UnityFactory.factory.GetAllDragonBonesData().ContainsValue(dragonBonesData) && _armatureNames != null) { var armatureIndex = EditorGUILayout.Popup("Armature", _armatureIndex, _armatureNames.ToArray()); if (_armatureIndex != armatureIndex) { _armatureIndex = armatureIndex; var armatureName = _armatureNames[_armatureIndex]; UnityEditor.ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); _UpdateParameters(); if (_armatureComponent.bonesRoot != null && _armatureComponent.unityBones != null) { _armatureComponent.ShowBones(); } _armatureComponent.gameObject.name = armatureName; MarkSceneDirty(); } } // Animation if (_animationNames != null && _animationNames.Count > 0) { EditorGUILayout.BeginHorizontal(); List <string> anims = new List <string>(_animationNames); anims.Insert(0, "<None>"); var animationIndex = EditorGUILayout.Popup("Animation", _animationIndex + 1, anims.ToArray()) - 1; if (animationIndex != _animationIndex) { _animationIndex = animationIndex; if (animationIndex >= 0) { _armatureComponent.animationName = _animationNames[animationIndex]; var animationData = _armatureComponent.animation.animations[_armatureComponent.animationName]; _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); _UpdateParameters(); } else { _armatureComponent.animationName = null; _playTimesPro.intValue = 0; _armatureComponent.animation.Stop(); } MarkSceneDirty(); } if (_animationIndex >= 0) { if (_armatureComponent.animation.isPlaying) { if (GUILayout.Button("Stop")) { _armatureComponent.animation.Stop(); } } else { if (GUILayout.Button("Play")) { _armatureComponent.animation.Play(null, _playTimesPro.intValue); } } } EditorGUILayout.EndHorizontal(); //playTimes EditorGUILayout.BeginHorizontal(); var playTimes = _playTimesPro.intValue; EditorGUILayout.PropertyField(_playTimesPro, false); if (playTimes != _playTimesPro.intValue) { if (!string.IsNullOrEmpty(_armatureComponent.animationName)) { _armatureComponent.animation.Reset(); _armatureComponent.animation.Play(_armatureComponent.animationName, _playTimesPro.intValue); } } EditorGUILayout.EndHorizontal(); // TimeScale var timeScale = _timeScalePro.floatValue; EditorGUILayout.PropertyField(_timeScalePro, false); if (timeScale != _timeScalePro.floatValue) { _armatureComponent.animation.timeScale = _timeScalePro.floatValue; } } // EditorGUILayout.Space(); if (!_armatureComponent.isUGUI) { //Sorting Mode _sortingModeIndex = EditorGUILayout.Popup("Sorting Mode", (int)_armatureComponent.sortingMode, _sortingMode.ToArray()); if (_sortingModeIndex != (int)_armatureComponent.sortingMode) { Undo.RecordObject(_armatureComponent, "Sorting Mode"); _armatureComponent.sortingMode = (SortingMode)_sortingModeIndex; // 里面return了,没有赋值成功 if (_armatureComponent.sortingMode != (SortingMode)_sortingModeIndex) { _sortingModeIndex = (int)_armatureComponent.sortingMode; } MarkSceneDirty(); } // Sorting Layer _sortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", _sortingLayerIndex, _sortingLayerNames.ToArray()); if (_sortingLayerNames[_sortingLayerIndex] != _armatureComponent.sortingLayerName) { Undo.RecordObject(_armatureComponent, "Sorting Layer"); _armatureComponent.sortingLayerName = _sortingLayerNames[_sortingLayerIndex]; MarkSceneDirty(); } // Sorting Order var sortingOrder = EditorGUILayout.IntField("Order in Layer", _armatureComponent.sortingOrder); if (sortingOrder != _armatureComponent.sortingOrder) { Undo.RecordObject(_armatureComponent, "Edit Sorting Order"); _armatureComponent.sortingOrder = sortingOrder; MarkSceneDirty(); } // ZSpace EditorGUILayout.BeginHorizontal(); _armatureComponent.zSpace = EditorGUILayout.Slider("Z Space", _armatureComponent.zSpace, 0.0f, 0.5f); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); // Flip EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Flip"); var flipX = _flipXPro.boolValue; var flipY = _flipYPro.boolValue; _flipXPro.boolValue = GUILayout.Toggle(_flipXPro.boolValue, "X", GUILayout.Width(30)); _flipYPro.boolValue = GUILayout.Toggle(_flipYPro.boolValue, "Y", GUILayout.Width(30)); if (flipX != _flipXPro.boolValue || flipY != _flipYPro.boolValue) { _armatureComponent.armature.flipX = _flipXPro.boolValue; _armatureComponent.armature.flipY = _flipYPro.boolValue; MarkSceneDirty(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //normals EditorGUILayout.BeginHorizontal(); _armatureComponent.addNormal = EditorGUILayout.Toggle("Normals", _armatureComponent.addNormal); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } if (_armatureComponent.armature != null && _armatureComponent.armature.parent == null) { if (_armatureComponent.unityBones != null && _armatureComponent.bonesRoot != null) { _armatureComponent.boneHierarchy = EditorGUILayout.Toggle("Bone Hierarchy", _armatureComponent.boneHierarchy); } EditorGUILayout.BeginHorizontal(); if (!Application.isPlaying) { if (_armatureComponent.unityBones != null && _armatureComponent.bonesRoot != null) { if (GUILayout.Button("Remove Bones", GUILayout.Height(20))) { if (EditorUtility.DisplayDialog("DragonBones Alert", "Are you sure you want to remove bones", "Yes", "No")) { _armatureComponent.RemoveBones(); } } } else { if (GUILayout.Button("Show Bones", GUILayout.Height(20))) { _armatureComponent.ShowBones(); } } } if (!Application.isPlaying && !_armatureComponent.isUGUI) { UnityCombineMesh ucm = _armatureComponent.gameObject.GetComponent <UnityCombineMesh>(); if (!ucm) { if (GUILayout.Button("Add Mesh Combine", GUILayout.Height(20))) { ucm = _armatureComponent.gameObject.AddComponent <UnityCombineMesh>(); } } } EditorGUILayout.EndHorizontal(); } serializedObject.ApplyModifiedProperties(); if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }
public static bool ChangeDragonBonesData(UnityArmatureComponent _armatureComponent, TextAsset dragonBoneJSON) { if (dragonBoneJSON != null) { var textureAtlasJSONs = new List <string>(); UnityEditor.GetTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBoneJSON.GetInstanceID())); /*UnityDragonBonesData.TextureAtlas[] textureAtlas = new UnityDragonBonesData.TextureAtlas[textureAtlasJSONs.Count]; * for(int i = 0;i < textureAtlasJSONs.Count; ++i) * { * string path = textureAtlasJSONs[i]; * //load textureAtlas data * UnityDragonBonesData.TextureAtlas ta = new UnityDragonBonesData.TextureAtlas(); * ta.textureAtlasJSON = AssetDatabase.LoadAssetAtPath<TextAsset>(path); * //load texture * path = path.Substring(0,path.LastIndexOf(".json")); * ta.texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path+".png"); * //load material * ta.material = AssetDatabase.LoadAssetAtPath<Material>(path+"_Mat.mat"); * ta.uiMaterial = AssetDatabase.LoadAssetAtPath<Material>(path+"_UI_Mat.mat"); * textureAtlas[i] = ta; * }*/ UnityDragonBonesData.TextureAtlas[] textureAtlas = UnityEditor.GetTextureAtlasByJSONs(textureAtlasJSONs); UnityDragonBonesData data = UnityEditor.CreateUnityDragonBonesData(dragonBoneJSON, textureAtlas); _armatureComponent.unityData = data; var dragonBonesData = UnityFactory.factory.LoadData(data, _armatureComponent.isUGUI); if (dragonBonesData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.unityData = data; var armatureName = dragonBonesData.armatureNames[0]; ChangeArmatureData(_armatureComponent, armatureName, dragonBonesData.name); _armatureComponent.gameObject.name = armatureName; EditorUtility.SetDirty(_armatureComponent); return(true); } else { EditorUtility.DisplayDialog("Error", "Could not load dragonBones data.", "OK", null); return(false); } } else if (_armatureComponent.unityData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.unityData = null; if (_armatureComponent.armature != null) { _armatureComponent.Dispose(false); } EditorUtility.SetDirty(_armatureComponent); return(true); } return(false); }