Exemple #1
0
        public static void InitializeMaps()
        {
            playerIconObj = RegisterDynamicObjectWithUI("PlayerIcon", -1, Vector3.zero, Vector3.forward, "Player", "PlayerIcon", "PlayerIcon", null, null);
            playerIconObj.SetWorldPositionGetter(
                () => {
                return(GameManager.playerExists ? GameManager.playerActor.GetPosition() : Vector3.zero);
                // Transform t = UIManager.GetMainCamera().transform;
                // return t == null ? Vector3.zero : t.position;
            }
                );
            playerIconObj.SetWorldForwardGetter(
                () => {
                return(GameManager.playerExists ? GameManager.playerActor.GetForward() : Vector3.forward);

                // Transform t = UIManager.GetMainCamera().transform;
                // return t == null ? Vector3.forward : t.forward;
            }
                );

            playerIconObj.ShowMapType(UIMapsObject.ShowType.MainMap, true);
            playerIconObj.ShowMapType(UIMapsObject.ShowType.MiniMap, true);



            string[] directions = new string[] { "N", "S", "E", "W" };

            float distanceValue = 99999;

            Vector3[] dirs = new Vector3[] {
                Vector3.forward *distanceValue,
                -Vector3.forward *distanceValue,
                      Vector3.right *distanceValue,
                -Vector3.right *distanceValue
            };

            for (int i = 0; i < 4; i++)
            {
                Vector3 d = dirs[i];

                UIMapsObject regObj = RegisterDynamicObjectWithUI(
                    "Direction " + directions[i], -(i + 2), Vector3.zero, d,
                    null, "DirectionIcon", null, "DirectionIcon", null
                    );

                regObj.SetWorldPositionGetter(
                    () => {
                    return((GameManager.playerExists ? GameManager.playerActor.GetPosition() : Vector3.zero) + d);

                    // Transform t = UIManager.GetMainCamera().transform;
                    // if (t == null) return d;
                    // return t.position + d;
                }
                    );
                regObj.SetMarkerInitializer((m) => (m.mainGraphic as UIText).SetText(directions[i]));

                regObj.ShowMapType(UIMapsObject.ShowType.Compass, true);
                regObj.ShowMapType(UIMapsObject.ShowType.MiniMap, true);
            }
        }
Exemple #2
0
 public void InitializeMapMarker(UIMapsObject registeredObject)
 {
     this.registeredObject = registeredObject;
     if (messageText != null)
     {
         messageText.SetText(registeredObject.message);
     }
 }
Exemple #3
0
        public void RegisterWithUI()
        {
            registeredUIObj = UIMaps.RegisterStaticObjectWithUI(registerKey, transform.position, transform.forward, message, miniMapIconName, mainMapIconName, compassIconName, worldViewIconName, true);

            registeredUIObj.ShowMapType(UIMapsObject.ShowType.MainMap, true);

            // if we're registered with ui throug this script, it means we've loaded locally
            // so add to the mini map / compass
            registeredUIObj.ShowMapType(UIMapsObject.ShowType.MiniMap, true);
            registeredUIObj.ShowMapType(UIMapsObject.ShowType.Compass, true);
        }
Exemple #4
0
        // protected override void OnDisable () {
        //     base.OnDisable();
        //     if (Application.isPlaying) {
        //         UIMaps.onObjectDeregister -= OnObjectDeregister;
        //     }
        // }



        void OnObjectDeregister(UIMapsObject deregistered)
        {
            if (deregistered == currentWaypointRegisterObj)
            {
                if (currentWaypointRegisterObj != null)
                {
                    currentWaypointRegisterObj = null;
                }
                // AddWaypoint(0);
            }
        }
Exemple #5
0
        public static UIMapsObject RegisterDynamicObjectWithUI(
            string debugName,
            int key, Vector3 worldPosition, Vector3 worldForward, string message,
            string miniMapIconName, string mainMapIconName, string compassIconName, string worldViewIconName
            )
        {
            if (dynamicObjects.ContainsKey(key))
            {
                Debug.LogWarning(debugName + ": already registered with ui");
                return(dynamicObjects[key]);
            }
            UIMapsObject obj = new UIMapsObject(worldPosition, worldForward, message, miniMapIconName, mainMapIconName, compassIconName, worldViewIconName, true);

            obj.loadedLocally = true;
            dynamicObjects.Add(key, obj);
            return(obj);
        }
Exemple #6
0
        public static UIMapsObject RegisterStaticObjectWithUI(
            int key,
            Vector3 worldPosition, Vector3 worldForward,
            string message,
            string miniMapIconName, string mainMapIconName, string compassIconName, string worldViewIconName, bool loadedLocally
            )
        {
            UIMapsObject obj;

            if (!staticObjects.TryGetValue(key, out obj))
            {
                obj = new UIMapsObject(worldPosition, worldForward, message, miniMapIconName, mainMapIconName, compassIconName, worldViewIconName, true);
                staticObjects.Add(key, obj);
            }
            obj.loadedLocally = loadedLocally;
            return(obj);
        }
Exemple #7
0
        void DrawRegisterWithMapObject()
        {
            if (GUILayout.Button("Register/Update With Static Object Registry"))
            {
                if (string.IsNullOrEmpty(uiObj.staticMapObjectRegisterName))
                {
                    Debug.LogError("Need a static map object registry to register with");
                    return;
                }
                StaticMapsObjectRegistry mapObjRegister = GameSettings.GetSettings <StaticMapsObjectRegistry>(uiObj.staticMapObjectRegisterName);
                if (mapObjRegister == null)
                {
                    return;
                }

                UIMapsObject obj = GetRegisteredObjectOnStaticRegister(mapObjRegister);

                obj.InitializeWithValues(uiObj.transform.position, uiObj.transform.forward, uiObj.message, uiObj.miniMapIconName, uiObj.mainMapIconName, uiObj.compassIconName, uiObj.worldViewIconName);
            }
        }
Exemple #8
0
        UIMapsObject GetRegisteredObjectOnStaticRegister(StaticMapsObjectRegistry mapObjRegister)
        {
            int registerKey = uiObj.registerKey;

            for (int i = 0; i < mapObjRegister.staticObjects.Count; i++)
            {
                if (mapObjRegister.staticObjects[i].key == registerKey)
                {
                    return(mapObjRegister.staticObjects[i]);
                }
            }

            Debug.Log("static object '" + uiObj.gameObject.name + " is not registered with register group '" + mapObjRegister.name + "', adding it...");
            UIMapsObject neRegisteredObj = new UIMapsObject(uiObj.transform.position, uiObj.transform.forward, uiObj.message, uiObj.miniMapIconName, uiObj.mainMapIconName, uiObj.compassIconName, uiObj.worldViewIconName, false);

            neRegisteredObj.key = registerKey;
            mapObjRegister.staticObjects.Add(neRegisteredObj);
            EditorUtility.SetDirty(mapObjRegister);
            return(neRegisteredObj);
        }
Exemple #9
0
        public MapMarker AddMapMarker(MapMarker prefab, UIMapsObject regObj)
        {
            MapMarker newMarker = markerPool.GetAvailable(prefab, null, false, null);

            newMarker.InitializeMapMarker(regObj);
            mapMarkers.Add(newMarker);

            newMarker.transform.SetParent(transform, Vector3.zero, Quaternion.identity, Vector3.one);
            newMarker.EnableMapMarker(true);

            UIBaseParameters.CopyParameters(ref newMarker.parameters, markerParameters);
            newMarker.UpdateElementLayout();//true);
            if (onMarkerAdd != null)
            {
                onMarkerAdd(newMarker);
            }


            newMarker.gameObject.SetActive(true);
            return(newMarker);
        }
Exemple #10
0
            public void Show(bool show, string iconPrefabName, UIBaseMap mapInstance, UIMapsObject regObj, System.Action <MapMarker> markerInitializer)
            {
                if (mapInstance == null)
                {
                    return;
                }

                if (show)
                {
                    if (mapMarker == null)
                    {
                        MapMarker prefab = GetMapMarkerPrefab(iconPrefabName);
                        if (prefab != null)
                        {
                            mapMarker = mapInstance.AddMapMarker(prefab, regObj);
                            if (markerInitializer != null)
                            {
                                markerInitializer(mapMarker);
                            }
                        }
                    }
                }
                else
                {
                    if (mapMarker != null)
                    {
                        // should set to null
                        mapMarker = mapInstance.RemoveMapMarker(mapMarker);
                    }
                }
            }
Exemple #11
0
 void RegisterWithUI()
 {
     registeredUIObj = UIMaps.RegisterDynamicObjectWithUI(gameObject.name, GetInstanceID(), transform.position, transform.forward, message, miniMapIconName, mainMapIconName, compassIconName, worldViewIconName);
     registeredUIObj.SetWorldPositionGetter(() => transform.position);
     registeredUIObj.SetWorldForwardGetter(() => transform.forward);
 }
Exemple #12
0
 public void DeregisterWithUI()
 {
     registeredUIObj = UIMaps.DeregisterDynamicObjectWithUI(GetInstanceID());
 }
Exemple #13
0
 public static bool StaticObjectRegistered(int key, out UIMapsObject obj)
 {
     return(staticObjects.TryGetValue(key, out obj));
 }
Exemple #14
0
 public static bool RegisteredObjectIsPlayer(UIMapsObject obj)
 {
     return(obj == playerIconObj);
 }
Exemple #15
0
 public void DeregisterWithUI()
 {
     registeredUIObj = UIMaps.DeregisterStaticObjectWithUI(registerKey);
 }
Exemple #16
0
        void AddWaypoint(float zOffset)
        {
            if (defaultWaypointRegisteredObj == null && currentWaypointRegisterObj == null)
            {
                // if (currentWaypointMarker != null) {

                // TODO: Get ground Y
                if (selectedMarker == null || UIMaps.RegisteredObjectIsPlayer(selectedMarker.uIRegisteredObject))
                {
                    Vector3 worldPos = Vector3.zero;
                    Vector2 wPos     = (move);// + Vector2.one * zOffset);// * mapSize;
                    Debug.LogError(wPos);


                    worldPos.x = mapCenter.x + wPos.x * mapRadius * 2;
                    worldPos.z = mapCenter.y + wPos.y * mapRadius * 2;
                    Debug.LogError(worldPos);

                    // register the default empty icon
                    defaultWaypointRegisteredObj = UIMaps.RegisterDynamicObjectWithUI(
                        "MapWaypoint", GetInstanceID(), worldPos, Vector3.forward, "Waypoint", null, null, null, null
                        );

                    defaultWaypointRegisteredObj.SetAsWaypoint(true);

                    defaultWaypointRegisteredObj.ShowMapType(UIMapsObject.ShowType.MainMap, true);
                    defaultWaypointRegisteredObj.ShowMapType(UIMapsObject.ShowType.MiniMap, true);
                    defaultWaypointRegisteredObj.ShowMapType(UIMapsObject.ShowType.Compass, true);
                    defaultWaypointRegisteredObj.ShowMapType(UIMapsObject.ShowType.ScreenMap, true);
                }
                else
                {
                    // Debug.Log("making waypoing already thtere");
                    currentWaypointRegisterObj = selectedMarker.uIRegisteredObject;

                    // worldPos = selectedMarker.GetMarkerPosition();
                    currentWaypointRegisterObj.SetAsWaypoint(true);

                    // alraedy showing map...
                    // currentWaypointMarker.uIRegisteredObject.ShowMainMap(true);

                    currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.MiniMap, true);
                    currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.Compass, true);
                    currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.ScreenMap, true);

                    // currentWaypointMarker = AddMapMarker ("MapWaypoint", GetInstanceID(), waypointIcon, () => worldPos, "Waypoint");
                }
            }
            else
            {
                if (currentWaypointRegisterObj != null)
                {
                    currentWaypointRegisterObj.SetAsWaypoint(false);

                    currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.ScreenMap, false);

                    if (!currentWaypointRegisterObj.loadedLocally)
                    {
                        currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.MiniMap, false);
                        currentWaypointRegisterObj.ShowMapType(UIMapsObject.ShowType.Compass, false);
                    }
                    currentWaypointRegisterObj = null;
                }
                // else {
                // }
                if (defaultWaypointRegisteredObj != null)
                {
                    defaultWaypointRegisteredObj = UIMaps.DeregisterDynamicObjectWithUI(GetInstanceID());
                }

                // currentWaypointMarker = null;
                // defaultWaypointRegisteredObj = null;



                // RemoveMapMarker(GetInstanceID());
                // currentWaypointMarker = null;
            }
        }