Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
knowlife4 committed Jan 16, 2023
1 parent 968d906 commit a70a311
Show file tree
Hide file tree
Showing 76 changed files with 5,876 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ECT/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
8 changes: 8 additions & 0 deletions ECT/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions ECT/Assets/Editor/BranchEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UIElements;

namespace ECT.UnityEditor
{
[CustomPropertyDrawer(typeof(ECTBranch<>), true)]
public class BranchEditor : PropertyDrawer
{
ReorderableList componentList;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);

if(componentList == null) PrepareList(property);

componentList.DoList(position);

EditorGUI.EndProperty();
}

public void PrepareList (SerializedProperty property)
{
var components = property.FindPropertyRelative("Components");
componentList = new(property.serializedObject, components, false, true, true, true)
{
drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
EditorGUI.PropertyField(rect, components.GetArrayElementAtIndex(index));
},

drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, "Components");
}
};
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return componentList?.GetHeight() ?? base.GetPropertyHeight(property, label);
}
}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Editor/BranchEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions ECT/Assets/Editor/ComponentEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UIElements;

namespace ECT.UnityEditor
{
[CustomPropertyDrawer(typeof(ECTComponent<,,>), true)]
public class ComponentEditor : PropertyDrawer
{
Editor editor;

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, new(), true);

// Make child fields be indented
EditorGUI.indentLevel++;

// background
GUILayout.BeginVertical("box");

if (!editor)
Editor.CreateCachedEditor(property.objectReferenceValue, null, ref editor);

// Draw object properties
EditorGUI.BeginChangeCheck();
if (editor) // catch empty property
{
editor.OnInspectorGUI ();
}
if (EditorGUI.EndChangeCheck())
property.serializedObject.ApplyModifiedProperties();

GUILayout.EndVertical ();

// Set indent back to what it was
EditorGUI.indentLevel--;
}
}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Editor/ComponentEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ECT/Assets/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions ECT/Assets/Runtime/ECTBranch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ECT
{
[System.Serializable]
public class ECTBranch<MyComponent> : IBranch where MyComponent : class, IComponent
{
public MyComponent[] Components;
}

public interface IBranch
{

}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Runtime/ECTBranch.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions ECT/Assets/Runtime/ECTComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using UnityEngine;

namespace ECT
{
public abstract class ECTComponent<MyRoot, MyParent, MyComponent> : ScriptableObject, IComponent where MyRoot : class, IParent where MyParent : class, IParent where MyComponent : class, IComponent
{
protected MyComponent ThisComponent => this as MyComponent;

protected abstract ISystem System { get; }
public ISystem CreateSystem() => System;

protected virtual IReference CreateReference (MyRoot root, MyParent parent, ISystem system) => new ComponentReference(ThisComponent, root, parent, system);
public IReference CreateReference(IParent root, IParent parent)
{
ISystem system = System;
if(parent as MyParent == null) Debug.Log(typeof(MyParent));
IReference reference = CreateReference((MyRoot)root, (MyParent)parent, system);
system.SetReference(reference);

return reference;
}

public abstract class ComponentSystem<Component> : ECTSystem<ComponentReference, Component, MyRoot, MyParent> where Component : class, IComponent {}

public class ComponentReference : ECTReference<MyRoot, MyParent, MyComponent>
{
public ComponentReference(MyComponent reference, MyRoot root, MyParent parent, ISystem system) : base(reference, root, parent, system) {}
}

public abstract class ComponentGroup : ECTComponent<MyRoot, MyParent, MyComponent>, IParent
{
public ECTBranch<ChildComponent> Components;

protected override IReference CreateReference(MyRoot root, MyParent parent, ISystem system) => new ComponentGroupReference(this, root, parent, system, Components);

public abstract class ChildComponent : ECTComponent<MyRoot, ComponentGroup, ChildComponent> {}

public class ComponentGroupReference : ECTReference<MyRoot, MyParent, ComponentGroup>
{
public ECTReferenceBranch ReferenceBranch { get; }

public ComponentGroupReference(ComponentGroup reference, MyRoot root, MyParent parent, ISystem system, ECTBranch<ChildComponent> branch) : base(reference, root, parent, system) => ReferenceBranch = new(branch.Components);

public override FindSystem Get<FindSystem>() => System is FindSystem system ? system : ReferenceBranch.Get<FindSystem>();
}

public new abstract class ComponentSystem<Component> : ECTSystem<ComponentGroupReference, Component, MyRoot, MyParent> where Component : class, IComponent
{
protected override void OnUpdate() => Reference.ReferenceBranch.Update(Reference.Root, Reference.Component);
}
}
}

public interface IComponent
{
public ISystem CreateSystem();
public IReference CreateReference(IParent root, IParent parent);
}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Runtime/ECTComponent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions ECT/Assets/Runtime/ECTEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using UnityEngine;

namespace ECT
{
public abstract class ECTEntity<MyEntity> : MonoBehaviour, IEntity where MyEntity : class, IEntity
{
public ECTBranch<ECTComponent<MyEntity, MyEntity, EntityComponent>> ComponentBranch;

public ECTReferenceBranch ReferenceBranch { get; set; }

public abstract class EntityComponent : ECTComponent<MyEntity, MyEntity, EntityComponent> {}

void Awake ()
{
ReferenceBranch = new(ComponentBranch.Components);
}
}

public interface IEntity : IParent
{

}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Runtime/ECTEntity.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ECT/Assets/Runtime/ECTParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ECT
{
public interface IParent
{

}
}
11 changes: 11 additions & 0 deletions ECT/Assets/Runtime/ECTParent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions ECT/Assets/Runtime/ECTReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace ECT
{
[System.Serializable]
public abstract class ECTReference<MyRoot, MyParent, MyComponent> : IReference where MyRoot : class, IParent where MyParent : class, IParent where MyComponent : class, IComponent
{
public ECTReference(MyComponent component, MyRoot root, MyParent parent, ISystem system)
{
Component = component;
Root = root;
Parent = parent;
System = system;
}

public bool State = true;
public MyComponent Component { get; }
public MyRoot Root { get; }
public MyParent Parent { get; }
public ISystem System { get; }

bool IReference.State { get => State; set => State = value; }
IComponent IReference.Component => Component;
IParent IReference.Root => Root;
IParent IReference.Parent => Parent;

public virtual FindSystem Get<FindSystem>() where FindSystem : class, ISystem => System as FindSystem;
}

public interface IReference
{
public bool State { get; set; }
public IComponent Component { get; }
public IParent Root { get; }
public IParent Parent { get; }
public ISystem System { get; }
public FindSystem Get<FindSystem>() where FindSystem : class, ISystem;
}
}
Loading

0 comments on commit a70a311

Please sign in to comment.