public static void Create() { PlayerScriptable asset = ScriptableObject.CreateInstance <PlayerScriptable>(); AssetDatabase.CreateAsset(asset, "Assets/Scripts/ScriptableObjects/PlayerStuff/Player.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
void EditSelectedPlayer() { if (Selection.activeGameObject != null && Selection.activeGameObject.tag == "Player") { if (GUILayout.Button("Edit Selected Player")) { var activePlayer = Selection.activeGameObject.GetComponent <Player>(); playerScriptable = activePlayer.data; } } }
private void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); // EditorGUILayout.LabelField("Edit Custom Player", mystyle); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); playerScriptable = (PlayerScriptable)EditorGUILayout.ObjectField("Scriptable Player", playerScriptable, typeof(PlayerScriptable), false); EditSelectedPlayer(); if (playerScriptable != null) { EditorGUILayout.Space(); playerScriptable.name = EditorGUILayout.TextField("Name", playerScriptable.name); playerScriptable.Life = EditorGUILayout.FloatField("Life", playerScriptable.Life); playerScriptable.speed = EditorGUILayout.FloatField("Speed", playerScriptable.speed); EditorGUILayout.Space(); playerScriptable.VerticalMovement = EditorGUILayout.Toggle("Vertical Movement", playerScriptable.VerticalMovement); playerScriptable.HorizontalMovement = EditorGUILayout.Toggle("Horizontal Movement", playerScriptable.HorizontalMovement); playerScriptable.MeleAttack = EditorGUILayout.Toggle("Melee Attack", playerScriptable.MeleAttack); playerScriptable.RangeAttack = EditorGUILayout.Toggle("Range Attack", playerScriptable.RangeAttack); if (!playerScriptable.VerticalMovement) { playerScriptable.CanJump = EditorGUILayout.Toggle("Can Jump", playerScriptable.CanJump); if (playerScriptable.CanJump) { playerScriptable.jumpForce = EditorGUILayout.FloatField("Jump Force", playerScriptable.jumpForce); } } deadIndex = EditorGUILayout.Popup("Death Types", deadIndex, DeathType); playerScriptable.currentDeath = deadIndex; EditorUtility.SetDirty(playerScriptable); //para que se guarde los cambios if (GUILayout.Button("Create Scriptable Player")) { var scriptable = CreateInstance <PlayerScriptable>(); if (!AssetDatabase.IsValidFolder("Assets/Resources/Data")) { AssetDatabase.CreateFolder("Assets/Resources", "Data"); Debug.Log("The introduced folder doesn't exist, so I just created a default one for you."); AssetDatabase.Refresh(); } var path = "Assets/Resources/Data/" + playerScriptable.name + ".asset"; path = AssetDatabase.GenerateUniqueAssetPath(path); AssetDatabase.CreateAsset(scriptable, path); Save(); } if (GUILayout.Button("Save as Player Prefab")) { var myObject = GameObject.CreatePrimitive(PrimitiveType.Cube); var script = myObject.AddComponent <Player>(); script.data = playerScriptable; string path = "Assets/Resources/Prefabs/" + playerScriptable.name + ".prefab"; Debug.Log("the prefab was saved in " + path); PrefabUtility.SaveAsPrefabAssetAndConnect(myObject, path, InteractionMode.AutomatedAction); Save(); } } else { if (GUILayout.Button("Create New Scriptable Player")) { EditNewPlayer(); } } }
void EditNewPlayer() { playerScriptable = CreateInstance <PlayerScriptable>(); playerScriptable.name = "New Player"; }