Esempio n. 1
0
    public static void AfterSimulation(TIExportAR exportItem = null, bool export = false)
    {
        ++handlerCallBack;
        if (handlerCallBack >= handlers.Count)
        {
            if (!export)
            {
                ConnectionVoxelContainer.RemoveAllConnections();
                CollisionVoxelContainer.RemoveAllGos();

                foreach (GameObject go in GlobalReferences.FrozenParts.Values)
                {
                    go.transform.parent = null;
                    Part part = go.GetComponent <Part>();

                    CollisionVoxelContainer.StoreGameObject(go);

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

                for (int i = rbs.Count - 1; i >= 0; --i)
                {
                    MonoBehaviour.Destroy(rbs[i]);
                }

                simulationInProgress = false;
                simulationDone       = false;
            }
            else
            {
                string c = expCount.ToString();
                while (c.Length < countDigits)
                {
                    c = "0" + c;
                }
                SaveLoad.SaveGame(c + "_", true, folder);
            }


            for (int i = handlers.Count - 1; i >= 0; --i)
            {
                MonoBehaviour.Destroy(handlers[i]);
            }
            handlers.Clear();
            handlerCallBack = 0;

            if (export)
            {
                Export(exportItem);
            }
        }
    }
Esempio n. 2
0
    public static void ParentAndSimulate(TIExportAR exportItem = null, bool export = false)
    {
        //SaveTemp();
        savePositions.Clear();
        saveRotations.Clear();

        rbs = new List <Rigidbody>();

        foreach (GameObject go in GlobalReferences.FrozenParts.Values)
        {
            Part part     = go.GetComponent <Part>();
            int  parentId = part.Parent;

            savePositions.Add(part.ID, go.transform.position);
            saveRotations.Add(part.ID, go.transform.rotation);

            MonoBehaviour.Destroy(go.GetComponent <ConstantForce>());

            if (parentId != -1 && GlobalReferences.FrozenParts.ContainsKey(parentId))
            {
                go.transform.parent = GlobalReferences.FrozenParts[parentId].transform;
            }
            else
            {
                Rigidbody rb = go.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rbs.Add(rb);
                }
                else
                {
                    rbs.Add(go.AddComponent <Rigidbody>());
                }

                if (export)
                {
                    SimulationProcessHandler handler = go.AddComponent <SimulationProcessHandler>();
                    handlers.Add(handler);
                    handler.ExportItem            = exportItem;
                    handler.Sim                   = export;
                    handler.SimulationTerminated += new SimulationProcessHandler.SimulationHandler(AfterSimulation);
                }
            }
        }
        foreach (Rigidbody rb in rbs)
        {
            rb.useGravity  = true;
            rb.constraints = RigidbodyConstraints.None;
            rb.ResetCenterOfMass();
        }

        ChangeColliders(false);
    }
Esempio n. 3
0
    public static void ExportToAR(TIExportAR exportItem)
    {
        folder      = "ar-export_" + SaveLoad.BuildDateString() + "/";
        countDigits = GlobalReferences.FrozenParts.Count.ToString().Length;

        Export(exportItem);

        simulationInProgress = true;

        ControllerReferences.ControllerTarget.SetActive(false);

        expCount = GlobalReferences.FrozenParts.Count;
    }
Esempio n. 4
0
    static void Export(TIExportAR exportItem)
    {
        if (GlobalReferences.FrozenParts.Count > 1)
        {
            int k = 0;

            foreach (int kk in GlobalReferences.FrozenParts.Keys)
            {
                if (kk > k)
                {
                    k = kk;
                }
            }

            GlobalReferences.DeletePart(k);

            ParentAndSimulate(exportItem, true);

            --expCount;
        }
        else
        {
            exportItem.ResetTool();

            simulationInProgress = false;

            int k = 0;
            foreach (int i in GlobalReferences.FrozenParts.Keys)
            {
                k = i;
            }

            GlobalReferences.DeletePart(k);

            expCount = 0;
            AssemblyIO.Load(expTempPath);

            ControllerReferences.ControllerTarget.SetActive(true);
        }
    }