public JsonTreePrototype(TreePrototype src_, ResourceMapper resMap)
        {
            src            = src_;
            prefabId       = resMap.getRootPrefabId(src.prefab, true);
            prefabObjectId = resMap.getPrefabObjectId(src.prefab, true);

            meshIdData = new MeshIdData(src.prefab, resMap);

            /*
             * meshId = -1;
             * meshMaterials.Clear();
             *
             * var srcObj = src.prefab as GameObject;
             * if (!srcObj)
             *      return;
             * var filter = srcObj.GetComponent<MeshFilter>();
             * if (filter && filter.sharedMesh){
             *      meshId = resMap.getMeshId(filter.sharedMesh);
             * }
             * var renderer = srcObj.GetComponent<Renderer>();
             * if (renderer){
             *      foreach(var cur in renderer.sharedMaterials){
             *              meshMaterials.Add(resMap.getMaterialId(cur));
             *      }
             * }
             */
        }
        public JsonTerrainDetailPrototype(DetailPrototype data_, ResourceMapper resMap)
        {
            data = data_;

            textureId            = resMap.getTextureId(data.prototypeTexture);
            detailPrefabId       = resMap.getRootPrefabId(data.prototype, true);
            detailPrefabObjectId = resMap.getPrefabObjectId(data.prototype, true);

            meshIdData = new MeshIdData(data.prototype, resMap);
            //meshId = resMap.getPrefabObjectId
        }
Example #3
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);
            }
        }