示例#1
0
 public void SetInactive(int conID)
 {
     if (ActiveConnections.Contains(conID) && connections.Count > conID)
     {
         activeConnections.Remove(conID);
         ConnectionVoxelContainer.RemoveConnection(connections[conID]);
     }
 }
示例#2
0
    public static void UpdateData(byte[] data)
    {
        LoadAggregationContainer     container   = ReadData(data);
        Dictionary <int, GameObject> checkFrozen = new Dictionary <int, GameObject>();

        foreach (KeyValuePair <int, GameObject> pair in GlobalReferences.FrozenParts)
        {
            checkFrozen.Add(pair.Key, pair.Value);
        }

        foreach (PartSpawnData item in container.data)
        {
            GameObject checkGo = GlobalReferences.FrozenParts[item.id];
            if (checkGo == null)
            {
                Debug.LogError("Part " + item.id + " not found in check");
                continue;
            }

            Vector3           oldPos      = checkGo.transform.position;
            List <Connection> connections = checkGo.GetComponent <Part>().Connections;

            if (Vector3.Distance(oldPos, item.Position) > 0.001f)
            {
                CollisionVoxelContainer.RemoveGameObject(checkGo);

                foreach (Connection con in connections)
                {
                    ConnectionVoxelContainer.RemoveConnection(con);
                }
            }

            checkGo.transform.position = item.Position;
            checkGo.transform.rotation = item.Rotation;

            if (Vector3.Distance(oldPos, item.Position) > 0.001f)
            {
                CollisionVoxelContainer.StoreGameObject(checkGo);

                foreach (Connection con in connections)
                {
                    ConnectionVoxelContainer.StoreConnection(con);
                }
            }

            checkFrozen.Remove(item.id);
        }

        GameObject[] leftovers = checkFrozen.Values.ToArray <GameObject>();

        for (int i = leftovers.Length - 1; i >= 0; --i)
        {
            GameObject go       = leftovers[i];
            Part       leftover = go.GetComponent <Part>();
            Debug.LogError("Part " + leftover.ID + " was left over in check and will be deleted");
            leftover.LocalDelete();
        }
    }
示例#3
0
    public void Disable()
    {
        if (disabled)
        {
            return;
        }

        foreach (int i in ActiveConnections)
        {
            ConnectionVoxelContainer.RemoveConnection(Connections[i]);
        }

        GetComponent <MeshRenderer>().material = MaterialHolder.DisabledMat;

        disabled = true;
    }
示例#4
0
    public override void OnEvent(BlockFreeze evnt)
    {
        Destroy(gameObject.GetComponent <ConstantForce>());
        Part p = gameObject.GetComponent <Part>();

        gameObject.transform.position = evnt.BlockPosition;
        gameObject.transform.rotation = evnt.BlockRotation;

        p.FreezePart(evnt.ID);
        p.Parent    = evnt.ParentID;
        p.ParentCon = evnt.ParentCon;

        Part parentPart = GlobalReferences.FrozenParts[evnt.ParentID].GetComponent <Part>();

        ConnectionVoxelContainer.RemoveConnection(parentPart.Connections[evnt.ParentCon]);
        ConnectionVoxelContainer.RemoveConnection(gameObject.GetComponent <Part>().Connections[evnt.ConnectionID]);

        parentPart.ChildCons.Add(evnt.ConnectionID);
        parentPart.SetInactive(parentPart.Connections[evnt.ParentCon]);
        p.SetInactive(p.Connections[evnt.ConnectionID]);

        parentPart.Children.Add((int)p.ID);

        gameObject.transform.position = evnt.BlockPosition;
        gameObject.transform.rotation = evnt.BlockRotation;

        if (PlacementReferences.InfiniteParts && entity.IsOwner && p.Respawn)
        {
            GameObject go = GlobalReferences.PartSpawner.SpawnPart(p.TemplateID);
            go.GetComponent <Part>().Respawn = true;

            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.AffectPart(go);
                GlobalReferences.FreeParts.Remove(go);
            }
        }
        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo && entity.IsOwner)
        {
            GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
        }

        if (entity.IsOwner)
        {
            //entity.Freeze(true);
        }
    }
示例#5
0
    private void RealizeConnection()
    {
        if (lastDistAngle < connectionThreshold && ConnectionVoxelContainer.RevealConnections(bestOnPart).Contains(closestConnection))
        {
            Vector3    pos = gameObject.transform.position;
            Quaternion rot = gameObject.transform.rotation;

            AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject);

            if (!CollisionDetection())
            {
                Part p = gameObject.GetComponent <Part>();
                p.FreezePart();
                p.Parent    = closestConnection.ParentPart.ID;
                p.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);

                ConnectionVoxelContainer.RemoveConnection(closestConnection);
                ConnectionVoxelContainer.RemoveConnection(bestOnPart);

                bestOnPart.ParentPart.SetInactive(bestOnPart);
                closestConnection.ParentPart.SetInactive(closestConnection);
                closestConnection.ParentPart.ChildCons.Add(bestOnPart.ParentPart.Connections.IndexOf(bestOnPart));

                closestConnection.ParentPart.Children.Add((int)p.ID);

                GameObject _g = PartsHolder.SpawnPart(p.TemplateID);
                _g.SetActive(true);
                if (GlobalReferences.PlacementType == PlacementTypeTool.PlaceChoreo.Choreo)
                {
                    GlobalReferences.AffectPart(_g);
                    GlobalReferences.FreeParts.Remove(_g);
                }

                ConnectionScanningHandler handler = gameObject.GetComponent <ConnectionScanningHandler>();
                if (handler != null)
                {
                    handler.TerminateConnection();
                }
            }
            else
            {
                gameObject.transform.position = pos;
                gameObject.transform.rotation = rot;
            }
        }
    }
示例#6
0
    public void SetInactive(Connection c)
    {
        int i = 0;

        foreach (Connection con in Connections)
        {
            if (c == con)
            {
                if (ActiveConnections.Contains(i))
                {
                    activeConnections.Remove(i);

                    ConnectionVoxelContainer.RemoveConnection(con);
                    return;
                }
            }
            ++i;
        }
    }
示例#7
0
    void FreezeSinglePlayer()
    {
        Part p = gameObject.GetComponent <Part>();

        p.FreezePart();

        p.Parent    = closestConnection.ParentPart.ID;
        p.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);

        p.ConToParent = bestOnPart.ParentPart.Connections.IndexOf(bestOnPart);

        ConnectionVoxelContainer.RemoveConnection(closestConnection);
        ConnectionVoxelContainer.RemoveConnection(bestOnPart);

        closestConnection.ParentPart.ChildCons.Add(bestOnPart.ParentPart.Connections.IndexOf(bestOnPart));
        closestConnection.ParentPart.Children.Add((int)p.ID);


        bestOnPart.ParentPart.SetInactive(bestOnPart);
        closestConnection.ParentPart.SetInactive(closestConnection);

        if (PlacementReferences.InfiniteParts && p.Respawn)
        {
            GameObject go = GlobalReferences.PartSpawner.SpawnPart(p.TemplateID);
            go.GetComponent <Part>().Respawn = true;

            if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
            {
                GlobalReferences.AffectPart(go);
                GlobalReferences.FreeParts.Remove(go);
            }
        }
        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.Choreo)
        {
            GlobalReferences.ChangeAffectedNumber(PlacementReferences.AffectedParts);
        }
    }
示例#8
0
    private void EnableDisable(Collider other)
    {
        if (Enable && AddRem == AddRemove.Remove)
        {
            Part p = other.gameObject.GetComponent <Part>();
            if (p != null && !Removed.ContainsKey((int)p.ID))
            {
                List <Connection> tempCons = new List <Connection>();
                foreach (int i in p.ActiveConnections)
                {
                    ConnectionVoxelContainer.RemoveConnection(p.Connections[i]);
                    tempCons.Add(p.Connections[i]);
                }
                Removed.Add((int)p.ID, tempCons);
            }

            other.GetComponent <MeshRenderer>().material = disableMat;
        }
        else if (Enable && AddRem == AddRemove.Add)
        {
            Part p = other.gameObject.GetComponent <Part>();
            if (p != null && Removed.ContainsKey((int)p.ID))
            {
                foreach (Connection c in Removed[(int)p.ID])
                {
                    ConnectionVoxelContainer.StoreConnection(c);
                }

                Removed.Remove((int)p.ID);
                other.GetComponent <MeshRenderer>().material = enableMat;
            }
        }
        else
        {
            purgatory.Add(other);
        }
    }