Example #1
0
        public void Write(SceneWriter writer, object component)
        {
            Component script = component as Component;

            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshFilter[]      meshFilters = script.GetComponentsInChildren <MeshFilter>();
            CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
            for (int i = 0; i < meshFilters.Length; i++)
            {
                combine[i].mesh      = meshFilters[i].sharedMesh;
                combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }
            Mesh mesh = new Mesh();

            mesh.CombineMeshes(combine);
            MeshRenderer mr = script.GetComponentInChildren <MeshRenderer>();

            writer.WriteElement("sharedMaterials", mr.sharedMaterials);
            writer.WriteElement("triangles", mesh.triangles);
            writer.WriteElement("vertices", mesh.vertices);
            //writer.WriteElement("normals", mesh.normals);
            writer.WriteElement("uv", mesh.uv);
            Debug.Log(script.name + " batched " + combine.Length + " objects into a mesh of " + (mesh.triangles.Length / 3) + " triangles and " + mesh.vertices.Length + " vertices.");

            if (mesh.vertices.Length > short.MaxValue)
            {
                Debug.LogWarning("BATCHED TOO MANY TRIANGLES!!");
            }
        }
Example #2
0
 public void Write(SceneWriter scene, object component)
 {
     Animation anim = component as Animation;
     if (anim == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + component.GetType());
     }
     scene.WriteElement("enabled", anim.enabled);
     if (anim.clip != null)
     {
         scene.WriteElement("clip", scene.SanitizeFileName(anim.name + "-" + anim.clip.name));
     }
     scene.WriteElement("playAutomatically", anim.playAutomatically);
     scene.WriteElement("wrapMode", anim.wrapMode);
     AnimationClip[] clips = AnimationUtility.GetAnimationClips(anim);
     string[] clipNames = new string[clips.Length];
     for (int i = 0; i < clips.Length; i++)
     {
         if (clips[i] == null)
         {
             continue;
         }
         clipNames[i] = scene.SanitizeFileName(anim.name + "-" + clips[i].name);
         scene.AddAnimationClip(clipNames[i], clips[i]);
     }
     scene.WriteElement("clips", clipNames);
 }
Example #3
0
        public void Write(SceneWriter scene, object component)
        {
            Animation anim = component as Animation;

            if (anim == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            scene.WriteElement("enabled", anim.enabled);
            scene.WriteElement("asset", scene.SanitizeFileName(anim.name));
            if (anim.clip != null)
            {
                scene.WriteElement("clip", scene.SanitizeFileName(anim.clip.name));
            }
            scene.WriteElement("playAutomatically", anim.playAutomatically);
            scene.WriteElement("wrapMode", anim.wrapMode);
            AnimationClip[] clips     = AnimationUtility.GetAnimationClips(anim);
            string[]        clipNames = new string[clips.Length];
            for (int i = 0; i < clips.Length; i++)
            {
                if (clips[i] == null)
                {
                    continue;
                }
                clipNames[i] = scene.SanitizeFileName(clips[i].name);
                scene.AddAnimationClip(scene.SanitizeFileName(anim.name), clips[i]);
            }
            scene.WriteElement("clips", clipNames);
        }
Example #4
0
        public void Write(SceneWriter writer, object component)
        {
            LineRenderer pr = component as LineRenderer;

            if (pr == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("enabled", pr.enabled);
            writer.WriteElement("sharedMaterials", pr.sharedMaterials);

            writer.WriteElement("useWorldSpace", pr.useWorldSpace);

            Component c = pr.gameObject.GetComponent("FFWD_LineRendererExport");

            if (c != null)
            {
                writeValue <object>(writer, c, "startWidth");
                writeValue <object>(writer, c, "endWidth");
                writeValue <object>(writer, c, "startColor");
                writeValue <object>(writer, c, "endColor");

                writeValue <object>(writer, c, "positions");
            }
        }
Example #5
0
        public void Write(SceneWriter writer, object component)
        {
            ParticleRenderer pr = component as ParticleRenderer;

            if (pr == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("enabled", pr.enabled);
            writer.WriteElement("sharedMaterials", pr.sharedMaterials);
            //writer.WriteElement("stretchParticles", pr.);
            writer.WriteElement("lengthScale", pr.lengthScale);
            writer.WriteElement("velocityScale", pr.velocityScale);
            //writer.WriteElement("cameraVelocityScale", pr.cameraVelocityScale);
            writer.WriteElement("maxParticleSize", pr.maxParticleSize);
            writer.WriteElement("uvAnimation", new Vector3(pr.uvAnimationXTile, pr.uvAnimationYTile, pr.uvAnimationCycles));

            Component c = pr.GetComponent("FFWD_EllipsoidParticleEmitterExport");

            if (c == null)
            {
                // Added for backwards compatibility
                c = pr.GetComponent("XNAEllipsoidParticleEmitter");
            }
            if (c != null)
            {
                writeValue <object>(writer, c, "stretchParticles");
            }
        }
Example #6
0
 public void Write(SceneWriter writer, object component)
 {
     Renderer mr = component as Renderer;
     if (mr == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + component.GetType());
     }
     if (!mr.enabled)
     {
         writer.WriteElement("enabled", mr.enabled);
     }
     if (mr.lightmapIndex > -1)
     {
         writer.WriteElement("lightmapIndex", mr.lightmapIndex);
         writer.WriteElement("lightmapTilingOffset", mr.lightmapTilingOffset);
     }
     writer.WriteElement("sharedMaterials", mr.sharedMaterials);
     SkinnedMeshRenderer smr = mr as SkinnedMeshRenderer;
     if (smr != null)
     {
         string[] bones = new string[smr.bones.Length];
         for (int i = 0; i < smr.bones.Length; i++)
         {
             bones[i] = smr.bones[i].name;
         }
         writer.WriteElement("bones", bones);
         writer.WriteMesh(smr.sharedMesh, "sharedMesh");
     }
     if (mr is LineRenderer)
     {
         writer.WriteElement("useWorldSpace", (mr as LineRenderer).useWorldSpace);
     }
 }
Example #7
0
        public void Write(SceneWriter writer, object component)
        {
            Component script = component as Component;
            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshFilter[] meshFilters = script.GetComponentsInChildren<MeshFilter>();
            CombineInstance[] combine = new CombineInstance[meshFilters.Length];
            for ( int i = 0; i < meshFilters.Length; i++) {
                combine[i].mesh = meshFilters[i].sharedMesh;
                combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }
            Mesh mesh = new Mesh();
            mesh.CombineMeshes(combine);
            MeshRenderer mr = script.GetComponentInChildren<MeshRenderer>();
            writer.WriteElement("sharedMaterials", mr.sharedMaterials);
            writer.WriteElement("triangles", mesh.triangles);
            writer.WriteElement("vertices", mesh.vertices);
            //writer.WriteElement("normals", mesh.normals);
            writer.WriteElement("uv", mesh.uv);
            Debug.Log(script.name + " batched " + combine.Length + " objects into a mesh of " + (mesh.triangles.Length / 3) + " triangles and " + mesh.vertices.Length + " vertices.");

            if (mesh.vertices.Length > short.MaxValue)
            {
                Debug.LogWarning("BATCHED TOO MANY TRIANGLES!!");
            }
        }
Example #8
0
        public void Write(SceneWriter writer, object component)
        {
            Renderer mr = component as Renderer;

            if (mr == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            if (!mr.enabled)
            {
                writer.WriteElement("enabled", mr.enabled);
            }
            if (mr.lightmapIndex > -1)
            {
                writer.WriteElement("lightmapIndex", mr.lightmapIndex);
                writer.WriteElement("lightmapTilingOffset", mr.lightmapTilingOffset);
            }
            writer.WriteElement("sharedMaterials", mr.sharedMaterials);
            SkinnedMeshRenderer smr = mr as SkinnedMeshRenderer;

            if (smr != null)
            {
                string[] bones = new string[smr.bones.Length];
                for (int i = 0; i < smr.bones.Length; i++)
                {
                    bones[i] = smr.bones[i].name;
                }
                writer.WriteElement("bones", bones);
                writer.WriteMesh(smr.sharedMesh, "sharedMesh");
            }
            if (mr is LineRenderer)
            {
                writer.WriteElement("useWorldSpace", (mr as LineRenderer).useWorldSpace);
            }
        }
Example #9
0
        public void Write(SceneWriter writer, object component)
        {
            AnimationCurve curve = component as AnimationCurve;

            if (curve == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("PreLoop", ConvertLoopType(curve.preWrapMode));
            writer.WriteElement("PostLoop", ConvertLoopType(curve.postWrapMode));
            StringBuilder sb = new StringBuilder();

            // NOTE: Keyframe.tangentMode might say something about if the tangetn is smooth or broken?

            Keyframe[] normalizedKeys = new Keyframe[curve.keys.Length];
            for (int i = 0; i < curve.keys.Length; i++)
            {
                Keyframe k = curve.keys[i];
                normalizedKeys[i] = new Keyframe(k.time, k.value, k.inTangent, k.outTangent);
                if (i > 0)
                {
                    Keyframe j = curve.keys[i - 1];
                    normalizedKeys[i - 1].outTangent = DenormalizeTangent(j.time, k.time, j.outTangent);
                    normalizedKeys[i].inTangent      = DenormalizeTangent(j.time, k.time, k.inTangent);
                }
            }

            foreach (Keyframe item in normalizedKeys)
            {
                sb.AppendFormat("{0} {1} {2} {3} {4} ", item.time, item.value, item.inTangent, item.outTangent, "Smooth");
            }
            writer.WriteElement("Keys", sb.ToString().TrimEnd());
        }
Example #10
0
        public void Write(SceneWriter scene, object component)
        {
            MonoBehaviour script = component as MonoBehaviour;

            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            // Gather all nodes under this and export the data as a dictionary
            Dictionary <int, int> nodeRefs = new Dictionary <int, int>();
            Type   findType     = component.GetType().GetField("component").FieldType;
            string propertyName = component.GetType().GetField("propertyName").GetValue(component).ToString();

            Component[] nodes = script.GetComponentsInChildren(findType);
            foreach (Component node in nodes)
            {
                FieldInfo          field = node.GetType().GetField(propertyName);
                UnityEngine.Object obj   = (field.GetValue(node) as UnityEngine.Object);
                if (obj != null)
                {
                    nodeRefs.Add(node.GetInstanceID(), obj.GetInstanceID());
                }
            }
            scene.WriteElement("fieldName", propertyName);
            scene.WriteElement("map", nodeRefs);
        }
Example #11
0
        public void Write(SceneWriter writer, object component)
        {
            AnimationCurve curve = component as AnimationCurve;
            if (curve == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("PreLoop", ConvertLoopType(curve.preWrapMode));
            writer.WriteElement("PostLoop", ConvertLoopType(curve.postWrapMode));
            StringBuilder sb = new StringBuilder();

            // NOTE: Keyframe.tangentMode might say something about if the tangetn is smooth or broken?

            Keyframe[] normalizedKeys = new Keyframe[curve.keys.Length];
            for (int i = 0; i < curve.keys.Length; i++)
            {
                Keyframe k = curve.keys[i];
                normalizedKeys[i] = new Keyframe(k.time, k.value, k.inTangent, k.outTangent);
                if (i > 0)
                {
                    Keyframe j = curve.keys[i - 1];
                    normalizedKeys[i - 1].outTangent = DenormalizeTangent(j.time, k.time, j.outTangent);
                    normalizedKeys[i].inTangent = DenormalizeTangent(j.time, k.time, k.inTangent);
                }
            }

            foreach (Keyframe item in normalizedKeys)
            {
                sb.AppendFormat("{0} {1} {2} {3} {4} ", item.time, item.value, item.inTangent, item.outTangent, "Smooth");
            }
            writer.WriteElement("Keys", sb.ToString().TrimEnd());
        }
Example #12
0
        private void writeValue <T>(SceneWriter writer, Component c, string fieldName)
        {
            Type      t     = c.GetType();
            FieldInfo f     = t.GetField(fieldName);
            object    value = f.GetValue(c);

            writer.WriteElement(fieldName, value);
        }
Example #13
0
        public static string RenderElement(SceneElement element)
        {
            SceneWriter     output       = new SceneWriter();
            OutputAttribute outputAttr   = OutputAttribute.Combine(element.GetAllAttributes <OutputAttribute>());
            ElementContext  sceneContext = new ElementContext(new ElementContext(null, new Scene()), element, outputAttr);

            sceneContext.LoadChildren(true);
            sceneContext.Write(output);
            return(output.ToString());
        }
Example #14
0
        private void writeValue <T>(SceneWriter writer, Component c, string fieldName)
        {
            FieldInfo f     = c.GetType().GetField(fieldName);
            object    value = f.GetValue(c);

            if (!((T)value).Equals(default(T)))
            {
                writer.WriteElement(fieldName, value);
            }
        }
Example #15
0
 public override void Write(SceneWriter scene, object collider)
 {
     base.Write(scene, collider);
     BoxCollider coll = collider as BoxCollider;
     if (coll == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + collider.GetType());
     }
     scene.WriteElement("center", coll.center);
     scene.WriteElement("size", coll.size);
 }
Example #16
0
        public override void Write(SceneWriter scene, object collider)
        {
            base.Write(scene, collider);
            SphereCollider coll = collider as SphereCollider;

            if (coll == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + collider.GetType());
            }
            scene.WriteElement("center", coll.center);
            scene.WriteElement("radius", coll.radius);
        }
Example #17
0
        public void Write(SceneWriter scene, object component)
        {
            Component beh = component as Component;
            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }
        }
Example #18
0
        public void Write(SceneWriter scene, object component)
        {
            MeshFilter filter = (component as Component).GetComponent <MeshFilter>();

            if (filter == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            if (filter.sharedMesh != null)
            {
                scene.WriteMesh(filter.sharedMesh, "mesh");
            }
        }
Example #19
0
        public void Setup()
        {
            ContractWriters.RawData.contractWriterTypeNames[GoodSongId] =
                typeof(GoodSongWriter).AssemblyQualifiedName;

            ContractWriters.RawData.contractWriterTypeNames[AnotherGoodSongId] =
                typeof(AnotherGoodSongWriter).AssemblyQualifiedName;

            _holder        = new GameObject("TestObject");
            _sceneWriter   = _holder.AddComponent <SceneWriter>();
            _testComponent = _holder.AddComponent <TestMusicComponent>();

            SetupComponentContexts();
        }
Example #20
0
        public void Write(SceneWriter scene, object component)
        {
            Component beh = component as Component;

            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }
        }
Example #21
0
 private void WriteFieldsForType(SceneWriter scene, MonoBehaviour component, Type t)
 {
     if (t != typeof(Behaviour))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     if (t == typeof(Behaviour))
     {
         if (!component.enabled)
         {
             scene.WriteElement("enabled", component.enabled);
         }
         return;
     }
     scene.WriteMembers(component, t, filter);
 }
Example #22
0
 private void WriteFieldsForType(SceneWriter scene, MonoBehaviour component, Type t)
 {
     if (t != typeof(Behaviour))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     if (t == typeof(Behaviour))
     {
         if (!component.enabled)
         {
             scene.WriteElement("enabled", component.enabled);
         }
         return;
     }
     scene.WriteMembers(component, t, filter);
 }
Example #23
0
        public virtual void Write(SceneWriter scene, object component)
        {
            MonoBehaviour beh = component as MonoBehaviour;
            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }
            if (!options.Contains("noExport"))
            {
                scene.WriteScript(beh, !options.Contains("noOverwrite"));
            }
        }
Example #24
0
        public virtual void Write(SceneWriter scene, object component)
        {
            MonoBehaviour beh = component as MonoBehaviour;

            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }
            if (!options.Contains("noExport"))
            {
                scene.WriteScript(beh, !options.Contains("noOverwrite"));
            }
        }
Example #25
0
        public void ExportMaterial(Material mat)
        {
            if (mat == null)
            {
                Debug.LogError("FFWD: Cannot export null material");
                return;
            }

            SceneWriter scene = new SceneWriter(resolver, assets);

            scene.ExportDir = Path.Combine(assets.XmlDir, "Scenes");
            ScriptTranslator.ScriptNamespace = config.scriptNamespace;

            string path = Path.ChangeExtension(AssetDatabase.GetAssetPath(mat).Replace("Assets/", "../"), "xml");

            //Debug.Log("Start resource export of " + path);
            scene.WriteResource(path, mat);
        }
Example #26
0
        public void ExportOpenScene()
        {
            progress.SetItemsToDo(1);

            SceneWriter scene = new SceneWriter(resolver, assets);

            scene.ExportDir = Path.Combine(assets.XmlDir, "Scenes");
            ScriptTranslator.ScriptNamespace = config.scriptNamespace;

            progress.Progress("----------------------- " + Path.GetFileName(EditorApplication.currentScene) + " -------------------------Start scene export", true);

            if (ValidateOpenScene())
            {
                scene.Write(Path.ChangeExtension(Path.GetFileName(EditorApplication.currentScene), "xml"));
            }
            else
            {
                Debug.LogError("Scene validation failed. Scene not exported!");
                return;
            }

            if (config.showComponentsNotWritten)
            {
                string skippedComponents = "";
                foreach (string item in scene.componentsNotWritten)
                {
                    if (config.allowedSkippedComponents.Contains(item))
                    {
                        continue;
                    }

                    if (!allComponentsNotWritten.Contains(item))
                    {
                        allComponentsNotWritten.Add(item);
                    }
                    skippedComponents += item + ", ";
                }
                if (skippedComponents != "")
                {
                    Debug.Log("Skipped component: " + skippedComponents);
                }
            }
            scene.componentsNotWritten.Clear();
        }
Example #27
0
 private void WriteFieldsForType(SceneWriter scene, MonoBehaviour component, Type t)
 {
     if (t != typeof(MonoBehaviour))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     FieldInfo[] memInfo = t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
     for (int m = 0; m < memInfo.Length; m++)
     {
         if (memInfo[m].GetCustomAttributes(typeof(HideInInspector), true).Length > 0)
         {
             continue;
         }
         if (filter.Includes(memInfo[m].Name))
         {
             scene.WriteElement(memInfo[m].Name, memInfo[m].GetValue(component), memInfo[m].FieldType);
         }
     }
 }
Example #28
0
 private void WriteFieldsForType(SceneWriter scene, MonoBehaviour component, Type t)
 {
     if (t != typeof(MonoBehaviour))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     FieldInfo[] memInfo = t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
     for (int m = 0; m < memInfo.Length; m++)
     {
         if (memInfo[m].GetCustomAttributes(typeof(HideInInspector), true).Length > 0)
         {
             continue;
         }
         if (filter.Includes(memInfo[m].Name))
         {
             scene.WriteElement(memInfo[m].Name, memInfo[m].GetValue(component), memInfo[m].FieldType);
         }
     }
 }
Example #29
0
 public void Write(SceneWriter scene, object component)
 {
     Rigidbody body = component as Rigidbody;
     if (body == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + component.GetType());
     }
     scene.WriteElement("mass", body.mass);
     scene.WriteElement("drag", body.drag);
     scene.WriteElement("angularDrag", body.angularDrag);
     if (body.freezeRotation)
     {
         scene.WriteElement("freezeRotation", body.freezeRotation);
     }
     if (body.isKinematic)
     {
         scene.WriteElement("isKinematic", body.isKinematic);
     }
 }
Example #30
0
 public virtual void Write(SceneWriter scene, object component)
 {
     Collider coll = component as Collider;
     if (coll == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + component.GetType());
     }
     scene.WriteElement("isTrigger", coll.isTrigger);
     if (coll.sharedMaterial != null)
     {
         if (coll.sharedMaterial.name.Contains("(Instance)"))
         {
             UnityEditor.EditorUtility.ResetToPrefabState(coll);
         }
         else
         {
             scene.WriteElement("material", coll.sharedMaterial.name);
         }
     }
 }
Example #31
0
        public void Write(SceneWriter scene, object component)
        {
            Rigidbody body = component as Rigidbody;

            if (body == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            scene.WriteElement("mass", body.mass);
            scene.WriteElement("drag", body.drag);
            scene.WriteElement("angularDrag", body.angularDrag);
            if (body.freezeRotation)
            {
                scene.WriteElement("freezeRotation", body.freezeRotation);
            }
            if (body.isKinematic)
            {
                scene.WriteElement("isKinematic", body.isKinematic);
            }
        }
Example #32
0
        public virtual void Write(SceneWriter scene, object component)
        {
            Collider coll = component as Collider;

            if (coll == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            scene.WriteElement("isTrigger", coll.isTrigger);
            if (coll.sharedMaterial != null)
            {
                if (coll.sharedMaterial.name.Contains("(Instance)"))
                {
                    UnityEditor.EditorUtility.ResetToPrefabState(coll);
                }
                else
                {
                    scene.WriteElement("material", coll.sharedMaterial.name);
                }
            }
        }
Example #33
0
        public void Write(SceneWriter writer, object component)
        {
            ParticleEmitter pr = component as ParticleEmitter;

            if (pr == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            writer.WriteElement("minEnergy", pr.minEnergy);
            writer.WriteElement("maxEnergy", pr.maxEnergy);
            writer.WriteElement("minEmission", pr.minEmission);
            writer.WriteElement("maxEmission", pr.maxEmission);

            writer.WriteElement("emit", pr.emit);
            writer.WriteElement("minSize", pr.minSize);
            writer.WriteElement("maxSize", pr.maxSize);

            writer.WriteElement("emitterVelocityScale", pr.emitterVelocityScale);
            writer.WriteElement("worldVelocity", pr.worldVelocity);
            writer.WriteElement("localVelocity", pr.localVelocity);
            writer.WriteElement("rndVelocity", pr.rndVelocity);
            writer.WriteElement("useWorldSpace", pr.useWorldSpace);
            writer.WriteElement("enabled", pr.enabled);

            Component c = pr.GetComponent("FFWD_EllipsoidParticleEmitterExport");

            if (c == null)
            {
                // Added for backwards compatibility
                c = pr.GetComponent("XNAEllipsoidParticleEmitter");
            }

            if (c != null)
            {
                writeValue <Vector3>(writer, c, "ellipsoid");
                writeValue <Boolean>(writer, c, "oneShot");
                writeValue <Vector3>(writer, c, "tangentVelocity");
                writeValue <float>(writer, c, "minEmitterRange");
            }
        }
Example #34
0
        public void Write(SceneWriter scene, object component)
        {
            MonoBehaviour script = component as MonoBehaviour;

            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshCollider collider = (component as MonoBehaviour).collider as MeshCollider;

            if (collider == null)
            {
                throw new Exception("XNAMeshCollider needs a MeshCollider on the same object");
            }
            ColliderWriter writer = new ColliderWriter();

            Quaternion yNeutralRotation = Quaternion.Euler(collider.transform.rotation.eulerAngles.x, 0, collider.transform.rotation.eulerAngles.z);

            Transform meshOrigin      = new GameObject().transform;
            Transform verticePosition = new GameObject().transform;

            verticePosition.parent = meshOrigin;
            Vector3[] rotatedVertices = new Vector3[collider.sharedMesh.vertices.Length];

            meshOrigin.transform.rotation = yNeutralRotation;

            for (int i = 0; i < rotatedVertices.Length; i++)
            {
                verticePosition.localPosition = collider.sharedMesh.vertices[i];
                rotatedVertices[i]            = verticePosition.position;
            }

            writer.Write(scene, collider);

            scene.WriteElement("triangles", collider.sharedMesh.triangles);
            scene.WriteElement("vertices", rotatedVertices);

            GameObject.DestroyImmediate(verticePosition.gameObject);
            GameObject.DestroyImmediate(meshOrigin.gameObject);
        }
Example #35
0
        public void Write(SceneWriter scene, object component)
        {
            MonoBehaviour beh = component as MonoBehaviour;
            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }

            if (options.Contains("Stub"))
            {
                scene.WriteScriptStub(beh);
            }
            else
            {
                scene.WriteScript(beh, false);
            }
        }
Example #36
0
 private void WriteFieldsForType(SceneWriter scene, Component component, Type t)
 {
     if (t != typeof(Component))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     if (t == typeof(Component))
     {
         return;
     }
     PropertyInfo[] memInfo = t.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
     for (int m = 0; m < memInfo.Length; m++)
     {
         if (memInfo[m].GetCustomAttributes(typeof(HideInInspector), true).Length > 0)
         {
             continue;
         }
         if (filter.Includes(memInfo[m].Name))
         {
             scene.WriteElement(memInfo[m].Name, memInfo[m].GetValue(component, null));
         }
     }
 }
Example #37
0
 private void WriteFieldsForType(SceneWriter scene, Component component, Type t)
 {
     if (t != typeof(Component))
     {
         WriteFieldsForType(scene, component, t.BaseType);
     }
     if (t == typeof(Component))
     {
         return;
     }
     PropertyInfo[] memInfo = t.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
     for (int m = 0; m < memInfo.Length; m++)
     {
         if (memInfo[m].GetCustomAttributes(typeof(HideInInspector), true).Length > 0)
         {
             continue;
         }
         if (filter.Includes(memInfo[m].Name))
         {
             scene.WriteElement(memInfo[m].Name, memInfo[m].GetValue(component, null));
         }
     }
 }
Example #38
0
        public void Write(SceneWriter scene, object component)
        {
            MonoBehaviour beh = component as MonoBehaviour;

            if (beh == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }

            if (filter != null)
            {
                WriteFieldsForType(scene, beh, component.GetType());
            }

            if (options.Contains("Stub"))
            {
                scene.WriteScriptStub(beh);
            }
            else
            {
                scene.WriteScript(beh, false);
            }
        }
Example #39
0
        public void Write(SceneWriter scene, object component)
        {
            MonoBehaviour script = component as MonoBehaviour;
            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshCollider collider = (component as MonoBehaviour).collider as MeshCollider;
            if (collider == null)
            {
                throw new Exception("XNAMeshCollider needs a MeshCollider on the same object");
            }
            ColliderWriter writer = new ColliderWriter();

            Quaternion yNeutralRotation = Quaternion.Euler(collider.transform.rotation.eulerAngles.x, 0, collider.transform.rotation.eulerAngles.z);

            Transform meshOrigin = new GameObject().transform;
            Transform verticePosition = new GameObject().transform;
            verticePosition.parent = meshOrigin;
            Vector3[] rotatedVertices = new Vector3[collider.sharedMesh.vertices.Length];

            meshOrigin.transform.rotation = yNeutralRotation;

            for (int i = 0; i < rotatedVertices.Length; i++)
            {
                verticePosition.localPosition = collider.sharedMesh.vertices[i];
                rotatedVertices[i] = verticePosition.position;
            }

            writer.Write(scene, collider);

            scene.WriteElement("triangles", collider.sharedMesh.triangles);
            scene.WriteElement("vertices", rotatedVertices);

            GameObject.DestroyImmediate(verticePosition.gameObject);
            GameObject.DestroyImmediate(meshOrigin.gameObject);
        }
Example #40
0
 public void Write(SceneWriter scene, object component)
 {
     MonoBehaviour script = component as MonoBehaviour;
     if (script == null)
     {
         throw new Exception(GetType() + " cannot export components of type " + component.GetType());
     }
     // Gather all nodes under this and export the data as a dictionary
     Dictionary<int, int> nodeRefs = new Dictionary<int, int>();
     Type findType = component.GetType().GetField("component").FieldType;
     string propertyName = component.GetType().GetField("propertyName").GetValue(component).ToString();
     Component[] nodes = script.GetComponentsInChildren(findType);
     foreach (Component node in nodes)
     {
         FieldInfo field = node.GetType().GetField(propertyName);
         UnityEngine.Object obj = (field.GetValue(node) as UnityEngine.Object);
         if (obj != null)
         {
             nodeRefs.Add(node.GetInstanceID(), obj.GetInstanceID());
         }
     }
     scene.WriteElement("fieldName", propertyName);
     scene.WriteElement("map", nodeRefs);
 }
Example #41
0
 protected virtual void WriteElement(SceneWriter scene, string name, object value)
 {
     scene.WriteElement(name, value);
 }
Example #42
0
 protected virtual void WriteElement(SceneWriter scene, string name, object value)
 {
     scene.WriteElement(name, value);
 }
 public void Write(SceneWriter scene, object component)
 {
     throw new NotImplementedException();
 }
Example #44
0
        public void ExportOpenScene()
        {
            progress.SetItemsToDo(1);

            SceneWriter scene = new SceneWriter(resolver, assets);
            scene.ExportDir = Path.Combine(assets.XmlDir, "Scenes");
            ScriptTranslator.ScriptNamespace = config.scriptNamespace;

            progress.Progress("----------------------- " + Path.GetFileName(EditorApplication.currentScene) + " -------------------------Start scene export", true);

            if (ValidateOpenScene())
            {
                scene.Write(Path.ChangeExtension(Path.GetFileName(EditorApplication.currentScene), "xml"));
            }
            else
            {
                Debug.LogError("Scene validation failed. Scene not exported!");
                return;
            }

            if (config.showComponentsNotWritten)
            {
                string skippedComponents = "";
                foreach (string item in scene.componentsNotWritten)
                {
                    if (config.allowedSkippedComponents.Contains(item)) { continue; }

                    if (!allComponentsNotWritten.Contains(item))
                    {
                        allComponentsNotWritten.Add(item);
                    }
                    skippedComponents += item + ", ";
                }
                if (skippedComponents != "")
                {
                    Debug.Log("Skipped component: " + skippedComponents);
                }
            }
            scene.componentsNotWritten.Clear();
        }
Example #45
0
        public void ExportResource(GameObject go)
        {
            if (go == null)
            {
                Debug.LogError("FFWD: Cannot export null resource");
                return;
            }

            SceneWriter scene = new SceneWriter(resolver, assets);
            scene.ExportDir = Path.Combine(assets.XmlDir, "Scenes");
            ScriptTranslator.ScriptNamespace = config.scriptNamespace;

            string path = Path.ChangeExtension(AssetDatabase.GetAssetPath(go).Replace("Assets/", "../"), "xml");
            //Debug.Log("Start resource export of " + path);
            scene.WriteResource(path, go);
        }
 public void Write(SceneWriter scene, object component)
 {
     throw new NotImplementedException();
 }