Beispiel #1
0
        /// <summary>
        /// Deserialize a previously serialized renderer.
        /// </summary>

        static public void Deserialize(this Renderer ren, DataNode data)
        {
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
            ren.castShadows = data.GetChild <bool>("castShadows", ren.castShadows);
#else
            DataNode cs = data.GetChild("castShadows");

            if (cs != null)
            {
                ren.shadowCastingMode = cs.Get <bool>() ?
                                        UnityEngine.Rendering.ShadowCastingMode.On :
                                        UnityEngine.Rendering.ShadowCastingMode.Off;
            }
            else
            {
                ren.shadowCastingMode = data.GetChild <UnityEngine.Rendering.ShadowCastingMode>("shadowCastingMode", ren.shadowCastingMode);
            }

            ren.reflectionProbeUsage = data.GetChild <UnityEngine.Rendering.ReflectionProbeUsage>("reflectionProbes", ren.reflectionProbeUsage);
#endif
            ren.receiveShadows = data.GetChild <bool>("receiveShadows", ren.receiveShadows);
#if UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3
            ren.useLightProbes = data.GetChild <bool>("useLightProbes", ren.useLightProbes);
#else
            var lpu = data.GetChild("lightProbeUsage");

            if (lpu != null)
            {
                ren.lightProbeUsage = (UnityEngine.Rendering.LightProbeUsage)lpu.Get <byte>((byte)ren.lightProbeUsage);
            }
            else
            {
                // Pre-Unity 5.4 format
                ren.lightProbeUsage = data.GetChild <bool>("useLightProbes", ren.lightProbeUsage != UnityEngine.Rendering.LightProbeUsage.Off) ?
                                      UnityEngine.Rendering.LightProbeUsage.BlendProbes : UnityEngine.Rendering.LightProbeUsage.Off;
            }
#endif

            DataNode matRoot = data.GetChild("Materials");

            if (matRoot != null && matRoot.children.size > 0)
            {
                Material[] mats = new Material[matRoot.children.size];

                for (int i = 0; i < matRoot.children.size; ++i)
                {
                    DataNode matNode = matRoot.children[i];
                    mats[i] = matNode.DeserializeMaterial();
                }
                ren.sharedMaterials = mats;
            }
        }
        /// <summary>
        /// Deserialize a previously serialized game object.
        /// </summary>

        static public void Deserialize(this GameObject go, DataNode root, bool includeChildren = true)
        {
            DataNode resNode = root.GetChild("Resources");

            if (resNode != null)
            {
                for (int i = 0; i < resNode.children.size; ++i)
                {
                    DataNode child = resNode.children[i];
                    if (child.name == "Texture")
                    {
                        child.DeserializeTexture();
                    }
                    else if (child.name == "Material")
                    {
                        child.DeserializeMaterial();
                    }
                    else if (child.name == "Mesh")
                    {
                        child.DeserializeMesh();
                    }
                }
            }

            if (includeChildren)
            {
                go.DeserializeHierarchy(root);
                for (int i = 0; i < mSerList.size; ++i)
                {
                    mSerList[i].go.DeserializeComponents(mSerList[i].node);
                }
                mSerList.Clear();
            }
            else
            {
                go.DeserializeComponents(root);
            }
        }
        /// <summary>
        /// Deserialize a previously serialized renderer.
        /// </summary>

        static public void Deserialize(this Renderer ren, DataNode data)
        {
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
            ren.castShadows = data.GetChild <bool>("castShadows", ren.castShadows);
#else
            DataNode cs = data.GetChild("castShadows");

            if (cs != null)
            {
                ren.shadowCastingMode = cs.Get <bool>() ?
                                        UnityEngine.Rendering.ShadowCastingMode.On :
                                        UnityEngine.Rendering.ShadowCastingMode.Off;
            }
            else
            {
                ren.shadowCastingMode = data.GetChild <UnityEngine.Rendering.ShadowCastingMode>("shadowCastingMode", ren.shadowCastingMode);
            }

            ren.reflectionProbeUsage = data.GetChild <UnityEngine.Rendering.ReflectionProbeUsage>("reflectionProbes", ren.reflectionProbeUsage);
#endif
            ren.receiveShadows = data.GetChild <bool>("receiveShadows", ren.receiveShadows);
            ren.useLightProbes = data.GetChild <bool>("useLightProbes", ren.useLightProbes);

            DataNode matRoot = data.GetChild("Materials");

            if (matRoot != null && matRoot.children.size > 0)
            {
                Material[] mats = new Material[matRoot.children.size];

                for (int i = 0; i < matRoot.children.size; ++i)
                {
                    DataNode matNode = matRoot.children[i];
                    mats[i] = matNode.DeserializeMaterial();
                }
                ren.sharedMaterials = mats;
            }
        }