public override void Sync(Component c)
        {
            this.name = "sync.ReflectionProbe";

            ReflectionProbe comp        = c as ReflectionProbe;
            var             textureData = SyncAssetData.GetAssetData <SyncTextureData>(comp.bakedTexture);

            if (textureData != null)
            {
                bakedTexture = textureData.uuid;
            }
        }
        public override void Sync(Component c)
        {
            comp = c as Renderer;

            this.casterShadow  = comp.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off;
            this.receiveShadow = comp.receiveShadows;

            if (comp.lightmapIndex >= 0 && LightmapSettings.lightmaps.Length > comp.lightmapIndex)
            {
                var lightmapData = LightmapSettings.lightmaps.GetValue(comp.lightmapIndex) as LightmapData;

                var lightmapTex = SyncAssetData.GetAssetData <SyncTextureData>(lightmapData.lightmapColor);
                if (lightmapTex != null)
                {
                    var lightmapSetting = new SyncLightMapSetting();
                    lightmapSetting.lightmapColor = lightmapTex.uuid;
                    lightmapSetting.uv            = new Vector4(comp.lightmapScaleOffset.z, comp.lightmapScaleOffset.w, comp.lightmapScaleOffset.x, comp.lightmapScaleOffset.y);

                    this.lightmapSetting = lightmapSetting.GetData();
                }
            }

            foreach (var m in comp.sharedMaterials)
            {
                var mtl = SyncAssetData.GetAssetData <SyncMaterialData>(m, this);
                if (mtl != null)
                {
                    this.materilas.Add(mtl.uuid);
                }
            }

            List <UnityEngine.Rendering.ReflectionProbeBlendInfo> probes = new List <UnityEngine.Rendering.ReflectionProbeBlendInfo>();

            comp.GetClosestReflectionProbes(probes);

            if (probes.Count != 0)
            {
                foreach (var probe in probes)
                {
                    // CocosSyncTool.Instance.SyncNode(probe.probe.transform);

                    var probeData = new SyncMeshRendererProbe();
                    probeData.probePath = Hierarchy.GetPath(probe.probe.transform, null);
                    probeData.weight    = probe.weight;

                    this.probes.Add(probeData.GetData());
                }
            }
        }
Пример #3
0
        void SyncSelectAsset()
        {
            BeginSync();

            foreach (var obj in Selection.objects)
            {
                if (obj is Texture)
                {
                    SyncAssetData.GetAssetData <SyncTextureData>(obj);
                }
                else if (obj is Material)
                {
                    SyncAssetData.GetAssetData <SyncMaterialData>(obj);
                }
            }

            SyncAssets();
            EndSync();
        }
Пример #4
0
        public override void Sync(Component c)
        {
            this.name = "cc.SkeletalAnimation";

            var motionsComp = c as Motions;
            var animator    = c.GetComponent <Animator>();

            if (!animator)
            {
                animator = c.gameObject.AddComponent <Animator>();
            }

            var animatorCtrl = new AnimatorController();

            animator.runtimeAnimatorController = animatorCtrl;

            animatorCtrl.AddLayer("Temp");

            int stateIndex = 0;

            foreach (var motion in motionsComp.motions)
            {
                if (!motion)
                {
                    continue;
                }

                var state = animatorCtrl.AddMotion(motion, 0);
                var clips = animatorCtrl.animationClips;

                var param = new AnimationClipParam();
                param.animator   = animator;
                param.stateName  = "state:" + stateIndex + "(" + state.name + ")";
                param.folderName = motionsComp.folderName;

                state.name = param.stateName;
                stateIndex++;

                var clipData = SyncAssetData.GetAssetData <SyncAnimationClipData>(clips[clips.Length - 1], param);
                this.clips.Add(clipData.uuid);
            }
        }
Пример #5
0
        public override void Sync(Component c)
        {
            base.Sync(c);

            name = "cc.MeshRenderer";
            var meshRenderer = c as MeshRenderer;

            var filter = comp.GetComponent <MeshFilter>();

            if (filter && filter.sharedMesh)
            {
                if (filter.sharedMesh.name.StartsWith("Combined Mesh"))
                {
                    if (meshRenderer)
                    {
                        var path = "CombinedMesh/" + filter.name + "_" + (meshRenderer.subMeshStartIndex) + "_" + (meshRenderer.subMeshStartIndex + meshRenderer.sharedMaterials.Length - 1);

                        var asset = new SyncMeshData();
                        asset.uuid = path;
                        asset.path = path;

                        asset.shouldCheckSrc = false;

                        asset.Sync(filter.sharedMesh, meshRenderer.subMeshStartIndex, meshRenderer.sharedMaterials.Length);

                        SyncAssetData.AddAssetData(asset);
                    }
                }
                else
                {
                    var meshData = SyncAssetData.GetAssetData <SyncMeshData>(filter.sharedMesh);
                    if (meshData != null)
                    {
                        this.mesh = meshData.uuid;
                    }
                }
            }
        }
Пример #6
0
        public override void Sync(Component c)
        {
            base.Sync(c);
            name = "cc.SkinnedMeshRenderer";

            SkinnedMeshRenderer renderer = c as SkinnedMeshRenderer;

            var meshData = SyncAssetData.GetAssetData <SyncMeshData>(renderer.sharedMesh);

            if (meshData != null)
            {
                mesh = meshData.uuid;
            }

            if (meshData != null)
            {
                var path = Path.Combine(Path.GetDirectoryName(meshData.path), Path.GetFileNameWithoutExtension(meshData.path), renderer.transform.name + ".skeleton");

                var asset = new SyncSkeletonData();
                asset.uuid = path;
                asset.path = path;

                asset.shouldCheckSrc = false;
                asset.virtualAsset   = true;
                asset.Sync(null, renderer);

                SyncAssetData.AddAssetData(asset);

                skeleton = path;
            }

            var rootBone = Hierarchy.GetRootBone(renderer);

            // CocosSyncTool.Instance.SyncNode(rootBone);
            rootBonePath = Hierarchy.GetPath(rootBone, null);
        }
        public override void Sync(UnityEngine.Object obj, object param1 = null)
        {
            this.name = "cc.Material";

            Material m           = obj as Material;
            var      propertyMap = new Dictionary <string, SyncShaderProperty>();

            var rendererData = param1 as SyncRendererData;

            if (rendererData != null && rendererData.comp != null)
            {
                List <UnityEngine.Rendering.ReflectionProbeBlendInfo> probes = new List <UnityEngine.Rendering.ReflectionProbeBlendInfo>();
                rendererData.comp.GetClosestReflectionProbes(probes);

                if (probes.Count != 0)
                {
                    defines.Add("USE_IBL=" + 2);
                }

                this.hasLightMap = rendererData.lightmapSetting != null;
            }

            var shader = SyncAssetData.GetAssetData <SyncShaderData>(m.shader);

            if (shader != null)
            {
                this.shaderUuid = shader.uuid;
            }


            for (var pi = 0; pi < m.shader.GetPropertyCount(); pi++)
            {
                var type = m.shader.GetPropertyType(pi);
                var name = m.shader.GetPropertyName(pi);

                if (propertyMap.ContainsKey(name))
                {
                    continue;
                }

                var prop = new SyncShaderProperty();
                prop.type = (int)type;

                if (PropertiesMap.ContainsKey(name))
                {
                    PropertiesMap.TryGetValue(name, out prop.name);
                    this.properties.Add(prop);
                }
                else
                {
                    prop.name = name;
                    this.extendProperties.Add(prop);
                }

                propertyMap.Add(name, prop);

                if (type == UnityEngine.Rendering.ShaderPropertyType.Color)
                {
                    prop.value = JsonUtility.ToJson(m.GetColor(name));
                }
                else if (type == UnityEngine.Rendering.ShaderPropertyType.Float || type == UnityEngine.Rendering.ShaderPropertyType.Range)
                {
                    prop.value = m.GetFloat(name).ToString();
                }
                else if (type == UnityEngine.Rendering.ShaderPropertyType.Texture)
                {
                    var t = m.GetTexture(name);
                    if (t)
                    {
                        var tex = SyncAssetData.GetAssetData <SyncTextureData>(t);
                        if (tex != null)
                        {
                            prop.value = tex.uuid;
                        }
                    }
                }
                else if (type == UnityEngine.Rendering.ShaderPropertyType.Vector)
                {
                    prop.value = JsonUtility.ToJson(m.GetVector(name));
                }
            }

            // defines
            SmoothChannel smoothChannel = SmoothChannel.None;

            var shaderKeywords = m.shaderKeywords;

            if (Array.IndexOf(shaderKeywords, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A") != -1)
            {
                smoothChannel = SmoothChannel.Albedo_A;
            }

            if (m.HasProperty("_MetallicGlossMap") && m.GetTexture("_MetallicGlossMap") != null)
            {
                if (smoothChannel == SmoothChannel.None)
                {
                    smoothChannel = SmoothChannel.Metallic_A;
                }

                ModifyValue(propertyMap, "_Metallic", "1");
            }

            if (smoothChannel != SmoothChannel.None)
            {
                float glossMapScale = 1;
                if (m.HasProperty("_GlossMapScale"))
                {
                    glossMapScale = m.GetFloat("_GlossMapScale");
                }
                ModifyValue(propertyMap, "_Glossiness", glossMapScale.ToString());
                ModifyValue(propertyMap, "_Smoothness", glossMapScale.ToString());
            }

            defines.Add("USE_SMOOTH_CHANNEL=" + (int)smoothChannel);

            if (m.enableInstancing)
            {
                defines.Add("USE_INSTANCING=" + m.enableInstancing);
            }

            // pipeline state
            if (m.HasProperty("_Cull"))
            {
                passState.cullMode = m.GetFloat("_Cull");
            }
            if (m.HasProperty("_DstBlend"))
            {
                passState.blendSrc = m.GetInt("_DstBlend");
            }
            if (m.HasProperty("_DstBlend"))
            {
                passState.blendDst = m.GetInt("_DstBlend");
            }
            if (m.HasProperty("_ZWrite"))
            {
                passState.zWrite = m.GetInt("_ZWrite");
            }

            // technique
            if (m.HasProperty("_Mode"))
            {
                var mode = m.GetFloat("_Mode");
                if ((BlendMode)mode == BlendMode.Transparent)
                {
                    technique = "transparent";
                }
            }
            else if (m.HasProperty("_Surface"))
            {
                var mode = m.GetFloat("_Surface");
                if (mode == 1)
                {
                    technique = "transparent";
                }
            }
        }