Skip to content

Commit 63cc44f

Browse files
committed
init pack
1 parent aa61ed3 commit 63cc44f

File tree

206 files changed

+5265
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+5265
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# SO.Architecture
2-
Scriptableobject Architecture for game Unity (Anti-Singleton)
1+
# ScriptableobjectArchitecture
2+
3+
## How To Install
4+
5+
### Add the lines below to `Packages/manifest.json`
6+
7+
for version `1.0.0`
8+
```csharp
9+
"com.virtuesky.scriptableobject.architecture":"https://github.com/VirtueSky/SO.Architecture.git#1.0.0",
10+
```

README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VirtueSky.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VirtueSky/Attributes.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VirtueSky/Attributes/GUIDAttribute.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using VirtueSky.Utils;
4+
5+
namespace VirtueSky.Attributes
6+
{
7+
public class GUIDAttribute : PropertyAttribute
8+
{
9+
public string prefix;
10+
11+
public GUIDAttribute()
12+
{
13+
this.prefix = string.Empty;
14+
}
15+
16+
public GUIDAttribute(string prefix)
17+
{
18+
this.prefix = prefix;
19+
}
20+
}
21+
22+
#if UNITY_EDITOR
23+
[CustomPropertyDrawer(typeof(GUIDAttribute))]
24+
public class GuidAttributeDrawer : PropertyDrawer
25+
{
26+
string Prefix => (attribute as GUIDAttribute).prefix;
27+
28+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
29+
{
30+
EditorGUI.BeginProperty(position, label, property);
31+
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
32+
33+
if (string.IsNullOrEmpty(property.stringValue))
34+
{
35+
property.stringValue = Prefix + SimpleMath.NewGuid();
36+
}
37+
38+
var w = position.width * 0.3f;
39+
40+
position.width = position.width * 0.7f;
41+
GUI.enabled = false;
42+
EditorGUI.PropertyField(position, property, GUIContent.none);
43+
GUI.enabled = true;
44+
45+
position.position += new Vector2(position.width, 0);
46+
position.width = w;
47+
if (GUI.Button(position, new GUIContent("Change")))
48+
{
49+
if (!property.serializedObject.isEditingMultipleObjects)
50+
property.stringValue = Prefix + SimpleMath.NewGuid();
51+
}
52+
53+
property.serializedObject.ApplyModifiedProperties();
54+
55+
EditorGUI.EndProperty();
56+
}
57+
}
58+
#endif
59+
}

VirtueSky/Attributes/GUIDAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.Text;
2+
using UnityEditor;
3+
using UnityEngine;
4+
using VirtueSky.EditorUtils;
5+
6+
namespace VirtueSky.Attributes
7+
{
8+
public class NamedIdAttribute : PropertyAttribute
9+
{
10+
public NamedIdAttribute()
11+
{
12+
}
13+
}
14+
15+
#if UNITY_EDITOR
16+
[CustomPropertyDrawer(typeof(NamedIdAttribute))]
17+
public class NamedIdAttributeDrawer : PropertyDrawer
18+
{
19+
NamedIdAttribute TargetAttribute => attribute as NamedIdAttribute;
20+
21+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
22+
{
23+
EditorGUI.BeginProperty(position, label, property);
24+
25+
Context(position, property);
26+
27+
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
28+
29+
var id = property.stringValue;
30+
if (string.IsNullOrEmpty(id))
31+
{
32+
id = ToSnakeCase(property.serializedObject.targetObject.name);
33+
property.stringValue = id;
34+
property.serializedObject.ApplyModifiedProperties();
35+
}
36+
37+
using (new EditorGUIUtils.DisabledGUI(true))
38+
{
39+
EditorGUI.TextField(position, id);
40+
}
41+
42+
EditorGUI.EndProperty();
43+
}
44+
45+
void Context(Rect rect, SerializedProperty property)
46+
{
47+
var current = Event.current;
48+
49+
if (rect.Contains(current.mousePosition) && current.type == EventType.ContextClick)
50+
{
51+
var menu = new GenericMenu();
52+
53+
menu.AddItem(new GUIContent("Reset"), false,
54+
() =>
55+
{
56+
property.stringValue = ToSnakeCase(property.serializedObject.targetObject.name);
57+
property.serializedObject.ApplyModifiedProperties();
58+
});
59+
menu.ShowAsContext();
60+
61+
current.Use();
62+
}
63+
}
64+
65+
public static string ToSnakeCase(string text)
66+
{
67+
if (text.Length < 2)
68+
{
69+
return text;
70+
}
71+
72+
var sb = new StringBuilder();
73+
sb.Append(char.ToLowerInvariant(text[0]));
74+
for (var i = 1; i < text.Length; ++i)
75+
{
76+
var c = text[i];
77+
if (char.IsUpper(c))
78+
{
79+
sb.Append('_');
80+
sb.Append(char.ToLowerInvariant(c));
81+
}
82+
else
83+
{
84+
sb.Append(c);
85+
}
86+
}
87+
88+
return sb.ToString();
89+
}
90+
}
91+
#endif
92+
}

VirtueSky/Attributes/NamedIdAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VirtueSky/Core.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VirtueSky/Core/BaseMono.cs

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
using System;
2+
using System.Linq;
3+
using UnityEditor;
4+
using UnityEngine;
5+
using VirtueSky.Attributes;
6+
using VirtueSky.ObjectPooling;
7+
using VirtueSky.Utils;
8+
using System.IO;
9+
10+
namespace VirtueSky.Core
11+
{
12+
13+
public class BaseMono : MonoBehaviour, IEntity
14+
{
15+
[Header("Base")] [SerializeField, NamedId]
16+
string id;
17+
18+
[SerializeField] public Pools pools;
19+
[SerializeField] public Ticker ticker;
20+
[SerializeField] bool earlyTick;
21+
[SerializeField] bool tick;
22+
[SerializeField] bool lateTick;
23+
[SerializeField] bool fixedTick;
24+
25+
public string Id => id;
26+
27+
#if UNITY_EDITOR
28+
[ContextMenu("ResetId")]
29+
public void ResetId()
30+
{
31+
id = NamedIdAttributeDrawer.ToSnakeCase(name);
32+
EditorUtility.SetDirty(this);
33+
}
34+
#endif
35+
36+
void OnEnable()
37+
{
38+
BindVariable();
39+
ListenEvents();
40+
SubTick();
41+
DoEnable();
42+
}
43+
44+
void OnDisable()
45+
{
46+
DoDisable();
47+
UnsubTick();
48+
// StopListenEvents();
49+
UnbindVariable();
50+
}
51+
52+
private void OnDestroy()
53+
{
54+
DoDestroy();
55+
}
56+
57+
public virtual void BindVariable()
58+
{
59+
}
60+
61+
public virtual void ListenEvents()
62+
{
63+
}
64+
65+
void SubTick()
66+
{
67+
if (earlyTick) ticker.SubEarlyTick(this);
68+
if (tick) ticker.SubTick(this);
69+
if (lateTick) ticker.SubLateTick(this);
70+
if (fixedTick) ticker.SubFixedTick(this);
71+
}
72+
73+
public virtual void DoEnable()
74+
{
75+
}
76+
77+
public virtual void Initialize()
78+
{
79+
}
80+
81+
public virtual void EarlyTick()
82+
{
83+
}
84+
85+
public virtual void Tick()
86+
{
87+
}
88+
89+
public virtual void LateTick()
90+
{
91+
}
92+
93+
public virtual void FixedTick()
94+
{
95+
}
96+
97+
public virtual void CleanUp()
98+
{
99+
}
100+
101+
public virtual void DoDisable()
102+
{
103+
}
104+
105+
public virtual void DoDestroy()
106+
{
107+
}
108+
109+
void UnsubTick()
110+
{
111+
if (earlyTick) ticker.UnsubEarlyTick(this);
112+
if (tick) ticker.UnsubTick(this);
113+
if (lateTick) ticker.UnsubLateTick(this);
114+
if (fixedTick) ticker.UnsubFixedTick(this);
115+
}
116+
117+
public virtual void StopListenEvents()
118+
{
119+
}
120+
121+
public virtual void UnbindVariable()
122+
{
123+
}
124+
125+
#if UNITY_EDITOR
126+
void Reset()
127+
{
128+
ticker = AssetUtils.FindAssetAtFolder<Ticker>(new string[] { "Assets" }).FirstOrDefault();
129+
if (ticker == null)
130+
{
131+
CreateSettingAssets<Ticker>();
132+
ticker = AssetUtils.FindAssetAtFolder<Ticker>(new string[] { "Assets" }).FirstOrDefault();
133+
}
134+
135+
pools = AssetUtils.FindAssetAtFolder<Pools>(new string[] { "Assets" }).FirstOrDefault();
136+
if (pools == null)
137+
{
138+
CreateSettingAssets<Pools>();
139+
pools = AssetUtils.FindAssetAtFolder<Pools>(new string[] { "Assets" }).FirstOrDefault();
140+
}
141+
142+
EditorUtility.SetDirty(this);
143+
}
144+
145+
private void CreateSettingAssets<T>() where T : ScriptableObject
146+
{
147+
var setting = UnityEngine.ScriptableObject.CreateInstance<T>();
148+
UnityEditor.AssetDatabase.CreateAsset(setting, $"{DefaultResourcesPath()}/{typeof(T).Name}.asset");
149+
UnityEditor.AssetDatabase.SaveAssets();
150+
UnityEditor.AssetDatabase.Refresh();
151+
152+
Debug.Log($"{typeof(T).Name} was created ad {DefaultResourcesPath()}/{typeof(T).Name}.asset");
153+
}
154+
155+
private string DefaultResourcesPath()
156+
{
157+
const string defaultResourcePath = "Assets/_Root/Resources";
158+
if (!Directory.Exists(defaultResourcePath))
159+
{
160+
Directory.CreateDirectory(defaultResourcePath);
161+
}
162+
163+
return defaultResourcePath;
164+
}
165+
#endif
166+
}
167+
}

0 commit comments

Comments
 (0)