Exemplo n.º 1
0
        public static void CreateProfile(string mapTexturePath, Vector2Int mapTextureSize, Bounds mapBounds)
        {
            // check given path
            if (mapTexturePath.Length <= 0)
            {
                return;
            }

            // get map texture
            Sprite mapTexture = AssetDatabase.LoadAssetAtPath <Sprite> (mapTexturePath);

            // create map profile
            HNSMapProfile profile = ScriptableObject.CreateInstance <HNSMapProfile> ();

            profile.Init(mapTexture, mapTextureSize, mapBounds);

            // create asset & save changes
            string path        = Path.Combine(Path.GetDirectoryName(mapTexturePath), Path.GetFileNameWithoutExtension(mapTexturePath).Replace("_Map", "")).Replace('\\', '/');
            string profilePath = AssetDatabase.GenerateUniqueAssetPath(path + "_Profile.asset");

            AssetDatabase.CreateAsset(profile, profilePath);
            AssetDatabase.SaveAssets();

            // highlight profile in project window
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = profile;
        }
Exemplo n.º 2
0
        public void InitMinimap(HNSMapProfile profile)
        {
            // check references
            if (Minimap.Panel == null || Minimap.MapContainer == null || Minimap.ElementContainer == null)
            {
                ReferencesMissing("Minimap");
                return;
            }

            // create minimap image gameobject
            GameObject imageGO = new GameObject(profile.MapTexture.name);

            imageGO.transform.SetParent(Minimap.MapContainer, false);

            // setup minimap image component
            Image image = imageGO.AddComponent <Image>();

            image.sprite         = profile.MapTexture;
            image.preserveAspect = true;
            image.SetNativeSize();

            // create custom layers
            if (profile.CustomLayers.Count > 0)
            {
                int layerCount = 0;
                foreach (CustomLayer layer in profile.CustomLayers.Reverse <CustomLayer>())
                {
                    if (layer.sprite == null)
                    {
                        continue;
                    }

                    // create layer image gameobject
                    GameObject layerGO = new GameObject(layer.name + "_Layer_" + layerCount++);
                    layerGO.transform.SetParent(Minimap.MapContainer, false);
                    layerGO.SetActive(layer.enabled);

                    // setup minimap image component
                    Image layerImage = layerGO.AddComponent <Image>();
                    layerImage.sprite         = layer.sprite;
                    layerImage.preserveAspect = true;
                    layerImage.SetNativeSize();

                    // assign layer instance
                    layer.instance = layerGO;
                }
            }

            // show minimap
            ShowMinimap(true);
        }
Exemplo n.º 3
0
 public static float GetMapAspect(this HNSMapProfile profile)
 {
     return((float)profile.MapTextureSize.x / (float)profile.MapTextureSize.y);
 }
Exemplo n.º 4
0
 public static Vector2 GetMapUnitScale(this HNSMapProfile profile)
 {
     return(new Vector2(profile.MapTextureSize.x / profile.MapBounds.size.x, profile.MapTextureSize.y / profile.MapBounds.size.z));
 }
Exemplo n.º 5
0
        public void UpdateMinimap(Transform rotationReference, MinimapModes minimapMode, Transform playerTransform, HNSMapProfile profile, float scale)
        {
            // assign map rotation
            Quaternion identityRotation = Minimap.Panel.transform.rotation;
            Quaternion mapRotation      = identityRotation;

            if (minimapMode == MinimapModes.RotateMinimap)
            {
                mapRotation = Quaternion.Euler(Minimap.Panel.transform.eulerAngles.x, Minimap.Panel.transform.eulerAngles.y, rotationReference.eulerAngles.y);
            }

            //修改 小地图旋转逻辑
            // set player indicator rotation
            if (Minimap.PlayerIndicator != null)
            {
                //修改~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Transform snakeHead = GameObject.FindGameObjectWithTag("PlayerHead").transform;
                Minimap.PlayerIndicator.transform.localRotation = snakeHead.localRotation;
                //End修改~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                //if (minimapMode == MinimapModes.RotateMinimap)
                //	Minimap.PlayerIndicator.transform.rotation = identityRotation;
                //else
                //	Minimap.PlayerIndicator.transform.rotation = Quaternion.Euler (Minimap.Panel.transform.eulerAngles.x, Minimap.Panel.transform.eulerAngles.y, -rotationReference.eulerAngles.y);
            }

            // calculate map position  计算地图位置
            Vector2 unitScale = profile.GetMapUnitScale();
            Vector3 posOffset = profile.MapBounds.center - playerTransform.position;
            //Vector3 mapPos = new Vector3(posOffset.x * unitScale.x, posOffset.z * unitScale.y, 0f) * scale;     ///
            //修改小地图移动逻辑
            //S修改~~~~~~~~~~~      posOffset-玩家的pos   unitScale偏移量系数
            Vector3 mapPos = new Vector3(posOffset.x * unitScale.x, posOffset.y * unitScale.x, 0f) * scale;

            //Debug.Log("小地图移动逻辑:" + mapPos);
            //End 修改

            // adjust map position when using minimap rotation mode 使用小地图旋转模式时调整地图位置
            if (minimapMode == MinimapModes.RotateMinimap)
            {
                mapPos = playerTransform.MinimapRotationOffset(mapPos);
            }


            // set map position, rotation and scale
            Minimap.MapContainer.localPosition = new Vector2(mapPos.x, mapPos.y);
            Minimap.MapContainer.rotation      = mapRotation;
            Minimap.MapContainer.localScale    = new Vector3(scale, scale, 1f);
        }
Exemplo n.º 6
0
        public void UpdateMinimap(Transform rotationReference, MinimapModes minimapMode, Transform playerTransform, HNSMapProfile profile, float scale)
        {
            Quaternion identityRotation = Minimap.Panel.transform.rotation;
            Quaternion mapRotation      = identityRotation;

            if (minimapMode == MinimapModes.RotateMinimap)
            {
                mapRotation = Quaternion.Euler(Minimap.Panel.transform.eulerAngles.x, Minimap.Panel.transform.eulerAngles.y, rotationReference.eulerAngles.y);
            }


            if (Minimap.PlayerIndicator != null)
            {
                if (minimapMode == MinimapModes.RotateMinimap)
                {
                    Minimap.PlayerIndicator.transform.rotation = identityRotation;
                }
                else
                {
                    Minimap.PlayerIndicator.transform.rotation = Quaternion.Euler(Minimap.Panel.transform.eulerAngles.x, Minimap.Panel.transform.eulerAngles.y, -rotationReference.eulerAngles.y);
                }
            }


            Vector2 unitScale = profile.GetMapUnitScale();
            Vector3 posOffset = profile.MapBounds.center - playerTransform.position;
            Vector3 mapPos    = new Vector3(posOffset.x * unitScale.x, posOffset.z * unitScale.y, 0f) * scale;


            if (minimapMode == MinimapModes.RotateMinimap)
            {
                mapPos = playerTransform.MinimapRotationOffset(mapPos);
            }

            Minimap.MapContainer.localPosition = new Vector2(mapPos.x, mapPos.y);
            Minimap.MapContainer.rotation      = mapRotation;
            Minimap.MapContainer.localScale    = new Vector3(scale, scale, 1f);
        }
        /// <summary>
        /// Applies a new scene configuration.
        /// </summary>
        /// <param name="config">Scene Configuration.</param>
        public void ApplySceneConfiguration(HNSSceneConfiguration config)
        {
            if (config == null)
            {
                return;
            }

            // override radar settings
            if (config.overrideRadarSettings)
            {
                // radar usage changed?
                if (_HUDNavigationCanvas != null && this.useRadar != config.useRadar)
                {
                    _HUDNavigationCanvas.ShowRadar(config.useRadar);
                }

                this.useRadar             = config.useRadar;
                this.radarMode            = config.radarMode;
                this.radarZoom            = config.radarZoom;
                this.radarRadius          = config.radarRadius;
                this.radarMaxRadius       = config.radarMaxRadius;
                this.useRadarHeightSystem = config.useRadarHeightSystem;
                this.radarDistanceAbove   = config.radarDistanceAbove;
                this.radarDistanceBelow   = config.radarDistanceBelow;
            }

            // override compass bar settings
            if (config.overrideCompassBarSettings)
            {
                // compass bar usage changed?
                if (_HUDNavigationCanvas != null && this.useCompassBar != config.useCompassBar)
                {
                    _HUDNavigationCanvas.ShowCompassBar(config.useCompassBar);
                }

                this.useCompassBar    = config.useCompassBar;
                this.compassBarRadius = config.compassBarRadius;
            }

            // override indicator settings
            if (config.overrideIndicatorSettings)
            {
                // indicator usage changed?
                if (_HUDNavigationCanvas != null && this.useIndicators != config.useIndicators)
                {
                    _HUDNavigationCanvas.ShowIndicators(config.useIndicators);
                }

                this.useIndicators            = config.useIndicators;
                this.indicatorRadius          = config.indicatorRadius;
                this.indicatorHideDistance    = config.indicatorHideDistance;
                this.useOffscreenIndicators   = config.useOffscreenIndicators;
                this.indicatorOffscreenBorder = config.indicatorOffscreenBorder;
                this.useIndicatorScaling      = config.useIndicatorScaling;
                this.indicatorScaleRadius     = config.indicatorScaleRadius;
                this.indicatorMinScale        = config.indicatorMinScale;
                this.useIndicatorFading       = config.useIndicatorFading;
                this.indicatorFadeRadius      = config.indicatorFadeRadius;
                this.indicatorMinFade         = config.indicatorMinFade;
            }

            // override minimap settings
            if (config.overrideMinimapSettings)
            {
                // assign new minimap profile
                if (this.currentMinimapProfile != config.minimapProfile)
                {
                    this.currentMinimapProfile = config.minimapProfile;
                    if (_HUDNavigationCanvas != null)
                    {
                        _HUDNavigationCanvas.SetMinimapProfile(this.currentMinimapProfile);
                    }
                }

                // minimap usage changed?
                if (_HUDNavigationCanvas != null && this.useMinimap != config.useMinimap)
                {
                    _HUDNavigationCanvas.ShowMinimap(config.useMinimap);
                }

                this.useMinimap             = config.useMinimap;
                this.minimapMode            = config.minimapMode;
                this.minimapScale           = config.minimapScale;
                this.minimapRadius          = config.minimapRadius;
                this.showMinimapBounds      = config.showMinimapBounds;
                this.useMinimapHeightSystem = config.useMinimapHeightSystem;
                this.minimapDistanceAbove   = config.minimapDistanceAbove;
                this.minimapDistanceBelow   = config.minimapDistanceBelow;
            }
        }