string DoesAssetExists(Sprite pNewSprite) { string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { return(null); } string[] aAssetGUIDs = AssetDatabase.FindAssets(pNewSprite.texture.name, aAssetFolder); if (aAssetGUIDs.Length <= 0) { return(null); } string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) != typeof(AssetMetaData)) { return(null); } AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType != AssetMetaData.AssetType.TextureAsset) { return(null); } return(aCurrentAssetData.mGUID); }
public static void UpdateAssetMetaData(AssetMetaData AssetmetaData) { using (DOAMEntities db = new DOAMEntities()) { db.Entry(AssetmetaData).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public static void AddAssetMetaData(AssetMetaData AssetmetaData) { using (DOAMEntities db = new DOAMEntities()) { db.AssetMetaDatas.Add(AssetmetaData); db.SaveChanges(); } }
void SaveAsScriptableAsset(MouseUpEvent aEv) { EditorUtility.SetDirty(mCurrentAssetData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); mCurrentAssetData = null; mTypeOfAsset.value = AssetMetaData.AssetType.None; }
public static void OnCollectSoundSelection(AudioClip pClip, ObjectField pField) { if (pClip == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { ShowSelectionWarning(); ResetCollectSelection(pField); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pClip.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.AudioAsset) { switch (GameObjectEditor.GetCurrentScriptable().mType) { case GameScriptable.ObjectType.Item: Item aTempObj = (Item)GameObjectEditor.GetCurrentScriptable(); aTempObj.mSoundGUID = aCurrentAssetData.mGUID; aTempObj.mItemCollectSound = pClip; break; case GameScriptable.ObjectType.SpawnFactory: SpawnFactory aTmpObj = (SpawnFactory)GameObjectEditor.GetCurrentScriptable(); aTmpObj.mSoundGUID = aCurrentAssetData.mGUID; aTmpObj.mSpawnSound = pClip; break; } } else { ShowSelectionWarning(); ResetCollectSelection(pField); return; } } else { ShowSelectionWarning(); ResetCollectSelection(pField); return; } } else { ShowSelectionWarning(); ResetCollectSelection(pField); return; } }
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\","); } }
private void DoAssetStoreSearch(AssetMetaData assetPackage) { var nameParts = assetPackage.Name.Split(' '); var query = ""; foreach (var namePart in nameParts) { query = $"{query}&q={namePart}"; } Process.Start($"https://assetstore.unity.com/search?{query.TrimStart('&')}"); }
public ActionResult CreateMetaData([Bind(Include = "AssetMetaDataID,Value,MetaDataID,AssetID")] AssetMetaData assetMetaData) { if (ModelState.IsValid) { MyApp.Domain.Services.AssetMetaDataService.AddAssetMetaData(assetMetaData); return(RedirectToAction("ALLDetails", "Assets", new { id = assetMetaData.AssetID })); } //ViewBag.AssetID = new SelectList(MyApp.Application.Services.AssetControllerService.GetListeAsset(), "AssetID", "Name", assetMetaData.AssetID); ViewBag.MetaDataID = new SelectList(MyApp.Application.Services.MetaDataControllerService.GetListeMetaData(), "MetaDataID", "Title", assetMetaData.MetaDataID); return(View(assetMetaData)); }
void ActivateObjectFieldOfType(AssetMetaData.AssetType pType) { if (mAssetEditorData.Contains(mObjectData)) { mAssetEditorData.Remove(mObjectData); } if (mCurrentAssetData != null) { EditorUtility.SetDirty(mCurrentAssetData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); mCurrentAssetData = null; } mSelectionField.value = null; SetObjectFieldType(pType); }
public static void OnAttackSoundSelection(AudioClip pAttackSound, ObjectField pField) { if (pAttackSound == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { ShowSelectionWarning(); ResetAttackSoundSelection(pField); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pAttackSound.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.AudioAsset) { Enemy aTmpObj = (Enemy)GameObjectEditor.GetCurrentScriptable(); aTmpObj.mAttackSoundGUID = aCurrentAssetData.mGUID; aTmpObj.mAttackSound = pAttackSound; } else { ShowSelectionWarning(); ResetAttackSoundSelection(pField); return; } } else { ShowSelectionWarning(); ResetAttackSoundSelection(pField); return; } } else { ShowSelectionWarning(); ResetAttackSoundSelection(pField); return; } }
public static void OnSpawnEnemySelection(Enemy pEnemy, ObjectField pField) { if (pEnemy == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { ShowSelectionWarning(); ResetSpawnEnemySelection(pField); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pEnemy.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.PrefabAsset) { SpawnFactory aTmpObj = (SpawnFactory)GameObjectEditor.GetCurrentScriptable(); aTmpObj.mEnemyGUID = aCurrentAssetData.mGUID; aTmpObj.mSpawnEnemy = pEnemy; } else { ShowSelectionWarning(); ResetSpawnEnemySelection(pField); return; } } else { ShowSelectionWarning(); ResetSpawnEnemySelection(pField); return; } } else { ShowSelectionWarning(); ResetSpawnEnemySelection(pField); return; } }
public static void OnGamePlayMusicSelection(AudioClip pGamePlayMusic, ObjectField pField) { if (pGamePlayMusic == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { ShowSelectionWarning(); ResetGameplayMusic(pField); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pGamePlayMusic.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.AudioAsset) { Level aTmpObj = LevelEditor.GetActiveLevel(); aTmpObj.mGUIDGameplayMusic = aCurrentAssetData.mGUID; aTmpObj.mGameplayMusic = pGamePlayMusic; } else { ShowSelectionWarning(); ResetGameplayMusic(pField); return; } } else { ShowSelectionWarning(); ResetGameplayMusic(pField); return; } } else { ShowSelectionWarning(); ResetGameplayMusic(pField); return; } }
void OnProjectileSelection(Projectile pProjectile) { if (pProjectile == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { GenHelpers.ShowSelectionWarning(); ResetProjectileSelection(); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pProjectile.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.PrefabAsset) { mActivePlayer.mGUIDProjectile = aCurrentAssetData.mGUID; mActivePlayer.mProjectile = pProjectile; } else { GenHelpers.ShowSelectionWarning(); ResetProjectileSelection(); return; } } else { GenHelpers.ShowSelectionWarning(); ResetProjectileSelection(); return; } } else { GenHelpers.ShowSelectionWarning(); ResetProjectileSelection(); return; } }
void OnTeleportSoundSelection(AudioClip pTeleportSound) { if (pTeleportSound == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { GenHelpers.ShowSelectionWarning(); ResetTeleportSelection(); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pTeleportSound.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.AudioAsset) { mActivePlayer.mGUIDTeleportSound = aCurrentAssetData.mGUID; mActivePlayer.mTeleportSound = pTeleportSound; } else { GenHelpers.ShowSelectionWarning(); ResetTeleportSelection(); return; } } else { GenHelpers.ShowSelectionWarning(); ResetTeleportSelection(); return; } } else { GenHelpers.ShowSelectionWarning(); ResetTeleportSelection(); return; } }
private void ShowMetaData(AssetMetaData ap) { treeAssetContents.Tag = ap; treeAssetContents.Nodes.Clear(); var mappedNodes = new Dictionary <string, TreeNode>(); foreach (string asset in ap.Assets) { var assetParts = asset.Split('/'); var path = ""; TreeNode currentNode = null; for (int i = 0; i < assetParts.Length; ++i) { path += $"{assetParts[i]}/"; if (mappedNodes.ContainsKey(path)) { currentNode = mappedNodes[path]; } else { if (currentNode == null) { currentNode = mappedNodes[path] = treeAssetContents.Nodes.Add(assetParts[i]); } else { currentNode = mappedNodes[path] = currentNode.Nodes.Add(assetParts[i]); } currentNode.ContextMenuStrip = treeAssetContentsContextMenuStrip; } } } if (treeAssetContents.Nodes.Count > 0) { treeAssetContents.Nodes[0].Expand(); foreach (TreeNode n in treeAssetContents.Nodes[0].Nodes) { n.Expand(); } } }
static void SaveAssetData(AssetMetaData pData, ref StringBuilder pResources) { System.Type aAssetType = typeof(Object); string aSaveFolder = "/Assets/Resources/"; switch (pData.mType) { case AssetMetaData.AssetType.None: return; case AssetMetaData.AssetType.PrefabAsset: return; case AssetMetaData.AssetType.AudioAsset: aSaveFolder += "Audios/"; aAssetType = typeof(AudioClip); break; case AssetMetaData.AssetType.FontAsset: aSaveFolder += "Fonts/"; aAssetType = typeof(Font); break; case AssetMetaData.AssetType.TextureAsset: aSaveFolder += "Textures/"; aAssetType = typeof(Texture); break; default: return; } string aOldPath = AssetDatabase.GUIDToAssetPath(pData.mGUID); string aFileName = aOldPath.Substring(aOldPath.LastIndexOf('/') + 1); pData.mAssetFilePath = ".." + aSaveFolder + aFileName; if (!IsAssetInResources(Application.dataPath + aSaveFolder + aFileName)) { AssetDatabase.CopyAsset(aOldPath, "Assets" + aSaveFolder + aFileName); SaveToFile(pData.ToString(), Application.dataPath + aSaveFolder + aFileName + ".json"); } if (!IsPathInResources(pResources, pData.mAssetFilePath + ".json")) { pResources.Append("\"" + pData.mAssetFilePath + ".json\","); } }
public ActionResult Edit([Bind(Include = "AssetMetaDataID,Value,MetaDataID,AssetID")] AssetMetaData assetMetaData) { try { if (ModelState.IsValid) { MyApp.Domain.Services.AssetMetaDataService.UpdateAssetMetaData(assetMetaData); return(RedirectToAction("Index")); } ViewBag.AssetID = new SelectList(MyApp.Application.Services.AssetControllerService.GetListeAsset(), "AssetID", "Name", assetMetaData.AssetID); ViewBag.MetaDataID = new SelectList(MyApp.Application.Services.MetaDataControllerService.GetListeMetaData(), "MetaDataID", "Title", assetMetaData.MetaDataID); return(View(assetMetaData)); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "AssetMetaDatas", "Edit"))); } }
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\","); } }
static void SetAssetData() { mCurrentAssets = new Dictionary <AssetMetaData.AssetType, List <AssetMetaData> >(); mCurrentAssets.Add(AssetMetaData.AssetType.AudioAsset, new List <AssetMetaData>()); mCurrentAssets.Add(AssetMetaData.AssetType.FontAsset, new List <AssetMetaData>()); mCurrentAssets.Add(AssetMetaData.AssetType.TextureAsset, new List <AssetMetaData>()); mCurrentAssets.Add(AssetMetaData.AssetType.PrefabAsset, new List <AssetMetaData>()); string aBaseFolderPath = "Assets/ScriptableObjects/Asset Meta Data/"; string[] aAssetFiles = Directory.GetFiles(aBaseFolderPath); foreach (string aAssets in aAssetFiles) { AssetMetaData aAsset = AssetDatabase.LoadAssetAtPath <AssetMetaData>(aAssets); if (aAsset != null) { mCurrentAssets[aAsset.mType].Add(aAsset); } } }
public static void OnSpriteSelection(Sprite pSelectedSprite, ObjectField pField) { if (pSelectedSprite == null) { return; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { ShowSelectionWarning(); ResetSpriteSelection(pField); return; } string[] aAssetGUIDs = AssetDatabase.FindAssets(pSelectedSprite.texture.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { AssetMetaData aCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); if (aCurrentAssetData.mType == AssetMetaData.AssetType.TextureAsset) { switch (GameObjectEditor.GetCurrentScriptable().mType) { case GameScriptable.ObjectType.SpawnFactory: SpawnFactory aTempObj = (SpawnFactory)GameObjectEditor.GetCurrentScriptable(); aTempObj.mTextureGUID = aCurrentAssetData.mGUID; aTempObj.mDisplaySprite = pSelectedSprite; break; case GameScriptable.ObjectType.StaticObject: StaticObject aTObj = (StaticObject)GameObjectEditor.GetCurrentScriptable(); aTObj.mTextureGUID = aCurrentAssetData.mGUID; aTObj.mDisplaySprite = pSelectedSprite; break; case GameScriptable.ObjectType.Item: Item aTmpObj = (Item)GameObjectEditor.GetCurrentScriptable(); aTmpObj.mTextureGUID = aCurrentAssetData.mGUID; aTmpObj.mDisplaySprite = pSelectedSprite; break; default: ShowSelectionWarning(); ResetSpriteSelection(pField); break; } } else { ShowSelectionWarning(); ResetSpriteSelection(pField); return; } } else { ShowSelectionWarning(); ResetSpriteSelection(pField); return; } } else { ShowSelectionWarning(); ResetSpriteSelection(pField); return; } }
void SetSelectedObjectData(Object pObject) { if (pObject == null) { return; } string aAssetExtension = pObject.name; switch ((AssetMetaData.AssetType)mTypeOfAsset.value) { case AssetMetaData.AssetType.None: return; case AssetMetaData.AssetType.TextureAsset: aAssetExtension = "Textures/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject)); break; case AssetMetaData.AssetType.AudioAsset: aAssetExtension = "Audios/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject)); break; case AssetMetaData.AssetType.FontAsset: aAssetExtension = "Fonts/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject)); break; case AssetMetaData.AssetType.PrefabAsset: ((GameScriptable)pObject).mIsPrefab = true; EditorUtility.SetDirty(pObject); aAssetExtension = "Prefabs/" + aAssetExtension + ".json"; break; } string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" }; if (!AssetDatabase.IsValidFolder(aAssetFolder[0])) { AssetDatabase.CreateFolder("Assets/ScriptableObjects", "Asset Meta Data"); } string[] aAssetGUIDs = AssetDatabase.FindAssets(pObject.name, aAssetFolder); if (aAssetGUIDs.Length > 0) { for (int i = 1; i < aAssetGUIDs.Length; i++) { AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(aAssetGUIDs[i])); } string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData)) { mCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData)); } } if (mCurrentAssetData == null) { mCurrentAssetData = (AssetMetaData)ScriptableObject.CreateInstance(typeof(AssetMetaData)); mCurrentAssetData.mAssetFilePath = "../Assets/Resources/" + aAssetExtension; mCurrentAssetData.mType = (AssetMetaData.AssetType)mTypeOfAsset.value; mCurrentAssetData.mGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(pObject)); AssetDatabase.CreateAsset(mCurrentAssetData, aAssetFolder[0] + "/" + pObject.name + ".asset"); } EditorUtility.SetDirty(mCurrentAssetData); mObjectData.Bind(new SerializedObject(mCurrentAssetData)); mAssetEditorData.Add(mObjectData); }
static void SaveLevelOrderJSON(LevelOrder pOrder) { CreateLevelFolder(); CreateResourcesFolder(); SetAssetData(); if (mCurrentAssets[AssetMetaData.AssetType.PrefabAsset].Count <= 0) { EditorUtility.DisplayDialog("No Data", "Please Create Levels and Scriptable Objects Before Saving", "Okay"); return; } AssetMetaData aCurrentPlayer = null; foreach (AssetMetaData aPrefab in mCurrentAssets[AssetMetaData.AssetType.PrefabAsset]) { string aPath = AssetDatabase.GUIDToAssetPath(aPrefab.mGUID); if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(Player)) { aCurrentPlayer = aPrefab; break; } } if (aCurrentPlayer == null) { EditorUtility.DisplayDialog("No Data", "Please Create Levels and Scriptable Objects Before Saving", "Okay"); return; } StringBuilder aLevelOrderJSON = new StringBuilder("{\n\"Levels\" : {\n"); int aI = 0; foreach (Level aLevel in pOrder.mAllLevels) { if (aLevel.mStartPosition.mWorldPosition.x < 0 && aLevel.mStartPosition.mWorldPosition.y < 0) { continue; } if (aLevel.mEndPosition.mWorldPosition.x < 0 && aLevel.mEndPosition.mWorldPosition.y < 0) { continue; } StringBuilder aResourcesArray = new StringBuilder("\"resources\": ["); StringBuilder aLevelJSON = new StringBuilder("{\"GameObjects\": ["); aLevelJSON.Append(GetStartPositionJson(aLevel.mStartPosition, ref aResourcesArray, aCurrentPlayer)); aLevelJSON.Append(","); aLevelJSON.Append(GetEndPositionJson(aLevel.mEndPosition, ref aResourcesArray)); aLevelJSON.Append(","); for (int aJ = 0; aJ < aLevel.mLevelData.Count; aJ++) { foreach (GameScriptable aScriptable in aLevel.mLevelData[aJ].mScriptables) { aLevelJSON.Append(GetGameScriptableJson(aLevel.mLevelData[aJ].mPosition, aScriptable, ref aResourcesArray)); aLevelJSON.Append(","); } } aLevelJSON.Remove(aLevelJSON.Length - 1, 1); aLevelJSON.Append("]"); aResourcesArray.Remove(aResourcesArray.Length - 1, 1); aResourcesArray.Append("]"); aLevelJSON.Append("," + aResourcesArray.ToString()); aLevelJSON.Append("," + "\"Timer\" : " + aLevel.mTime); aLevelJSON.Append("}"); SaveToFile(aLevelJSON.ToString(), Application.dataPath + "/Assets/Level Data/" + aLevel.mName + ".json"); aLevelOrderJSON.Append("\"" + aI + "\" : \"../Assets/Level Data/" + aLevel.mName + ".json\","); aI++; } aLevelOrderJSON.Remove(aLevelOrderJSON.Length - 1, 1); aLevelOrderJSON.Append("\n}\n"); string[] aItems = SaveItemPrefabs(); aLevelOrderJSON.Append("," + aItems[0] + "\n"); aLevelOrderJSON.Append("," + aItems[1]); aLevelOrderJSON.Append("\n}"); SaveToFile(aLevelOrderJSON.ToString(), Application.dataPath + "/Assets/GauntletGame.json"); AssetDatabase.Refresh(); }
static StringBuilder GetStartPositionJson(Level.GamePositions pStartPosition, ref StringBuilder pResources, AssetMetaData pPlayer) { StringBuilder aStartPositionGobj = new StringBuilder("{\n"); aStartPositionGobj.Append("\"name\" : \"Start Position\",\n"); aStartPositionGobj.Append("\"Components\" : [\n"); GTransform aTransform = new GTransform(); aTransform.Position = new position(pStartPosition.mWorldPosition.x * 64.00001f, pStartPosition.mWorldPosition.y * 64.00001f); aStartPositionGobj.Append(aTransform.ToString()); aStartPositionGobj.Append(",\n"); PlayerSpawner aSpawner = new PlayerSpawner(); aSpawner.mPlayerPrefabGUID = pPlayer.mGUID; SavePlayer(pPlayer, ref pResources); aStartPositionGobj.Append(aSpawner.ToString()); aStartPositionGobj.Append("]\n"); aStartPositionGobj.Append("}\n"); return(aStartPositionGobj); }