├── LICENSE.md ├── Runtime ├── CMS │ ├── README.md │ ├── Common │ │ ├── NullEntity.cs │ │ ├── NullEntity.cs.meta │ │ ├── SFXTag.cs.meta │ │ ├── SFXDefinition.cs.meta │ │ ├── AnythingTag.cs │ │ ├── SFXDefinition.cs │ │ ├── AnythingTag.cs.meta │ │ ├── CMSEntityPfb.cs.meta │ │ ├── ReflectionUtil.cs.meta │ │ ├── ReflectionUtil.cs │ │ ├── SFXTag.cs │ │ └── CMSEntityPfb.cs │ ├── .DS_Store │ ├── Common.meta │ ├── README.md.meta │ ├── CMS.cs.meta │ └── CMS.cs ├── .DS_Store ├── Editor │ ├── CMSMenuItems.cs.meta │ └── CMSMenuItems.cs ├── CMS.asmdef.meta ├── CMS.meta ├── Editor.meta ├── manifest.json └── CMS.asmdef ├── README.md ├── LICENSE.md.meta ├── README.md.meta ├── package.json.meta ├── Runtime.meta ├── manifest.json ├── package.json └── .gitignore /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License -------------------------------------------------------------------------------- /Runtime/CMS/README.md: -------------------------------------------------------------------------------- 1 | # CMS 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # test-package 2 | # CMS 3 | -------------------------------------------------------------------------------- /Runtime/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koster/CMS/HEAD/Runtime/.DS_Store -------------------------------------------------------------------------------- /Runtime/CMS/Common/NullEntity.cs: -------------------------------------------------------------------------------- 1 | public class NullEntity : CMSEntity 2 | { 3 | } -------------------------------------------------------------------------------- /Runtime/CMS/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koster/CMS/HEAD/Runtime/CMS/.DS_Store -------------------------------------------------------------------------------- /Runtime/CMS/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e03ff52dfac4455ba42b70895bf5376 3 | timeCreated: 1712395322 -------------------------------------------------------------------------------- /Runtime/CMS/Common/NullEntity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0b16bf721414d2d9fa939b65d46c05f 3 | timeCreated: 1712525641 -------------------------------------------------------------------------------- /Runtime/CMS/Common/SFXTag.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fff6eed1fca645cdb0867dd63fa968eb 3 | timeCreated: 1712395316 -------------------------------------------------------------------------------- /Runtime/Editor/CMSMenuItems.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b245b8992c944ee0bc73dc8dee8a6a8c 3 | timeCreated: 1730279357 -------------------------------------------------------------------------------- /Runtime/CMS/Common/SFXDefinition.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88c3d6d78610445ba0f4643c060e5d95 3 | timeCreated: 1712398431 -------------------------------------------------------------------------------- /Runtime/CMS/Common/AnythingTag.cs: -------------------------------------------------------------------------------- 1 | namespace Common 2 | { 3 | public class AnythingTag : EntityComponentDefinition 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29142cd29f2f443438519ea88a487a34 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cd05b9920a0040ea939c756ab921bd7 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 655326dece9d14269b360873c875534c 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/CMS/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5681e66cb70b1496fa6155df5853d699 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c985d84653b4e4364a9454f10d256e69 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/CMS.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5e33a9421ef5468a8b7c132c84cab00 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/CMS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32be3126d8da04696ac8a2206073079e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 968490bbc8fcd40aabd82ce546017d92 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.mackysoft.serializereference-extensions": "https://github.com/mackysoft/Unity-SerializeReferenceExtensions.git?path=Assets/MackySoft/MackySoft.SerializeReferenceExtensions" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Runtime/Editor/CMSMenuItems.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | 3 | public static class CMSMenuItems 4 | { 5 | [MenuItem("CMS/Reload")] 6 | public static void CMSReload() 7 | { 8 | CMS.Unload(); 9 | CMS.Init(); 10 | } 11 | } -------------------------------------------------------------------------------- /Runtime/CMS/Common/SFXDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | [Serializable] 6 | public class SFXArray : EntityComponentDefinition 7 | { 8 | public List files = new List(); 9 | public float volume = 1f; 10 | } 11 | -------------------------------------------------------------------------------- /Runtime/CMS/CMS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ce84d408fd51574cabb669b285eb03a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/CMS/Common/AnythingTag.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0e25090d7bd7614fa61733b68f3040d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/CMS/Common/CMSEntityPfb.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1729a46f79086449a991b5512530e60 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/CMS/Common/ReflectionUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e8431f6fdcfc7e4ea32f6baa8411c4d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "scopedRegistries": [ 3 | { 4 | "name": "OpenUPM", 5 | "url": "https://package.openupm.com", 6 | "scopes": [ 7 | "com.mackysoft" 8 | ] 9 | } 10 | ], 11 | "dependencies": { 12 | "com.xk.cms": "https://github.com/koster/CMS.git", 13 | "com.mackysoft.serializereference-extensions": "1.6.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Runtime/CMS.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CMS", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:49b49c76ee64f6b41bf28ef951cb0e50" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [], 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /Runtime/CMS/Common/ReflectionUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | public static class ReflectionUtil 6 | { 7 | public static Type[] FindAllSubslasses() 8 | { 9 | Type baseType = typeof(T); 10 | Assembly assembly = Assembly.GetAssembly(baseType); 11 | 12 | Type[] types = assembly.GetTypes(); 13 | Type[] subclasses = types.Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract).ToArray(); 14 | 15 | return subclasses; 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/CMS/Common/SFXTag.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Common 5 | { 6 | [Serializable] 7 | public class SFXTag : EntityComponentDefinition 8 | { 9 | public string sfx_id; 10 | public float Cooldown = 0.1f; 11 | public bool VaryPitch; 12 | } 13 | 14 | [Serializable] 15 | public class MusicTag : EntityComponentDefinition 16 | { 17 | public AudioClip clip; 18 | } 19 | 20 | [Serializable] 21 | public class AmbientTag : EntityComponentDefinition 22 | { 23 | public AudioClip clip; 24 | } 25 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.xk.cms", 3 | "version": "1.0.1", 4 | "displayName": "CMS", 5 | "description": "A simple content management system!", 6 | "unity": "2020.1", 7 | "scopedRegistries": [ 8 | { 9 | "name": "OpenUPM", 10 | "url": "https://package.openupm.com", 11 | "scopes": [ 12 | "com.mackysoft" 13 | ] 14 | } 15 | ], 16 | "dependencies": { 17 | "com.mackysoft.serializereference-extensions": "1.6.1" 18 | }, 19 | "author": { 20 | "name": "xk", 21 | "email": "itiskoster@gmail.com", 22 | "url": "https://www.twitch.tv/xkoster" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/CMS/Common/CMSEntityPfb.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | public class CMSEntityPfb : MonoBehaviour 5 | { 6 | [SerializeReference, SubclassSelector] 7 | public List Components; 8 | 9 | public string GetId() 10 | { 11 | #if UNITY_EDITOR 12 | // Get the path of the prefab in the Resources folder 13 | string path = UnityEditor.AssetDatabase.GetAssetPath(gameObject); 14 | 15 | // Remove the "Assets/Resources/" part and ".prefab" to match the Resources.Load format 16 | if (path.StartsWith("Assets/ldgame/data/Resources/") && path.EndsWith(".prefab")) 17 | { 18 | path = path.Substring("Assets/ldgame/data/Resources/".Length); 19 | path = path.Substring(0, path.Length - ".prefab".Length); 20 | } 21 | 22 | return path; 23 | #endif 24 | } 25 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | .idea* 59 | 60 | # Crashlytics generated file 61 | crashlytics-build.properties 62 | 63 | force_level 64 | force_level_ap 65 | 66 | webgl_build 67 | webgl_build/* 68 | build_wgl/* 69 | 70 | Recordings/* 71 | UserSettings/Layouts/* -------------------------------------------------------------------------------- /Runtime/CMS/CMS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Common; 4 | using UnityEngine; 5 | using Object = UnityEngine.Object; 6 | 7 | public static class CMS 8 | { 9 | static CMSTable all = new CMSTable(); 10 | 11 | static bool isInit; 12 | 13 | public static void Init() 14 | { 15 | if (isInit) 16 | return; 17 | isInit = true; 18 | 19 | AutoAdd(); 20 | } 21 | 22 | static void AutoAdd() 23 | { 24 | var subs = ReflectionUtil.FindAllSubslasses(); 25 | foreach (var subclass in subs) 26 | all.Add(Activator.CreateInstance(subclass) as CMSEntity); 27 | 28 | var resources = Resources.LoadAll("CMS"); 29 | foreach (var resEntity in resources) 30 | { 31 | Debug.Log("LOAD ENTITY " + resEntity.GetId()); 32 | all.Add(new CMSEntity() 33 | { 34 | id = resEntity.GetId(), 35 | components = resEntity.Components 36 | }); 37 | } 38 | } 39 | 40 | public static T Get(string def_id = null) where T : CMSEntity 41 | { 42 | if (def_id == null) 43 | def_id = E.Id(); 44 | var findById = all.FindById(def_id) as T; 45 | 46 | if (findById == null) 47 | { 48 | // ok fuck it 49 | throw new Exception("unable to resolve entity id '" + def_id + "'"); 50 | } 51 | 52 | return findById; 53 | } 54 | 55 | 56 | public static T GetData(string def_id = null) where T : EntityComponentDefinition, new() 57 | { 58 | return Get(def_id).Get(); 59 | } 60 | 61 | public static List GetAll() where T : CMSEntity 62 | { 63 | var allSearch = new List(); 64 | 65 | foreach (var a in all.GetAll()) 66 | if (a is T) 67 | allSearch.Add(a as T); 68 | 69 | return allSearch; 70 | } 71 | 72 | public static List<(CMSEntity e, T tag)> GetAllData() where T : EntityComponentDefinition, new() 73 | { 74 | var allSearch = new List<(CMSEntity, T)>(); 75 | 76 | foreach (var a in all.GetAll()) 77 | if (a.Is(out var t)) 78 | allSearch.Add((a, t)); 79 | 80 | return allSearch; 81 | } 82 | 83 | public static void Unload() 84 | { 85 | isInit = false; 86 | all = new CMSTable(); 87 | } 88 | } 89 | 90 | public class CMSTable where T : CMSEntity, new() 91 | { 92 | List list = new List(); 93 | Dictionary dict = new Dictionary(); 94 | 95 | public void Add(T inst) 96 | { 97 | if (inst.id == null) 98 | inst.id = E.Id(inst.GetType()); 99 | 100 | list.Add(inst); 101 | dict.Add(inst.id, inst); 102 | } 103 | 104 | public T New(string id) 105 | { 106 | var t = new T(); 107 | t.id = id; 108 | list.Add(t); 109 | dict.Add(id, t); 110 | return t; 111 | } 112 | 113 | public List GetAll() 114 | { 115 | return list; 116 | } 117 | 118 | public T FindById(string id) 119 | { 120 | return dict.GetValueOrDefault(id); 121 | } 122 | 123 | public T2 FindByType() where T2 : T 124 | { 125 | foreach(var v in list) 126 | if (v is T2 v2) 127 | return v2; 128 | return null; 129 | } 130 | } 131 | 132 | public partial class CMSEntity 133 | { 134 | public string id; 135 | 136 | public List components = new List() { new AnythingTag() }; 137 | 138 | public T Define() where T : EntityComponentDefinition, new() 139 | { 140 | var t = Get(); 141 | if (t != null) 142 | return t; 143 | 144 | var entity_component = new T(); 145 | components.Add(entity_component); 146 | return entity_component; 147 | } 148 | 149 | public bool Is(out T unknown) where T : EntityComponentDefinition, new() 150 | { 151 | unknown = Get(); 152 | return unknown != null; 153 | } 154 | 155 | public bool Is() where T : EntityComponentDefinition, new() 156 | { 157 | return Get() != null; 158 | } 159 | 160 | public bool Is(Type type) 161 | { 162 | return components.Find(m => m.GetType() == type) != null; 163 | } 164 | 165 | public T Get() where T : EntityComponentDefinition, new() 166 | { 167 | return components.Find(m => m is T) as T; 168 | } 169 | } 170 | 171 | [Serializable] 172 | public class EntityComponentDefinition 173 | { 174 | } 175 | 176 | public static class CMSUtil 177 | { 178 | public static T Load(this string path) where T : Object 179 | { 180 | return Resources.Load(path); 181 | } 182 | 183 | public static Sprite LoadFromSpritesheet(string imageName, string spriteName) 184 | { 185 | Sprite[] all = Resources.LoadAll(imageName); 186 | 187 | foreach(var s in all) 188 | { 189 | if (s.name == spriteName) 190 | { 191 | return s; 192 | } 193 | } 194 | return null; 195 | } 196 | } 197 | 198 | public static class E 199 | { 200 | public static string Id(Type getType) 201 | { 202 | return getType.FullName; 203 | } 204 | 205 | public static string Id() 206 | { 207 | return ID.Get(); 208 | } 209 | } 210 | 211 | static class ID 212 | { 213 | static string cache; 214 | 215 | public static string Get() 216 | { 217 | if (cache == null) 218 | cache = typeof(T).FullName; 219 | return cache; 220 | } 221 | 222 | public static string Get() 223 | { 224 | return ID.Get(); 225 | } 226 | } 227 | --------------------------------------------------------------------------------