GithubHelp home page GithubHelp logo

ecs.database's Introduction

Actors DataBase

A simple to use in memory DB made for Actors Framework.

How to Install

Add "com.pixeye.ecsdb": "https://github.com/dimmpixeye/ecs.database.git", into your project manifest.json file. If you use Assembly Defininition (AD) files then don't forget to add Pixeye.Framework.DataBase to your AD source.

How to use

Make a data class and Components helper for getting data from entity.

using System.Runtime.CompilerServices;
using Pixeye.Framework;

namespace Pixeye.Source
{
	[System.Serializable]
	sealed class DataMotion
	{
		public float speedWalk;
		public float speedRun;
		public float speedRush;
	}

	#region HELPERS   

	static partial class Components
	{
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static DataMotion DataMotion(in this ent entity)
		{
			return DBHelper.source[entity.id].nodes[Data.Indexer<DataMotion>.ID] as DataMotion;
		}
	}

	#endregion
}

Make a data base class where you define and load data.

// make a static class and name is like DataBase. It doesn't really matter.
	static class DataBase
	{

                 // Play Setup method before scene starts. All your data loading stuff goes here.
                [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
	        static void Setup()
	         {
	              // Load Pawns
		        Pawns.LoadGunner();
	                Pawns.LoadCivil();
		        Pawns.LoadEngineer();
                 }
     
                        // I prefer to split data types of different domains into nested classes.
		internal static class Pawns
		{               
                        // Data holders
			public static Data Gunner;
			public static Data Civil;
			public static Data Engineer;
			public static Data Digger;
			public static Data Mutant;
			public static Data Stalker;


			//===============================//
			// Pawn Engineer
			//===============================//
                        // Just a method to fetch data
			public static void LoadEngineer()
			{
				var data = Engineer = new Data();

				// Data Motion
				var dataMotion = data.Add<DataMotion>();

				dataMotion.speedWalk = 35;
				dataMotion.speedRun  = 80;
				dataMotion.speedRush = 100;

			}

Use it in your project!

               public static void NewPawnEngineer()
		{
			ent entity = Entity.Create();
                        // Bind entity with data from DB
			entity.Set(DataBase.Pawns.Engineer);

			var cAI = entity.Set<ComponentAI>();
                        // recieve variables from Data Components
			cAI.speed = entity.DataMotion().speedWalk;
		}

ecs.database's People

Contributors

allexeee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.