-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Alexejhero/misc-stuff
Ency paths and Coordinated spawns
- Loading branch information
Showing
38 changed files
with
499 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Nautilus.Handlers; | ||
using NSpawnInfo = Nautilus.Handlers.SpawnInfo; | ||
|
||
namespace SCHIZO.Spawns; | ||
|
||
partial class CoordinatedSpawns | ||
{ | ||
protected override void Register() | ||
{ | ||
foreach (SpawnInfo spawnInfo in spawns) | ||
{ | ||
if (!spawnInfo.game.HasFlag(GAME)) continue; | ||
|
||
foreach (SpawnInfo.SpawnLocation location in spawnInfo.locations) | ||
{ | ||
NSpawnInfo nSpawnInfo = new((TechType)spawnInfo.item.techType, location.position, location.rotation); | ||
CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(nSpawnInfo); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ | |
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
Unity/Assets/Editor/Scripts/Extensions/GameAttributeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using SCHIZO.Helpers; | ||
using SCHIZO.Registering; | ||
using UnityEditor; | ||
|
||
namespace Editor.Scripts.Extensions | ||
{ | ||
public static class GameAttributeExtensions | ||
{ | ||
public static bool TryGetGame(this GameAttribute attr, out Game game) => TryGetGame(attr, null, out game); | ||
public static bool TryGetGame(this GameAttribute attr, SerializedProperty property, out Game game) | ||
{ | ||
game = attr.game; | ||
if (game > 0 || string.IsNullOrEmpty(attr.gameMember)) return true; | ||
if (property == null) return false; | ||
|
||
object target = property.GetParent().GetSerializedValue<object>(); | ||
game = ReflectionHelpers.GetMemberValue<Game>(target, attr.gameMember); | ||
return true; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Unity/Assets/Editor/Scripts/Extensions/GameAttributeExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
Unity/Assets/Editor/Scripts/Extensions/SerializedPropertyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using SCHIZO.Helpers; | ||
using UnityEditor; | ||
|
||
namespace Editor.Scripts.Extensions | ||
{ | ||
public static class SerializedPropertyExtensions | ||
{ | ||
// most (all) of the code is adapted from this thread: https://forum.unity.com/threads/get-a-general-object-value-from-serializedproperty.327098/ | ||
private delegate FieldInfo GetFieldInfo(SerializedProperty prop, out Type type); | ||
private static readonly GetFieldInfo fieldInfoGetter = Setup(); | ||
|
||
public static FieldInfo GetFieldInfoAndStaticType(this SerializedProperty prop, out Type type) | ||
{ | ||
return fieldInfoGetter(prop, out type); | ||
} | ||
|
||
private static GetFieldInfo Setup() | ||
{ | ||
Type t = Type.GetType("UnityEditor.ScriptAttributeUtility, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); | ||
MethodInfo mi = t.GetMethod("GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); | ||
return (GetFieldInfo) Delegate.CreateDelegate(typeof(GetFieldInfo), mi); | ||
} | ||
|
||
public static T GetCustomAttribute<T>(this SerializedProperty prop) where T : Attribute | ||
{ | ||
FieldInfo info = prop.GetFieldInfoAndStaticType(out _); | ||
return info.GetCustomAttribute<T>(); | ||
} | ||
|
||
public static bool TryGetAttributeInHierarchy<T>(this SerializedProperty prop, out T attribute, out SerializedProperty ancestorWithAttribute) where T : Attribute | ||
{ | ||
attribute = null; | ||
ancestorWithAttribute = null; | ||
foreach (SerializedProperty ancestor in prop.WalkHierarchy()) | ||
{ | ||
attribute = ancestor.GetCustomAttribute<T>(); | ||
if (attribute != null) | ||
{ | ||
ancestorWithAttribute = ancestor; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static SerializedProperty GetParent(this SerializedProperty property) | ||
{ | ||
int i = property.propertyPath.LastIndexOf('.'); | ||
return i < 0 ? null | ||
: property.serializedObject.FindProperty(property.propertyPath.Substring(0, i)); | ||
} | ||
|
||
public static IEnumerable<SerializedProperty> WalkHierarchy(this SerializedProperty prop) | ||
{ | ||
for (SerializedProperty curr = prop; curr != null; curr = curr.GetParent()) | ||
yield return curr; | ||
} | ||
|
||
public static T GetSerializedValue<T>(this SerializedProperty property) | ||
{ | ||
// adapted from https://github.com/lordofduct/spacepuppy-unity-framework-4.0/blob/679088a9fca826764de39390b4e08c6feaa06b52/Framework/com.spacepuppy.core/Editor/src/EditorHelper.cs#L278 | ||
string path = property.propertyPath.Replace(".Array.data[", "["); | ||
object obj = property.serializedObject.targetObject; | ||
|
||
foreach (string elem in path.Split('.')) | ||
{ | ||
if (elem[elem.Length - 1] == ']') | ||
{ | ||
string memberName = elem.Substring(0, elem.LastIndexOf('[')); | ||
string indexer = elem.Substring(memberName.Length, elem.Length - memberName.Length); | ||
int index = int.Parse(indexer.Substring(1, indexer.Length - 2)); | ||
IList valueList = ReflectionHelpers.GetMemberValue<IList>(obj, memberName); | ||
obj = valueList[index]; | ||
} | ||
else | ||
{ | ||
obj = ReflectionHelpers.GetMemberValue<object>(obj, elem); | ||
} | ||
} | ||
|
||
return (T)obj; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Unity/Assets/Editor/Scripts/Extensions/SerializedPropertyExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.