コード例 #1
0
    void SpawnBlock(PartToken token, Vector3 pos, Quaternion rot, int owner)
    {
        if (GlobalReferences.FrozenParts.ContainsKey(token.ID))
        {
            return;
        }

        GameObject newBlock = GlobalReferences.PartSpawner.SpawnGhostPart(token.TemplateID);

        newBlock.transform.position = pos;
        newBlock.transform.rotation = rot;

        Part newPart = newBlock.GetComponent <Part>();

        newPart.PartOwner = owner;

        newPart.FreezePart(token.ID);

        if (!GlobalReferences.PartIDLedger.ContainsKey(token.ID))
        {
            GlobalReferences.PartIDLedger.Add(token.ID, GlobalReferences.GetNextID());
        }

        if (token.Disabled)
        {
            newPart.Disable();
        }
    }
コード例 #2
0
    public static void SpawnBlockParent(PartTokenParent token, Vector3 pos, Quaternion rot, int owner)
    {
        if (GlobalReferences.FrozenParts.ContainsKey(token.ID))
        {
            Debug.LogError("Frozen Parts already containts Key " + token.ID);
            return;
        }

        GameObject newBlock = GlobalReferences.PartSpawner.SpawnGhostPart(token.TemplateID, pos, rot);

        Destroy(newBlock.GetComponent <ConstantForce>());
        Destroy(newBlock.GetComponent <Rigidbody>());

        Part newPart = newBlock.GetComponent <Part>();

        newPart.SetInactive(token.Con);
        newPart.Parent    = token.Parent;
        newPart.ParentCon = token.ParentCon;
        newPart.PartOwner = owner;

        if (token.Parent != -1 && GlobalReferences.FrozenParts.ContainsKey(token.Parent))
        {
            Part parentPart = GlobalReferences.FrozenParts[token.Parent].GetComponent <Part>();
            parentPart.Children.Add(token.ID);
            parentPart.ChildCons.Add(token.Con);
            try
            {
                parentPart.SetInactive(parentPart.Connections[token.ParentCon]);
            }
            catch
            {
                Debug.LogError("parentPart: " + parentPart.ID + " doesnt contain connection: " + token.ParentCon);
            }
        }
        else if (token.Parent != -1)
        {
            var wait = newBlock.AddComponent <NetworkPartWaitForParent>();
            wait.Initialize(token.Parent, token.ID, token.Con, token.ParentCon);
        }

        newPart.FreezePart(token.ID);

        if (!GlobalReferences.PartIDLedger.ContainsKey(token.ID))
        {
            GlobalReferences.PartIDLedger.Add(token.ID, GlobalReferences.GetNextID());
        }

        if (token.Disabled)
        {
            newPart.Disable();
        }

        //Debug.Log("#43 Block Transform Done: " + token.ID + ", Position = " + newBlock.transform.position.ToString("F2") + ", Rotation = " + newBlock.transform.rotation.eulerAngles.ToString("F2"));
    }
コード例 #3
0
ファイル: Part.cs プロジェクト: jpdrude/DisCo-Code
    public void FreezePart(int _id = -1)
    {
        if (!TestDeleteSpawn())
        {
            Destroy(gameObject);
            return;
        }

        placedMat = Resources.Load <Material>("Materials/" + MaterialHolder.MatSet + "/PlacedMaterial");
        gameObject.GetComponent <MeshRenderer>().material = placedMat;

        gameObject.layer = 9;

        if (GetComponent <ConstantForce>() != null)
        {
            Destroy(gameObject.GetComponent <ConstantForce>());
        }

        if (GetComponent <Rigidbody>() != null)
        {
            Destroy(gameObject.GetComponent <Rigidbody>());
        }

        if (GetComponent <PartBehaviour>() != null)
        {
            Destroy(gameObject.GetComponent <PartBehaviour>());
        }

        if (GetComponent <ConnectionScanning>() != null)
        {
            Destroy(gameObject.GetComponent <ConnectionScanning>());
        }

        if (GetComponent <KillTimer>() != null)
        {
            Destroy(GetComponent <KillTimer>());
        }

        gameObject.isStatic = true;

        foreach (int i in ActiveConnections)
        {
            ConnectionVoxelContainer.StoreConnection(connections[i]);
        }

        CollisionVoxelContainer.StoreGameObject(gameObject);


        if (GlobalReferences.AffectedParts.Contains(gameObject))
        {
            GlobalReferences.AffectedParts.Remove(gameObject);
        }

        if (GlobalReferences.FreeParts.Contains(gameObject))
        {
            GlobalReferences.FreeParts.Remove(gameObject);
        }

        if (_id == -1)
        {
            id = GlobalReferences.GetNextID();
        }
        else
        {
            id = _id;
        }

        GlobalReferences.FrozenParts.Add((int)ID, gameObject);
        gameObject.name = name + "_" + id;

        if (TICtrlZ.LastID != ID)
        {
            TICtrlZ.History.Push(new HistoryItem(ID));
        }

        //Debug.Log("#43 Block Transform Frozen: " + ID + ", Position = " + transform.position.ToString("F2") + ", Rotation = " + transform.rotation.eulerAngles.ToString("F2"));
    }
コード例 #4
0
ファイル: SaveJson.cs プロジェクト: jpdrude/DisCo-Code
    private static JsonAssembly BuildAssembly(Dictionary <int, GameObject> parts, int ID)
    {
        Dictionary <string, JsonPart> jsonParts = new Dictionary <string, JsonPart>();

        Matrix4x4 transM = new Matrix4x4(new Vector4(1, 0, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 0, 1));

        foreach (KeyValuePair <int, GameObject> dicEntry in parts)
        {
            if (dicEntry.Value != null)
            {
                if (BoltNetwork.IsRunning && !GlobalReferences.PartIDLedger.ContainsKey(dicEntry.Key))
                {
                    GlobalReferences.PartIDLedger.Add(dicEntry.Key, GlobalReferences.GetNextID());
                    Debug.LogError("PartIdLedger didn't contain a Key for " + dicEntry.Key + ", was changed to: " + GlobalReferences.PartIDLedger[dicEntry.Key]);
                }

                Part      p = dicEntry.Value.GetComponent <Part>();
                Matrix4x4 m = p.gameObject.transform.localToWorldMatrix;

                m = transM * m;
                m = m * Matrix4x4.TRS(p.PartOffset, Quaternion.identity, Vector3.one);
                string templateName = GlobalReferences.TemplateParts[p.TemplateID].GetComponent <Part>().name;

                if (!BoltNetwork.IsRunning)
                {
                    JsonPart jsonP = new JsonPart(p.Parent, templateName, new JsonTransform(m), p.ParentCon, p.ConToParent, p.ActiveConnections, p.Children);
                    jsonParts.Add(dicEntry.Key.ToString(), jsonP);
                }
                else
                {
                    int parent = p.Parent;

                    if (parent != -1 && BoltNetwork.IsRunning)
                    {
                        try
                        {
                            parent = GlobalReferences.PartIDLedger[p.Parent];
                        }
                        catch
                        {
                            Debug.LogError("PartIdLedger didn't contain the parent: " + parent + " for part: " + dicEntry.Key + ", parent will be set to null");
                            parent = -1;
                        }
                    }

                    List <int> children = new List <int>();

                    foreach (int i in p.Children)
                    {
                        if (BoltNetwork.IsRunning)
                        {
                            try
                            {
                                children.Add(GlobalReferences.PartIDLedger[i]);
                            }
                            catch
                            {
                                Debug.LogError("PartIdLedger didn't contain the child: " + i + " for part: " + dicEntry.Key + ", child will be ommited");
                            }
                        }
                        else
                        {
                            children.Add(i);
                        }
                    }

                    JsonPart jsonP = new JsonPart(parent, templateName, new JsonTransform(m), p.ParentCon, p.ConToParent, p.ActiveConnections, children);

                    if (BoltNetwork.IsRunning)
                    {
                        jsonParts.Add(GlobalReferences.PartIDLedger[dicEntry.Key].ToString(), jsonP);
                    }
                    else
                    {
                        jsonParts.Add(dicEntry.Key.ToString(), jsonP);
                    }
                }
            }
        }

        JsonAssembly assembly = new JsonAssembly(ID.ToString(), jsonParts);

        return(assembly);
    }