private static void SendToComponent(IActionGUI actionComponent) { var netObject = ((Component)actionComponent).GetComponent <NetworkIdentity>(); var componentType = actionComponent.GetType(); var childActions = netObject.GetComponentsInChildren(componentType); int componentLocation = 0; bool found = false; foreach (var action in childActions) { if ((action as IServerActionGUI) == actionComponent) { found = true; break; } componentLocation++; } if (found) { var msg = new RequestGameAction { NetObject = netObject.netId, ComponentLocation = componentLocation, ComponentType = componentType, }; msg.Send(); return; } Logger.LogError("Failed to find IServerActionGUI on NetworkIdentity"); }
private static void SendToComponent(IActionGUI actionComponent) { var netObject = ((Component)actionComponent).GetComponent <NetworkIdentity>(); var componentType = actionComponent.GetType(); var childActions = netObject.GetComponentsInChildren(componentType); int componentLocation = 0; bool found = false; foreach (var action in childActions) { if ((action as IServerActionGUI) == actionComponent) { found = true; break; } componentLocation++; } if (found) { var msg = new NetMessage { NetObject = netObject.netId, ComponentLocation = componentLocation, ComponentID = componentTypeToComponentID[componentType], }; Send(msg); return; } Logger.LogError("Failed to find IServerActionGUI on NetworkIdentity", Category.UserInput); }
public static void Show(IActionGUI iActionGUI) { foreach (var actionButton in Instance.DicIActionGUI) { //If there is a duplicate of this button, don't spawn it! if (actionButton.Value.ActionData == iActionGUI.ActionData) { return; } } UIAction _UIAction; if (Instance.PooledUIAction.Count > 0) { _UIAction = Instance.PooledUIAction[0]; Instance.PooledUIAction.RemoveAt(0); } else { _UIAction = Instantiate(Instance.UIAction); _UIAction.transform.SetParent(Instance.Panel.transform, false); } Instance.DicIActionGUI[iActionGUI] = _UIAction; _UIAction.SetUp(iActionGUI); }
public static void Send(IActionGUI iServerActionGUI) { if (iServerActionGUI is Component) { SendToComponent(iServerActionGUI); } //else not doing anything, implying custom sending }
public override void Process(NetMessage msg) { IActionGUI action = null; if (msg.actionListID != 0) { //SO action singleton ID action = UIActionSOSingleton.Instance.FromID(msg.actionListID); } else if (msg.spellListIndex >= 0) { //SpellList singleton index var spellData = SpellList.Instance.FromIndex(msg.spellListIndex); if (UIActionManager.HasActionData(spellData, out action) == false) { // no need to instantiate a spell if server asks to hide one anyway if (msg.ProposedAction == UpdateType.StateChange && msg.showAlert == false) { return; } action = spellData.AddToPlayer(PlayerManager.LocalPlayerScript); } } else { // Action pre-placed on a networked object LoadNetworkObject(msg.NetObject); var actions = NetworkObject.GetComponentsInChildren(DeserializeType(msg.ComponentID)); if ((actions.Length > msg.ComponentLocation)) { action = (actions[msg.ComponentLocation] as IActionGUI); } } if (action != null) { switch (msg.ProposedAction) { case UpdateType.FrontIcon: UIActionManager.SetSprite(action, msg.SpriteLocation); break; case UpdateType.BackgroundIcon: UIActionManager.SetBackground(action, msg.SpriteLocation); break; case UpdateType.StateChange: UIActionManager.ToggleLocal(action, msg.showAlert); break; case UpdateType.Cooldown: UIActionManager.SetCooldownLocal(action, msg.cooldown); break; } } }
public void SetUp(IActionGUI _iActionGUI) { this.gameObject.SetActive(true); iActionGUI = _iActionGUI; IconFront.SetInfo(_iActionGUI.ActionData.Sprites); if (_iActionGUI.ActionData.Backgrounds.Count > 0) { IconBackground.SetInfo(_iActionGUI.ActionData.Backgrounds); } }
public static void SetBackground(IActionGUI iActionGUI, int Location) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.IconBackground.ChangeSprite(Location); } else { Logger.Log("iActionGUI Not present", Category.UI); } }
/// <summary> /// Sets the sprite of the action button. /// </summary> public static void SetSpriteSO(IActionGUI iActionGUI, SpriteDataSO sprite, bool networked = true) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.IconFront.SetSpriteSO(sprite, Network: networked); } else { Logger.Log("iActionGUI Not present", Category.UI); } }
public static void SetSprite(IActionGUI iActionGUI, Sprite sprite) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.IconFront.SetSprite(sprite); } else { Logger.Log("iActionGUI Not present", Category.UI); } }
public static void SetCooldownLocal(IActionGUI iActionGUI, float cooldown) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.CooldownOpacity.localScale = Vector3Int.one; // Enable opacity. _UIAction.CooldownOpacity.LeanScaleY(0f, cooldown); } else { Logger.Log("iActionGUI not present!", Category.UI); } }
public static void Hide(IActionGUI iActionGUI) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.Pool(); Instance.PooledUIAction.Add(_UIAction); Instance.DicIActionGUI.Remove(iActionGUI); } else { Logger.Log("iActionGUI Not present", Category.UI); } }
public static bool HasActionData(ActionData actionData, [CanBeNull] out IActionGUI actionInstance) { foreach (var key in Instance.DicIActionGUI.Keys) { if (key.ActionData == actionData) { actionInstance = key; return(true); } } actionInstance = null; return(false); }
/// <summary> /// Sets the sprite of the action button. /// </summary> public static void SetSpriteSO(IActionGUI iActionGUI, SpriteDataSO sprite, bool networked = true, List <Color> palette = null) { Debug.Assert(!(sprite.IsPalette && palette == null), "Paletted sprites should never be set without a palette"); if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.IconFront.SetSpriteSO(sprite, Network: networked); _UIAction.IconFront.SetPaletteOfCurrentSprite(palette); } else { Logger.Log("iActionGUI Not present", Category.UI); } }
public static void Toggle(IActionGUI iActionGUI, bool Add, GameObject recipient = null) { if (Add) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { Logger.Log("iActionGUI Already added", Category.UI); return; } Show(iActionGUI); } else { Hide(iActionGUI); } }
/// <summary> /// Set the action button visibility, locally (clientside) /// </summary> public static void ToggleLocal(IActionGUI iActionGUI, bool show) { if (show) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { Logger.Log("iActionGUI Already added", Category.UI); return; } Show(iActionGUI); } else { Hide(iActionGUI); } }
public static void SetCooldownLocal(IActionGUI iActionGUI, float cooldown) { if (Instance.DicIActionGUI.ContainsKey(iActionGUI)) { var _UIAction = Instance.DicIActionGUI[iActionGUI]; _UIAction.CooldownOpacity.LeanScaleY(0f, cooldown).setFrom(1f); if (cooldown > 5) { Instance.StartCoroutine(Instance.CooldownCountdown(_UIAction, cooldown)); } } else { Logger.Log("iActionGUI not present!", Category.UI); } }
public static void Show(IActionGUI iActionGUI) { UIAction _UIAction; if (Instance.PooledUIAction.Count > 0) { _UIAction = Instance.PooledUIAction[0]; Instance.PooledUIAction.RemoveAt(0); } else { _UIAction = Instantiate(Instance.UIAction); _UIAction.transform.SetParent(Instance.Panel.transform, false); } Instance.DicIActionGUI[iActionGUI] = _UIAction; _UIAction.SetUp(iActionGUI); }
public void SetUp(IActionGUI action) { this.gameObject.SetActive(true); iActionGUI = action; actionData = iActionGUI.ActionData; if (actionData == null) { Logger.LogWarningFormat("UIAction {0}: action data is null!", Category.UIAction, iActionGUI); return; } IconFront.SetCatalogue(actionData.Sprites, 0, NetWork: false); if (actionData.Backgrounds.Count > 0) { IconBackground.SetCatalogue(actionData.Backgrounds, 0, NetWork: false); } }
public static NetMessage SetAction(GameObject recipient, IActionGUI iServerActionGUI, bool _showAlert) { return(_Send(recipient, iServerActionGUI, UpdateType.StateChange, _showAlert)); }
public static SetActionUIMessage SetSprite(GameObject recipient, IActionGUI iServerActionGUI, int FrontIconlocation) { return(_Send(recipient, iServerActionGUI, UpdateType.FrontIcon, location: FrontIconlocation)); }
public static NetMessage SetAction(GameObject recipient, IActionGUI iServerActionGUI, float cooldown) { return(_Send(recipient, iServerActionGUI, UpdateType.Cooldown, cooldown: cooldown)); }
/// <summary> /// Set the action button visibility for the given player, with network sync /// </summary> public static void Toggle(IActionGUI iActionGUI, bool show, GameObject recipient) { SetActionUIMessage.SetAction(recipient, iActionGUI, show); }
public static NetMessage SetBackgroundSprite(GameObject recipient, IActionGUI iServerActionGUI, int FrontIconlocation) { return(_Send(recipient, iServerActionGUI, UpdateType.BackgroundIcon, location: FrontIconlocation)); }
private static NetMessage _Send(GameObject recipient, IActionGUI action, UpdateType ProposedAction, bool show = false, float cooldown = 0, int location = 0) { // SO action singleton ID if (action is UIActionScriptableObject actionFromSO) { NetMessage msg = new NetMessage { actionListID = UIActionSOSingleton.ActionsTOID[actionFromSO], showAlert = show, cooldown = cooldown, SpriteLocation = location, ProposedAction = ProposedAction, ComponentID = SerializeType(actionFromSO.GetType()), spellListIndex = -1 }; SendTo(recipient, msg); return(msg); } // SpellList singleton index else if (action is Spell spellAction) { NetMessage msg = new NetMessage { spellListIndex = spellAction.SpellData.Index, showAlert = show, cooldown = cooldown, SpriteLocation = location, ProposedAction = ProposedAction, ComponentID = SerializeType(spellAction.GetType()), }; SendTo(recipient, msg); return(msg); } else { // Action pre-placed on a networked object var netObject = (action as Component).GetComponent <NetworkIdentity>(); var type = action.GetType(); var foundActions = netObject.GetComponentsInChildren(type); var componentLocation = 0; bool isFound = false; foreach (var foundAction in foundActions) { if ((foundAction as IActionGUI) == action) { isFound = true; break; } componentLocation++; } if (isFound) { NetMessage msg = new NetMessage { NetObject = netObject.netId, ComponentLocation = componentLocation, ComponentID = SerializeType(type), cooldown = cooldown, showAlert = show, SpriteLocation = location, ProposedAction = ProposedAction, spellListIndex = -1 }; SendTo(recipient, msg); return(msg); } else { Logger.LogError("Failed to find IActionGUI on NetworkIdentity", Category.UserInput); } } return(new NetMessage()); }
public static void SetCooldown(IActionGUI iActionGUI, float cooldown, GameObject recipient) { SetActionUIMessage.SetAction(recipient, iActionGUI, cooldown); }