Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alfredo1995/scriptable-object
A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances.
https://github.com/alfredo1995/scriptable-object
csharp unity
Last synced: about 18 hours ago
JSON representation
A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances.
- Host: GitHub
- URL: https://github.com/alfredo1995/scriptable-object
- Owner: alfredo1995
- Created: 2023-10-11T04:58:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-14T09:11:22.000Z (6 months ago)
- Last Synced: 2024-05-14T10:31:40.201Z (6 months ago)
- Topics: csharp, unity
- Language: C#
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A ScriptableObject is a data container used to save large amounts of data.
One of the main use cases for ScriptableObjects is to reduce your project's memory usage by avoiding copies of values.
This is useful if your project has a Prefab that stores unalterable data.1° Create script > ScriptableObject
* criar a pasta ScriptableObject > criar o script TestScriptableObject* estender a class ScriptableObject para dizer que agora são contenie de dados
* definir alguns campos para ter um objecto programavelpublic class TestScriptableObject : ScriptableObject
{
public string myString;
}* criar uma instacia do objeto programavel
* adicionar o atributo de menu de criação de ativos, 2 parametros (nome do arquivo, nome do menu e
* nome do menu, criado a pasta dos objestos programaveis> [CreateAssetMenu(fileName = "TestScriptableObject ", menuName = "ScriptableObject/TestScriptableObject")]
public class ScriptableObject : ScriptableObject { public string myString; }
2° Editor da unity
create > ScriptableObject > TestScriptableObject
3° Usar o script table object , criando script Testing
* criar um gameobject empty > anexar o script Testing
* adiconar um campo para o tipo do nosso objeto
* acessar a string criada e de um nome a elapublic class Testing : MonoBehaviour
{
[SerializeField] private TestScriptableObject testScriptableObject;private void start ()
{
Debug.Log(testScriptableObject.myString);
}
}4° fazer os teste
* temos um campo do tipo test scriptable object para arrastar o obj programavel
* testa duplicando o script table objet teste, nomeando e definindo uma nova string a ser salva mySting* sempre que for usar o arquivo, faça a referencia no gameobjeto contendo o script testScriptableObject
* temos a mensagem diferente, temos 2 script diferente objetos, cada um com sua propria instancia de dados
5° Uso mais basicos dos objetos
[createAssetMenu(fileName = "TestScriptableObject ", menuName = "ScriptableObject/TestScriptableObject")]
public class TestScriptableObject : ScriptableObject
{
public string mySting;
public int myInt;
public Sprite[] spriteArray; //usado em sistema de grade "grid system"
}* temos os nossos campos para serem configurados para criar quantas instacia de dados quisemos