public static JsonLight[] makeLightArray(Light l)
        {
            if (!l)
            {
                return(null);
            }
            var result = new JsonLight(l);

            return(new JsonLight[] { result });
        }
Example #2
0
        public JsonLight[] makeLight(Light l)
        {
            if (!l)
            {
                return(null);
            }
            var result = new JsonLight();

            result.color          = l.color;
            result.range          = l.range;
            result.spotAngle      = l.spotAngle;
            result.type           = l.type.ToString();
            result.renderMode     = l.renderMode.ToString();
            result.shadowStrength = l.shadowStrength;
            result.shadows        = l.shadows.ToString();
            result.intensity      = l.intensity;
            return(new JsonLight[] { result });
        }
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);
            }
        }