Esempio n. 1
0
    public static RequestGameAction Send(IServerActionGUI iServerActionGUI)
    {
        var  netObject          = (iServerActionGUI as Component).GetComponent <NetworkIdentity>();
        var  _ComponentType     = iServerActionGUI.GetType();
        var  iServerActionGUIs  = netObject.GetComponentsInChildren(_ComponentType);
        var  _ComponentLocation = 0;
        bool Found = false;

        foreach (var _iServerActionGUI in iServerActionGUIs)
        {
            if ((_iServerActionGUI as IServerActionGUI) == iServerActionGUI)
            {
                Found = true;
                break;
            }
            _ComponentLocation++;
        }
        if (Found)
        {
            RequestGameAction msg = new RequestGameAction
            {
                NetObject         = netObject.netId,
                ComponentLocation = _ComponentLocation,
                ComponentType     = _ComponentType,
            };
            msg.Send();
            return(msg);
        }
        else
        {
            Logger.LogError("Failed to find IServerActionGUI on NetworkIdentity");
        }
        return(null);
    }
Esempio n. 2
0
    public void ButtonPress()
    {
        SoundManager.Play("Click01");
        //calling clientside code
        if (iActionGUI.ActionData.CallOnClient)
        {
            iActionGUI.CallActionClient();
        }

        //sending a message to server asking to run serverside code
        if (iActionGUI.ActionData.CallOnServer)
        {
            if (iActionGUI is IServerActionGUI)
            {
                if (iActionGUI is UIActionScriptableObject actionSO)
                {
                    RequestGameActionSO.Send(actionSO);
                }
                else
                {
                    RequestGameAction.Send(iActionGUI as IServerActionGUI);
                }
            }
        }
    }
Esempio n. 3
0
        private void UseAction()
        {
            // Calling clientside code. If this is a spell,
            // then the spell will call the server to run on the server itself.
            // Not sure why we don't call the spell serverside from here, too...
            // The spell's server request can provide a click position.
            if (iActionGUI.ActionData.CallOnClient)
            {
                iActionGUI.CallActionClient();
            }

            // Sending a message to server asking to run serverside code.
            // TODO: Doesn't support click positions yet.
            // Once it does, consider moving the spell's server request to rely on this here instead, if possible.
            if (iActionGUI.ActionData.CallOnServer == false)
            {
                return;
            }
            if (iActionGUI is IServerActionGUI)
            {
                if (iActionGUI is UIActionScriptableObject actionSO)
                {
                    RequestGameActionSO.Send(actionSO);
                }
                else
                {
                    RequestGameAction.Send(iActionGUI as IServerActionGUI);
                }
            }
        }
    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,
                ComponentID       = componentTypeToComponentID[componentType],
            };
            msg.Send();
            return;
        }

        Logger.LogError("Failed to find IServerActionGUI on NetworkIdentity");
    }
Esempio n. 5
0
    public void ButtonPress()
    {
        SoundManager.Play("Click01");
        if (iActionGUI.ActionData.CallOnClient)
        {
            iActionGUI.CallActionClient();
        }

        if (iActionGUI.ActionData.CallOnServer)
        {
            if (iActionGUI is IServerActionGUI)
            {
                if (iActionGUI is UIActionScriptableObject)
                {
                    var iIActionScriptableObject = iActionGUI as UIActionScriptableObject;
                    RequestGameActionSO.Send(iIActionScriptableObject);
                }
                else
                {
                    RequestGameAction.Send(iActionGUI as IServerActionGUI);
                }
            }
        }
    }