/// <summary> /// - Create a factory instance. (typically only one global factory instance is required) /// </summary> /// <version>DragonBones 3.0</version> /// <language>en_US</language> /// <summary> /// - 创建一个工厂实例。 (通常只需要一个全局工厂实例) /// </summary> /// <version>DragonBones 3.0</version> /// <language>zh_CN</language> public BaseFactory(DataParser dataParser = null) { if (BaseFactory._objectParser == null) { BaseFactory._objectParser = new ObjectDataParser(); } if (BaseFactory._binaryParser == null) { BaseFactory._binaryParser = new BinaryDataParser(); } this._dataParser = dataParser != null ? dataParser : BaseFactory._objectParser; }
public static UnityDragonBonesData CreateUnityDragonBonesData(TextAsset dragonBonesAsset, UnityDragonBonesData.TextureAtlas[] textureAtlas) { if (dragonBonesAsset != null) { bool isDirty = false; string path = AssetDatabase.GetAssetPath(dragonBonesAsset); path = path.Substring(0, path.Length - 5); int index = path.LastIndexOf("_ske"); if (index > 0) { path = path.Substring(0, index); } // string dataPath = path + "_Data.asset"; var jsonObject = (Dictionary <string, object>)MiniJSON.Json.Deserialize(dragonBonesAsset.text); if (dragonBonesAsset.text == "DBDT") { int headerLength = 0; jsonObject = BinaryDataParser.DeserializeBinaryJsonData(dragonBonesAsset.bytes, out headerLength); } else { jsonObject = MiniJSON.Json.Deserialize(dragonBonesAsset.text) as Dictionary <string, object>; } var dataName = jsonObject.ContainsKey("name") ? jsonObject["name"] as string : ""; //先从缓存里面取 UnityDragonBonesData data = UnityFactory.factory.GetCacheUnityDragonBonesData(dataName); //缓存中没有,从资源里面取 if (data == null) { data = AssetDatabase.LoadAssetAtPath <UnityDragonBonesData>(dataPath); } //资源里面也没有,那么重新创建 if (data == null) { data = UnityDragonBonesData.CreateInstance <UnityDragonBonesData>(); data.dataName = dataName; AssetDatabase.CreateAsset(data, dataPath); isDirty = true; } // if (string.IsNullOrEmpty(data.dataName) || !data.dataName.Equals(dataName)) { //走到这里,说明原先已经创建了,之后手动改了名字,既然又走了创建流程,那么名字也重置下 data.dataName = dataName; isDirty = true; } if (data.dragonBonesJSON != dragonBonesAsset) { data.dragonBonesJSON = dragonBonesAsset; isDirty = true; } if (textureAtlas != null && textureAtlas.Length > 0 && textureAtlas[0] != null && textureAtlas[0].texture != null) { if (data.textureAtlas == null || data.textureAtlas.Length != textureAtlas.Length) { isDirty = true; } else { for (int i = 0; i < textureAtlas.Length; ++i) { if (textureAtlas[i].material != data.textureAtlas[i].material || textureAtlas[i].uiMaterial != data.textureAtlas[i].uiMaterial || textureAtlas[i].texture != data.textureAtlas[i].texture || textureAtlas[i].textureAtlasJSON != data.textureAtlas[i].textureAtlasJSON ) { isDirty = true; break; } } } data.textureAtlas = textureAtlas; } if (isDirty) { AssetDatabase.Refresh(); EditorUtility.SetDirty(data); } // UnityFactory.factory.AddCacheUnityDragonBonesData(data); AssetDatabase.SaveAssets(); return(data); } return(null); }