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(); }
void OnEnable() { _armatureComponent = target as UnityArmatureComponent; _dragonBoneJSON = _armatureComponent == null ? null : _armatureComponent.dragonBonesJSON; // // _nowTime = System.DateTime.Now.Ticks; _sortingLayerNames = _getSortingLayerNames(); _sortingLayerIndex = _sortingLayerNames.IndexOf(_armatureComponent.sortingLayerName); // Update armature. if ( !EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature == null && _armatureComponent.dragonBonesJSON != null && !string.IsNullOrEmpty(_armatureComponent.armatureName) ) { // Load data. var dragonBonesData = _armatureComponent.LoadData(_armatureComponent.dragonBonesJSON, _armatureComponent.textureAtlasJSON); // Refresh texture atlas. UnityFactory.factory.RefreshAllTextureAtlas(); // Refresh armature. _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); } } // 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 static bool _changeDragonBonesData(UnityArmatureComponent _armatureComponent, TextAsset dragonBoneJSON) { if (dragonBoneJSON != null) { var textureAtlasJSONs = new List <string>(); _getTextureAtlasConfigs(textureAtlasJSONs, AssetDatabase.GetAssetPath(dragonBoneJSON.GetInstanceID())); var dragonBonesData = _armatureComponent.LoadData(dragonBoneJSON, textureAtlasJSONs); if (dragonBonesData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.dragonBonesJSON = dragonBoneJSON; _armatureComponent.textureAtlasJSON = textureAtlasJSONs; //_clearGameObjectChildren(_armatureComponent.gameObject); 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.dragonBonesJSON != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.dragonBonesJSON = null; if (_armatureComponent.armature != null) { _armatureComponent.Dispose(false); } //_clearGameObjectChildren(_armatureComponent.gameObject); EditorUtility.SetDirty(_armatureComponent); return(true); } return(false); }
static int LoadData(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); DragonBones.UnityArmatureComponent obj = (DragonBones.UnityArmatureComponent)ToLua.CheckObject <DragonBones.UnityArmatureComponent>(L, 1); UnityEngine.TextAsset arg0 = (UnityEngine.TextAsset)ToLua.CheckObject <UnityEngine.TextAsset>(L, 2); System.Collections.Generic.List <string> arg1 = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 3, typeof(System.Collections.Generic.List <string>)); DragonBones.DragonBonesData o = obj.LoadData(arg0, arg1); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void OnEnable() { _armatureComponent = this.target as UnityArmatureComponent; _dragonBoneJSON = _armatureComponent == null ? null : _armatureComponent.dragonBonesJSON; // _nowTime = System.DateTime.Now.Ticks; _sortingLayerNames = _getSortingLayerNames(); _sortingLayerIndex = _getSortingLayerIndex(_armatureComponent.sortingLayerName); // Create armature. if ( !EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature == null && _armatureComponent.dragonBonesJSON != null && DragonBones.IsAvailableString(_armatureComponent.armatureName) ) { var dragonBonesData = _armatureComponent.LoadData(_armatureComponent.dragonBonesJSON, _armatureComponent.textureAtlasJSON); UnityFactory.factory.RefreshAllTextureAtlas(); _changeArmature(_armatureComponent.armatureName, dragonBonesData.name); _armatureComponent.armature.InvalidUpdate(null, true); if (DragonBones.IsAvailableString(_armatureComponent.animationName)) { _armatureComponent.animation.Play(_armatureComponent.animationName); } } // Update hideFlags. if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature != null && _armatureComponent.armature.parent != null ) { _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable; } else { _armatureComponent.gameObject.hideFlags = HideFlags.None; } // _update(); }
void Awake() { _nowTime = System.DateTime.Now.Ticks; _armatureComponent = this.target as UnityArmatureComponent; _dragonBoneJSON = _armatureComponent.draggonBonesJSON; if ( !EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.draggonBonesJSON != null && _armatureComponent.armature == null ) { 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(); _sortingLayerNames = _getSortingLayerNames(); _selectedOption = _getSortingLayerIndex(_armatureComponent.sortingLayerName); // if (!EditorApplication.isPlayingOrWillChangePlaymode && _armatureComponent.armature != null && _armatureComponent.armature.parent != null ) { _armatureComponent.gameObject.hideFlags = HideFlags.NotEditable; } else { _armatureComponent.gameObject.hideFlags = HideFlags.None; } }
public override void OnInspectorGUI() { // DragonBones Data GUILayout.BeginHorizontal(); _dragonBoneJSON = EditorGUILayout.ObjectField("DragonBones Data", _dragonBoneJSON, typeof(TextAsset), false) as TextAsset; if ( _armatureComponent.dragonBonesJSON != _dragonBoneJSON && GUILayout.Button(_armatureComponent.armature == null ? "Create" : "Change") ) { if (_dragonBoneJSON != null) { var textureAtlasJSON = new List <string>(); _getTextureAtlasConfigs(textureAtlasJSON, AssetDatabase.GetAssetPath(_dragonBoneJSON.GetInstanceID())); var dragonBonesData = _armatureComponent.LoadData(_dragonBoneJSON, textureAtlasJSON); if (dragonBonesData != null) { _armatureComponent.dragonBonesJSON = _dragonBoneJSON; _armatureComponent.textureAtlasJSON = textureAtlasJSON; _clearGameObjectChildren(_armatureComponent.gameObject); _changeArmature(dragonBonesData.armatureNames[0], dragonBonesData.name); _update(); } else { _dragonBoneJSON = _armatureComponent.dragonBonesJSON; EditorUtility.DisplayDialog("Error", "Could not load dragonBones data.", "OK", null); } } else { _armatureComponent.dragonBonesJSON = null; if (_armatureComponent.armature != null) { _armatureComponent.Dispose(false); } _clearGameObjectChildren(_armatureComponent.gameObject); } } GUILayout.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; _clearGameObjectChildren(_armatureComponent.gameObject); _changeArmature(_armatureNames[_armatureIndex], dragonBonesData.name); _update(); EditorUtility.SetDirty(_armatureComponent); } } // Animation if (_animationNames != null && _animationNames.Count > 0) { GUILayout.BeginHorizontal(); var animationIndex = EditorGUILayout.Popup("Animation", _animationIndex, _animationNames.ToArray()); if (animationIndex != _animationIndex) { _animationIndex = animationIndex; _armatureComponent.animationName = _animationNames[animationIndex]; _armatureComponent.animation.Play(_armatureComponent.animationName); _update(); EditorUtility.SetDirty(_armatureComponent); } if (_animationIndex >= 0) { if (_armatureComponent.animation.isPlaying) { if (GUILayout.Button("Stop")) { _armatureComponent.animation.Stop(); } } else { if (GUILayout.Button("Play")) { _armatureComponent.animation.Play(); } } } GUILayout.EndHorizontal(); } EditorGUILayout.Space(); // Sorting Layer _sortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", _sortingLayerIndex, _sortingLayerNames); if (_sortingLayerNames[_sortingLayerIndex] != _armatureComponent.sortingLayerName) { Undo.RecordObject(_armatureComponent, "Sorting Layer"); _armatureComponent.sortingLayerName = _sortingLayerNames[_sortingLayerIndex]; EditorUtility.SetDirty(_armatureComponent); } // 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); } // ZSpace GUILayout.BeginHorizontal(); _armatureComponent.zSpace = EditorGUILayout.Slider("Z Space", _armatureComponent.zSpace, 0.0f, 0.2f); GUILayout.EndHorizontal(); // TimeScale GUILayout.BeginHorizontal(); _armatureComponent.animation.timeScale = EditorGUILayout.Slider("Time Scale", _armatureComponent.animation.timeScale, 0.0f, 2.0f); GUILayout.EndHorizontal(); EditorGUILayout.Space(); } if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }
public override void OnInspectorGUI() { //DrawDefaultInspector(); //EditorGUILayout.Space(); // 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 { //try //{ //var dragonBonesData = UnityFactory.factory.loadDragonBonesData(_dragonBoneJSON); //if (dragonBonesData == null) //{ //_dragonBoneJSON = _armatureComponent.draggonBonesJSON; //} //else //{ //UnityFactory.factory.removeDragonBonesData(_dragonBoneJSON.name); //} //} //catch //{ //_dragonBoneJSON = _armatureComponent.draggonBonesJSON; //} } } 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 { _changeArmature(dragonBonesData.armatureNames[0], dragonBonesData.name); _update(); } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_armatureComponent.armature != null) { _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); } 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; _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); } } // ZSpace GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Z Space", GUILayout.Width(120.0f)); _armatureComponent.zSpace = GUILayout.HorizontalSlider(_armatureComponent.zSpace, 0.0f, 20.0f); 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(); } if (!EditorApplication.isPlayingOrWillChangePlaymode && Selection.activeObject == _armatureComponent.gameObject) { EditorUtility.SetDirty(_armatureComponent); HandleUtility.Repaint(); } }
public static bool _changeDragonBonesData(UnityArmatureComponent _armatureComponent, TextAsset dragonBoneJSON, TextAsset textureAtlasJSON = null) { if (dragonBoneJSON != null) { //龙骨图集的url string texturePath = AssetDatabase.GetAssetPath(dragonBoneJSON.GetInstanceID()); string textureAtlasUrl = texturePath; string textureName = ""; string suffix = ""; if (textureAtlasJSON != null) { texturePath = textureAtlasUrl = AssetDatabase.GetAssetPath(textureAtlasJSON.GetInstanceID()); textureName = textureAtlasJSON.name; int index = textureAtlasUrl.LastIndexOf("Assets/") + 1; textureAtlasUrl = textureAtlasUrl.Substring(index + 7); //textureAtlasUrl = textureAtlasUrl.Remove(index); //index = textureAtlasUrl.IndexOf("Resources/") + "Resources/".Length; //textureAtlasUrl = textureAtlasUrl.Substring(index, textureAtlasUrl.Length - index); } else { suffix = "tex"; //textureAtlasUrl = AssetDatabase.GetAssetPath(textureAtlasJSON.GetInstanceID()); //index = textureAtlasUrl.IndexOf("Resources/"); //lastIndex = atlasUrl.LastIndexOf(".json"); //atlasUrl = atlasUrl.Substring(index + resLen, atlasUrl.Length - (index + resLen + ".json".Length)); } var textureAtlasJSONs = new List <string>(); _getTextureAtlasConfigs(textureAtlasJSONs, texturePath, null, suffix); var dragonBonesData = _armatureComponent.LoadData(dragonBoneJSON, textureAtlasJSONs); if (dragonBonesData != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.dragonBonesJSON = dragonBoneJSON; _armatureComponent.textureAtlasJSON = textureAtlasJSONs; _armatureComponent.textureAtlasName = textureName; _clearGameObjectChildren(_armatureComponent.gameObject); UnityFactory.factory.LoadTextureAtlasData(textureAtlasUrl + textureName, textureName); var armatureName = dragonBonesData.armatureNames[0]; _changeArmatureData(_armatureComponent, armatureName, dragonBonesData.name, _armatureComponent.textureAtlasName); _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.dragonBonesJSON != null) { Undo.RecordObject(_armatureComponent, "Set DragonBones"); _armatureComponent.dragonBonesJSON = null; if (_armatureComponent.armature != null) { _armatureComponent.Dispose(false); } EditorUtility.SetDirty(_armatureComponent); return(true); } return(false); }