Exemplo n.º 1
0
    public static List <ServerGib> CreateGibs(
        string entityToCreatePath,
        GameObject creator,
        GameObject gibSource,
        Vector3 inheritVelocity,
        float spreadVelocity)
    {
        List <ServerGib> serverGibList = new List <ServerGib>();

        foreach (MeshRenderer componentsInChild in (MeshRenderer[])gibSource.GetComponentsInChildren <MeshRenderer>(true))
        {
            MeshFilter component1         = (MeshFilter)((Component)componentsInChild).GetComponent <MeshFilter>();
            Vector3    localPosition1     = ((Component)componentsInChild).get_transform().get_localPosition();
            Vector3    normalized         = ((Vector3) ref localPosition1).get_normalized();
            Matrix4x4  localToWorldMatrix = creator.get_transform().get_localToWorldMatrix();
            Vector3    pos    = Vector3.op_Addition(((Matrix4x4) ref localToWorldMatrix).MultiplyPoint(((Component)componentsInChild).get_transform().get_localPosition()), Vector3.op_Multiply(normalized, 0.5f));
            Quaternion rot    = Quaternion.op_Multiply(creator.get_transform().get_rotation(), ((Component)componentsInChild).get_transform().get_localRotation());
            BaseEntity entity = GameManager.server.CreateEntity(entityToCreatePath, pos, rot, true);
            if (Object.op_Implicit((Object)entity))
            {
                ServerGib component2 = (ServerGib)((Component)entity).GetComponent <ServerGib>();
                ((Component)component2).get_transform().set_position(pos);
                ((Component)component2).get_transform().set_rotation(rot);
                component2._gibName = ((Object)componentsInChild).get_name();
                component2.PhysicsInit(component1.get_sharedMesh());
                Vector3 localPosition2 = ((Component)componentsInChild).get_transform().get_localPosition();
                Vector3 vector3_1      = Vector3.op_Multiply(((Vector3) ref localPosition2).get_normalized(), spreadVelocity);
                component2.rigidBody.set_velocity(Vector3.op_Addition(inheritVelocity, vector3_1));
                Rigidbody rigidBody = component2.rigidBody;
                Vector3   vector3_2 = Vector3Ex.Range(-1f, 1f);
                Vector3   vector3_3 = Vector3.op_Multiply(((Vector3) ref vector3_2).get_normalized(), 1f);
                rigidBody.set_angularVelocity(vector3_3);
                component2.rigidBody.WakeUp();
                component2.Spawn();
                serverGibList.Add(component2);
            }
        }
        foreach (ServerGib serverGib1 in serverGibList)
        {
            foreach (ServerGib serverGib2 in serverGibList)
            {
                if (!Object.op_Equality((Object)serverGib1, (Object)serverGib2))
                {
                    Physics.IgnoreCollision((Collider)serverGib2.GetCollider(), (Collider)serverGib1.GetCollider(), true);
                }
            }
        }
        return(serverGibList);
    }
Exemplo n.º 2
0
    public static List <ServerGib> CreateGibs(string entityToCreatePath, GameObject creator, GameObject gibSource, Vector3 inheritVelocity, float spreadVelocity)
    {
        List <ServerGib> serverGibs = new List <ServerGib>();

        MeshRenderer[] componentsInChildren = gibSource.GetComponentsInChildren <MeshRenderer>(true);
        for (int i = 0; i < (int)componentsInChildren.Length; i++)
        {
            MeshRenderer meshRenderer = componentsInChildren[i];
            MeshFilter   component    = meshRenderer.GetComponent <MeshFilter>();
            Vector3      vector3      = meshRenderer.transform.localPosition;
            Vector3      vector31     = vector3.normalized;
            Matrix4x4    matrix4x4    = creator.transform.localToWorldMatrix;
            Vector3      vector32     = matrix4x4.MultiplyPoint(meshRenderer.transform.localPosition) + (vector31 * 0.5f);
            Quaternion   quaternion   = creator.transform.rotation * meshRenderer.transform.localRotation;
            BaseEntity   baseEntity   = GameManager.server.CreateEntity(entityToCreatePath, vector32, quaternion, true);
            if (baseEntity)
            {
                ServerGib serverGib = baseEntity.GetComponent <ServerGib>();
                serverGib.transform.position = vector32;
                serverGib.transform.rotation = quaternion;
                serverGib._gibName           = meshRenderer.name;
                serverGib.PhysicsInit(component.sharedMesh);
                vector3 = meshRenderer.transform.localPosition;
                Vector3 vector33 = vector3.normalized * spreadVelocity;
                serverGib.rigidBody.velocity = inheritVelocity + vector33;
                Rigidbody rigidbody = serverGib.rigidBody;
                vector3 = Vector3Ex.Range(-1f, 1f);
                rigidbody.angularVelocity = vector3.normalized * 1f;
                serverGib.rigidBody.WakeUp();
                serverGib.Spawn();
                serverGibs.Add(serverGib);
            }
        }
        foreach (ServerGib serverGib1 in serverGibs)
        {
            foreach (ServerGib serverGib2 in serverGibs)
            {
                if (serverGib1 == serverGib2)
                {
                    continue;
                }
                Physics.IgnoreCollision(serverGib2.GetCollider(), serverGib1.GetCollider(), true);
            }
        }
        return(serverGibs);
    }