Ejemplo n.º 1
0
        public JsonSkinRendererData(SkinnedMeshRenderer rend, GameObjectMapper objMap, ResourceMapper resMap)
        {
            if (!rend)
            {
                throw new System.ArgumentNullException("rend");
            }
            quality = rend.quality.ToString();
            skinnedMotionVectors = rend.skinnedMotionVectors;
            updateWhenOffscreen  = rend.updateWhenOffscreen;

            boneNames.Clear();
            boneIds.Clear();
            foreach (var cur in rend.bones)
            {
                boneNames.Add(cur.name);
                boneTransforms.Add(cur.localToWorldMatrix);
                boneIds.Add(objMap.getId(cur.gameObject));
            }

            var sharedMesh = rend.sharedMesh;

            meshId = resMap.getOrRegMeshId(rend, null);            //resMap.getMeshId(sharedMesh);

            materials.Clear();
            var sharedMats = rend.sharedMaterials;

            foreach (var curMat in sharedMats)
            {
                materials.Add(resMap.getMaterialId(curMat));
            }
        }
Ejemplo n.º 2
0
        public JsonGameObject(GameObject obj, GameObjectMapper objMap, ResourceMapper resMap)
        {
            name          = obj.name;
            scenePath     = obj.getScenePath();
            instanceId    = obj.GetInstanceID();
            id            = objMap.getId(obj);
            localPosition = obj.transform.localPosition;
            localRotation = obj.transform.localRotation;
            localScale    = obj.transform.localScale;
            worldMatrix   = obj.transform.localToWorldMatrix;
            localMatrix   = worldMatrix;
            if (obj.transform.parent)
            {
                localMatrix = obj.transform.parent.worldToLocalMatrix * worldMatrix;
            }

            isStatic = obj.isStatic;
            var flags = GameObjectUtility.GetStaticEditorFlags(obj);

            lightMapStatic        = (flags & StaticEditorFlags.LightmapStatic) != 0;
            occluderStatic        = (flags & StaticEditorFlags.OccluderStatic) != 0;
            occludeeStatic        = (flags & StaticEditorFlags.OccludeeStatic) != 0;
            navigationStatic      = (flags & StaticEditorFlags.NavigationStatic) != 0;
            reflectionProbeStatic = (flags & StaticEditorFlags.ReflectionProbeStatic) != 0;

            activeSelf        = obj.activeSelf;
            activeInHierarchy = obj.activeInHierarchy;

            //var prefType = PrefabUtility.GetPrefabType(obj);
            //prefabType = prefType.ToString();
            prefabRootId   = resMap.getRootPrefabId(obj, true);
            prefabObjectId = resMap.getPrefabObjectId(obj, true);
            prefabInstance = Utility.isPrefabInstance(obj) || Utility.isPrefabModelInstance(obj);
            //prefabInstance = (prefType == PrefabType.PrefabInstance) || (prefType == PrefabType.ModelPrefabInstance);

            renderer         = JsonRendererData.makeRendererArray(obj.GetComponent <Renderer>(), resMap);
            light            = JsonLight.makeLightArray(obj.GetComponent <Light>());
            reflectionProbes =
                ExportUtility.convertComponents <ReflectionProbe, JsonReflectionProbe>(obj,
                                                                                       (c) => new JsonReflectionProbe(c, resMap)
                                                                                       );
            terrains =
                ExportUtility.convertComponents <Terrain, JsonTerrain>(obj,
                                                                       (c) => new JsonTerrain(c, resMap)
                                                                       );

            skinRenderers =
                ExportUtility.convertComponentsList <SkinnedMeshRenderer, JsonSkinRendererData>(obj,
                                                                                                (c) => new JsonSkinRendererData(c, objMap, resMap)
                                                                                                );

            int colliderIndex = 0;

            colliders = ExportUtility.convertComponentsList <Collider, JsonCollider>(
                obj, (arg) => new JsonCollider(arg, colliderIndex++, resMap)
                ).Where(c => c.isSupportedType()).ToList();

            for (int i = colliders.Count - 1; i >= 0; i--)
            {
                var curCollider = colliders[i];
                if ((curCollider == null) || !curCollider.isSupportedType())
                {
                    colliders.RemoveAt(i);
                }
            }

            rigidbodies = ExportUtility.convertComponentsList <Rigidbody, JsonRigidbody>(
                obj, (arg) => new JsonRigidbody(arg)
                );

            joints = ExportUtility.convertComponentsList <Joint, JsonPhysicsJoint>(
                obj, (arg) => new JsonPhysicsJoint(arg)
                );

            /*
             * if (rigidbodies.Count > 1){
             *      //Logger.log
             * }
             */

            ///..... I think those can be replaced with linq queries (-_-)

            /*
             * animators = obj.GetComponents<Animator>().Where((arg) => arg)
             *      .Select((Animator arg) => new JsonAnimator(arg, resMap))
             *      .ToList();*/

            animators =
                ExportUtility.convertComponentsList <Animator, JsonAnimator>(obj,
                                                                             (c) => new JsonAnimator(c, resMap));

            var meshFilter = obj.GetComponent <MeshFilter>();

            if (meshFilter)
            {
                mesh = resMap.getOrRegMeshId(meshFilter);
            }

            foreach (Transform curChild in obj.transform)
            {
                var childId = objMap.getId(curChild.gameObject);

                /* ????
                 * if (childId < 0){
                 *      //throw new System.ArgumentException("Could not find child id
                 * }
                 */
                if (!childId.isValid)
                {
                }
                //var childId = objMap.getId(curChild.gameObject);
                children.Add(childId);
                childNames.Add(curChild.name);
            }
            if (obj.transform.parent)
            {
                parentName = obj.transform.parent.name;
                parent     = objMap.findId(obj.transform.parent.gameObject);
            }
        }