Exemplo n.º 1
0
        private async Task ProcessAndInstantiateMap(GameObject map)
        {
            await Task.Factory.StartNew(() =>
            {
                Logger.LogText("Instantiate map");

                _mapInstance = map;
                _descriptor  = _mapInstance?.GetComponent <MapDescriptor>();

                ProcessChildObjects(map);

                Transform fakeSkybox = _mapInstance.transform.Find("FakeSkybox");
                if (fakeSkybox != null)
                {
                    Material oldMat = fakeSkybox.GetComponent <Renderer>().material;
                    if (oldMat.HasProperty("_Tex"))
                    {
                        oldMat.SetTexture("_Tex", Resources.Load <Texture2D>("objects/forest/materials/sky"));
                        oldMat.SetColor("_Color", new Color(1, 1, 1, 1));
                    }
                }

                GameObject FallEmergencyTeleport = new GameObject("FallEmergencyTeleport");
                FallEmergencyTeleport.layer      = Constants.MaskLayerHandTrigger;
                FallEmergencyTeleport.AddComponent <BoxCollider>().isTrigger = true;
                FallEmergencyTeleport.transform.SetParent(_mapInstance.transform);
                FallEmergencyTeleport.transform.localScale    = new Vector3(2000f, 1f, 2000f);
                FallEmergencyTeleport.transform.localPosition = new Vector3(0f, -300f, 0f);

                Teleporter emergencyFallTeleporter     = FallEmergencyTeleport.AddComponent <Teleporter>();
                emergencyFallTeleporter.TeleportPoints = _mapInstance.GetComponent <MapDescriptor>().SpawnPoints.ToList();
                emergencyFallTeleporter.TagOnTeleport  = true;
                emergencyFallTeleporter.TeleporterType = TeleporterType.Map;
            });
        }
    void GeneratePreview()
    {
        VmodMonkeMapLoader.Behaviours.MapDescriptor targetDescriptor = (VmodMonkeMapLoader.Behaviours.MapDescriptor)target;
        GameObject previewSource = targetDescriptor.gameObject;

        if (previewSource == null)
        {
            return;
        }
        bool foundCamera = false;

        foreach (Camera cam in targetDescriptor.gameObject.GetComponentsInChildren <Camera>())
        {
            if (cam != null && cam.gameObject.name == "ThumbnailCamera")
            {
                foundCamera      = true;
                textureGenerated = true;
                texture          = ExporterUtils.CaptureScreenshot(cam, 512, 512);
                texture.Apply();
            }
        }
        if (!foundCamera)
        {
            textureGenerated = true;
            try
            {
                texture = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/Textures/TemplatePrefabs/NoThumbnailCamera.png");
                texture.Apply();
            }
            catch
            {
                // error loading texture. probably doesn't exist. oh well
            }
        }
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        VmodMonkeMapLoader.Behaviours.MapDescriptor targetDescriptor = (VmodMonkeMapLoader.Behaviours.MapDescriptor)target;

        DrawDefaultInspector();

        GUILayout.Space(10);

        if (GUILayout.Button("Export Map"))
        {
            if (!ExporterUtils.BuildTargetInstalled(BuildTarget.Android) && EditorUtility.DisplayDialog("Android Build Support missing", "You don't have Android Build Support installed for this Unity version. Please install it and do NOT continue unless you know for sure what you're doing.", "Cancel", "Continue Anyways"))
            {
                return;
            }

            GameObject noteObject = targetDescriptor.gameObject;
            string     path       = EditorUtility.SaveFilePanel("Save map file", "", targetDescriptor.MapName + ".gtmap", "gtmap");

            if (path != "")
            {
                EditorUtility.SetDirty(targetDescriptor);

                if (noteObject.transform.Find("ThumbnailCamera") != null)
                {
                    ExporterUtils.ExportPackage(noteObject, path, "Map", ExporterUtils.MapDescriptorToJSON(targetDescriptor));
                    EditorUtility.DisplayDialog("Exportation Successful!", "Exportation Successful!", "OK");
                    EditorUtility.RevealInFinder(path);
                }
                else
                {
                    EditorUtility.DisplayDialog("Exportation Failed!", "No thumbnail camera.", "OK");
                }
            }
            Debug.Log("YOO");
        }
    }
Exemplo n.º 4
0
        public IEnumerator LoadMapFromPackageFileAsync(MapInfo mapInfo, Action <bool> isSuccess)
        {
            if (_isLoading)
            {
                yield break;
            }

            _isLoading = true;
            _lobbyName = "";

            UnloadMap();
            Logger.LogText("Loading map: " + mapInfo.FilePath + " -> " + mapInfo.PackageInfo.Descriptor.Name);

            var bundleDataStream = MapFileUtils.GetMapDataStreamFromZip(mapInfo);

            if (bundleDataStream == null)
            {
                Logger.LogText("Bundle not found in package");

                _isLoading = false;
                isSuccess(false);
                yield break;
            }

            var loadBundleRequest = AssetBundle.LoadFromStreamAsync(bundleDataStream);

            yield return(loadBundleRequest);

            var bundle = loadBundleRequest.assetBundle;

            if (bundle == null)
            {
                Logger.LogText("Bundle NOT LOADED");

                _isLoading = false;
                isSuccess(false);
                yield break;
            }

            Logger.LogText("Bundle loaded");

            var assetNames = bundle.GetAllAssetNames();

            Logger.LogText("Asset count: " + assetNames.Length + ", assets: " + string.Join(";", assetNames));

            Logger.LogText("Asset name: " + mapInfo.PackageInfo.Descriptor.Name);

            string[] scenePath = bundle.GetAllScenePaths();

            if (scenePath.Length <= 0)
            {
                Logger.LogText("Bundle NOT LOADED");

                _isLoading = false;
                isSuccess(false);
                yield break;
            }

            var scene = SceneManager.LoadSceneAsync(scenePath[0], LoadSceneMode.Additive);

            yield return(scene);

            GameObject[]  allObjects = Object.FindObjectsOfType <GameObject>();
            MapDescriptor descriptor = Object.FindObjectOfType <MapDescriptor>();

            foreach (GameObject gameObject in allObjects)
            {
                if (gameObject.scene.name != "GorillaTagNewVisuals" && gameObject.scene.name != "DontDestroyOnLoad")
                {
                    if (gameObject.transform.parent == null & gameObject.transform != descriptor.transform)
                    {
                        gameObject.transform.SetParent(descriptor.transform);
                    }
                }
            }
            GameObject map = descriptor.gameObject;

            if (map == null)
            {
                _isLoading = false;
                isSuccess(false);
                bundle.Unload(false);
                yield break;
            }

            Logger.LogText("Map asset loaded: " + map.name);
            _lobbyName = mapInfo.PackageInfo.Descriptor.Author + "_" + mapInfo.PackageInfo.Descriptor.Name;
            if (!String.IsNullOrWhiteSpace(mapInfo.PackageInfo.Config.GUID))
            {
                _lobbyName = mapInfo.PackageInfo.Config.GUID + "_" + mapInfo.PackageInfo.Config.Version;
            }

            Exception ex = null;

            yield return(ProcessAndInstantiateMap(map).AsIEnumerator(exception => ex = exception));

            yield return(null);

            if (ex != null)
            {
                Logger.LogException(ex);

                isSuccess(false);
                _isLoading = false;
                bundle.Unload(false);
                yield break;
            }

            bundle.Unload(false);
            bundleDataStream.Close();

            _isLoading = false;
            isSuccess(true);
        }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        VmodMonkeMapLoader.Behaviours.MapDescriptor targetDescriptor = (VmodMonkeMapLoader.Behaviours.MapDescriptor)target;

        GUILayout.BeginVertical();
        DrawPropertiesExcluding(serializedObject, "GravitySpeed", "SlowJumpLimit", "FastJumpLimit", "SlowJumpMultiplier", "FastJumpMultiplier", "SpawnPoints", "CustomSkybox", "ExportLighting", "m_Script");
        // Don't like these hardcoded values. Maybe find a more automatic solution
        // DrawDefaultInspector();

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        playerSettingsOpened = EditorGUILayout.Foldout(playerSettingsOpened, "Player Settings");
        if (playerSettingsOpened)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical(GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.9f));
            DrawPropertiesExcluding(serializedObject, "MapName", "AuthorName", "Description", "SpawnPoints", "CustomSkybox", "ExportLighting", "m_Script");
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }

        mapSettingsOpened = EditorGUILayout.Foldout(mapSettingsOpened, "Map Settings");
        if (mapSettingsOpened)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical(GUILayout.Width(EditorGUIUtility.currentViewWidth * 0.9f));
            DrawPropertiesExcluding(serializedObject, "MapName", "AuthorName", "Description", "m_Script", "GravitySpeed", "SlowJumpLimit", "FastJumpLimit", "SlowJumpMultiplier", "FastJumpMultiplier");
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Thumbnail Preview");
        GUILayout.Button("Refresh Preview");
        GUILayout.EndHorizontal();
        GUILayout.Space(10);

        if (textureGenerated == false)
        {
            GeneratePreview();
        }

        float smallest         = EditorGUIUtility.currentViewWidth;
        float width            = smallest * .9f;
        float widthCenter      = (EditorGUIUtility.currentViewWidth - (width < 512 ? width : 512)) / 2;
        float heightDifference = smallest * .02f;

        GUILayout.EndVertical();
        float lastSpace = GUILayoutUtility.GetLastRect().height;

        // Debug.Log(lastSpace);
        GUILayout.Space(width);

        GUI.Label(new Rect(widthCenter + 7, lastSpace, width, width), texture);

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        if (GUILayout.Button("Export Map"))
        {
            if (!ExporterUtils.BuildTargetInstalled(BuildTarget.Android) && EditorUtility.DisplayDialog("Android Build Support missing", "You don't have Android Build Support installed for this Unity version. Please install it and do NOT continue unless you know for sure what you're doing.", "Cancel", "Continue Anyways"))
            {
                return;
            }

            GameObject noteObject = targetDescriptor.gameObject;
            string     path       = EditorUtility.SaveFilePanel("Save map file", "", targetDescriptor.MapName + ".gtmap", "gtmap");

            if (path != "")
            {
                EditorUtility.SetDirty(targetDescriptor);

                ExporterUtils.ExportPackage(noteObject, path, "Map", ExporterUtils.MapDescriptorToJSON(targetDescriptor));
            }
        }

        try
        {
            serializedObject.ApplyModifiedProperties();
        }
        catch
        {
            // serialized object doesn't exist. sometimes this happens when switching scenes.
        }
    }
    public void OnSceneGUI()
    {
        VmodMonkeMapLoader.Behaviours.MapDescriptor targetDescriptor = (VmodMonkeMapLoader.Behaviours.MapDescriptor)target;
        GameObject gameObject = targetDescriptor.gameObject;

        Handles.BeginGUI();
        GUILayout.BeginVertical(MapDescriptorConfig.textStyle, GUILayout.Width(MapDescriptorConfig.guiWidth));

        GUILayout.Label(targetDescriptor.MapName, EditorStyles.boldLabel);

        MapDescriptorConfig.DisplayTeleporters     = GUILayout.Toggle(MapDescriptorConfig.DisplayTeleporters, "Display Teleporters");
        MapDescriptorConfig.DisplaySpawnPoints     = GUILayout.Toggle(MapDescriptorConfig.DisplaySpawnPoints, "Display Spawn Points");
        MapDescriptorConfig.DisplayTagZones        = GUILayout.Toggle(MapDescriptorConfig.DisplayTagZones, "Display Tag Zones");
        MapDescriptorConfig.DisplayObjectTriggers  = GUILayout.Toggle(MapDescriptorConfig.DisplayObjectTriggers, "Display Object Triggers");
        MapDescriptorConfig.DisplaySurfaceSettings = GUILayout.Toggle(MapDescriptorConfig.DisplaySurfaceSettings, "Display Surface Settings");
        MapDescriptorConfig.DisplayRoundEndActions = GUILayout.Toggle(MapDescriptorConfig.DisplayRoundEndActions, "Display Round End Action Objects");

        GUILayout.Space(5.0f);
        MapDescriptorConfig.DisplayNames = GUILayout.Toggle(MapDescriptorConfig.DisplayNames, "Display Object Names");

        GUILayout.EndVertical();
        Handles.EndGUI();

        if (MapDescriptorConfig.DisplaySpawnPoints)
        {
            targetDescriptor.SpawnPoints = GetAllSpawnPoints(gameObject).ToArray();
            foreach (var point in targetDescriptor.SpawnPoints)
            {
                DrawSpawnPoint(point);
            }
        }

        if (MapDescriptorConfig.DisplayTeleporters)
        {
            foreach (var tele in gameObject.GetComponentsInChildren <VmodMonkeMapLoader.Behaviours.Teleporter>(true))
            {
                TeleporterEditor.DrawTeleport(tele);
            }
        }

        if (MapDescriptorConfig.DisplayTagZones)
        {
            foreach (var zone in gameObject.GetComponentsInChildren <VmodMonkeMapLoader.Behaviours.TagZone>(true))
            {
                TagZoneEditor.DrawTagZone(zone);
            }
        }

        if (MapDescriptorConfig.DisplayObjectTriggers)
        {
            foreach (var trigger in gameObject.GetComponentsInChildren <VmodMonkeMapLoader.Behaviours.ObjectTrigger>(true))
            {
                TriggerEditor.DrawTrigger(trigger);
            }
        }

        if (MapDescriptorConfig.DisplaySurfaceSettings)
        {
            foreach (var surface in gameObject.GetComponentsInChildren <VmodMonkeMapLoader.Behaviours.SurfaceClimbSettings>(true))
            {
                SurfaceClimbSettingsEditor.DrawSurface(surface);
            }
        }

        if (MapDescriptorConfig.DisplayRoundEndActions)
        {
            foreach (var roundEndActions in gameObject.GetComponentsInChildren <VmodMonkeMapLoader.Behaviours.RoundEndActions>(true))
            {
                RoundEndActionsEditor.DrawRoundEnd(roundEndActions);
            }
        }
    }