Exemplo n.º 1
0
            public virtual JObject Serialize()
            {
                obj.Add(new JProperty(
                            HT_node_colliderExtensionFactory.TYPE,
                            Type.ToString()
                            ));

                if (IsTrigger != ISTRIGGER_DEFAULT)
                {
                    obj.Add(new JProperty(
                                HT_node_colliderExtensionFactory.ISTRIGGER,
                                IsTrigger
                                ));
                }

                if (Center != CENTER_DEFAULT)
                {
                    obj.Add(new JProperty(
                                HT_node_colliderExtensionFactory.CENTER,
                                new JArray(Center.X, Center.Y, Center.Z)
                                ));
                }

                return(obj);
            }
Exemplo n.º 2
0
    public XElement Serialize()
    {
        List <XElement> xMat = new List <XElement>();

        foreach (LevelMat mat in materials)
        {
            xMat.Add(mat.Serialize());
        }
        List <XElement> content = new List <XElement>()
        {
            SerializeValue("name", name),
            SerializeValue("pos", VecStr(position)),
            SerializeValue("rot", QuatStr(rotation)),
            SerializeValue("scl", VecStr(scale)),
            SerializeValue("collider", collider.ToString()),
            MeshXml(mesh),
            new XElement(
                "mat",
                xMat
                )
        };

        if (animation != null)
        {
            content.Add(animation.Serialize());
        }
        return(new XElement(
                   "lel", // lel = level element
                   content.ToArray()
                   ));
    }
Exemplo n.º 3
0
    void OnCollisionEnter(Collision collision)
    {
        if (audioLib == null)
        {
            return;
        }

        CollisionAudio ca = collision.gameObject.GetComponent <CollisionAudio> ();

        if (gameObject.GetInstanceID() < collision.gameObject.GetInstanceID())
        {
            return;
        }

        if (ca == null)
        {
            return;
        }

        ColliderType ta = ca.colliderType;
        ColliderType tb = colliderType;

        if (ta > tb)
        {
            ColliderType tmp = ta;
            ta = tb;
            tb = tmp;
        }

        AudioClip c = audioLib.getClip(string.Format("{0}_{1}", ta.ToString(), tb.ToString()));

        if (c == null)
        {
            c = audioLib.getClip(string.Format("{1}_{0}", ta.ToString(), tb.ToString()));
        }
        playAudioEffect(c);
    }
Exemplo n.º 4
0
 public void resetCorrespondType()
 {
     Debug.Log(gameObject.name + ", resetCollisionFrom. selfType:" + _selfType.ToString());
     resetCorrespondType(_selfType);
 }
Exemplo n.º 5
0
 public ChooseType(ColliderType t, bool choose = true)
 {
     type     = t;
     name     = t.ToString();
     isChoose = choose;
 }
Exemplo n.º 6
0
        public void Combine()
        {
            if (objectToCombine.childCount <= 0 ||
                !objectToCombine.TryGetComponent(out MeshFilter parentMeshFilter) ||
                !objectToCombine.TryGetComponent(out MeshRenderer parentMeshRenderer))
            {
                Debug.LogError("Error, cannot combine, check that the parent has at least 1 child to combine, contains a mesh filter and a mesh renderer.");
                return;
            }

            List <MeshFilter> meshFilters = new List <MeshFilter>();

            if (includeParentMesh)
            {
                if (parentMeshFilter.mesh == null)
                {
                    Debug.LogError("You have selected include parent mesh, but parent mesh doesn't exist.");
                }
                else
                {
                    meshFilters.Add(parentMeshFilter);
                }
            }

            int amountOfChildrenWithoutMeshFilter = 0;

            for (int i = 0; i < objectToCombine.childCount; i++)
            {
                Transform child = objectToCombine.GetChild(i);
                if (child.TryGetComponent(out MeshFilter childMeshFilter))
                {
                    meshFilters.Add(childMeshFilter);
                }
                else
                {
                    amountOfChildrenWithoutMeshFilter++;
                }

                if (child.childCount >= 1)
                {
                    for (int j = 0; j < child.childCount; j++)
                    {
                        if (child.GetChild(j).TryGetComponent(out MeshFilter childChildMeshFilter))
                        {
                            meshFilters.Add(childChildMeshFilter);
                        }
                        else
                        {
                            amountOfChildrenWithoutMeshFilter++;
                        }
                    }
                }
            }

            if (amountOfChildrenWithoutMeshFilter > 0)
            {
                Debug.LogWarning($"Parent contained {amountOfChildrenWithoutMeshFilter} children without a mesh filter, is this intended?");
            }

            CombineInstance[] combineInstance = new CombineInstance[meshFilters.Count];

            for (int i = 0; i < meshFilters.Count; i++)
            {
                combineInstance[i].mesh      = meshFilters[i].mesh;
                combineInstance[i].transform = meshFilters[i].transform.localToWorldMatrix;
                if (whatToDoToOldObjects == OldObjectSetting.Disable)
                {
                    meshFilters[i].gameObject.SetActive(false);
                }
                else if (whatToDoToOldObjects == OldObjectSetting.Remove)
                {
                    DestroyImmediate(meshFilters[i].gameObject);
                }
            }

            parentMeshFilter.mesh.CombineMeshes(combineInstance, mergeSubMeshes,
                                                includeTransformMatrices, includeLightMapData);
            parentMeshRenderer.material = materialToUse;
            if (colliderToAdd != ColliderType.DontAdd)
            {
                Type collider = Type.GetType(colliderToAdd.ToString());
                if (collider != null)
                {
                    objectToCombine.gameObject.AddComponent(collider);
                }
                else
                {
                    Debug.LogError($"Collider of the name {collider} does not exist. Make sure you typed it correctly (e.g BoxCollider, MeshCollider)");
                }
            }

            objectToCombine.gameObject.SetActive(true);
        }