static void SaveEnemyPrefab(AssetMetaData pEnemy, ref StringBuilder pResources) { if (pEnemy == null) { return; } Enemy aEnemy = AssetDatabase.LoadAssetAtPath <Enemy>(AssetDatabase.GUIDToAssetPath(pEnemy.mGUID)); string aEnemyFilePath = "/Assets/Resources/Prefabs/" + aEnemy.mName + ".json"; pEnemy.mAssetFilePath = ".." + aEnemyFilePath; if (aEnemy.mEnemyType == Enemy.Type.ProjectileThrower) { SaveProjectile(GetAssetFromGUID(aEnemy.mProjectileGUID, AssetMetaData.AssetType.PrefabAsset), ref pResources); } SaveAssetData(GetAssetFromGUID(aEnemy.mEnemyAnimations[0].mTextureAssetGUID, AssetMetaData.AssetType.TextureAsset), ref pResources); if (!IsAssetInResources(Application.dataPath + aEnemyFilePath)) { GEnemy aEnemyComp = new GEnemy(); aEnemyComp.mType = aEnemy.mEnemyType; aEnemyComp.mSpeed = aEnemy.mSpeed; aEnemyComp.mStopRange = aEnemy.mStopRange; if (aEnemyComp.mType == Enemy.Type.ProjectileThrower) { aEnemyComp.mProjectileGUID = aEnemy.mProjectileGUID; } GSprite aSprite = new GSprite(aEnemy.mDisplaySprite.rect, aEnemy.mEnemyAnimations[0].mTextureAssetGUID, aEnemy.mDisplaySprite.texture.height, (int)aEnemy.mRenderLayer); GRigidbody aRigidBody = new GRigidbody(); GCircleCollider aCollider = new GCircleCollider(32.00001f, false); StringBuilder aEnemyObject = new StringBuilder("{\n"); aEnemyObject.Append("\"name\" : \"" + aEnemy.mName + "\",\n"); aEnemyObject.Append("\"Components\" : [\n"); aEnemyObject.Append(aSprite.ToString() + ",\n"); aEnemyObject.Append(aEnemyComp.ToString() + ",\n"); aEnemyObject.Append(aCollider.ToString() + ",\n"); aEnemyObject.Append(aRigidBody.ToString() + ",\n"); aEnemyObject.Append("{\n\"class\" : \"Animator\",\n\"Name\" : \"" + aEnemy.mName + "\"\n},\n"); foreach (AnimationData aData in aEnemy.mEnemyAnimations) { GAnimation aAnimation = new GAnimation(aData); aEnemyObject.Append(aAnimation.ToString() + ",\n"); } aEnemyObject.Remove(aEnemyObject.Length - 2, 2); aEnemyObject.Append("]\n"); aEnemyObject.Append("}\n"); SaveToFile(aEnemyObject.ToString(), Application.dataPath + aEnemyFilePath); SaveToFile(pEnemy.ToString(), Application.dataPath + aEnemyFilePath + ".json"); } if (!IsPathInResources(pResources, pEnemy.mAssetFilePath + ".json")) { pResources.Append("\"" + pEnemy.mAssetFilePath + ".json\","); } }
static void SaveProjectile(AssetMetaData pProjectile, ref StringBuilder pResources) { if (pProjectile == null) { return; } Projectile aProjectile = AssetDatabase.LoadAssetAtPath <Projectile>(AssetDatabase.GUIDToAssetPath(pProjectile.mGUID)); string aProjectileFilePath = "/Assets/Resources/Prefabs/" + aProjectile.mName + ".json"; pProjectile.mAssetFilePath = ".." + aProjectileFilePath; SaveAssetData(GetAssetFromGUID(aProjectile.mProjectileAnimation[0].mTextureAssetGUID, AssetMetaData.AssetType.TextureAsset), ref pResources); if (!IsAssetInResources(Application.dataPath + aProjectileFilePath)) { GProjectile aProj = new GProjectile(); aProj.mPoolCount = aProjectile.mPoolCount; aProj.mSpeed = aProjectile.mSpeed; GCircleCollider aCollider = new GCircleCollider(32.00001f, true); GRigidbody aRigidBody = new GRigidbody(); GSprite aSprite = new GSprite(aProjectile.mDisplaySprite.rect, aProjectile.mProjectileAnimation[0].mTextureAssetGUID, aProjectile.mDisplaySprite.texture.height, (int)aProjectile.mRenderLayer); StringBuilder aProjectileObject = new StringBuilder("{\n"); aProjectileObject.Append("\"name\" : \"" + aProjectile.mName + "\",\n"); aProjectileObject.Append("\"Components\" : [\n"); aProjectileObject.Append(aSprite.ToString() + ",\n"); aProjectileObject.Append(aProj.ToString() + ",\n"); aProjectileObject.Append(aCollider.ToString() + ",\n"); aProjectileObject.Append(aRigidBody.ToString() + ",\n"); aProjectileObject.Append("{\n\"class\" : \"Animator\",\n\"Name\" : \"" + aProjectile.mName + "\"\n},\n"); foreach (AnimationData aData in aProjectile.mProjectileAnimation) { GAnimation aAnimation = new GAnimation(aData); aProjectileObject.Append(aAnimation.ToString() + ",\n"); } aProjectileObject.Remove(aProjectileObject.Length - 2, 2); aProjectileObject.Append("]\n"); aProjectileObject.Append("}\n"); SaveToFile(aProjectileObject.ToString(), Application.dataPath + aProjectileFilePath); SaveToFile(pProjectile.ToString(), Application.dataPath + aProjectileFilePath + ".json"); } if (!IsPathInResources(pResources, pProjectile.mAssetFilePath + ".json")) { pResources.Append("\"" + pProjectile.mAssetFilePath + ".json\","); } }