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); }
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 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()); }