Playability

Fixed loadout generator tutorial edge cases
Recreated missing items
Created field shader & test scene
This commit is contained in:
Reinier Vens 2022-08-08 22:43:55 +01:00
commit 47e500e1ce
72 changed files with 3579 additions and 693 deletions

View file

@ -113,10 +113,10 @@ public abstract class DatabaseListView : EditorWindow
margin = new RectOffset(0, 0, 0, 0)
};
_jsonStore = new MultiFileJsonBackingStore(FilePath);
//_jsonStore = new MultiFileJsonBackingStore(FilePath);
_msgPackStore = new SingleFileMessagePackBackingStore(Path.Combine(FilePath, "AetherDB.msgpack"));
cultCache = new CultCache();
cultCache.AddBackingStore(_jsonStore);
//cultCache.AddBackingStore(_jsonStore);
cultCache.AddBackingStore(_msgPackStore);
cultCache.AddBackingStore(new MultiFileMessagePackBackingStore(FilePath), typeof(NameFile));
cultCache.PullAllBackingStores();

View file

@ -47,9 +47,10 @@ public class ActionGameManager : MonoBehaviour
if (_cultCache != null) return _cultCache;
_cultCache = new CultCache();
_cultCache.AddBackingStore(new MultiFileJsonBackingStore(GameDataDirectory.FullName));
// _cultCache.AddBackingStore(
// new SingleFileMessagePackBackingStore(Path.Combine(GameDataDirectory.FullName, "AetherDB.msgpack")));
//RethinkConnection.RethinkConnect(_cultCache, "gamecult.org:28016", DatabaseName);
//_cultCache.AddBackingStore(new MultiFileJsonBackingStore(GameDataDirectory.FullName));
_cultCache.AddBackingStore(
new SingleFileMessagePackBackingStore(Path.Combine(GameDataDirectory.FullName, "AetherDB.msgpack")));
// Particularly heavy objects should be stored in / retrieved from MsgPack files as it's much tighter than JSON
// Such as NameFiles, which are just huge collections of geonames used to condition Markov chains
@ -425,7 +426,7 @@ public class ActionGameManager : MonoBehaviour
slot.PointerEnterTrigger.OnPointerEnterAsObservable().Subscribe(_ =>
{
//Debug.Log($"Pointer entered action bar slot {controlPath}");
Debug.Log($"Pointer entered action bar slot {controlPath}");
RegisterDragTarget(dragAction =>
{
//Debug.Log("Registering binding!");
@ -520,6 +521,8 @@ public class ActionGameManager : MonoBehaviour
.5f) : new LoadoutGenerator(
ref ItemManager.Random,
ItemManager,
CurrentGalaxy,
Zone.GalaxyZone,
nearestFaction,
.5f);
@ -730,8 +733,7 @@ public class ActionGameManager : MonoBehaviour
{
SectorMap.QueueZoneReveal(CurrentGalaxy.Entrance.AdjacentZones.Prepend(CurrentGalaxy.Entrance));
PopulateLevel(CurrentGalaxy.Entrance);
var loadoutGenerator = IsTutorial ? new LoadoutGenerator(ref ItemManager.Random, ItemManager, null, 2) :
new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentGalaxy, Zone.GalaxyZone, null, 2);
var loadoutGenerator = new LoadoutGenerator(ref ItemManager.Random, ItemManager, CurrentGalaxy, Zone.GalaxyZone, IsTutorial ? CurrentGalaxy.ResolveFaction(Settings.TutorialGenerationSettings.ProtagonistFaction) : null, 2);
var ship = EntitySerializer.Unpack(
ItemManager,
Zone,

View file

@ -183,7 +183,7 @@ public class EntityInstance : MonoBehaviour
_pingBrightness = pingMesh.material.GetFloat("_Depth");
_currentPing = (pingInstance, pingMesh);
};
sensor.OnPingEnd += () => Destroy(_currentPing.transform.gameObject);
sensor.OnPingEnd += OnSensorPingEnd;
}
if (behavior is InstantWeapon instantWeapon)
@ -443,7 +443,12 @@ public class EntityInstance : MonoBehaviour
_influenceInstance.transform.localScale = Vector3.one * orbital.SecurityRadius;
}
}
private void OnSensorPingEnd()
{
Destroy(_currentPing.transform.gameObject);
}
public Transform GetBarrel(HardpointData hardpoint)
{
if (Barrels.ContainsKey(hardpoint))
@ -519,6 +524,8 @@ public class EntityInstance : MonoBehaviour
public virtual void OnDestroy()
{
if(_sensor!=null)
_sensor.OnPingEnd -= OnSensorPingEnd;
if (_influenceInstance) Destroy(_influenceInstance.gameObject);
Destroy(LocalSpace.gameObject);
foreach(var x in _subscriptions)

View file

@ -0,0 +1,147 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using Unity.Mathematics;
using UnityEngine.Animations;
using static Unity.Mathematics.math;
public class FieldDriver : MonoBehaviour
{
[Inspectable]
public float TestMagnitude;
public float2 Throttle;
[Inspectable]
public float ThrottleDecay = 1;
[Inspectable]
public float FlowSpeed;
[Inspectable]
public float FlowSpeedThrottleExponent;
[Inspectable]
public float FlowMagnitude;
[Inspectable]
public float FlowMagnitudeThrottleExponent;
[Inspectable]
public float FlowOpacityThrottleExponent;
public int MaxHits;
[Inspectable]
public ExponentialCurve MagnitudeTimeScaling;
[Inspectable]
public float MeleeRange;
[Inspectable]
public float MeleeRangeExponent;
[Inspectable]
public float MeleeFlatness;
[Inspectable]
public float MeleeShaping;
[Inspectable]
public float MeleeDuration;
[Inspectable]
public float MeleeAngle;
[Inspectable]
public float MeleeAngleExponent;
[Inspectable]
public Axis RefractionAxis = Axis.X;
private Material _field;
private ComputeBuffer _hitBuffer;
private List<FieldHit> _hits = new List<FieldHit>();
private float _pushWaveOffset;
private double2 _throttle;
private float _meleeTime;
private bool _meleeActive;
private struct FieldHit
{
public float3 Position;
public float3 Direction;
public float Magnitude;
public float Time;
}
void Start()
{
_field = GetComponent<MeshRenderer>().material;
var clickableCollider = GetComponent<ClickableCollider>();
if(clickableCollider!=null)
{
clickableCollider.OnClick += (_, _, ray, hit) =>
{
AddHit(hit.point, ray.direction, TestMagnitude);
};
}
_hitBuffer = new ComputeBuffer(MaxHits, 32);
}
public void AddHit(float3 position, float3 direction, float magnitude)
{
if (_hits.Count >= MaxHits) return;
var hit = new FieldHit
{
Position = normalize(transform.InverseTransformPoint(position)),
Direction = normalize(transform.rotation * direction),
Magnitude = magnitude,
Time = 0
};
Debug.Log($"Received hit: Position={hit.Position}, Direction={hit.Direction}");
_hits.Add(hit);
}
public int HitCount => _hits.Count;
public void Melee()
{
_meleeActive = true;
_meleeTime = 0;
}
void Update()
{
for (int i = 0; i < _hits.Count; i++)
{
var hit = _hits[i];
hit.Time += Time.deltaTime / MagnitudeTimeScaling.Evaluate(_hits[i].Magnitude);
_hits[i] = hit;
if (hit.Time > 1)
{
_hits.RemoveAt(i);
i--;
}
}
if (_meleeActive)
{
_meleeTime += Time.deltaTime / MeleeDuration;
if (_meleeTime > 1)
{
_meleeActive = false;
}
}
_throttle = AetheriaMath.Damp(_throttle, Throttle, ThrottleDecay, Time.deltaTime);
var throttleDir = (float2) normalize(_throttle);
var throttleMag = min(length(_throttle), 1);
_pushWaveOffset = frac(_pushWaveOffset + Time.deltaTime * FlowSpeed * (float) pow(throttleMag, FlowSpeedThrottleExponent));
var refractionRotation = Matrix4x4.Rotate(transform.rotation);
if (RefractionAxis == Axis.Y) refractionRotation = Matrix4x4.Rotate(Quaternion.Euler(90, 0, 0)) * refractionRotation;
if (RefractionAxis == Axis.X) refractionRotation = Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0)) * refractionRotation;
_hitBuffer.SetData(_hits);
_field.SetBuffer("_Hits", _hitBuffer);
_field.SetInt("_HitCount", _hits.Count);
_field.SetFloat("_PushWaveMagnitude", FlowMagnitude * (float) pow(throttleMag, FlowMagnitudeThrottleExponent));
_field.SetFloat("_PushOpacity", (float) pow(throttleMag, FlowOpacityThrottleExponent));
_field.SetFloat("_PushWaveOffset", _pushWaveOffset);
_field.SetVector("_PushDirection", new Vector4(throttleDir.x,0,throttleDir.y));
_field.SetVector("_InverseScale", new Vector4(1/transform.localScale.x,1/transform.localScale.y,1/transform.localScale.z));
_field.SetMatrix("_ReflRotate", refractionRotation);
_field.SetVector("_MeleeDirection", Quaternion.AngleAxis(sign(_meleeTime*2-1) * MeleeAngle * pow(abs(_meleeTime * 2 - 1), MeleeAngleExponent), Vector3.up) * -Vector3.forward);
_field.SetFloat("_MeleeDisplacement", pow(1 - 2 * abs(_meleeTime - .5f), MeleeRangeExponent) * MeleeRange);
_field.SetFloat("_MeleeShape", MeleeShaping);
_field.SetFloat("_MeleeFlattening", MeleeFlatness);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9ee74b07ad0390459302080d186cc58
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -38,6 +38,21 @@ public static class AetheriaMath
return lerp(a, b, 1 - exp(-lambda * dt));
}
public static double Damp(double a, double b, double lambda, double dt)
{
return lerp(a, b, 1 - exp(-lambda * dt));
}
public static double2 Damp(double2 a, double2 b, double2 lambda, double2 dt)
{
return lerp(a, b, 1 - exp(-lambda * dt));
}
public static double3 Damp(double3 a, double3 b, double3 lambda, double3 dt)
{
return lerp(a, b, 1 - exp(-lambda * dt));
}
//first-order intercept using absolute target position
public static float3 FirstOrderIntercept
(

View file

@ -13,13 +13,13 @@ using static Unity.Mathematics.math;
[Serializable, MessagePackObject, JsonObject]
public class ExponentialCurve
{
[JsonProperty("exponent"), Key(0)]
[JsonProperty("exponent"), Key(0), Inspectable]
public float Exponent;
[JsonProperty("multiplier"), Key(1)]
[JsonProperty("multiplier"), Key(1), Inspectable]
public float Multiplier;
[JsonProperty("constant"), Key(2)]
[JsonProperty("constant"), Key(2), Inspectable]
public float Constant;
public float Evaluate(float value) => Multiplier * pow(value, Exponent) + Constant;
@ -28,13 +28,13 @@ public class ExponentialCurve
[Serializable, MessagePackObject, JsonObject]
public class ExponentialLerp
{
[JsonProperty("exponent"), Key(0)]
[JsonProperty("exponent"), Key(0), Inspectable]
public float Exponent;
[JsonProperty("max"), Key(1)]
[JsonProperty("max"), Key(1), Inspectable]
public float Minimum;
[JsonProperty("min"), Key(2)]
[JsonProperty("min"), Key(2), Inspectable]
public float Maximum;
public float Evaluate(float value) => Minimum + pow(saturate(value), Exponent) * (Maximum - Minimum);

View file

@ -27,10 +27,12 @@ public class Galaxy
public GalaxyZone Exit { get; }
public Dictionary<Faction, FactionRelationship> FactionRelationships { get; } = new Dictionary<Faction, FactionRelationship>();
private Action<string> Log { get; }
public bool IsPrelude { get; }
private HashSet<Guid> _containedFactions;
private GalaxyZone[] _exitPath;
private Dictionary<Faction, MarkovNameGenerator> _nameGenerators = new Dictionary<Faction, MarkovNameGenerator>();
private readonly CultCache _cache;
public GalaxyZone[] ExitPath
{
@ -44,6 +46,8 @@ public class Galaxy
public Galaxy(CultCache cultCache, SavedGame savedGame, Action<string> log)
{
IsPrelude = savedGame.IsTutorial;
_cache = cultCache;
Log = log;
Background = savedGame.Background;
@ -94,6 +98,8 @@ public class Galaxy
Action<string> progressCallback = null,
uint seed = 0)
{
_cache = cache;
IsPrelude = false;
Background = background;
Log = log;
var factions = cache.GetAll<Faction>();
@ -125,6 +131,11 @@ public class Galaxy
progressCallback?.Invoke("Done!");
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
}
public Faction ResolveFaction(string name)
{
return _cache.GetAll<Faction>().FirstOrDefault(f => f.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase));
}
public Galaxy(
TutorialGenerationSettings settings,
@ -137,7 +148,8 @@ public class Galaxy
Action<string> progressCallback = null,
uint seed = 0)
{
Faction ResolveFaction(string name) => cache.GetAll<Faction>().FirstOrDefault(f => f.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase));
_cache = cache;
IsPrelude = true;
Background = background;
Log = log;

View file

@ -30,18 +30,18 @@ public class LoadoutGenerator
Faction = faction;
PriceExponent = priceExponent;
}
public LoadoutGenerator(
ref Random random,
ItemManager itemManager,
Faction faction,
float priceExponent)
{
Random = random;
ItemManager = itemManager;
Faction = faction;
PriceExponent = priceExponent;
}
//
// public LoadoutGenerator(
// ref Random random,
// ItemManager itemManager,
// Faction faction,
// float priceExponent)
// {
// Random = random;
// ItemManager = itemManager;
// Faction = faction;
// PriceExponent = priceExponent;
// }
public EntityPack GenerateShipLoadout(Predicate<HullData> hullFilter = null)
{
@ -86,7 +86,6 @@ public class LoadoutGenerator
var hull = ItemManager.CreateInstance(hullData) as EquippableItem;
var entity = new OrbitalEntity(ItemManager, null, hull, Guid.Empty, ItemManager.GameplaySettings.DefaultEntitySettings);
entity.Faction = Faction;
OutfitEntity(entity);
var emptyShape = entity.UnoccupiedSpace;
@ -100,6 +99,8 @@ public class LoadoutGenerator
{
throw new InvalidLoadoutException("Failed to equip selected docking bay!");
}
OutfitEntity(entity);
var cargo = entity.CargoBays.First();
IEnumerable<EquippableItemData> inventory = RandomItems<EquippableItemData>(16, 1,
@ -119,21 +120,9 @@ public class LoadoutGenerator
public HullData RandomHull(HullType type, Predicate<HullData> hullFilter = null)
{
return ItemManager.ItemData.GetAll<HullData>()
.Where(item =>
item.Price > 0 &&
return RandomItem<HullData>(0, item =>
(hullFilter?.Invoke(item) ?? true) &&
item.HullType == type &&
item.Manufacturer != Guid.Empty &&
(Galaxy?.ContainsFaction(item.Manufacturer) ?? true) &&
(Faction == null || item.Manufacturer == Faction.ID || Faction.Allegiance.ContainsKey(item.Manufacturer)))
.WeightedRandomElements(ref Random,
item =>
(Faction == null || item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance[item.Manufacturer]) / // Prioritize items from allied manufacturers
(Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
1
).FirstOrDefault();
item.HullType == type);
}
public T[] RandomItems<T>(int count, float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
@ -142,13 +131,14 @@ public class LoadoutGenerator
.Where(item =>
item.Price > 0 &&
item.Manufacturer != Guid.Empty &&
(Galaxy?.ContainsFaction(item.Manufacturer) ?? true) &&
(Faction == null || Faction.Allegiance.ContainsKey(item.Manufacturer)) &&
(Galaxy.IsPrelude || Galaxy.ContainsFaction(item.Manufacturer) &&
(Faction == null || Faction.Allegiance.ContainsKey(item.Manufacturer))) &&
(filter?.Invoke(item) ?? true))
.WeightedRandomElements(ref Random, item =>
(Faction == null || item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance[item.Manufacturer]) * // Prioritize items from allied manufacturers
Faction == null ? 1 :
(item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance.ContainsKey(item.Manufacturer) ? Faction.Allegiance[item.Manufacturer] : 0.0f / // Prioritize items from allied manufacturers
(Galaxy?.ContainsFaction(item.Manufacturer) ?? false ? Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1 : 1)) * // Penalize distance to manufacturer headquarters
pow(item.Shape.Coordinates.Length, sizeExponent) / // Prioritize larger items
(Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1) / // Penalize distance to manufacturer headquarters
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
count
);

View file

@ -245,9 +245,7 @@ public static class ZoneGenerator
LoadoutGenerator GetLoadoutGenerator(Faction faction)
{
if (!loadoutGenerators.ContainsKey(faction))
loadoutGenerators[faction] = isTutorial
? new LoadoutGenerator(ref random, itemManager, faction, .5f)
: new LoadoutGenerator(ref random, itemManager, galaxy, galaxyZone, faction, .5f);
loadoutGenerators[faction] = new LoadoutGenerator(ref random, itemManager, galaxy, galaxyZone, faction, .5f);
return loadoutGenerators[faction];
}

View file

@ -10,7 +10,7 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, /*IPointerUpHandler, IPointerDownHandler,*/ IPointerClickHandler
public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, /*IPointerUpHandler, */IPointerDownHandler, IPointerClickHandler
{
//public bool EnableMouse => PointerIsInside && !_catching;
public bool PointerIsInside { get; private set; }
@ -19,6 +19,7 @@ public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHan
public Subject<PointerEventData> OnEnter = new Subject<PointerEventData>();
public Subject<PointerEventData> OnExit = new Subject<PointerEventData>();
public Subject<PointerEventData> OnClick = new Subject<PointerEventData>();
public Subject<PointerEventData> OnDown = new Subject<PointerEventData>();
// private float downTime;
@ -54,10 +55,10 @@ public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHan
// OnClick?.Invoke(eventData);
// }
//
// public void OnPointerDown(PointerEventData eventData)
// {
// downTime = Time.time;
// }
public void OnPointerDown(PointerEventData eventData)
{
OnDown.OnNext(eventData);
}
public void OnPointerClick(PointerEventData eventData)
{

View file

@ -19,15 +19,17 @@ public class ClickRaycaster : MonoBehaviour
void Start()
{
_clickCatcher = GetComponent<ClickCatcher>();
_clickCatcher.OnClick.Subscribe(pointer =>
_clickCatcher.OnDown.Subscribe(pointer =>
{
RaycastHit hit;
Physics.Raycast(RayCamera.ScreenPointToRay(pointer.position), out hit, 1000, Layers.value);
var ray = RayCamera.ScreenPointToRay(pointer.position);
Physics.Raycast(ray, out hit, 1000, Layers.value);
if (hit.collider != null)
{
//Debug.Log($"Clicked on gameobject {hit.collider.gameObject}");
var clickable = hit.collider.GetComponent<ClickableCollider>();
if (clickable != null)
clickable.Click(pointer);
clickable.Click(pointer, ray, hit);
}
else OnClickMiss?.Invoke(pointer);
});

View file

@ -10,9 +10,9 @@ using UnityEngine.EventSystems;
public class ClickableCollider : MonoBehaviour
{
public event Action<ClickableCollider, PointerEventData> OnClick;
public event Action<ClickableCollider, PointerEventData, Ray, RaycastHit> OnClick;
public void Click(PointerEventData eventData) => OnClick?.Invoke(this, eventData);
public void Click(PointerEventData eventData, Ray ray, RaycastHit raycastHit) => OnClick?.Invoke(this, eventData, ray, raycastHit);
public void Clear()
{

View file

@ -0,0 +1,30 @@
using System;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class FieldTester : MonoBehaviour
{
public Camera Camera;
public FieldDriver TestField;
public PropertiesPanel Properties;
private AetheriaInput _input;
private bool _forceThrust;
private void Start()
{
_input = new AetheriaInput();
_input.Player.Enable();
Properties.AddField("FOV", () => Camera.fieldOfView, f => Camera.fieldOfView = f, 15, 45);
Properties.AddButton("Melee", () => TestField.Melee());
Properties.AddField("Force Thrust", () => _forceThrust, b => _forceThrust = b);
Properties.Inspect(TestField, true, true);
Properties.AddProperty("Current Hits", () => TestField.HitCount.ToString());
}
private void Update()
{
TestField.Throttle = _forceThrust ? float2(0,1) : _input.Player.Move.ReadValue<Vector2>();
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 686a80c9880b431b94a9b0029d39cf1f
timeCreated: 1659655755

View file

@ -101,7 +101,7 @@ public class SectorMap : MonoBehaviour
if (!_revealedZones.Contains(zone))
{
var zoneInstance = ZonePrototype.Instantiate<SectorZoneUI>();
zoneInstance.Clickable.OnClick += (clickableCollider, data) => ZoneClicked.OnNext(zone);
zoneInstance.Clickable.OnClick += (clickableCollider, data, ray, hit) => ZoneClicked.OnNext(zone);
if(zone == _currentPlayerLocation)
MarkPlayerLocation(zoneInstance);
_zoneInstances[zone] = zoneInstance;

View file

@ -585,78 +585,74 @@ public class PropertiesPanel : MonoBehaviour
}
}
// public void Inspect(object obj, bool inspectablesOnly = false, bool readWrite = false, bool topLevel = true)
// {
// if(topLevel)
// Clear();
//
// var fields = obj.GetType().GetFields();
// foreach (var field in fields)
// Inspect(obj, field, inspectablesOnly, readWrite);
//
// if(topLevel)
// foreach (var field in _propertyFields)
// field.transform.SetSiblingIndex(_propertyFields.IndexOf(field));
//
// RefreshValues();
// }
//
// public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false, bool readWrite = false)
// {
// var inspectable = field.GetCustomAttribute<InspectableFieldAttribute>();
// if (inspectable == null && inspectablesOnly) return;
// var type = field.FieldType;
//
// if (type == typeof(float))
// {
// if (readWrite)
// {
// var ranged = inspectable as RangedFloatInspectableAttribute;
// if (ranged != null)
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f),
// ranged.Min, ranged.Max);
// else
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f));
// } else Inspect(field.Name.SplitCamelCase(), () => ((float) field.GetValue(obj)).ToString("0.##"));
// }
// else if (type == typeof(int))
// {
// if (readWrite)
// {
// var ranged = inspectable as RangedIntInspectableAttribute;
// if (ranged != null)
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f),
// ranged.Min, ranged.Max);
// else
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f));
// } else Inspect(field.Name.SplitCamelCase(), () => ((int) field.GetValue(obj)).ToString());
// }
// else if (type.IsEnum)
// {
// if (readWrite)
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), i => field.SetValue(obj, i),
// Enum.GetNames(field.FieldType));
// else
// Inspect(field.Name.SplitCamelCase(), () => Enum.GetName(type, field.GetValue(obj)).SplitCamelCase());
// }
// else if (type == typeof(string))
// {
// if (readWrite)
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj), i => field.SetValue(obj, i));
// else
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj));
// }
// //else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
// else if (field.FieldType == typeof(bool)) Inspect(field.Name, () => (bool) field.GetValue(obj), b => field.SetValue(obj, b));
// else if (type.GetCustomAttribute<InspectableFieldAttribute>() != null)
// {
// if(!_propertyFields.Any() || !_propertyFields.Last().gameObject.name.ToUpper().Contains("DIVIDER"))
// _propertyFields.Add(Divider.Instantiate<Prototype>());
// Inspect(field.GetValue(obj), inspectablesOnly, readWrite, false);
// }
// else
// Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated.");
// }
public void Inspect(object obj, bool inspectablesOnly = false, bool readWrite = false, bool topLevel = true)
{
var fields = obj.GetType().GetFields();
foreach (var field in fields)
Inspect(obj, field, inspectablesOnly, readWrite);
// if(topLevel)
// foreach (var field in _propertyFields)
// field.transform.SetSiblingIndex(_propertyFields.IndexOf(field));
RefreshValues();
}
public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false, bool readWrite = false)
{
var inspectable = field.GetCustomAttribute<InspectableAttribute>();
if (inspectable == null && inspectablesOnly) return;
var type = field.FieldType;
if (type == typeof(float))
{
if (readWrite)
{
if (inspectable is InspectableRangedFloatAttribute ranged)
AddField(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f),
ranged.Min, ranged.Max);
else
AddField(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f));
} else AddProperty(field.Name.SplitCamelCase(), () => ((float) field.GetValue(obj)).ToString("0.##"));
}
else if (type == typeof(int))
{
if (readWrite)
{
if (inspectable is InspectableRangedIntAttribute ranged)
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f),
ranged.Min, ranged.Max);
else
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f));
} else AddProperty(field.Name.SplitCamelCase(), () => ((int) field.GetValue(obj)).ToString());
}
else if (type.IsEnum)
{
if (readWrite)
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), i => field.SetValue(obj, i),
Enum.GetNames(field.FieldType));
else
AddProperty(field.Name.SplitCamelCase(), () => Enum.GetName(type, field.GetValue(obj)).SplitCamelCase());
}
else if (type == typeof(string))
{
if (readWrite)
AddField(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj), i => field.SetValue(obj, i));
else
AddProperty(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj));
}
//else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
else if (field.FieldType == typeof(bool)) AddField(field.Name, () => (bool) field.GetValue(obj), b => field.SetValue(obj, b));
else if (type.GetCustomAttribute<InspectableAttribute>() != null)
{
// if(!_propertyFields.Any() || !_propertyFields.Last().gameObject.name.ToUpper().Contains("DIVIDER"))
// _propertyFields.Add(Divider.Instantiate<Prototype>());
var list = AddList(field.Name);
list.Inspect(field.GetValue(obj), inspectablesOnly, readWrite, false);
}
else
Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated.");
}
public void RefreshValues()
{

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class SpriteCursor : MonoBehaviour
{
public Canvas Canvas;
private RectTransform _rectTransform;
void Start()
{
_rectTransform = GetComponent<RectTransform>();
}
void Update()
{
_rectTransform.anchoredPosition = Mouse.current.position.ReadValue() / Canvas.scaleFactor;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4fa6ea658c486044c8e34b8846940726
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: