Skip to content

Commit

Permalink
- Added access function to closed property on Path
Browse files Browse the repository at this point in the history
- Fixed bug where spawn action uses prefab even when there's a spawner
  • Loading branch information
DiogoDeAndrade committed Feb 10, 2024
1 parent ef1a080 commit c3c86ea
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 107 deletions.
200 changes: 101 additions & 99 deletions Assets/OkapiKit/Scripts/Actions/ActionSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,43 @@ public override string GetRawDescription(string ident, GameObject gameObject)
{
string desc = GetPreconditionsString(gameObject);

if (prefabObject)
spawner = GetComponent<Spawner>();
if (spawner != null)
{
desc += $"spawns prefab {prefabObject.name}";
switch (spawnPosition)
{
case SpawnPosition.Default:
desc += " at original position";
break;
case SpawnPosition.This:
desc += $" at the position of this object ({name})";
break;
case SpawnPosition.Target:
var targetName = (targetPosition) ? (targetPosition.name) : ("UNDEFINED");
desc += $" at the position of {targetName}";
break;
case SpawnPosition.Tag:
var tagName = (targetTag) ? (targetTag.name) : ("UNDEFINED");
desc += $" at the position of object with tag [{tagName}] (if multiple objects have the same tag, selects a random one)";
break;
default:
break;
}
if ((needParent) && (setParent))
{
desc += ", setting it as parent";
}
desc += $"spawns an entity using spawner {name}";
}
else
{
spawner = GetComponent<Spawner>();
if (spawner == null)
if (prefabObject)
{
desc += $"spawns an entity using spawner, but there's no spawner in object!";
desc += $"spawns prefab {prefabObject.name}";
switch (spawnPosition)
{
case SpawnPosition.Default:
desc += " at original position";
break;
case SpawnPosition.This:
desc += $" at the position of this object ({name})";
break;
case SpawnPosition.Target:
var targetName = (targetPosition) ? (targetPosition.name) : ("UNDEFINED");
desc += $" at the position of {targetName}";
break;
case SpawnPosition.Tag:
var tagName = (targetTag) ? (targetTag.name) : ("UNDEFINED");
desc += $" at the position of object with tag [{tagName}] (if multiple objects have the same tag, selects a random one)";
break;
default:
break;
}
if ((needParent) && (setParent))
{
desc += ", setting it as parent";
}
}
else
{
desc += $"spawns an entity using spawner {name}";
desc += $"spawns an entity, but there's no prefab nor a spawner defined!";
}
}
return desc;
Expand All @@ -84,111 +84,113 @@ protected override void CheckErrors()
{
base.CheckErrors();

if (prefabObject == null)
var spawner = GetComponent<Spawner>();
if (spawner == null)
{
var spawner = GetComponent<Spawner>();
if (spawner == null)
if (prefabObject == null)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Spawn prefab not defined!\nEither define a prefab to spawn, or add a Spawner system on this object!", "This action spawns (creates) a new object, so we need to define which object we want to create.\nWe can do that by defining a prefab object, or if we want to do something more complex (like selecting a random object from a list, or spawning randomly inside of an area, or at certain points), we need to create a Spawner system on this object. "));
}
else
{
spawner.ForceCheckErrors();
var actionLogs = spawner.logs;
foreach (var log in actionLogs)
#if UNITY_EDITOR
if ((PrefabUtility.GetPrefabAssetType(prefabObject) == PrefabAssetType.NotAPrefab) ||
(prefabObject.scene == null) ||
(prefabObject.scene.rootCount != 0))
{
_logs.Add(new LogEntry(log.type, $"On spawner: " + log.text, log.tooltip));
_logs.Add(new LogEntry(LogEntry.Type.Error, "Spawn object is not a prefab!", "Object needs to be a prefab, not an object that belongs to the scene, because those can be destroyed.\nA prefab is an object that doesn't belong to a scene, but belongs to the project (so it's on the Project view, not on the Hierarchy).\nTo create a new prefab, just drag the object from the hierarchy to the project.\nIf the object is already a prefab object by itself, select the original object on the project view, instead of the hierarchy view."));
}
}
}
else
{
#if UNITY_EDITOR
if ((PrefabUtility.GetPrefabAssetType(prefabObject) == PrefabAssetType.NotAPrefab) ||
(prefabObject.scene == null) ||
(prefabObject.scene.rootCount != 0))
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Spawn object is not a prefab!", "Object needs to be a prefab, not an object that belongs to the scene, because those can be destroyed.\nA prefab is an object that doesn't belong to a scene, but belongs to the project (so it's on the Project view, not on the Hierarchy).\nTo create a new prefab, just drag the object from the hierarchy to the project.\nIf the object is already a prefab object by itself, select the original object on the project view, instead of the hierarchy view."));
}
#endif

if (spawnPosition == SpawnPosition.Target)
{
if (targetPosition == null)
if (spawnPosition == SpawnPosition.Target)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Target position is not set!", "If you want to spawn the object at a particular point, you need to provide which point"));
if (targetPosition == null)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Target position is not set!", "If you want to spawn the object at a particular point, you need to provide which point"));
}
}
}
if (spawnPosition == SpawnPosition.Tag)
{
if (targetTag == null)
if (spawnPosition == SpawnPosition.Tag)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Target tag is not set!", "If you want to spawn the object at the position of an object with a specific tag, please define what tag.\nIf there's multiple objects with the same tag, a random one will be chosen."));
if (targetTag == null)
{
_logs.Add(new LogEntry(LogEntry.Type.Error, "Target tag is not set!", "If you want to spawn the object at the position of an object with a specific tag, please define what tag.\nIf there's multiple objects with the same tag, a random one will be chosen."));
}
}
}
}
}
else
{
spawner.ForceCheckErrors();
var actionLogs = spawner.logs;
foreach (var log in actionLogs)
{
_logs.Add(new LogEntry(log.type, $"On spawner: " + log.text, log.tooltip));
}
}
}

public override void Execute()
{
if (!enableAction) return;
if (!EvaluatePreconditions()) return;

if (prefabObject)
if (spawner == null)
{
spawner = GetComponent<Spawner>();
}
if (spawner != null)
{
switch (spawnPosition)
spawner.Spawn();
}
else
{
if (prefabObject)
{
case SpawnPosition.Default:
Instantiate(prefabObject);
break;
case SpawnPosition.This:
{
var obj = Instantiate(prefabObject, transform.position, transform.rotation);
if (setParent)
switch (spawnPosition)
{
case SpawnPosition.Default:
Instantiate(prefabObject);
break;
case SpawnPosition.This:
{
obj.transform.SetParent(transform);
var obj = Instantiate(prefabObject, transform.position, transform.rotation);
if (setParent)
{
obj.transform.SetParent(transform);
}
}
}
break;
case SpawnPosition.Target:
{
var obj = Instantiate(prefabObject, targetPosition.position, targetPosition.rotation);
if (setParent)
break;
case SpawnPosition.Target:
{
obj.transform.SetParent(targetPosition.transform);
var obj = Instantiate(prefabObject, targetPosition.position, targetPosition.rotation);
if (setParent)
{
obj.transform.SetParent(targetPosition.transform);
}
}
}
break;
case SpawnPosition.Tag:
{
var targetObjs = HypertaggedObject.FindGameObjectsWithHypertag(targetTag);
if ((targetObjs != null) && (targetObjs.Count > 0))
break;
case SpawnPosition.Tag:
{
var targetObj = targetObjs[UnityEngine.Random.Range(0, targetObjs.Count)];
if (targetObj)
var targetObjs = HypertaggedObject.FindGameObjectsWithHypertag(targetTag);
if ((targetObjs != null) && (targetObjs.Count > 0))
{
var obj = Instantiate(prefabObject, targetObj.transform.position, targetObj.transform.rotation);
if (setParent)
var targetObj = targetObjs[UnityEngine.Random.Range(0, targetObjs.Count)];
if (targetObj)
{
obj.transform.SetParent(targetObj.transform);
var obj = Instantiate(prefabObject, targetObj.transform.position, targetObj.transform.rotation);
if (setParent)
{
obj.transform.SetParent(targetObj.transform);
}
}
}
}
}
break;
default:
break;
break;
default:
break;
}
return;
}
return;
}

if (spawner == null)
{
spawner = GetComponent<Spawner>();
}
if (spawner != null)
{
spawner.Spawn();
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Assets/OkapiKit/Scripts/Systems/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Path : OkapiElement
[SerializeField]
private bool onlyDisplayWhenSelected = true;
[SerializeField]
private Color displayColor = Color.white;
private Color displayColor = Color.yellow;

private bool isSmooth => type == Type.Smooth;

Expand Down Expand Up @@ -62,6 +62,8 @@ public void SetEditPoints(List<Vector3> inPoints)
public bool isWorldSpace => worldSpace;
public bool isLocalSpace => !worldSpace;

public bool isClosed => closed;

protected override void Awake()
{
base.Awake();
Expand Down
4 changes: 2 additions & 2 deletions Assets/OkapiKit/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "com.videojogoslusofona.okapikit",
"displayName": "OkapiKit",
"version": "1.11.0",
"version": "1.11.1",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code.",
"keywords": [ "kit" ],
"category": "kit",
"dependencies": {},
"author": {
"name": "Diogo de Andrade - ULHT",
"name": "Videojogos ULHT",
"url": "https://github.com/VideojogosLusofona"
}
}
6 changes: 3 additions & 3 deletions Assets/OkapiKitSamples/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "com.videojogoslusofona.okapikit.samples",
"displayName": "OkapiKit Samples",
"version": "1.11.0",
"version": "1.11.1",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code. This package is just the samples for OkapiKit, they are not required to use Okapi Kit, and requires the Okapi Kit package.",
"keywords": [ "okapi", "samples" ],
"category": "samples",
"dependencies": {},
"relatedPackages": {
"com.videojogoslusofona.okapikit": "1.11.0"
"com.videojogoslusofona.okapikit": "1.11.1"
},
"author": {
"name": "Diogo de Andrade - ULHT",
"name": "Videojogos ULHT",
"url": "https://github.com/VideojogosLusofona"
}
}
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## V1.11.1

- Added access function to closed property on Path
- Fixed bug where spawn action uses prefab even when there's a spawner

## V1.11.0

- Added special values to SetAnimationParameter action - velocity.x/y, with abs
Expand Down
13 changes: 11 additions & 2 deletions Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Features:
- Conditions that can have visual support and interfaces on scene view should be created
- Add Network Object support to Okapi
- Add target to ActionSetParent (need rename of variables)
- Spawner with boxes should have options for direction
- Spawner should have random direction possibility
- Path shows direction (debug)
- Probes:
- Circle
- Box
Expand All @@ -22,6 +25,8 @@ Features:

Usability:
----------
- Warning: when a button name is not defined (or doesn't exist, if possible)
- Warning: destroy action should be the last
- How to make simple actions more accessible? (see Simple Usage)
- Add a tree view to explore objects in the games
- Add triggers/actions directly in the objects
Expand All @@ -41,10 +46,14 @@ Videos:

Bugs:
-----
- Collision detection fails because of using RigidBody2D.MovePosition() instead of actual physics
- Preserve velocity with Movement
- Preserve gravity with velocity set (?)
- Tooltips don't work with Naughty Attributes range
- Maybe make my own to be able to have tooltips, or propose a fix
- Inertia on Movement_XY should only appear when Input control
- There's a strange bug with bounding boxes spawner, need to check it out (Breno project)
- Target tag on Shake should disappear when an object is set
- Shake should be linked to target, not to action itself (can't destroy action after a shake)
- Shake should return object to initial state (or have option for it)

Polish:
-------
Expand Down

0 comments on commit c3c86ea

Please sign in to comment.