Exemple #1
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();
            }
        }
    }
Exemple #2
0
    public void Right()
    {
        if (choseChild && !choseChildConnection)
        {
            if (childIndex == -1)
            {
                return;
            }

            childProxies[childIndex].SetActive(false);
            ++childIndex;
            if (childIndex >= childProxies.Count)
            {
                childIndex = 0;
            }

            childProxies[childIndex].SetActive(true);
            childProxies[childIndex].GetComponent <MeshRenderer>().material = MaterialHolder.SelectedMat;
        }
        else if (choseChildConnection)
        {
            Part childPart = childProxies[childIndex].GetComponent <Part>();
            ++conIndex;
            if (conIndex >= childPart.ActiveConnections.Count)
            {
                conIndex = 0;
            }

            if (ConnectionScanning.RuleActive(chosenConnection, childPart.Connections[childPart.ActiveConnections[conIndex]]))
            {
                bool orientCheck = false;
                for (int i = 0; i < 10; ++i)
                {
                    orientCheck = AlignPlane.Orient(childPart.Connections[childPart.ActiveConnections[conIndex]].Pln, chosenConnection.Pln, childProxies[childIndex]);
                    if (orientCheck)
                    {
                        break;
                    }
                }
                if (!orientCheck)
                {
                    Right();
                }
            }
            else
            {
                Right();
            }

            childProxies[childIndex].GetComponent <MeshRenderer>().material = MaterialHolder.SelectedMat;
        }
    }
Exemple #3
0
    public void Left()
    {
        if (choseChild && !choseChildConnection)
        {
            if (childIndex == -1)
            {
                return;
            }

            childProxies[childIndex].SetActive(false);
            --childIndex;
            if (childIndex < 0)
            {
                childIndex = childProxies.Count - 1;
            }

            childProxies[childIndex].SetActive(true);
        }
        else if (choseChildConnection)
        {
            Part childPart = childProxies[childIndex].GetComponent <Part>();
            --conIndex;
            if (conIndex < 0)
            {
                conIndex = childPart.ActiveConnections.Count - 1;
            }

            if (ConnectionScanning.RuleActive(chosenConnection, childPart.Connections[childPart.ActiveConnections[conIndex]]))
            {
                bool orientCheck = false;
                for (int i = 0; i < 10; ++i)
                {
                    orientCheck = AlignPlane.Orient(childPart.Connections[childPart.ActiveConnections[conIndex]].Pln, chosenConnection.Pln, childProxies[childIndex]);
                    if (orientCheck)
                    {
                        break;
                    }
                }
                if (!orientCheck)
                {
                    Left();
                }
            }
            else
            {
                Left();
            }
        }
    }
Exemple #4
0
    List <GameObject> SpawnChildProxies(Connection c)
    {
        List <GameObject> childPartsProxies = new List <GameObject>();

        for (int i = 0; i < GlobalReferences.TemplateParts.Count; ++i)
        {
            GameObject go = PartsHolder.Holder.SpawnGhostPart(i);
            go.AddComponent <CheckGrowCollision>();
            Destroy(go.GetComponent <ConnectionScanning>());

            List <Connection> templateCons = new List <Connection>();
            Part templatePart = go.GetComponent <Part>();

            foreach (int id in templatePart.ActiveConnections)
            {
                templateCons.Add(templatePart.Connections[id]);
            }

            foreach (Connection templateC in templateCons)
            {
                if (ConnectionScanning.RuleActive(templateC, c))
                {
                    AlignPlane.Orient(templateC.Pln, c.Pln, go);
                    go.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                    childPartsProxies.Add(go);
                    go.SetActive(false);
                    break;
                }
            }

            if (!childPartsProxies.Contains(go))
            {
                Destroy(go);
            }
        }

        if (childPartsProxies.Count > 0)
        {
            childPartsProxies[0].SetActive(true);
            childIndex = 0;
        }

        return(childPartsProxies);
    }
Exemple #5
0
    void ResetPart()
    {
        KillTimer kill = GetComponent <KillTimer>();

        if (kill != null)
        {
            kill.Kill();
        }

        GetComponent <MeshRenderer>().enabled = true;

        GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;

        /*
         * Vector3 minS = PartsHolder.MinSpawnArea;
         * Vector3 maxS = PartsHolder.MaxSpawnArea;
         * gameObject.transform.position = new Vector3(Random.Range(minS.x, maxS.x), Random.Range(minS.y, maxS.y), Random.Range(minS.z, maxS.z));
         */

        gameObject.transform.position = respawnPosition;
        gameObject.transform.rotation = respawnRotation;

        ConstantForce force = gameObject.GetComponent <ConstantForce>();

        if (force == null)
        {
            force = gameObject.AddComponent <ConstantForce>();
        }

        gameObject.layer = 8;

        ConnectionScanning scan = gameObject.GetComponent <ConnectionScanning>();

        if (scan == null)
        {
            scan             = gameObject.AddComponent <ConnectionScanning>();
            scan.WaitSeconds = 1;
        }

        PartBehaviour behaviour = gameObject.GetComponent <PartBehaviour>();

        if (behaviour == null)
        {
            behaviour = gameObject.AddComponent <PartBehaviour>();
        }

        if (PlacementReferences.PlacementType == PlacementReferences.PlaceChoreo.PickNChose)
        {
            scan.enabled      = false;
            behaviour.enabled = false;
        }

        var handler = GetComponent <ConnectionScanningHandler>();

        if (handler != null)
        {
            handler.FailedConnection(gameObject);
        }


        Destroy(this);
    }
Exemple #6
0
    //initialize
    #region
    public void Initialize(string _name, List <Connection> _connections, int _id, int _templateId, Vector3 _partOffset, Mesh _geometry = null, int _spawnNumber = 0, List <Mesh> _collider = null, int _parent = -1)
    {
        name        = _name;
        parent      = _parent;
        id          = _id;
        templateID  = _templateId;
        partOffset  = _partOffset;
        geometry    = _geometry;
        spawnNumber = _spawnNumber;


        int count = 0;

        foreach (Connection _conn in _connections)
        {
            _conn.Pln.Parent = transform;
            connections.Add(_conn);
            activeConnections.Add(count);
            ++count;
            _conn.GenerateRulesTable(GlobalReferences.Rules);
            _conn.ParentPart = this;
        }

        //check geometry and colliders
        #region
        if (geometry != null && (gameObject.GetComponent <MeshFilter>() != null || gameObject.GetComponent <MeshRenderer>() != null))
        {
            if (gameObject.GetComponent <MeshFilter>() != null)
            {
                Destroy(gameObject.GetComponent <MeshFilter>());
            }
            if (gameObject.GetComponent <MeshRenderer>() != null)
            {
                Destroy(gameObject.GetComponent <MeshRenderer>());
            }
        }

        if (geometry != null)
        {
            MeshFilter mf = gameObject.AddComponent <MeshFilter>();
            mf.mesh = geometry;
            MeshRenderer mr = gameObject.AddComponent <MeshRenderer>();
            mr.material = Resources.Load <Material>("Materials/" + MaterialHolder.MatSet + "/unaffectedMaterial");
        }
        else if (geometry == null && (gameObject.GetComponent <MeshFilter>() == null || gameObject.GetComponent <MeshRenderer>() == null))
        {
            throw new System.Exception("Get your Geometry straight!");
        }
        else
        {
            geometry = gameObject.GetComponent <MeshFilter>().sharedMesh;
        }


        if (_collider == null && gameObject.GetComponent <MeshCollider>() == null && gameObject.GetComponent <BoxCollider>() == null && gameObject.GetComponent <SphereCollider>() == null && gameObject.GetComponent <CapsuleCollider>() == null)
        {
            MeshCollider mc = gameObject.AddComponent <MeshCollider>();
            mc.convex     = true;
            mc.sharedMesh = geometry;
        }
        else if (_collider != null)
        {
            int j = 0;
            foreach (Mesh m in _collider)
            {
                MeshCollider mc = gameObject.AddComponent <MeshCollider>();
                mc.convex     = true;
                mc.sharedMesh = m;
                ++j;
            }
        }
        #endregion

        //Add Components
        #region
        if (gameObject.GetComponent <Rigidbody>() == null)
        {
            Rigidbody rg = gameObject.AddComponent <Rigidbody>();
            rg.useGravity  = false;
            rg.drag        = 1;
            rg.angularDrag = 3;
        }

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

        if (gameObject.GetComponent <PartBehaviour>() == null)
        {
            PartBehaviour behav = gameObject.AddComponent <PartBehaviour>();
            behav.enabled = false;
        }

        if (gameObject.GetComponent <ConnectionScanning>() == null)
        {
            ConnectionScanning scan = gameObject.AddComponent <ConnectionScanning>();
            scan.enabled = false;
        }
        #endregion
    }