void CheckAndGetDclSceneMetaObject()
        {
            var rootGameObjects = new List <GameObject>();

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                var roots = SceneManager.GetSceneAt(i).GetRootGameObjects();
                rootGameObjects.AddRange(roots);
            }

            foreach (var go in rootGameObjects)
            {
                if (go.name == ".dcl")
                {
                    sceneMeta = go.GetComponent <DclSceneMeta>();
                    if (!sceneMeta)
                    {
                        sceneMeta = go.AddComponent <DclSceneMeta>();
                        EditorUtility.SetDirty(sceneMeta);
                        EditorSceneManager.MarkSceneDirty(go.scene);
                    }

                    return;
                }
            }

            //Did not find .dcl object. Create one.
            var o = new GameObject(".dcl");

            sceneMeta = o.AddComponent <DclSceneMeta>();
            EditorUtility.SetDirty(sceneMeta);
            EditorSceneManager.MarkSceneDirty(o.scene);
        }
        public static void TraverseAllScene(StringBuilder xmlBuilder, List <GameObject> meshesToExport, SceneStatistics statistics, SceneWarningRecorder warningRecorder)
        {
            var rootGameObjects = new List <GameObject>();

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                var roots = SceneManager.GetSceneAt(i).GetRootGameObjects();
                rootGameObjects.AddRange(roots);
            }

            if (xmlBuilder != null)
            {
                xmlBuilder.AppendIndent(indentUnit, 3);
                xmlBuilder.AppendFormat("<scene position={{{0}}}>\n", Vector3ToJSONString(new Vector3(5, 0, 5)));
            }

            _sceneMeta = Object.FindObjectOfType <DclSceneMeta>();
            primitiveMaterialsToExport = new List <Material>();
            primitiveTexturesToExport  = new List <Texture>();
            GameObjectToNodeTypeDict.Clear();

            //====== Start Traversing ======
            foreach (var rootGO in rootGameObjects)
            {
                RecursivelyTraverseTransform(rootGO.transform, xmlBuilder, meshesToExport, 4, statistics, warningRecorder, GameObjectToNodeTypeDict);
            }
            foreach (var material in primitiveMaterialsToExport)
            {
                var materialXml = xmlBuilder != null ? new StringBuilder() : null;
                TraverseMaterial(material, materialXml, warningRecorder);

                //Append materials
                if (xmlBuilder != null)
                {
                    xmlBuilder.AppendIndent(indentUnit, 4);
                    xmlBuilder.Append(materialXml).Append("\n");
                }
            }

            //Check textures
            if (warningRecorder != null)
            {
                foreach (var texture in primitiveTexturesToExport)
                {
                    CheckTextureValidity(texture, warningRecorder);
                }
            }

            statistics.materialCount += primitiveMaterialsToExport.Count; //TODO: include glTF's materials
            statistics.textureCount  += primitiveTexturesToExport.Count;  //TODO: include glTF's textures

            if (xmlBuilder != null)
            {
                xmlBuilder.AppendIndent(indentUnit, 3);
                xmlBuilder.Append("</scene>");
            }
        }
        //public  static readonly  Dictionary<GameObject, EDclNodeType> GameObjectToNodeTypeDict = new Dictionary<GameObject, EDclNodeType>();


        public static ResourceRecorder TraverseAllScene(StringBuilder exportStr, SceneStatistics statistics,
                                                        SceneWarningRecorder warningRecorder)
        {
            var rootGameObjects = new List <GameObject>();

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                var roots = SceneManager.GetSceneAt(i).GetRootGameObjects();
                rootGameObjects.AddRange(roots);
            }

            _sceneMeta = Object.FindObjectOfType <DclSceneMeta>();

            _resourceRecorder = new ResourceRecorder();

            //GameObjectToNodeTypeDict.Clear();

            //====== Start Traversing ======
            foreach (var rootGO in rootGameObjects)
            {
                RecursivelyTraverseTransform(rootGO.transform, exportStr, _resourceRecorder, 4, statistics,
                                             warningRecorder);
            }

            //Append PlayAudio functions
            if (exportStr != null)
            {
                if (_resourceRecorder.audioSourceAddFunctions.Count > 0)
                {
                    exportStr.AppendLine();
                    exportStr.AppendLine(
                        @"export class AutoPlayUnityAudio implements ISystem {
  activate() {");
                    foreach (var functionName in _resourceRecorder.audioSourceAddFunctions)
                    {
                        exportStr.AppendIndent(indentUnit, 2).AppendFormat("{0}()\n", functionName);
                    }
                    exportStr.AppendLine(
                        @"  }
}
engine.addSystem(new AutoPlayUnityAudio())
");
                }
            }

            if (statistics != null)
            {
                statistics.textureCount = _resourceRecorder.primitiveTexturesToExport.Count +
                                          _resourceRecorder.gltfTextures.Count;
            }

            return(_resourceRecorder);
        }
Ejemplo n.º 4
0
        //public  static readonly  Dictionary<GameObject, EDclNodeType> GameObjectToNodeTypeDict = new Dictionary<GameObject, EDclNodeType>();


        public static ResourceRecorder TraverseAllScene(StringBuilder exportStr, SceneStatistics statistics, SceneWarningRecorder warningRecorder)
        {
            var rootGameObjects = new List <GameObject>();

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                var roots = SceneManager.GetSceneAt(i).GetRootGameObjects();
                rootGameObjects.AddRange(roots);
            }

            _sceneMeta = Object.FindObjectOfType <DclSceneMeta>();

            resourceRecorder = new ResourceRecorder();

            //GameObjectToNodeTypeDict.Clear();

            //====== Start Traversing ======
            foreach (var rootGO in rootGameObjects)
            {
                RecursivelyTraverseTransform(rootGO.transform, exportStr, resourceRecorder, 4, statistics, warningRecorder);
            }

            //Append PlayAudio functions
            if (exportStr != null)
            {
                if (resourceRecorder.audioSourceAddFunctions.Count > 0)
                {
                    exportStr.AppendLine();
                    exportStr.AppendLine("Input.instance.subscribe(\"BUTTON_UP\", e => {");
                    foreach (var functionName in resourceRecorder.audioSourceAddFunctions)
                    {
                        exportStr.AppendIndent(indentUnit, 1).AppendFormat("{0}()\n", functionName);
                    }
                    exportStr.AppendLine("})\n");
                }
            }

            if (statistics != null)
            {
                statistics.textureCount = resourceRecorder.primitiveTexturesToExport.Count + resourceRecorder.gltfTextures.Count;
            }

            return(resourceRecorder);
        }