Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //FORCEFIELDS
        if (other.CompareTag("Deactivator"))
        {
            AudioSource.PlayClipAtPoint(gotItem, transform.position);
            Deactivator deact = other.GetComponent<Deactivator>();
            Forcefield field = deact.GetForcefield();
            field.Deactivate();
            deact.Remove();
        }

        //FINAL DOOR
        //Pick up final keycard
        if (other.CompareTag("Keycard"))
        {
            if(keycard == null)
            {
                keycard = other.gameObject;
                AudioSource.PlayClipAtPoint(gotKeycard, transform.position);

                keycard.transform.SetParent(transform);
                keycard.transform.position = transform.position + Vector3.right * 0.5f + Vector3.up * 1.5f;
            }
        }
    }
Exemplo n.º 2
0
    public virtual void ExplodePartial(int start)
    {
        for (int submesh = 0; submesh < M.subMeshCount; submesh++)
        {
            int[] indices = M.GetTriangles(submesh);

            for (int i = start; i < indices.Length - grandStep - 2; i += grandStep)
            {
                for (int n = 0; n < 3; n++)
                {
                    int index = indices[i + n];
                    newVerts[n]   = verts[index];
                    newUvs[n]     = uvs[index];
                    newNormals[n] = normals[index];
                }
                mesh          = new Mesh();
                mesh.vertices = newVerts;
                mesh.normals  = newNormals;
                mesh.uv       = newUvs;

                mesh.triangles = triangles;

                GO = ObjectsPool.Spawn(pooledObjectName, Vector3.zero, Quaternion.identity);

                if (GO != null)
                {
                    GO.SetActive(true);

                    Deactivator deactivator = GO.GetComponent <Deactivator>();

                    GO.layer = LayerMask.NameToLayer(layerName);

                    deactivator.attachedRenderer.material = MR.materials[submesh];
                    deactivator.attachedFilter.mesh       = mesh;

                    GO.transform.position   = transform.position;
                    GO.transform.rotation   = transform.rotation;
                    GO.transform.localScale = new Vector3(MR.transform.localScale.x * scaleFactor, MR.transform.localScale.y, MR.transform.localScale.z * scaleFactor);

                    if (changeForwardVector)
                    {
                        GO.transform.forward = transform.up;
                    }

                    GO.AddComponent <BoxCollider>();

                    deactivator.attachedRigid.AddExplosionForce(explosionForce, explosionOrigin, 50, upwardsModifier);
                    deactivator.attachedRigid.useGravity  = useGravity;
                    deactivator.attachedRigid.drag        = drag;
                    deactivator.attachedRigid.angularDrag = angularDrag;

                    deactivator.TriggerDeactivation(Random.Range(minimumAliveTime, maximumAliveTime));
                }
            }
        }
        Destroy(this);
    }
Exemplo n.º 3
0
        public TwComponentFactory(IEnumerable <MethodInfo> initialization, ConstructorInfo constructor, IResolver resolver)
        {
            foreach (var init in initialization)
            {
                Initialization(init, resolver);
            }

            if (constructor is null)
            {
                return;
            }

            (_activator, _constructorArgTypes) = GetActivator(constructor);
            _deactivator = GetDeactivator(constructor.DeclaringType);
        }
Exemplo n.º 4
0
    protected override void ActivateClient()
    {
        var wheel_stack = Owner.GetComponent <MovementController>().GetWheelDriverStack();

        deactivator = wheel_stack.Push(new JammedWheelDriver(wheel_stack.GetPrototype().GetSteering()));
    }
Exemplo n.º 5
0
    private void SplitInTwo()
    {
        int above = 0;
        int below = 0;

        Vector3[] vertices = M.vertices;

        for (int submesh = 0; submesh < M.subMeshCount; submesh++)
        {
            int[] subMeshIndices = M.GetIndices(submesh);

            for (int i = 0; i < subMeshIndices.Length; i += 3)
            {
                above = 0;
                below = 0;

                if (vertices[subMeshIndices[i]].y <= cutHeight)
                {
                    below++;
                }
                else
                {
                    above++;
                }

                if (vertices[subMeshIndices[i + 1]].y <= cutHeight)
                {
                    below++;
                }
                else
                {
                    above++;
                }
                if (vertices[subMeshIndices[i + 2]].y <= cutHeight)
                {
                    below++;
                }
                else
                {
                    above++;
                }

                if (above == 3 || below == 3)
                {
                    if (above == 3)
                    {
                        upIndices[submesh].Add(subMeshIndices[i]);
                        upIndices[submesh].Add(subMeshIndices[i + 1]);
                        upIndices[submesh].Add(subMeshIndices[i + 2]);

                        upIndices[upIndices.Length - 1].Add(subMeshIndices[i + 2]);
                        upIndices[upIndices.Length - 1].Add(subMeshIndices[i + 1]);
                        upIndices[upIndices.Length - 1].Add(subMeshIndices[i]);
                    }
                    else
                    {
                        lowIndices[submesh].Add(subMeshIndices[i]);
                        lowIndices[submesh].Add(subMeshIndices[i + 1]);
                        lowIndices[submesh].Add(subMeshIndices[i + 2]);

                        lowIndices[lowIndices.Length - 1].Add(subMeshIndices[i + 2]);
                        lowIndices[lowIndices.Length - 1].Add(subMeshIndices[i + 1]);
                        lowIndices[lowIndices.Length - 1].Add(subMeshIndices[i]);
                    }
                }
            }
        }
        DetermineVertexPositions(vertices);

        if (upperVertices != 0)
        {
            upper = ObjectsPool.Spawn(pooledObjectName, Vector3.zero, Quaternion.identity);

            upper.layer = LayerMask.NameToLayer("Fragments");
            upper.transform.position = transform.position;

            upper.transform.rotation   = SMR.transform.rotation;
            upper.transform.localScale = transform.localScale;

            upper.SetActive(true);
            upper.name = "upper";

            Mesh mesh = new Mesh();
            mesh.SetVertices(upperVertexList);

            mesh.subMeshCount = upIndices.Length;
            for (int i = 0; i < upIndices.Length; i++)
            {
                mesh.SetIndices(ApplyIndexChange(upIndices[i], vertexPosChange), MeshTopology.Triangles, i);
            }

            mesh.SetNormals(upNormals);
            mesh.SetUVs(0, upperUVs);

            Deactivator deactivator = upper.GetComponent <Deactivator>();
            deactivator.TriggerDeactivation(deactivateTime);

            Destroy(upper.GetComponent <MeshFilter>());
            Destroy(upper.GetComponent <MeshRenderer>());
            SkinnedMeshRenderer upSMR = upper.AddComponent <SkinnedMeshRenderer>();
            upSMR.sharedMesh      = mesh;
            upSMR.sharedMaterials = upMaterials;

            upSMR.sharedMesh.RecalculateBounds();
            upSMR.rootBone = upper.transform;

            BoxCollider box = upper.AddComponent <BoxCollider>();
            box.center = upSMR.sharedMesh.bounds.center;
            box.size   = upSMR.sharedMesh.bounds.size;

            deactivator.attachedRigid.AddForceAtPosition(upper.transform.forward * 0.5f, upper.transform.position, ForceMode.Impulse);
        }

        if (lowerVertices != 0)
        {
            lower = ObjectsPool.Spawn(pooledObjectName, Vector3.zero, Quaternion.identity);

            lower.layer = LayerMask.NameToLayer("Fragments");
            lower.transform.position = transform.position;

            lower.transform.rotation   = SMR.transform.rotation;
            lower.transform.localScale = transform.localScale;

            lower.SetActive(true);
            lower.name = "lower";

            Mesh meshLow = new Mesh();
            meshLow.SetVertices(lowerVertexList);
            meshLow.subMeshCount = lowIndices.Length;


            for (int i = 0; i < lowIndices.Length; i++)
            {
                meshLow.SetIndices(ApplyIndexChange(lowIndices[i], vertexPosChange), MeshTopology.Triangles, i);
            }

            meshLow.SetNormals(lowNormals);
            meshLow.SetUVs(0, lowUVs);

            Deactivator deactivatorLow = lower.GetComponent <Deactivator>();
            deactivatorLow.TriggerDeactivation(deactivateTime);

            Destroy(lower.GetComponent <MeshFilter>());
            Destroy(lower.GetComponent <MeshRenderer>());
            SkinnedMeshRenderer lowSMR = lower.AddComponent <SkinnedMeshRenderer>();
            lowSMR.sharedMaterials = lowMaterials;

            lowSMR.sharedMesh = meshLow;
            lowSMR.sharedMesh.RecalculateBounds();

            BoxCollider boxLow = lower.AddComponent <BoxCollider>();
            boxLow.center = lowSMR.sharedMesh.bounds.center;
            boxLow.size   = lowSMR.sharedMesh.bounds.size * 0.95f;

            deactivatorLow.attachedRigid.AddForceAtPosition(lower.transform.forward * 0.5f, lower.transform.position, ForceMode.Impulse);
        }
    }
            private void TimedOut()
            {
                if (_received)
                {
                    Deactivate();
                }
                else
                {
                    if (!_timedOut)
                    {
                        _timedOut = true;
                        _timeoutTime = DateTime.Now;
                    }

                    if (DateTime.Now.Subtract(_timeoutTime) > TimeSpan.FromSeconds(10))
                    {
                        Deactivate();
                    }
                    else
                    {
                        _deactivator = new Deactivator(ShortTimelapse, TimedOut);
                    }
                }
            }
 public void Trigger(int duration)
 {
     _received = false;
     _timedOut = false;
     if (_deactivator != null)
     {
         _deactivator.Cancelled = true;
     }
     _deactivator = new Deactivator(duration, TimedOut);
 }
Exemplo n.º 8
0
    protected override void ActivateServer()
    {
        var tail_stack = Owner.GetComponent <TailController>().GetDetacherDriverStack();

        deactivator = tail_stack.Push(new InvincibleDetacherDriver());
    }
    private void ExplodePartial(int start)
    {
        for (int submesh = 0; submesh < M.subMeshCount; submesh++)
        {
            int[] indices = M.GetTriangles(submesh);
            GetTriangles(indices);

            for (int i = triList.Count - 1; i >= 0; i -= grandStep)
            {
                Tri tri = triList[i];

                Vector3 direction1 = Vector3.Normalize(-normals[tri.x]) * extrudeFactor;
                Vector3 direction2;
                int[]   triangles = new int[0];

                mesh = new Mesh();


                if (GetMatchingTri(tri.x, tri.y, tri.z))
                {
                    newVerts   = new Vector3[8];
                    newNormals = new Vector3[8];
                    newUvs     = new Vector2[8];
                    direction2 = Vector3.Normalize(-normals[matchedIndex]) * extrudeFactor;

                    newVerts[0]   = verts[tri.x];
                    newUvs[0]     = uvs[tri.x];
                    newNormals[0] = normals[tri.x];

                    newVerts[1]   = verts[tri.y];
                    newUvs[1]     = uvs[tri.y];
                    newNormals[1] = normals[tri.y];

                    newVerts[2]   = verts[tri.z];
                    newUvs[2]     = uvs[tri.z];
                    newNormals[2] = normals[tri.z];

                    newVerts[3]   = verts[matchedIndex];
                    newUvs[3]     = uvs[matchedIndex];
                    newNormals[3] = normals[matchedIndex];

                    newVerts[4]   = newVerts[0] + direction1;
                    newUvs[4]     = uvs[tri.x];
                    newNormals[4] = newNormals[0];

                    newVerts[5]   = newVerts[1] + direction1;
                    newUvs[5]     = uvs[tri.y];
                    newNormals[5] = newNormals[1];

                    newVerts[6]   = newVerts[2] + direction1;
                    newUvs[6]     = uvs[tri.z];
                    newNormals[6] = newNormals[2];


                    newVerts[7]   = newVerts[3] + direction2;
                    newUvs[7]     = uvs[matchedIndex];
                    newNormals[7] = newNormals[3];

                    triangles = new int[] { 0, 1, 2, 3, 1, 0, /*up tris*/ 6, 4, 2, 0, 2, 4, /*side1 */ 5, 2, 1, 2, 5, 6, /*side2*/ 0, 4, 7, 7, 3, 0, /*side3*/ 7, 5, 1, 7, 1, 3, /*side4*/ 6, 5, 4, 4, 5, 7 /*down*/ };
                }
                else
                {
                    newVerts   = new Vector3[6];
                    newNormals = new Vector3[6];
                    newUvs     = new Vector2[6];

                    newVerts[0]   = verts[tri.x];
                    newUvs[0]     = uvs[tri.x];
                    newNormals[0] = normals[tri.x];

                    newVerts[1]   = verts[tri.y];
                    newUvs[1]     = uvs[tri.y];
                    newNormals[1] = normals[tri.y];

                    newVerts[2]   = verts[tri.z];
                    newUvs[2]     = uvs[tri.z];
                    newNormals[2] = normals[tri.z];

                    newVerts[3]   = newVerts[0] + direction1;
                    newUvs[3]     = uvs[tri.x];
                    newNormals[3] = newNormals[0];

                    newVerts[4]   = newVerts[1] + direction1;
                    newUvs[4]     = uvs[tri.y];
                    newNormals[4] = newNormals[1];

                    newVerts[5]   = newVerts[2] + direction1;
                    newUvs[5]     = uvs[tri.z];
                    newNormals[5] = newNormals[2];


                    triangles = new int[] { 0, 1, 2, /*up*/ 4, 1, 0, 0, 3, 4, /*side1*/ 0, 2, 5, 1, 4, 5, /*side2*/ 5, 4, 3, 5, 3, 0, /*side3*/ 5, 2, 1 /*down*/ };
                }

                mesh.vertices  = newVerts;
                mesh.normals   = newNormals;
                mesh.uv        = newUvs;
                mesh.triangles = triangles;

                //GO = pool.getPooledObject();
                GO = ObjectsPool.Spawn(pooledObjectName, Vector3.zero, Quaternion.identity);
                if (GO != null)
                {
                    GO.SetActive(true);

                    Deactivator deactivator = GO.GetComponent <Deactivator>();

                    GO.layer = LayerMask.NameToLayer("Fragments");

                    GO.transform.position   = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                    GO.transform.rotation   = transform.rotation;
                    GO.transform.localScale = new Vector3(scaleFactor.x, scaleFactor.y, scaleFactor.z);

                    deactivator.attachedRenderer.material = MR.materials[submesh];
                    deactivator.attachedFilter.mesh       = mesh;
                    deactivators.Add(deactivator);

                    GO.AddComponent <BoxCollider>();
                }
            }
        }

        // Spawn PowerUp
        SpawnPowerUp();

        MR.enabled = false;
        GetComponent <Rigidbody>().isKinematic = true;
        GetComponent <Collider>().enabled      = false;
        if (GetComponent <NavMeshObstacle>() != null)
        {
            GetComponent <NavMeshObstacle>().enabled = false;
        }

        if (respawn)
        {
            Invoke("TriggerRespawn", timeTillRespawn);
        }
    }