Beispiel #1
0
    public void PickupPart()
    {
        if (BoltNetwork.IsRunning)
        {
            BoltEntity entity = pickup.GetComponent <BoltEntity>();

            if (!entity.IsOwner)
            {
                Vector3    pos    = entity.gameObject.transform.position;
                Quaternion rot    = entity.gameObject.transform.rotation;
                int        tempID = entity.gameObject.GetComponent <Part>().TemplateID;

                var destroy = BlockDestroy.Create(entity);
                destroy.Send();

                PartToken token = new PartToken();
                token.TemplateID = tempID;
                //token.Free = true;
                //token.Position = pos;
                //token.Rotation = rot;

                GameObject go = BoltNetwork.Instantiate(BoltPrefabs.AbstractBlock, token, pos, rot);
                pickup = go;
            }
        }

        Pickup();
    }
Beispiel #2
0
    void DeleteFreeParts()
    {
        //GlobalReferences.NumOfParts = 0;

        for (int i = GlobalReferences.FreeParts.Count - 1; i >= 0; --i)
        {
            GameObject go = GlobalReferences.FreeParts[i];

            if (BoltNetwork.IsRunning)
            {
                BlockDestroy destroy = BlockDestroy.Create(go.GetComponent <NetworkBlockBehaviour>().entity);
                destroy.destroyWithoutRespawn = true;
                destroy.Send();
            }
            else
            {
                if (GlobalReferences.Parts.Contains(go))
                {
                    GlobalReferences.Parts.Remove(go);
                }

                if (GlobalReferences.FreeParts.Contains(go))
                {
                    GlobalReferences.FreeParts.Remove(go);
                }
                Destroy(go);
            }
        }
    }
Beispiel #3
0
    //Events
    #region
    public override void OnEvent(CheckBlockFreeze evnt)
    {
        if (BoltNetwork.IsServer)
        {
            Part p          = gameObject.GetComponent <Part>();
            Part parentPart = GlobalReferences.FrozenParts[evnt.ParentID].GetComponent <Part>();

            Connection bestOnPart        = p.Connections[evnt.ConnectionID];
            Connection closestConnection = parentPart.Connections[evnt.ParentCon];

            gameObject.transform.position = evnt.BlockPosition;
            gameObject.transform.rotation = evnt.BlockRotation;
            //AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject);

            if (!ConnectionScanning.CollisionDetection(gameObject) && CheckOriginAlignment(bestOnPart, closestConnection, evnt.BlockPosition, evnt.BlockRotation))// && CheckConncetionAlignment(bestOnPart, closestConnection))//, transform, parentPart.transform))
            {
                var token = new PartTokenParent();
                token.TemplateID = p.TemplateID;

                token.ID = UnityEngine.Random.Range(int.MinValue, int.MaxValue);

                while (GlobalReferences.FrozenParts.ContainsKey(token.ID))
                {
                    token.ID = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
                }


                token.Parent    = evnt.ParentID;
                token.ParentCon = evnt.ParentCon;

                token.Con = evnt.ConnectionID;

                var spawn = SpawnFrozenBlock.Create();
                spawn.token    = token;
                spawn.Position = evnt.BlockPosition;
                spawn.Rotation = evnt.BlockRotation;
                spawn.Send();

                var destroy = BlockDestroy.Create(entity);
                destroy.Send();

                //Debug.Log("#43 Spawning Block: " + token.ID + ", Position = " + evnt.BlockPosition.ToString("F2") + ", Rotation = " + evnt.BlockRotation.eulerAngles.ToString("F2"));
            }
            else
            {
                var decline = DeclineBlockFreeze.Create(entity);
                decline.OldBlockPosition = evnt.OldBlockPosition;
                decline.OldBlockRotation = evnt.OldBlockRotation;

                decline.Send();
            }
        }
    }