diff --git a/Core/Game/Abilities/Ability.cs b/Core/Game/Abilities/Ability.cs index 3cfff71c..8f0ef4da 100644 --- a/Core/Game/Abilities/Ability.cs +++ b/Core/Game/Abilities/Ability.cs @@ -6,58 +6,37 @@ //======================================================================= using UnityEngine; using Lockstep.Data; - -namespace Lockstep -{ +namespace Lockstep { public abstract class Ability : CerealBehaviour { private bool isCasting; - private LSAgent _agent; - - public LSAgent Agent - { - get - { + private LSAgent _agent; + public LSAgent Agent { + get { #if UNITY_EDITOR - if (_agent == null) - return this.GetComponent(); + if (_agent == null) return this.GetComponent (); #endif - return _agent; - } - } - - public string MyAbilityCode { get; private set; } - - public AbilityInterfacer Interfacer { get; private set; } - - public int ID { get; private set; } - - public Transform CachedTransform { get { return Agent.CachedTransform; } } - - public GameObject CachedGameObject { get { return Agent.CachedGameObject; } } - - public int VariableContainerTicket { get; private set; } - - private LSVariableContainer _variableContainer; - - public LSVariableContainer VariableContainer { get { return _variableContainer; } } - - public bool IsCasting - { - get - { - return isCasting; - } - protected set - { - if (value != isCasting) - { - if (value == true) - { + return _agent; + } + } + public string MyAbilityCode {get; private set;} + public AbilityInterfacer Interfacer {get; private set;} + + public int ID {get; private set;} + public Transform CachedTransform {get {return Agent.CachedTransform;}} + public GameObject CachedGameObject {get {return Agent.CachedGameObject;}} + public int LSVariableContainerTicket {get; private set;} + + public bool IsCasting { + get { + return isCasting; + } + protected set { + if (value != isCasting) { + if (value == true) { Agent.CheckCasting = false; - } else - { + } else { Agent.CheckCasting = true; } isCasting = value; @@ -67,116 +46,77 @@ protected set - internal void Setup(LSAgent agent, int id) - { + public void Setup(LSAgent agent, int id) { System.Type mainType = this.GetType(); - if (mainType.IsSubclassOf(typeof(ActiveAbility))) - { - while ( mainType.BaseType != typeof(ActiveAbility)) - { - mainType = mainType.BaseType; - } - Interfacer = AbilityInterfacer.FindInterfacer(mainType); - if (Interfacer == null) - { - throw new System.ArgumentException("The Ability of type " + mainType + " has not been registered in database"); - } - this.MyAbilityCode = Interfacer.Name; - } else - { - this.MyAbilityCode = mainType.Name; + while (mainType.BaseType != typeof (Ability) && mainType.BaseType != typeof (ActiveAbility)) { + mainType = mainType.BaseType; + } + Interfacer = AbilityInterfacer.FindInterfacer(mainType); + if (Interfacer == null) { + throw new System.ArgumentException("The Ability of type " + mainType + " has not been registered in database"); } + this.MyAbilityCode = Interfacer.Name; _agent = agent; - ID = id; - TemplateSetup(); + ID = id; + TemplateSetup (); OnSetup(); - this.VariableContainerTicket = LSVariableManager.Register(this); - this._variableContainer = LSVariableManager.GetContainer(VariableContainerTicket); + this.LSVariableContainerTicket = LSVariableManager.Register(this); } - protected virtual void TemplateSetup() - { + protected virtual void TemplateSetup () { - } + } - protected virtual void OnSetup() - { - } + protected virtual void OnSetup() {} - internal void Initialize() - { - VariableContainer.Reset(); + public void Initialize() { IsCasting = false; OnInitialize(); } - protected virtual void OnInitialize() - { - } + protected virtual void OnInitialize() {} - internal void Simulate() - { + public void Simulate() { OnSimulate(); - if (isCasting) - { + if (isCasting) { OnCast(); } } + protected virtual void OnSimulate() {} - protected virtual void OnSimulate() - { - } + public void LateSimulate () { + OnLateSimulate (); + } + protected virtual void OnLateSimulate () { - internal void LateSimulate() - { - OnLateSimulate(); - } + } - protected virtual void OnLateSimulate() - { + protected virtual void OnCast() {} - } - - protected virtual void OnCast() - { - } - - internal void Visualize() - { + public void Visualize() { OnVisualize(); } - protected virtual void OnVisualize() - { - } + protected virtual void OnVisualize() {} - public void BeginCast() - { + public void BeginCast() { OnBeginCast(); } - protected virtual void OnBeginCast() - { - } + protected virtual void OnBeginCast() {} - public void StopCast() - { + public void StopCast() { OnStopCast(); } - protected virtual void OnStopCast() - { - } + protected virtual void OnStopCast() {} - public void Deactivate() - { + public void Deactivate() { IsCasting = false; OnDeactivate(); } - protected virtual void OnDeactivate() - { - } + protected virtual void OnDeactivate() {} } } \ No newline at end of file diff --git a/Core/Game/Abilities/ActiveAbility.cs b/Core/Game/Abilities/ActiveAbility.cs index c609312b..7ef077f3 100644 --- a/Core/Game/Abilities/ActiveAbility.cs +++ b/Core/Game/Abilities/ActiveAbility.cs @@ -3,11 +3,11 @@ namespace Lockstep { public abstract class ActiveAbility : Ability { - public ushort ListenInput {get; private set;} + public InputCode ListenInput {get; private set;} protected sealed override void TemplateSetup () { - ListenInput = Interfacer.ListenInputID; + ListenInput = Interfacer.ListenInput; } public void Execute(Command com) { diff --git a/Core/Game/Abilities/BehaviourHelper/BehaviourHelper.cs b/Core/Game/Abilities/BehaviourHelper/BehaviourHelper.cs index 5d84f373..8f1f6ef8 100644 --- a/Core/Game/Abilities/BehaviourHelper/BehaviourHelper.cs +++ b/Core/Game/Abilities/BehaviourHelper/BehaviourHelper.cs @@ -3,104 +3,76 @@ using Lockstep; using System.Collections.Generic; using System; - public abstract class BehaviourHelper : MonoBehaviour, IBehaviourHelper { - public BehaviourHelper() - { - - } - - private static FastList behaviourHelpers = new FastList(); - private static HashSet createdTypes = new HashSet(); - - public ushort CachedListenInput {get; private set;} + public BehaviourHelper () { - public virtual ushort ListenInput - { - get { return 0; } } - public void Initialize() - { - CachedListenInput = ListenInput; - OnInitialize(); - } + private static FastList behaviourHelpers = new FastList (); + private static HashSet createdTypes = new HashSet (); + - protected virtual void OnInitialize() - { + public virtual InputCode ListenInput { + get {return InputCode.None;} } - public void LateInitialize() - { + public void Initialize () + { + OnInitialize (); + } + + protected virtual void OnInitialize () + { + } + public void LateInitialize () { this.OnLateInitialize(); } - - protected virtual void OnLateInitialize() - { - - } - - public void Simulate() - { - OnSimulate(); - } - - protected virtual void OnSimulate() - { - } - - public void LateSimulate() - { - OnLateSimulate(); - } - - protected virtual void OnLateSimulate() - { - - } - - public void Visualize() - { - OnVisualize(); - } - - protected virtual void OnVisualize() - { - } - - public void Execute(Command com) - { - OnExecute(com); - } - - protected virtual void OnExecute(Command com) - { - } - - public void RawExecute (Command com) { - OnRawExecute (com); - } - protected virtual void OnRawExecute (Command com) { - - } - - public void GameStart () { - OnGameStart (); - } - - protected virtual void OnGameStart () { - - } - - public void Deactivate() - { - OnDeactivate(); - } - - protected virtual void OnDeactivate() - { + protected virtual void OnLateInitialize () { + + } + public void Simulate () + { + OnSimulate (); + } + + protected virtual void OnSimulate () + { + } + public void LateSimulate () { + OnLateSimulate (); + } + protected virtual void OnLateSimulate (){ + + } + + public void Visualize () + { + OnVisualize (); + } + + protected virtual void OnVisualize () + { + } + + public void Execute (Command com) + { + OnExecute (com); + } + + protected virtual void OnExecute (Command com) + { + } + + public void Deactivate () + { + OnDeactivate (); + } + + protected virtual void OnDeactivate () + { - } + + } } \ No newline at end of file diff --git a/Core/Game/Abilities/BehaviourHelper/BehaviourHelperManager.cs b/Core/Game/Abilities/BehaviourHelper/BehaviourHelperManager.cs index 3e5adb49..90088d5c 100644 --- a/Core/Game/Abilities/BehaviourHelper/BehaviourHelperManager.cs +++ b/Core/Game/Abilities/BehaviourHelper/BehaviourHelperManager.cs @@ -18,12 +18,6 @@ public static void LateInitialize () { } } - public static void GameStart () { - foreach (var helper in Helpers) { - helper.GameStart(); - } - } - public static void Simulate () { foreach (BehaviourHelper helper in Helpers) { helper.Simulate (); @@ -38,10 +32,9 @@ public static void LateSimulate () { public static void Execute (Command com) { foreach (BehaviourHelper helper in Helpers) { - if (helper.CachedListenInput == com.LeInput) { + if (helper.ListenInput == com.LeInput) { helper.Execute (com); } - helper.RawExecute(com); } } diff --git a/Core/Simulation/Math/Pan-Line-Algorithm.meta b/Core/Game/Abilities/BuildAbil.meta similarity index 67% rename from Core/Simulation/Math/Pan-Line-Algorithm.meta rename to Core/Game/Abilities/BuildAbil.meta index 5528fd62..ce6ce64f 100644 --- a/Core/Simulation/Math/Pan-Line-Algorithm.meta +++ b/Core/Game/Abilities/BuildAbil.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 615fb633fad344682aca5d2d92a83eb5 +guid: f6f80e1c64dfa4d279adedd519dad128 folderAsset: yes -timeCreated: 1451067379 +timeCreated: 1442625300 licenseType: Pro DefaultImporter: userData: diff --git a/Core/Game/Abilities/BuildAbil/Build.cs b/Core/Game/Abilities/BuildAbil/Build.cs new file mode 100644 index 00000000..2963b16e --- /dev/null +++ b/Core/Game/Abilities/BuildAbil/Build.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using System.Collections; + +namespace Lockstep +{ + public class Build : ActiveAbility + { + [SerializeField] + private BuildNode[] _tiles; + public BuildNode[] Tiles {get {return _tiles;}} + + public bool Disabled {get; set;} + + protected override void OnSetup () + { + for (ushort i = 0; i < Tiles.Length; i++) { + Tiles[i].Setup (i, this); + } + + } + + protected override void OnInitialize () + { + for (int i = 0; i < Tiles.Length;i ++) { + Tiles[i].Initialize(); + } + Disabled = false; + /*foreach (BuildNode node in _tiles) { + node.SendBuild(1); + }*/ + } + + protected override void OnExecute (Command com) + { + if (com.HasCount && com.HasTarget) + { + Tiles[com.Target].Execute (com); + } + } +#if UNITY_EDITOR + protected override void OnAfterSerialize () + { + BuildNode[] tempTiles = Agent.GetComponentsInChildrenOrderered (); + if (tempTiles .IsNotNull ()) _tiles = tempTiles; + } +#endif + } +} \ No newline at end of file diff --git a/Core/Game/Player/Commands/BackwardsCommand.cs.meta b/Core/Game/Abilities/BuildAbil/Build.cs.meta similarity index 75% rename from Core/Game/Player/Commands/BackwardsCommand.cs.meta rename to Core/Game/Abilities/BuildAbil/Build.cs.meta index 8128dd25..f80b88fc 100644 --- a/Core/Game/Player/Commands/BackwardsCommand.cs.meta +++ b/Core/Game/Abilities/BuildAbil/Build.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 9641815bce2ca4e15b97ae138609a4f2 -timeCreated: 1451677754 +guid: c649ae167a6174026949df8e16b8ba4c +timeCreated: 1442352430 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/Core/Game/Abilities/BuildAbil/BuildManager.cs b/Core/Game/Abilities/BuildAbil/BuildManager.cs new file mode 100644 index 00000000..ccbbfb30 --- /dev/null +++ b/Core/Game/Abilities/BuildAbil/BuildManager.cs @@ -0,0 +1,31 @@ +using UnityEngine; +using System.Collections; +using Lockstep; +public static class BuildManager { + public static void Visualize () { + BuildNode buildNode; + if (InputManager.GetInformationDown ()) { + + } + if (Interfacing.CachedDidHit) + { + if (Interfacing.MousedObject.tag == "BuildTile") + {/* + if (InputManager.GetInformationDown()) + { + CurrentBuildTile = Interfacing.MousedObject.GetComponent(); + if (CurrentBuildTile.CanBuild == false) + { + CurrentBuildTile = null; + } else + { + if (CurrentBuildTile.Agent.Controllable) + { + GUIManager.EnvironmentUI.BuildingMenu.Open(CurrentBuildTile); + } + } + }*/ + } + } + } +} diff --git a/Core/Game/Managers/Input/InputCodeManager.cs.meta b/Core/Game/Abilities/BuildAbil/BuildManager.cs.meta similarity index 75% rename from Core/Game/Managers/Input/InputCodeManager.cs.meta rename to Core/Game/Abilities/BuildAbil/BuildManager.cs.meta index dfed0a15..5751d1ab 100644 --- a/Core/Game/Managers/Input/InputCodeManager.cs.meta +++ b/Core/Game/Abilities/BuildAbil/BuildManager.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 67093f6f3e6244268b1f69ea9966972e -timeCreated: 1451427394 +guid: 002aed10254514e258572af0e241a59c +timeCreated: 1446832266 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/Core/Game/Abilities/BuildAbil/BuildMenu.cs b/Core/Game/Abilities/BuildAbil/BuildMenu.cs new file mode 100644 index 00000000..5aee1b7b --- /dev/null +++ b/Core/Game/Abilities/BuildAbil/BuildMenu.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; +using Lockstep; +public class BuildMenu : CerealBehaviour { + private LSUIWindow window; + public BuildNode CurrentBuildNode {get; private set;} + [SerializeField] + private BuildMenuTile[] _tiles; + BuildMenuTile[] Tiles {get {return _tiles;}} + private static BuildMenu instance; + public void Setup () { + window = GetComponent (); + instance = this; + for (int i = 0; i < _tiles.Length; i++) { + _tiles[i].Setup (i); + } + } + public void Initialize () { + StartCoroutine (StartClose ()); + } + IEnumerator StartClose () { + yield return null; + Close (); + } + public void Open (BuildNode node) + { + + CurrentBuildNode = node; + window.Show (); + + for (int i = 0; i < node.SpawnableAgents.Length; i++) { + Tiles[i].Open (node.SpawnableAgents[i]); + } + } + public void Close () { + window.Hide (); + foreach (BuildMenuTile tile in Tiles) { + tile.Close (); + } + + } + public static void Press (int index) { + instance.LocalPress (index); + } + private void LocalPress (int index) { + CurrentBuildNode.SendBuild (index); + Close (); + } + +#if UNITY_EDITOR + protected override void OnAfterSerialize () + { + _tiles = this.GetComponentsInChildrenOrderered () ?? _tiles; + } +#endif +} diff --git a/Core/Game/Player/Commands/Default/BaseSerializableValue.cs.meta b/Core/Game/Abilities/BuildAbil/BuildMenu.cs.meta similarity index 75% rename from Core/Game/Player/Commands/Default/BaseSerializableValue.cs.meta rename to Core/Game/Abilities/BuildAbil/BuildMenu.cs.meta index 21425307..7015d78d 100644 --- a/Core/Game/Player/Commands/Default/BaseSerializableValue.cs.meta +++ b/Core/Game/Abilities/BuildAbil/BuildMenu.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 2e109c9a7def0460faf8705eb304cddf -timeCreated: 1451622839 +guid: cd5bddb94befd42d3a9ff0bdfab9f58c +timeCreated: 1442352555 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/Core/Game/Abilities/BuildAbil/BuildMenuTile.cs b/Core/Game/Abilities/BuildAbil/BuildMenuTile.cs new file mode 100644 index 00000000..1aeadcc7 --- /dev/null +++ b/Core/Game/Abilities/BuildAbil/BuildMenuTile.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using System.Collections; +using Lockstep; +using UnityEngine.UI; +using Lockstep.Data; +#if UNITY_EDITOR +using UnityEditor; +#endif +namespace Lockstep +{ + public class BuildMenuTile : CerealBehaviour + { + [SerializeField] + private Image _image; + Image Imager {get{return _image;}} + [SerializeField] + private Button _button; + Button Buttoner {get {return _button;}} + [SerializeField] + private Text _text; + Text Texter {get {return _text;}} + + public int ID {get; private set;} + public void Setup (int id) { + this.ID = id; + if (Buttoner.IsNotNull ()) + _button.onClick.AddListener(Press); + } + + + public void Open (string agentCode) { + AgentInterfacer agentInfo = AgentController.GetAgentInterfacer (agentCode); + Imager.sprite = agentInfo.Icon; + Texter.text = agentCode.ToString (); + gameObject.SetActiveIfNot (true); + } + public void Close () { + gameObject.SetActiveIfNot (false); + } + public void Press () { + BuildMenu.Press(ID); + } +#if UNITY_EDITOR + protected override void OnAfterSerialize () { + _image = _image ?? this.GetComponentInChildrenOrderered (); + _button = _button ?? this.GetComponentInChildrenOrderered