diff --git a/Assets/IsoUnity/Editor/Inspector/ItemForkEditor.cs b/Assets/IsoUnity/Editor/Inspector/ItemForkEditor.cs
index 9d96135..1166ed4 100644
--- a/Assets/IsoUnity/Editor/Inspector/ItemForkEditor.cs
+++ b/Assets/IsoUnity/Editor/Inspector/ItemForkEditor.cs
@@ -12,7 +12,7 @@ public override void OnInspectorGUI()
{
var isf = target as ItemFork;
isf.contains = EditorGUILayout.Toggle("Contains", isf.contains);
- isf.item = EditorGUILayout.ObjectField("Item", (Object)isf.item, typeof(IsoUnity.Entities.Item), true) as IsoUnity.Entities.Item;
+ isf.item = EditorGUILayout.ObjectField("Item", (Object)isf.item, typeof(Item), true) as IsoUnity.Entities.Item;
isf.inventory = EditorGUILayout.ObjectField("Inventory", (Object)isf.inventory, typeof(IsoUnity.Entities.Inventory), true) as IsoUnity.Entities.Inventory;
}
}
diff --git a/Assets/IsoUnity/Resources/IsoSwitches.asset b/Assets/IsoUnity/Resources/IsoSwitches.asset
index 76f40b0..b615cec 100644
--- a/Assets/IsoUnity/Resources/IsoSwitches.asset
+++ b/Assets/IsoUnity/Resources/IsoSwitches.asset
@@ -11,4 +11,40 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4f903b5c05730594280dcba273e69bc4, type: 3}
m_Name: IsoSwitches
m_EditorClassIdentifier:
- switches: []
+ switches:
+ - {fileID: 114917095835242190}
+--- !u!114 &114119281123777720
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 0}
+ m_GameObject: {fileID: 0}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 8daaa0a8c5652f247939f4ab49339994, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ i: 0
+ f: 0
+ d: 0
+ s:
+ v2: {x: 0, y: 0}
+ v3: {x: 0, y: 0, z: 0}
+ v4: {x: 0, y: 0, z: 0, w: 0}
+ q: {x: 0, y: 0, z: 0, w: 0}
+ b: 0
+ c: 0
+ whatIs: System.Boolean
+--- !u!114 &114917095835242190
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 0}
+ m_GameObject: {fileID: 0}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 0887338ee6657394ebdae4d5c768a9de, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ id: hablado
+ state: {fileID: 114119281123777720}
diff --git a/Assets/IsoUnity/Source/Animations.meta b/Assets/IsoUnity/Source/Animations.meta
new file mode 100644
index 0000000..1aae1c7
--- /dev/null
+++ b/Assets/IsoUnity/Source/Animations.meta
@@ -0,0 +1,10 @@
+fileFormatVersion: 2
+guid: a402e27c9aec9d549a8de20b3bcaaf32
+folderAsset: yes
+timeCreated: 1527688176
+licenseType: Free
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/IsoUnity/Source/Animations/IsoAnimation.cs b/Assets/IsoUnity/Source/Animations/IsoAnimation.cs
new file mode 100644
index 0000000..e6c1f07
--- /dev/null
+++ b/Assets/IsoUnity/Source/Animations/IsoAnimation.cs
@@ -0,0 +1,27 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace IsoUnity
+{
+ [System.Serializable]
+ [CreateAssetMenu(fileName = "new IsoAnimation", menuName = "IsoUnity/IsoAnimation")]
+ public class IsoAnimation : ScriptableObject {
+
+ [System.Serializable]
+ public struct Frame {
+ public int column;
+ public float duration;
+ }
+
+ [SerializeField]
+ public bool loop = false;
+ [SerializeField]
+ public List frames = new List();
+ [SerializeField]
+ public string sheet;
+ [SerializeField]
+ public IsoDecoration overrideSheet;
+ }
+}
+
diff --git a/Assets/IsoUnity/Source/Animations/IsoAnimation.cs.meta b/Assets/IsoUnity/Source/Animations/IsoAnimation.cs.meta
new file mode 100644
index 0000000..32f5571
--- /dev/null
+++ b/Assets/IsoUnity/Source/Animations/IsoAnimation.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d3a9a02dbd6a69445a57c833e33785c1
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/IsoUnity/Source/Entity/Entity.cs b/Assets/IsoUnity/Source/Entity/Entity.cs
index 13265ec..dd3abac 100644
--- a/Assets/IsoUnity/Source/Entity/Entity.cs
+++ b/Assets/IsoUnity/Source/Entity/Entity.cs
@@ -6,6 +6,7 @@ namespace IsoUnity.Entities
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
+ [RequireComponent(typeof(DecorationAnimator))]
[RequireComponent(typeof(Mover))]
public class Entity : MonoBehaviour
{
@@ -59,9 +60,10 @@ public Option[] getOptions()
}
// Use this for initialization
- void Start()
+ private void OnEnable()
{
-
+ foreach(var es in GetComponents())
+ es.OnEntityReady();
}
@@ -81,6 +83,13 @@ public Mover mover
return this.GetComponent();
}
}
+ public DecorationAnimator decorationAnimator
+ {
+ get
+ {
+ return this.GetComponent();
+ }
+ }
// Update is called once per frame
void Update()
diff --git a/Assets/IsoUnity/Source/Entity/EntityScript.cs b/Assets/IsoUnity/Source/Entity/EntityScript.cs
index ca908de..d1c521b 100644
--- a/Assets/IsoUnity/Source/Entity/EntityScript.cs
+++ b/Assets/IsoUnity/Source/Entity/EntityScript.cs
@@ -11,10 +11,7 @@ public Entity Entity
get { return this.GetComponent(); }
}
// Use this for initialization
- /*public virtual void Start()
- {
-
- }*/
+ public virtual void OnEntityReady() {}
//Abstract Methods
public abstract void eventHappened(IGameEvent ge);
diff --git a/Assets/IsoUnity/Source/Entity/EventedEntityScript.cs b/Assets/IsoUnity/Source/Entity/EventedEntityScript.cs
index 226b674..a01ca53 100644
--- a/Assets/IsoUnity/Source/Entity/EventedEntityScript.cs
+++ b/Assets/IsoUnity/Source/Entity/EventedEntityScript.cs
@@ -9,7 +9,8 @@ namespace IsoUnity.Entities
{
public abstract class EventedEntityScript : EntityScript
{
- private bool inited = false;
+ public delegate IEnumerator CoroutineControllerDelegate(IGameEvent ge, IEnumerator toRun, MonoBehaviour holder);
+
private Dictionary calls;
private Dictionary attrInfo;
@@ -17,16 +18,26 @@ public override void eventHappened(IGameEvent ge)
{
Current = ge;
- EventHappened(this, calls, attrInfo, ge);
+ EventHappened(this, calls, attrInfo, ge, CoroutineController);
Current = null;
}
- private static IEnumerator CoroutineController(IGameEvent ge, IEnumerator toRun)
+ private static IEnumerator CoroutineController(IGameEvent ge, IEnumerator toRun, MonoBehaviour holder)
{
+ var eventedES = holder as EventedEntityScript;
+
// We wrap the coroutine
while (toRun.MoveNext())
+ {
+ // Free the current value
+ eventedES.Current = null;
yield return toRun.Current;
+ // Set the current event value
+ eventedES.Current = ge;
+ }
+ // Free the current value
+ eventedES.Current = null;
// And when it finishes, we finish the event
Game.main.eventFinished(ge);
@@ -39,15 +50,13 @@ public override Option[] getOptions()
protected IGameEvent Current { get; private set; }
- public override void tick()
+ protected virtual void Start()
{
- if (!inited)
- {
- Init(this.GetType(), ref calls, ref attrInfo);
- inited = true;
- }
+ Init(this.GetType(), ref calls, ref attrInfo);
}
+ public override void tick() { }
+
internal static void Init(Type type, ref Dictionary calls, ref Dictionary attrInfo)
{
calls = new Dictionary();
@@ -63,7 +72,7 @@ internal static void Init(Type type, ref Dictionary
}
}
- internal static void EventHappened(MonoBehaviour reference, Dictionary calls, Dictionary attrInfo, IGameEvent ge)
+ internal static void EventHappened(MonoBehaviour reference, Dictionary calls, Dictionary attrInfo, IGameEvent ge, CoroutineControllerDelegate coroutineController)
{
if (calls != null && calls.Count > 0)
{
@@ -84,7 +93,7 @@ internal static void EventHappened(MonoBehaviour reference, Dictionary sheets = new List();
+ [SerializeField]
+ public List isoAnimations = new List();
+ [SerializeField]
+ private Dictionary run = new Dictionary();
+ [SerializeField]
+ private Queue playQueue = new Queue();
+
+ // Animation variables
+ //[NonSerialized]
+ public int currentFrame;
+ //[NonSerialized]
+ public IsoAnimation currentAnimation;
+ //[NonSerialized]
+ public float timeInCurrentFrame;
+ //[NonSerialized]
+ public IsoDecoration currentSheet;
+ //[NonSerialized]
+ public bool animationLocked = false;
+
+ [GameEvent]
+ public IEnumerator AnimateEntity(string animation, string then = null)
+ {
+ // Clear the current animation
+ animationLocked = false;
+ currentAnimation = null;
+ playQueue.Clear();
+
+ // Find the animation
+ var isoAnimation = isoAnimations.Find(n => n.name.Equals(animation, StringComparison.InvariantCultureIgnoreCase));
+ if(isoAnimation == null)
+ yield return null;
+
+ // Find a sheet
+ IsoDecoration sheet = isoAnimation.isoAnimation.overrideSheet;
+ if(sheet == null){
+ NameIsoDecoration namedSheet = sheets.Find(s =>
+ {
+ return s.name.Equals(isoAnimation.isoAnimation.sheet, StringComparison.InvariantCultureIgnoreCase);
+ });
+ if (namedSheet != null) sheet = namedSheet.isoDecoration;
+ }
+ if(sheet == null)
+ yield return null;
+
+ var ge = Current;
+ // Stop all other animations
+ foreach(var kv in run)
+ run[kv.Key] = false;
+
+ // Add the new one
+ run.Add(ge, true);
+
+ // Perform the animation
+ foreach(var frame in isoAnimation.isoAnimation.frames)
+ {
+ SetFrame(sheet, frame.column);
+ yield return new WaitForSeconds(frame.duration);
+ if(!run[ge])
+ break;
+ }
+
+ var desiredRun = run[ge];
+ run.Remove(ge);
+ if(desiredRun && !string.IsNullOrEmpty(then))
+ Play(then);
+ }
+
+ public void Play(params string[] animations)
+ {
+ currentAnimation = null;
+ currentFrame = 0;
+ timeInCurrentFrame = 0f;
+ animationLocked = false;
+ playQueue.Clear();
+ foreach(var animation in animations)
+ {
+ playQueue.Enqueue(animation);
+ }
+ }
+
+ public override void Update()
+ {
+ var timeLeft = Time.deltaTime;
+ var desiredFrame = currentFrame;
+ var desiredAnimation = currentAnimation;
+ var lastValidAnimation = currentAnimation;
+ var lastValidFrame = currentFrame;
+
+ if (run.Count == 0 && (desiredAnimation != null || playQueue.Count > 0))
+ {
+ // While there's time left to reproduce
+ while (timeLeft > 0 && !animationLocked)
+ {
+ // Look for the next playable animation
+ while (desiredAnimation == null && playQueue.Count > 0)
+ {
+ var animationToPlay = playQueue.Dequeue();
+ var foundAnimation = isoAnimations.Find(n => n.name.Equals(animationToPlay, StringComparison.InvariantCultureIgnoreCase));
+ if (foundAnimation == null || foundAnimation.isoAnimation == null || foundAnimation.isoAnimation.frames.Count == 0)
+ continue;
+
+ currentSheet = foundAnimation.isoAnimation.overrideSheet;
+ if(currentSheet == null)
+ {
+ var foundSheet = sheets.Find(n => n.name.Equals(foundAnimation.isoAnimation.sheet, StringComparison.InvariantCultureIgnoreCase));
+ if (foundSheet != null) currentSheet = foundSheet.isoDecoration;
+ }
+
+ if (currentSheet == null)
+ continue;
+
+ lastValidAnimation = desiredAnimation = foundAnimation.isoAnimation;
+ lastValidFrame = desiredFrame = 0;
+ timeInCurrentFrame = 0f;
+ }
+
+ // And if we have animation we play it
+ if (desiredAnimation != null)
+ {
+ var looped = false;
+ var previousLoopedTimeLeft = 0f;
+ // We move through the frames untill we run out of time or frames
+ while(desiredAnimation != null && timeLeft > 0 && desiredFrame < desiredAnimation.frames.Count)
+ {
+ timeInCurrentFrame += timeLeft;
+ if(timeInCurrentFrame > desiredAnimation.frames[desiredFrame].duration)
+ {
+ timeLeft = timeInCurrentFrame - desiredAnimation.frames[desiredFrame].duration;
+ lastValidFrame = desiredFrame++;
+ timeInCurrentFrame = 0f;
+ } else timeLeft = 0;
+
+ if(desiredFrame == desiredAnimation.frames.Count)
+ {
+ desiredFrame = 0;
+ // In case of loop
+ if (desiredAnimation.loop)
+ {
+ lastValidFrame = 0;
+ // In case we already looped and time didn't decrease, this is an infinite loop
+ if(looped && previousLoopedTimeLeft == timeLeft)
+ {
+ animationLocked = true;
+ break;
+ }
+ previousLoopedTimeLeft = timeLeft;
+ looped = true;
+ }
+ else
+ {
+ desiredAnimation = null;
+ }
+ }
+ }
+ }
+ // But otherwise we exit
+ else break;
+ }
+ }
+
+ if(currentAnimation != desiredAnimation || currentAnimation != lastValidAnimation || currentFrame != desiredFrame || currentFrame != lastValidFrame)
+ {
+ currentAnimation = desiredAnimation;
+ currentFrame = desiredFrame;
+ if(lastValidAnimation != null && lastValidFrame < lastValidAnimation.frames.Count)
+ SetFrame(currentSheet, lastValidAnimation.frames[lastValidFrame].column);
+ }
+ }
+
+ private void SetFrame(IsoDecoration sheet, int column)
+ {
+ this.Entity.decoration.IsoDec = sheet;
+ var tileToSet = column;
+ if(sheet.nRows == 4)
+ tileToSet += (sheet.nCols * Mover.getDirectionIndex(this.Entity.mover.direction));
+ this.Entity.decoration.Tile = tileToSet;
+ this.Entity.decoration.updateTextures(false);
+ //this.Entity.decoration.adaptate();
+ }
+ }
+
+}
diff --git a/Assets/IsoUnity/Source/Entity/Scripts/DecorationAnimator.cs.meta b/Assets/IsoUnity/Source/Entity/Scripts/DecorationAnimator.cs.meta
new file mode 100644
index 0000000..d74e936
--- /dev/null
+++ b/Assets/IsoUnity/Source/Entity/Scripts/DecorationAnimator.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c36aa785ccb234442aaea560bf16d4ea
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/IsoUnity/Source/Entity/Scripts/Mover.cs b/Assets/IsoUnity/Source/Entity/Scripts/Mover.cs
index 1e3bcc2..54a73fc 100644
--- a/Assets/IsoUnity/Source/Entity/Scripts/Mover.cs
+++ b/Assets/IsoUnity/Source/Entity/Scripts/Mover.cs
@@ -113,11 +113,20 @@ internal void PushDestination()
// Move
private IGameEvent movementEvent;
+
+
+ private Cell next;
+ private Movement movement;
+
+ private bool step = false;
+ private Decoration dec;
/****************
* End Attributes
* ***************/
+ public bool Step { get { return step; } }
+
/******************
* MOVEMENT CONTROL
* *****************/
@@ -158,7 +167,7 @@ public void teleportTo(Cell c)
{
RoutePlanifier.cancelRoute(this);
this.movement = Movement.createMovement(MovementType.Instant,
- this.Entity, this, dec, normalSprite, this.transform.position,
+ this.Entity, this, this.transform.position,
c.transform.position, this.Entity.Position, c, null);
}
@@ -168,7 +177,7 @@ private Movement createTurnMovement(Direction dir)
mParams["direction"] = dir;
return Movement.createMovement(MovementType.Turn,
- this.Entity, this, dec, normalSprite, this.transform.position,
+ this.Entity, this, this.transform.position,
this.transform.position, this.Entity.Position, this.Entity.Position, mParams);
}
@@ -241,7 +250,7 @@ public override void tick()
{
base.tick();
- if (this.dec == null)
+ if (this.dec == null && Entity)
this.dec = Entity.decoration;
// Direction change responsive update
@@ -266,13 +275,13 @@ public bool IsMoving
return (movement != null && !movement.Ended);
}
}
-
-
- private Cell next;
- private Movement movement;
- private bool paso = false;
- private Decoration dec;
+ private IsoAnimation.Frame frame(int column, float duration){
+ return new IsoAnimation.Frame(){
+ column = column,
+ duration = duration
+ };
+ }
void Awake()
{
@@ -283,10 +292,161 @@ void Awake()
}
}
- void OnValidate()
+ private void SetUpSheets(bool replace = false)
{
+ var decorationAnimator = Entity.decorationAnimator;
+ if (decorationAnimator == null)
+ return;
+
+ var normal = Entity.decorationAnimator.sheets.Find(s => s.name == "normal");
+ var jump = Entity.decorationAnimator.sheets.Find(s => s.name == "jump");
+
+ if (replace)
+ {
+ decorationAnimator.sheets.Remove(normal);
+ normal = null;
+ decorationAnimator.sheets.Remove(jump);
+ jump = null;
+ }
+
+ // Normal sheet
+ if(normal == null)
+ {
+ decorationAnimator.sheets.Add(new DecorationAnimator.NameIsoDecoration()
+ {
+ name = "normal",
+ isoDecoration = normalSprite
+ });
+ }
+ else
+ {
+ normal.isoDecoration = normalSprite;
+ }
+
+ // Jump sheet
+ if(jump == null)
+ {
+ decorationAnimator.sheets.Add(new DecorationAnimator.NameIsoDecoration()
+ {
+ name = "jump",
+ isoDecoration = jumpingSprite
+ });
+ }
+ else
+ {
+ jump.isoDecoration = jumpingSprite;
+ }
+ }
+
+ private void SetUpAnimations(bool replace = false)
+ {
+ var decorationAnimator = Entity.decorationAnimator;
+ if (decorationAnimator == null)
+ return;
+
+ var idle = Entity.decorationAnimator.isoAnimations.Find(i => i.name == "idle");
+ var leftStep = Entity.decorationAnimator.isoAnimations.Find(i => i.name == "left step");
+ var rightStep = Entity.decorationAnimator.isoAnimations.Find(i => i.name == "right step");
+ var jump = Entity.decorationAnimator.isoAnimations.Find(i => i.name == "jump");
+
+ if (replace)
+ {
+ decorationAnimator.isoAnimations.Remove(idle);
+ idle = null;
+ decorationAnimator.isoAnimations.Remove(leftStep);
+ leftStep = null;
+ decorationAnimator.isoAnimations.Remove(rightStep);
+ rightStep = null;
+ decorationAnimator.isoAnimations.Remove(jump);
+ jump = null;
+ }
+
+ // Left step animation
+ if(idle == null)
+ {
+ var idleAnimation = ScriptableObject.CreateInstance();
+ idleAnimation.sheet = "normal";
+ idleAnimation.frames.Add(frame(0, 0)); // Instant
+ idleAnimation.loop = true;
+
+ decorationAnimator.isoAnimations.Add(new DecorationAnimator.NameIsoAnimation()
+ {
+ name = "idle",
+ isoAnimation = idleAnimation
+ });
+ }
+
+ // Left step animation
+ if(leftStep == null)
+ {
+ var leftStepAnim = ScriptableObject.CreateInstance();
+ leftStepAnim.sheet = "normal";
+ leftStepAnim.frames = new List()
+ {
+ frame(0, 0.075f),
+ frame(1, 0.15f),
+ frame(0, 0.075f)
+ };
+ Entity.decorationAnimator.isoAnimations.Add(new DecorationAnimator.NameIsoAnimation()
+ {
+ name = "left step",
+ isoAnimation = leftStepAnim
+ });
+ }
+
+ // Right step animation
+ if(!Entity.decorationAnimator.isoAnimations.Exists(i => i.name == "right step"))
+ {
+ var rightStepAnim = ScriptableObject.CreateInstance();
+ rightStepAnim.sheet = "normal";
+ rightStepAnim.frames = new List()
+ {
+ frame(0, 0.075f),
+ frame(2, 0.15f),
+ frame(0, 0.075f)
+ };
+ Entity.decorationAnimator.isoAnimations.Add(new DecorationAnimator.NameIsoAnimation()
+ {
+ name = "right step",
+ isoAnimation = rightStepAnim
+ });
+ }
+
+ // Jump animation
+ if(!Entity.decorationAnimator.isoAnimations.Exists(i => i.name == "jump"))
+ {
+ var jumpAnim = ScriptableObject.CreateInstance();
+ jumpAnim.sheet = "jump";
+ jumpAnim.frames = new List()
+ {
+ frame(0, 0.3f)
+ };
+ Entity.decorationAnimator.isoAnimations.Add(new DecorationAnimator.NameIsoAnimation()
+ {
+ name = "jump",
+ isoAnimation = jumpAnim
+ });
+ }
+ }
+ private bool entityReady = false;
+ private void OnValidate()
+ {
+ if(entityReady)
+ {
+ tick();
+ this.Update();
+ SetUpSheets(false);
+ SetUpAnimations(false);
+ }
+ }
+
+ public override void OnEntityReady()
+ {
+ entityReady = true;
tick();
this.Update();
+ SetUpSheets(false);
+ SetUpAnimations(false);
}
public override void Update()
@@ -324,8 +484,6 @@ public override void Update()
this.movement = Movement.createMovement(type, // type
this.Entity, // Entity
this, // Mover
- dec, // Decoration
- getSpritesheetForMovementType(type), // Sheet
transform.position, // Origin
next.transform.position + new Vector3(0, next.WalkingHeight + transform.localScale.y / 2, 0) + offset, // Destination
Entity.Position, // Cell Origin
@@ -352,7 +510,7 @@ public override void Update()
// If the movement has ended
if (this.movement.Ended)
{
- paso = !paso;
+ step = !step;
}
}
}
@@ -383,28 +541,6 @@ private MovementType getMovementTypeTo(Cell next, Dictionary par
return type;
}
- /**
- * Sprite Management
- * */
-
- private IsoDecoration getSpritesheetForMovementType(MovementType type)
- {
- switch (type)
- {
- case MovementType.Lineal:
- case MovementType.Fade:
- return normalSprite;
- case MovementType.Parabolic:
- return jumpingSprite;
- case MovementType.Instant:
- return normalSprite;
- case MovementType.Turn:
- return normalSprite;
- }
-
- return normalSprite;
- }
-
/**
* Movements
* */
@@ -417,8 +553,6 @@ private abstract class Movement
//Attributes
protected Entity entity;
protected Mover mover;
- protected Decoration dec;
- protected IsoDecoration sheet;
protected Vector3 from, to;
protected Cell origin, destination;
//protected MovementType type;
@@ -432,18 +566,25 @@ private abstract class Movement
public void addProgress(float time) { this.progress += time; }
public bool Ended { get { return Progress >= Duration; } }
public abstract float Duration { get; }
-
- private static int start=3
- ;
+ private bool started = false;
+ private static int start=3;
//Extra param input
protected virtual void setParams(Dictionary mParams) { }
+ // Start
+ protected virtual void Start() { }
/*************************
* GENERIC UPDATES
* ************************/
public virtual void Update(float progress)
{
+ if (!started)
+ {
+ started = true;
+ Start();
+ }
+
this.addProgress(progress);
if (!destination.Influences.Contains(entity))
destination.Influences.Add(entity);
@@ -480,34 +621,12 @@ public virtual void UpdateTextures()
}
}
- else if(dec && dec.IsoDec)
- {
- // Change the spritesheet
- this.setSpritesheet(sheet);
-
- // Step Addition
- int stepAdition = 0;
- if (dec.IsoDec.nCols > 1) // TODO: Wider spritesheets with more than 1 prite per step.
- if (Progress / Duration >= 0.15 && Progress / Duration <= 0.85)
- stepAdition = ((mover.paso) ? 1 : 2);
-
- dec.Tile = getDirectionIndex(mover.direction) * dec.IsoDec.nCols + stepAdition;
- }
- }
-
- private void setSpritesheet(IsoDecoration isoDec)
- {
- if (this.dec.IsoDec != isoDec)
- {
- this.dec.IsoDec = isoDec;
- this.dec.updateTextures(false);
- }
}
/********************
* Movement factory
* ***************/
- public static Movement createMovement(MovementType type, Entity entity, Mover mover, Decoration dec, IsoDecoration sheet,
+ public static Movement createMovement(MovementType type, Entity entity, Mover mover,
Vector3 from, Vector3 to, Cell origin, Cell destination, Dictionary mParams)
{
Movement movement = null;
@@ -530,8 +649,6 @@ public static Movement createMovement(MovementType type, Entity entity, Mover mo
movement.from = from;
movement.to = to;
movement.entity = entity;
- movement.dec = dec;
- movement.sheet = sheet;
movement.mover = mover;
return movement;
@@ -571,6 +688,12 @@ public override Vector3 getPositionAt(float moment)
return from + (to - from) * moment;
}
bool sonido = false;
+
+ protected override void Start() {
+ if (entity.mover.Step) entity.decorationAnimator.Play("left step", "idle");
+ else entity.decorationAnimator.Play("right step", "idle");
+ }
+
public override void Update(float progress)
{
@@ -591,6 +714,7 @@ public override void Update(float progress)
anim.SetFloat("speed", 0f);
}
}
+
}
@@ -619,6 +743,11 @@ public override Vector3 getPositionAt(float moment)
return from + (to - from) * moment + vectorHeight * (1f - 4f * Mathf.Pow(moment - 0.5f, 2));
}
+
+ protected override void Start() {
+ entity.decorationAnimator.Play("jump", "idle");
+ }
+
public override void Update(float progress)
{
base.Update(progress);
@@ -690,6 +819,10 @@ protected override void setParams(Dictionary mParams)
if (dir != null && dir is Direction) direction = (Direction)dir;
}
+ protected override void Start() {
+ entity.decorationAnimator.Play("idle");
+ }
+
public override void Update(float progress)
{
@@ -731,6 +864,11 @@ public override Vector3 getPositionAt(float moment)
return position;
}
+ protected override void Start() {
+ if (entity.mover.Step) entity.decorationAnimator.Play("left step", "right step", "idle");
+ else entity.decorationAnimator.Play("right step", "left step", "idle");
+ }
+
public override void Update(float progress)
{
var prevPos = entity.Position;
@@ -742,6 +880,8 @@ public override void Update(float progress)
renderer.material.color = new Color(Mathf.Abs((progress * 2f) - 1f), Mathf.Abs((progress * 2f) - 1f), Mathf.Abs((progress * 2f) - 1f), Mathf.Abs((progress * 2f) - 1f));
if (Progress / Duration > .5f && prevPos.Map != destination.Map) {
+
+
//TODO Dont like the register calls made here...
prevPos.Map.unRegisterEntity(entity);
entity.Position.Map.registerEntity(entity);
diff --git a/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs b/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs
index 0673ddc..514821f 100644
--- a/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs
+++ b/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs
@@ -11,30 +11,40 @@ public abstract class EventedEventManager : EventManager
{
private Dictionary calls;
private Dictionary attrInfo;
-
+
protected virtual void Start()
{
EventedEntityScript.Init(this.GetType(), ref calls, ref attrInfo);
}
- public override void Tick() { }
+ public override void Tick() {}
public override void ReceiveEvent(IGameEvent ge)
{
Current = ge;
- EventedEntityScript.EventHappened(this, calls, attrInfo, ge);
+ EventedEntityScript.EventHappened(this, calls, attrInfo, ge, CoroutineController);
Current = null;
}
- private IEnumerator CoroutineController(IGameEvent ge, IEnumerator toRun)
+ private static IEnumerator CoroutineController(IGameEvent ge, IEnumerator toRun, MonoBehaviour holder)
{
+ var eventedEM = holder as EventedEventManager;
+
// We wrap the coroutine
while (toRun.MoveNext())
+ {
+ // Free the current value
+ eventedEM.Current = null;
yield return toRun.Current;
+ // Set the current event value
+ eventedEM.Current = ge;
+ }
+ // Free the current value
+ eventedEM.Current = null;
// And when it finishes, we finish the event
Game.main.eventFinished(ge);
}
- protected IGameEvent Current { get; private set; }
+ protected IGameEvent Current { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs.meta b/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs.meta
index ca0525e..e62d805 100644
--- a/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs.meta
+++ b/Assets/IsoUnity/Source/EvenManagers/EventedEventManager.cs.meta
@@ -1,7 +1,5 @@
fileFormatVersion: 2
-guid: fa0276e9f0e50904eb94aea2dc9031e9
-timeCreated: 1521195810
-licenseType: Free
+guid: bf760dc6fceafeb46972e910b1872270
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/IsoUnity/Source/EvenManagers/TimerManager.cs.meta b/Assets/IsoUnity/Source/EvenManagers/TimerManager.cs.meta
index 45180b7..bdce39d 100644
--- a/Assets/IsoUnity/Source/EvenManagers/TimerManager.cs.meta
+++ b/Assets/IsoUnity/Source/EvenManagers/TimerManager.cs.meta
@@ -1,7 +1,5 @@
fileFormatVersion: 2
-guid: ff1e356c3e00f2c42bee6ae55a8a319b
-timeCreated: 1521195810
-licenseType: Free
+guid: eaafcf330d596484baeae54803aedd60
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/IsoUnity/Source/EvenManagers/WaitForEventFinished.cs b/Assets/IsoUnity/Source/EvenManagers/WaitForEventFinished.cs
index 89167c2..86d5892 100644
--- a/Assets/IsoUnity/Source/EvenManagers/WaitForEventFinished.cs
+++ b/Assets/IsoUnity/Source/EvenManagers/WaitForEventFinished.cs
@@ -11,7 +11,7 @@ public class WaitForEventFinished : IEnumerator, IEventManager
private bool finished = false;
public WaitForEventFinished(IGameEvent gameEvent)
{
- if(Game.main)
+ if (Game.main)
Game.main.RegisterEventManager(this);
waiting = gameEvent;
@@ -50,5 +50,5 @@ public void Reset()
throw new NotImplementedException();
}
- public void Tick(){}
-}
+ public void Tick() { }
+}
\ No newline at end of file
diff --git a/Assets/IsoUnity/Source/Game/Game.cs b/Assets/IsoUnity/Source/Game/Game.cs
index a057e90..c56b4cf 100644
--- a/Assets/IsoUnity/Source/Game/Game.cs
+++ b/Assets/IsoUnity/Source/Game/Game.cs
@@ -187,7 +187,7 @@ private void broadcastEvent(IGameEvent ge)
public void tick()
{
FlushRegistrations();
-
+
if (previousMap != map)
MapManager.getInstance().setActiveMap(previousMap = map);
@@ -206,7 +206,7 @@ public void tick()
foreach (Map eachMap in MapManager.getInstance().getMapList())
{
eachMap.tick();
- }
+ }
}
/**
@@ -240,4 +240,4 @@ void FlushRegistrations()
}
}
-}
\ No newline at end of file
+}
diff --git a/Assets/IsoUnity/Source/Map/Decoration.cs b/Assets/IsoUnity/Source/Map/Decoration.cs
index 148d2ff..17906e1 100644
--- a/Assets/IsoUnity/Source/Map/Decoration.cs
+++ b/Assets/IsoUnity/Source/Map/Decoration.cs
@@ -94,7 +94,7 @@ void Update()
if (tile != previousTile)
{
- tile = Mathf.Clamp(tile, 0, isoDec.nCols * isoDec.nRows);
+ tile = tile % (isoDec.nCols * isoDec.nRows);
updateTextures(false);
previousTile = tile;
}
diff --git a/Assets/IsoUnity/Source/Sequences/Forks/FormulaFork.cs b/Assets/IsoUnity/Source/Sequences/Forks/FormulaFork.cs
index f79c0dc..6f8bb1f 100644
--- a/Assets/IsoUnity/Source/Sequences/Forks/FormulaFork.cs
+++ b/Assets/IsoUnity/Source/Sequences/Forks/FormulaFork.cs
@@ -26,16 +26,16 @@ public string Formula
}
}
- public FormulaParser SequenceFormula { get; private set; }
+ public SequenceFormula SequenceFormula { get; private set; }
void Awake()
{
- SequenceFormula = new FormulaParser();
+ SequenceFormula = new SequenceFormula();
}
void OnEnable()
{
- SequenceFormula = new FormulaParser();
+ SequenceFormula = new SequenceFormula();
SequenceFormula.Formula = formula;
}
diff --git a/Assets/IsoUnity/Source/Sequences/Formula/FormulaSetter.cs b/Assets/IsoUnity/Source/Sequences/Formula/FormulaSetter.cs
index 6e39740..253d335 100644
--- a/Assets/IsoUnity/Source/Sequences/Formula/FormulaSetter.cs
+++ b/Assets/IsoUnity/Source/Sequences/Formula/FormulaSetter.cs
@@ -31,16 +31,16 @@ public string Formula
private string paramError;
- public FormulaParser SequenceFormula { get; private set; }
+ public SequenceFormula SequenceFormula { get; private set; }
void Awake()
{
- SequenceFormula = new FormulaParser();
+ SequenceFormula = new SequenceFormula();
}
void OnEnable()
{
- SequenceFormula = new FormulaParser();
+ SequenceFormula = new SequenceFormula();
SequenceFormula.Formula = formula;
}
diff --git a/Assets/IsoUnity/Source/Sequences/Formula/SequenceFormula.cs b/Assets/IsoUnity/Source/Sequences/Formula/SequenceFormula.cs
index 312fe46..f663ffa 100644
--- a/Assets/IsoUnity/Source/Sequences/Formula/SequenceFormula.cs
+++ b/Assets/IsoUnity/Source/Sequences/Formula/SequenceFormula.cs
@@ -3,7 +3,7 @@
using System.Reflection;
namespace IsoUnity.Sequences {
- public class FormulaParser {
+ public class SequenceFormula {
private Expression expression;
private string formula;
@@ -11,8 +11,8 @@ public class FormulaParser {
private string functionError;
private object expresionResult;
- public FormulaParser() : this(string.Empty) { }
- public FormulaParser(string formula)
+ public SequenceFormula() : this(string.Empty) { }
+ public SequenceFormula(string formula)
{
this.Formula = formula;
}
diff --git a/Assets/IsoUnity/Source/Sequences/Interpreter/Interpreters/DialogInterpreter.cs b/Assets/IsoUnity/Source/Sequences/Interpreter/Interpreters/DialogInterpreter.cs
index c8f73e5..dbbaa65 100644
--- a/Assets/IsoUnity/Source/Sequences/Interpreter/Interpreters/DialogInterpreter.cs
+++ b/Assets/IsoUnity/Source/Sequences/Interpreter/Interpreters/DialogInterpreter.cs
@@ -143,11 +143,11 @@ private string ParseFormulas(string toParse)
try
{
toParse = Regex.Replace(toParse, @"\<\$(.+)\$\>", m => {
- var formula = new FormulaParser(m.Groups[1].Value);
+ var formula = new SequenceFormula(m.Groups[1].Value);
return formula.IsValidExpression ? formula.Evaluate().ToString() : formula.Error;
}, RegexOptions.Multiline);
toParse = Regex.Replace(toParse, @"\$(\w+)", m => {
- var formula = new FormulaParser(m.Groups[1].Value);
+ var formula = new SequenceFormula(m.Groups[1].Value);
return formula.IsValidExpression ? formula.Evaluate().ToString() : formula.Error;
}, RegexOptions.Multiline);
diff --git a/Assets/IsoUnity/Source/Sequences/SequencedItem.cs b/Assets/IsoUnity/Source/Sequences/SequencedItem.cs
index 6cae191..a085fc7 100644
--- a/Assets/IsoUnity/Source/Sequences/SequencedItem.cs
+++ b/Assets/IsoUnity/Source/Sequences/SequencedItem.cs
@@ -10,8 +10,7 @@
namespace IsoUnity.Sequences {
- public class SequencedItem : IsoUnity.Entities.Item
- {
+ public class SequencedItem : IsoUnity.Entities.Item {
[SerializeField]
SequenceAsset s;
diff --git a/Assets/TRPGMaker/Scripts/Connectors/IsoUnityConnector.cs b/Assets/TRPGMaker/Scripts/Connectors/IsoUnityConnector.cs
index 74384e9..8923656 100644
--- a/Assets/TRPGMaker/Scripts/Connectors/IsoUnityConnector.cs
+++ b/Assets/TRPGMaker/Scripts/Connectors/IsoUnityConnector.cs
@@ -5,6 +5,7 @@
using IsoUnity.Entities;
using System.Linq;
using System;
+using UnityEngine.EventSystems;
public class IsoUnityConnector : EventedEventManager, ITRPGMapConnector
{
@@ -667,7 +668,7 @@ void OnMouseExit()
private void OnMouseDown()
{
- if (selectedCellEvent != null && arrowObject != null)
+ if (selectedCellEvent != null && arrowObject != null && !EventSystem.current.IsPointerOverGameObject())
{
Game.main.eventFinished(selectedCellEvent, new Dictionary
{