Skip to content

Commit

Permalink
Still working on the grid system
Browse files Browse the repository at this point in the history
Grid version os XY, follow and forward movement
Animation support on Grid XY movement (needs to extend to normal XY movement)
Added GridSystem and GridObject concepts, to allow for pushing, etc
  • Loading branch information
DiogoDeAndrade committed Nov 1, 2024
1 parent f71c510 commit 6082b22
Show file tree
Hide file tree
Showing 90 changed files with 7,234 additions and 405 deletions.
Binary file added Art/GridEvent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Assets/OkapiKit/Scripts/Base/GridHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;
using static OkapiKit.GridHelpers;

namespace OkapiKit
{
public static class GridHelpers
{



}
}
2 changes: 2 additions & 0 deletions Assets/OkapiKit/Scripts/Base/GridHelpers.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Assets/OkapiKit/Scripts/Base/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using UnityEngine;

namespace OkapiKit
{
public static class Helpers
{
public static void CheckErrorAnim(Animator anm, string logParameter, string parameterName, AnimatorControllerParameterType type, List<LogEntry> ret)
{
if (parameterName == "")
{
return;
}
for (int i = 0; i < anm.parameterCount; i++)
{
var param = anm.GetParameter(i);
if (param.name == parameterName)
{
if (param.type != type)
{
ret.Add(new LogEntry(LogEntry.Type.Error, $"Animation parameter type {parameterName} for {logParameter} is of wrong type (expected {type}, found {param.type})!", $"Animation parameter type {parameterName} for {logParameter} is of wrong type (expected {type}, found {param.type})!"));
}
return;
}
}

ret.Add(new LogEntry(LogEntry.Type.Error, $"Animation parameter {parameterName} for {logParameter} not found!", "The given animator doesn't have this parameter. Either set it to empty (so we don't try to drive it), or add it on the animator."));
}
}
}
2 changes: 2 additions & 0 deletions Assets/OkapiKit/Scripts/Base/Helpers.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/GridObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ namespace OkapiKit.Editor
[CustomEditor(typeof(GridObject))]
public class GridObjectEditor : OkapiBaseEditor
{
SerializedProperty propPivot;
SerializedProperty propCanPush;
SerializedProperty propMass;
SerializedProperty propSize;
SerializedProperty propStepAnimationCurve;

protected override void OnEnable()
{
base.OnEnable();

propPivot = serializedObject.FindProperty("_pivot");
propCanPush = serializedObject.FindProperty("_canPush");
propMass = serializedObject.FindProperty("_mass");
propSize = serializedObject.FindProperty("_size");
propStepAnimationCurve = serializedObject.FindProperty("stepAnimationCurve");
}

public override void OnInspectorGUI()
Expand All @@ -21,6 +33,22 @@ public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(propPivot, new GUIContent("Pivot", "Pivot of the visual object associated with this grid object.\nShould match the sprite placed on the sprite renderer, for example."));
EditorGUILayout.PropertyField(propCanPush, new GUIContent("Can be pushed?", "Can this object be pushed by others?"));
if (propCanPush.boolValue)
{
EditorGUILayout.PropertyField(propMass, new GUIContent("Mass", "What's the mass of this object? This is compared to the push strength of the object that's trying to push this one."));
EditorGUILayout.PropertyField(propSize, new GUIContent("Size", "What's the size of this object? This is used to test for overlaps during pushing."));
}
// Separator
Rect separatorRect = GUILayoutUtility.GetLastRect();
separatorRect.yMin = separatorRect.yMax + 5;
separatorRect.height = 5.0f;
EditorGUI.DrawRect(separatorRect, GUIUtils.ColorFromHex("#ff6060"));
EditorGUILayout.Space(separatorRect.height + 5);

EditorGUILayout.PropertyField(propStepAnimationCurve, new GUIContent("Animation Curve", "How do we animate each step position update. Simplest mode is to have a line going from bottom left to upper right."));

EditorGUI.EndChangeCheck();

serializedObject.ApplyModifiedProperties();
Expand Down
57 changes: 57 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/GridSystemEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using UnityEngine;
using UnityEditor;

namespace OkapiKit.Editor
{
[CustomEditor(typeof(GridSystem))]
public class GridSystemEditor : OkapiBaseEditor
{
SerializedProperty propGridcolliders;

protected override void OnEnable()
{
base.OnEnable();

propGridcolliders = serializedObject.FindProperty("gridcolliders");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

if (WriteTitle())
{
EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(propGridcolliders, new GUIContent("Grid Colliders", "These colliders will be used when we detect if the children grid objects can move through the environment.\nNormally, this is a list of the Tilemap Colliders or Composite Colliders of the tilemap below."));

EditorGUI.EndChangeCheck();

serializedObject.ApplyModifiedProperties();
(target as OkapiElement).UpdateExplanation();
}
}

protected override GUIStyle GetTitleSyle()
{
return GUIUtils.GetActionTitleStyle();
}

protected override GUIStyle GetExplanationStyle()
{
return GUIUtils.GetActionExplanationStyle();
}

protected override string GetTitle()
{
return "Grid System";
}

protected override Texture2D GetIcon()
{
return GUIUtils.GetTexture("GridObject");
}

protected override (Color, Color, Color) GetColors() => (GUIUtils.ColorFromHex("#93c08b"), GUIUtils.ColorFromHex("#2f4858"), GUIUtils.ColorFromHex("#527d4a"));
}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/GridSystemEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MovementGridFollowEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace OkapiKit.Editor
{
[CustomEditor(typeof(MovementGridFollow))]
public class MovementGridFollowEditor : MovementEditor
{
SerializedProperty propSpeed;
SerializedProperty propTargetType;
SerializedProperty propTargetTag;
SerializedProperty propTargetObject;
SerializedProperty propRelativeMovement;
SerializedProperty propRotateTowardsDirection;
SerializedProperty propAlignAxis;
SerializedProperty propMaxRotationSpeed;
SerializedProperty propCameraObject;
SerializedProperty propCameraTag;
SerializedProperty propCooldown;
SerializedProperty propPushStrength;

protected override void OnEnable()
{
base.OnEnable();

propSpeed = serializedObject.FindProperty("speed");
propTargetType = serializedObject.FindProperty("targetType");
propTargetTag = serializedObject.FindProperty("targetTag");
propTargetObject = serializedObject.FindProperty("targetObject");
propRelativeMovement = serializedObject.FindProperty("relativeMovement");
propRotateTowardsDirection = serializedObject.FindProperty("rotateTowardsDirection");
propAlignAxis = serializedObject.FindProperty("alignAxis");
propMaxRotationSpeed = serializedObject.FindProperty("maxRotationSpeed");
propCameraObject = serializedObject.FindProperty("cameraObject");
propCameraTag = serializedObject.FindProperty("cameraTag");
propCooldown = serializedObject.FindProperty("cooldown");
propPushStrength = serializedObject.FindProperty("pushStrength");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

if (WriteTitle())
{
EditorGUI.BeginChangeCheck();

DefaultMovementEditor();

EditorGUILayout.PropertyField(propSpeed, new GUIContent("Speed", "Maximum follow speed"));
EditorGUILayout.PropertyField(propCooldown, new GUIContent("Cooldown", "Time between grid movements"));
EditorGUILayout.PropertyField(propTargetType, new GUIContent("Target Type", "Type of target to follow.\nTag: Find the closest object tagged with the given tag, and follow it\nObject: Follow the linked object\nMouse: Follow the mouse cursor"));

MovementFollow.TargetType type = (MovementFollow.TargetType)propTargetType.intValue;
switch (type)
{
case MovementFollow.TargetType.Tag:
EditorGUILayout.PropertyField(propTargetTag, new GUIContent("Target Tag", "Find objects with this tag, and follow the closest one."));
break;
case MovementFollow.TargetType.Object:
EditorGUILayout.PropertyField(propTargetObject, new GUIContent("Target Object", "Follow this object."));
break;
case MovementFollow.TargetType.Mouse:
if (propCameraTag.objectReferenceValue == null)
{
if (propCameraObject.objectReferenceValue == null)
{
EditorGUILayout.PropertyField(propCameraTag, new GUIContent("Camera Tag", "Tag on the camera.\nYou can select the camera either by tag or by linking it, but not both at the same time.\nBy tag is the prefered method."));
EditorGUILayout.PropertyField(propCameraObject, new GUIContent("Camera Object", "Camera object.\nYou can select the camera either by tag or by linking it, but not both at the same time.\nBy tag is the prefered method."));
}
else
{
EditorGUILayout.PropertyField(propCameraObject, new GUIContent("Camera Object", "Camera object.\nYou can select the camera either by tag or by linking it, but not both at the same time.\nBy tag is the prefered method."));
}
}
else
{
EditorGUILayout.PropertyField(propCameraTag, new GUIContent("Camera Tag", "Tag on the camera.\nYou can select the camera either by tag or by linking it, but not both at the same time.\nBy tag is the prefered method."));
}
break;
default:
break;
}

if (type != MovementFollow.TargetType.Mouse)
{
EditorGUILayout.PropertyField(propRelativeMovement, new GUIContent("Relative Movement", "Is the follow movement relative?\nIf on, the object will preserve the relative position to the object being followed."));
}

EditorGUILayout.PropertyField(propRotateTowardsDirection, new GUIContent("Align With Direction", "If on, the object will be turned towards the target object."));
if (propRotateTowardsDirection.boolValue)
{
EditorGUILayout.PropertyField(propAlignAxis, new GUIContent("Alignment Axis", "Alignment axis (i.e. is the object pointing to the right or up?)"));
EditorGUILayout.PropertyField(propMaxRotationSpeed, new GUIContent("Max Rotation Speed", "What's the maximum rotation speed (degrees per second)?"));
}

EditorGUILayout.PropertyField(propPushStrength, new GUIContent("Push Strength", "This is the strength which is used to push other objects.\nThis is matched with the mass of the objects, and can be accumulated (i.e. you need a strength of 2 to push two objects with 1 mass at the same time).\nA strenght of zero disables the push system."));

EditorGUILayout.PropertyField(propDescription, new GUIContent("Description", "This is for you to leave a comment for yourself or others."));

EditorGUI.EndChangeCheck();

serializedObject.ApplyModifiedProperties();
(target as OkapiElement).UpdateExplanation();

StdEditor(false);
}
}

}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MovementGridFollowEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MovementGridForwardEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace OkapiKit.Editor
{
[CustomEditor(typeof(MovementGridForward))]
public class MovementGridForwardEditor : MovementEditor
{
SerializedProperty propSpeed;
SerializedProperty propAxis;
SerializedProperty propCooldown;
SerializedProperty propPushStrength;

protected override void OnEnable()
{
base.OnEnable();

propSpeed = serializedObject.FindProperty("speed");
propAxis = serializedObject.FindProperty("axis");
propCooldown = serializedObject.FindProperty("cooldown");
propPushStrength = serializedObject.FindProperty("pushStrength");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

if (WriteTitle())
{
EditorGUI.BeginChangeCheck();

DefaultMovementEditor();

EditorGUILayout.PropertyField(propSpeed, new GUIContent("Speed", "What's the movement speed (pixels/second)?"));
EditorGUILayout.PropertyField(propAxis, new GUIContent("Axis", "What is forward (i.e. is the object point to the right, or pointing up?)"));

EditorGUILayout.PropertyField(propCooldown, new GUIContent("Cooldown", "Time between grid movements"));

EditorGUILayout.PropertyField(propPushStrength, new GUIContent("Push Strength", "This is the strength which is used to push other objects.\nThis is matched with the mass of the objects, and can be accumulated (i.e. you need a strength of 2 to push two objects with 1 mass at the same time).\nA strenght of zero disables the push system."));

EditorGUILayout.PropertyField(propDescription, new GUIContent("Description", "This is for you to leave a comment for yourself or others."));

EditorGUI.EndChangeCheck();

serializedObject.ApplyModifiedProperties();
(target as OkapiElement).UpdateExplanation();

StdEditor(false);
}
}

}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MovementGridForwardEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6082b22

Please sign in to comment.