コード例 #1
0
    private void Update()
    {
        if (state == State.SELECTING)
        {
            // ignore when we are over UI
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            //check which objects we are over, pick the top one to spawn
            if (CommonInput.GetMouseButtonDown(0))
            {
                //NOTE: Avoiding multiple enumeration by converting IEnumerables to lists.
                var hitGOs = MouseUtils.GetOrderedObjectsUnderMouse(layerMask,
                                                                    go => go.GetComponent <CustomNetTransform>() != null).ToList();
                //warn about objects which cannot be cloned
                var nonPooledHits = hitGOs
                                    .Where(go => Spawn.DeterminePrefab(go) == null).ToList();
                if (nonPooledHits.Any())
                {
                    foreach (GameObject nonPooled in nonPooledHits)
                    {
                        Logger.LogWarningFormat("Object {0} does not have a PoolPrefabTracker component and its name" +
                                                " did not match one of our existing prefabs " +
                                                "therefore cannot be cloned (because we wouldn't know which prefab to instantiate). " +
                                                "Please attach this component to the object and specify the prefab" +
                                                " to allow it to be cloned.", Category.ItemSpawn, nonPooled.name);
                    }
                }

                var pooledHits = hitGOs.Where(go => Spawn.DeterminePrefab(go) != null).ToList();
                if (pooledHits.Any())
                {
                    toClone = pooledHits.First();
                    ToState(State.DRAWING);
                }
            }
        }
        else if (state == State.DRAWING)
        {
            cursorObject.transform.position = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);
            if (CommonInput.GetMouseButtonDown(0))
            {
                Vector3Int position = cursorObject.transform.position.RoundToInt();
                position.z = 0;
                if (MatrixManager.IsPassableAtAllMatricesOneTile(position, false))
                {
                    if (CustomNetworkManager.IsServer)
                    {
                        Spawn.ServerClone(toClone, position);
                    }
                    else
                    {
                        DevCloneMessage.Send(toClone, (Vector3)position, ServerData.UserID, PlayerList.Instance.AdminToken);
                    }
                }
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Ask the server to clone a specific object
    /// </summary>
    /// <param name="toClone">GameObject to clone, must have a network identity</param>
    /// <param name="worldPosition">world position to spawn it at</param>
    /// <returns></returns>
    public static void Send(GameObject toClone, Vector2 worldPosition)
    {
        DevCloneMessage msg = new DevCloneMessage
        {
            ToClone       = toClone ? toClone.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            WorldPosition = worldPosition
        };

        msg.Send();
    }
コード例 #3
0
    /// <summary>
    /// Ask the server to clone a specific object
    /// </summary>
    /// <param name="toClone">GameObject to clone, must have a network identity</param>
    /// <param name="worldPosition">world position to spawn it at</param>
    /// <param name="adminId">user id of the admin trying to perform this action</param>
    /// <param name="adminToken">token of the admin trying to perform this action</param>
    /// <returns></returns>
    public static void Send(GameObject toClone, Vector2 worldPosition, string adminId, string adminToken)
    {
        DevCloneMessage msg = new DevCloneMessage
        {
            ToClone       = toClone ? toClone.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
            WorldPosition = worldPosition,
            AdminId       = adminId,
            AdminToken    = adminToken
        };

        msg.Send();
    }