-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored SRML.Editor into a separate project and added new FieldRep…
…lacer system based on ScriptableObjects Removed TestDependency
- Loading branch information
1 parent
469bb27
commit 52d57b6
Showing
21 changed files
with
241 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace SRML.Editor | ||
{ | ||
[CreateAssetMenu(menuName = "SRML/Replacers/FieldReplacer")] | ||
public class FieldReplacer : ScriptableObject | ||
{ | ||
public InstanceInfo InstanceInfo; | ||
|
||
public bool ReplaceInChildren; | ||
|
||
[SerializeField] | ||
public List<FieldReplacement> FieldReplacements;// = new List<Replacement>(); | ||
|
||
} | ||
[CreateAssetMenu(menuName = "SRML/Replacers/FieldReplacement")] | ||
public class FieldReplacement : ScriptableObject //if this isnt a scriptable object unity absolutely refuses to serialize it correctly | ||
{ | ||
|
||
public string fieldToReplaceType; | ||
public string fieldToReplaceFieldName; | ||
|
||
public string replacementSourceType; | ||
public string replacementSourceFieldName; | ||
|
||
public bool TryResolveSource(out FieldInfo field) | ||
{ | ||
return Resolve(replacementSourceType, replacementSourceFieldName, out field); | ||
} | ||
public bool TryResolveTarget(out FieldInfo field) | ||
{ | ||
return Resolve(fieldToReplaceType,fieldToReplaceFieldName,out field); | ||
} | ||
|
||
private bool Resolve(String typeName, String fieldName, out FieldInfo field) | ||
{ | ||
Debug.Log("Found "+ Type.GetType(typeName + ", Assembly-CSharp")); | ||
if (Type.GetType(typeName+", Assembly-CSharp") is System.Type type && | ||
type.GetField(fieldName) is FieldInfo foundField) | ||
{ | ||
field = foundField; | ||
return true; | ||
} | ||
|
||
field = null; | ||
return false; | ||
} | ||
} | ||
} |
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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace SRML.Editor | ||
{ | ||
public class FieldReplacerContainer : MonoBehaviour | ||
{ | ||
public FieldReplacer Replacer; | ||
} | ||
} |
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,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace SRML.Editor | ||
{ | ||
[CreateAssetMenu(menuName = "SRML/Replacers/InstanceInfo")] | ||
public class InstanceInfo : ScriptableObject | ||
{ | ||
public IDType idType; | ||
public int ID; | ||
|
||
public enum IDType | ||
{ | ||
IDENTIFIABLE, | ||
GADGET, | ||
LANDPLOT | ||
// to be continued | ||
} | ||
} | ||
|
||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using SRML.Editor; | ||
|
||
namespace SRML.Editor | ||
{ | ||
internal static class ReplacerCache | ||
{ | ||
static Dictionary<FieldReplacer, ResolvedReplacer> replacers = new Dictionary<FieldReplacer, ResolvedReplacer>(); | ||
|
||
public static ResolvedReplacer GetReplacer(FieldReplacer replacer) | ||
{ | ||
if (replacers.TryGetValue(replacer, out var resolved)) return resolved; | ||
var newreplacer = ResolvedReplacer.Resolve(replacer); | ||
replacers.Add(replacer,newreplacer); | ||
return newreplacer; | ||
} | ||
|
||
public static void ClearCache() | ||
{ | ||
replacers.Clear(); | ||
} | ||
|
||
} | ||
} |
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,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using SRML.Editor; | ||
|
||
namespace SRML.Editor | ||
{ | ||
internal class ResolvedInstance | ||
{ | ||
public object Instance { get; private set; } | ||
public static ResolvedInstance Resolve(InstanceInfo info) | ||
{ | ||
var instance = new ResolvedInstance(); | ||
switch (info.idType) | ||
{ | ||
case InstanceInfo.IDType.IDENTIFIABLE: | ||
instance.Instance = GameContext.Instance.LookupDirector.GetPrefab((Identifiable.Id) info.ID); | ||
break; | ||
default: | ||
throw new NotImplementedException(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using SRML.Editor; | ||
|
||
namespace SRML.Editor | ||
{ | ||
internal class ResolvedReplacer | ||
{ | ||
public ResolvedInstance InstanceInfo; | ||
public Dictionary<FieldInfo,FieldInfo> FieldToField = new Dictionary<FieldInfo, FieldInfo>(); | ||
|
||
public static ResolvedReplacer Resolve(FieldReplacer replacer) | ||
{ | ||
ResolvedReplacer rep = new ResolvedReplacer(); | ||
rep.InstanceInfo = ResolvedInstance.Resolve(replacer.InstanceInfo); | ||
if (replacer.FieldReplacements == null) throw new Exception("No replacements found!"); | ||
foreach (var v in replacer.FieldReplacements) | ||
{ | ||
if (!v.TryResolveTarget(out var field1) || !v.TryResolveSource(out var field2)) | ||
throw new Exception($"Unable to resolve field! {v.replacementSourceFieldName}:{v.replacementSourceType} from {v.fieldToReplaceFieldName}:{v.fieldToReplaceType}"); | ||
rep.FieldToField.Add(field1,field2); | ||
} | ||
|
||
return rep; | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
SRML/SR/Editor/Replacers/LookupGameObjectReplacerWithName.cs
This file was deleted.
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
Oops, something went wrong.