Example #1
0
    //methods
    #region
    private void CheckForCloseConnections()
    {
        distAngle     = float.MaxValue;
        lastDistAngle = float.MaxValue;
        rot           = float.MaxValue;

        foreach (Connection c in connections)
        {
            foundC = ConnectionVoxelContainer.RevealConnections(c);

            if (foundC.Count == 0)
            {
                return;
            }

            //if (CheckWithJobs(c, foundC)) return;

            if (CheckWithoutJobs(c, foundC))
            {
                return;
            }

            //if (CheckWithJobsAngle(c, foundC)) return;
        }
    }
Example #2
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;
            }
        }
    }
Example #3
0
    //methods
    #region
    private void CheckForCloseConnections()
    {
        distAngle     = 100;
        lastDistAngle = 1000;
        rot           = 1000;
        foreach (Connection c in connections)
        {
            foundC = ConnectionVoxelContainer.RevealConnections(c);

            if (foundC.Count > 0)
            {
                foreach (Connection _c in foundC)
                {
                    if (_c.Pln.Parent != null)
                    {
                        dist      = Vector3.Distance(c.Pln.Origin, _c.Pln.Origin);
                        angle     = AlignPlane.BuildAngle(c.Pln.LocalZVector, _c.Pln.LocalZVector, true);
                        rot       = AlignPlane.BuildAngle(c.Pln.XVector, _c.Pln.XVector, false) * 10 * connectionThreshold;
                        distAngle = dist + AngleTightening(angle) + rot / 1000 * connectionThreshold;

                        string grammer = _c.ConType + ">" + c.ConType;
                        if (distAngle < lastDistAngle && _c.CheckForRule(c) != -1 && RuleActive(grammer))
                        {
                            closestConnection = _c;
                            bestOnPart        = c;
                            lastDistAngle     = distAngle;
                            if (lastDistAngle < connectionThreshold / 5)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
Example #4
0
    private void RealizeConnection()
    {
        if (lastDistAngle < connectionThreshold && ConnectionVoxelContainer.RevealConnections(bestOnPart).Contains(closestConnection))
        {
            Vector3    pos = gameObject.transform.position;
            Quaternion rot = gameObject.transform.rotation;

            if (!AlignPlane.Orient(bestOnPart.Pln, closestConnection.Pln, gameObject))
            {
                gameObject.transform.position = pos;
                gameObject.transform.rotation = rot;
                return;
            }

            //PlacementBehaviour.ReleasePart(true);


            Destroy(gameObject.GetComponent <ConstantForce>());
            Destroy(gameObject.GetComponent <PartBehaviour>());
            Destroy(gameObject.GetComponent <ConnectionScanning>());

            gameObject.layer = 13;


            var check = gameObject.AddComponent <CheckCollision>();
            check.respawnPosition   = pos;
            check.respawnRotation   = rot;
            check.closestConnection = closestConnection;
            check.bestOnPart        = bestOnPart;

            if (transform.parent != null)
            {
                transform.parent = null;
            }

            GetComponent <Rigidbody>().constraints            = RigidbodyConstraints.FreezeAll;
            GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous;
            Destroy(this);

            /*
             * if (BoltNetwork.IsRunning)
             * {
             *  var checkFreeze = CheckBlockFreeze.Create(gameObject.GetComponent<NetworkBlockBehaviour>().entity);
             *  checkFreeze.BlockPosition = gameObject.transform.position;
             *  checkFreeze.BlockRotation = gameObject.transform.rotation;
             *
             *  checkFreeze.OldBlockPosition = pos;
             *  checkFreeze.OldBlockRotation = rot;
             *
             *  if (closestConnection.ParentPart.ID != null)
             *  {
             *      checkFreeze.ParentID = (int)closestConnection.ParentPart.ID;
             *  }
             *  else
             *  {
             *      checkFreeze.ParentID = -1;
             *  }
             *
             *  checkFreeze.ParentCon = closestConnection.ParentPart.Connections.IndexOf(closestConnection);
             *  checkFreeze.ConnectionID = gameObject.GetComponent<Part>().Connections.IndexOf(bestOnPart);
             *
             *  checkFreeze.Send();
             * }
             */
        }
    }