Beispiel #1
0
        void AddRandomPOI()
        {
            // Create placeholder
            GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            obj.transform.position = new Vector3(Random.Range(-50, 50), 1, Random.Range(-50, 50));
            obj.GetComponent <Renderer> ().material = sphereMaterial;

            // Add POI info
            CompassProPOI poi = obj.AddComponent <CompassProPOI> ();

            // Title name and reveal text
            poi.title           = "Target " + (++poiNumber).ToString();
            poi.titleVisibility = TITLE_VISIBILITY.Always;
            poi.visitedText     = "Target " + poiNumber + " acquired!";

            // Assign icons
            int j = Random.Range(0, icons.Length / 2);

            poi.iconNonVisited = icons [j * 2];
            poi.iconVisited    = icons [j * 2 + 1];

            // Enable GameView gizmo
            poi.showPlayModeGizmo = true;

            // Assign random sound
            j = Random.Range(0, soundClips.Length);
            poi.visitedAudioClip = soundClips [j];
        }
Beispiel #2
0
 IEnumerator RemovePOI(CompassProPOI poi)
 {
     while (poi.transform.position.y < 5)
     {
         poi.transform.position   += Vector3.up * Time.deltaTime;
         poi.transform.localScale *= 0.9f;
         yield return(new WaitForEndOfFrame());
     }
     Destroy(poi.gameObject);
 }
 // Create random POIs
 void Start()
 {
     poi              = GetComponent <CompassProPOI>();
     poi.OnHeartbeat += OnHeartbeatHandler;
     rb = GetComponent <Rigidbody>();
 }
Beispiel #4
0
 void POIExit(CompassProPOI poi)
 {
     POIUnderMouse = null;
 }
Beispiel #5
0
 void POIHover(CompassProPOI poi)
 {
     POIUnderMouse = poi;
 }
Beispiel #6
0
 void POIClicked(CompassProPOI poi)
 {
     Debug.Log(poi.title + " has been clicked on minimap.");
 }
Beispiel #7
0
 void POIVisited(CompassProPOI poi)
 {
     Debug.Log(poi.title + " has been reached.");
     StartCoroutine(RemovePOI(poi));
     AddRandomPOI();
 }
        public static void GX_PopulateCompassBar()
        {
            // Wise code here to add interesting places to the compass bar.
            // To do this, we need a list of GameObjects to which attach the CompassProPOI script and set some properties.

            Sprite iconGenericBlack  = Resources.Load <Sprite>("CNPro/Sprites/icon-arrow-black");
            Sprite iconGenericWhite  = Resources.Load <Sprite>("CNPro/Sprites/icon-arrow-white");
            Sprite iconMonolithBlack = Resources.Load <Sprite>("CNPro/Sprites/icon-monolith-black");
            Sprite iconMonolithWhite = Resources.Load <Sprite>("CNPro/Sprites/icon-monolith-white");
            Sprite iconMineBlack     = Resources.Load <Sprite>("CNPro/Sprites/icon-mine-black");
            Sprite iconMineWhite     = Resources.Load <Sprite>("CNPro/Sprites/icon-mine-white");
            Sprite iconCityBlack     = Resources.Load <Sprite>("CNPro/Sprites/icon-city-black");
            Sprite iconCityWhite     = Resources.Load <Sprite>("CNPro/Sprites/icon-city-white");
            Sprite iconForestBlack   = Resources.Load <Sprite>("CNPro/Sprites/icon-forest-black");
            Sprite iconForestWhite   = Resources.Load <Sprite>("CNPro/Sprites/icon-forest-white");

            GameObject spawnedRoot = GameObject.Find("Spawned_GameObjects");

            if (spawnedRoot == null)
            {
                Debug.Log("Spawned_GameObjects not found in the scene. Have you used Gaia game object spawner?");
                return;
            }

            bool refresh = EditorUtility.DisplayDialog("Populate Compass Bar", "This option will add spawned game objects created with Gaia to the Compass Bar.\nA CompassPro POI game object will be added to the center of each spawned group with an automated setup (an icon will be added to rocks, villages and forests, and the radius of the area will automatically estimated).\n\nYou may just add new spawned objects to the compass bar or refresh all of them (if this is the first time you use this option, click on any button).", "Refresh all spawned objects", "Just add new stuff to the compass bar");

            Terrain terrain = GetActiveTerrain();

            for (int k = 0; k < spawnedRoot.transform.childCount; k++)
            {
                Transform spawned = spawnedRoot.transform.GetChild(k);
                if (spawned == null)
                {
                    continue;
                }

                // Get group renderers
                Renderer[] renderers      = spawned.GetComponentsInChildren <Renderer> ();
                int        renderersCount = renderers.Length;
                if (renderersCount == 0)
                {
                    continue;
                }

                // Check existing POI for this spawned group
                bool      newPOI = false;
                Transform t      = spawned.Find("CompassPOI");
                if (t == null)
                {
                    // Create POI game object
                    GameObject poiGO = new GameObject();
                    poiGO.name = "CompassPOI";
                    t          = poiGO.transform;
                    t.SetParent(spawned.transform, false);
                    t.localPosition = Misc.Vector3zero;
                    newPOI          = true;
                }
                CompassProPOI poi = t.GetComponent <CompassProPOI>();
                if (poi == null)
                {
                    newPOI = true;
                    poi    = t.gameObject.AddComponent <CompassProPOI>();
                }

                if (!newPOI && !refresh)
                {
                    continue;                                           // already has POI configured
                }
                poi.title = spawned.name;
                string uname = spawned.name.ToUpper();
                poi.visitedText = uname + " DISCOVERED";
                // try to find a suitable icon
                Sprite iconNonVisited = null, iconVisited = null;

                if (uname.Contains("ROCK"))
                {
                    iconNonVisited = iconMonolithBlack;
                    iconVisited    = iconMonolithWhite;
                }
                else if (uname.Contains("FARM"))
                {
                    iconNonVisited = iconMineBlack;
                    iconVisited    = iconMineWhite;
                }
                else if (uname.Contains("VILLAGE") || uname.Contains("TOWN") || uname.Contains("CITY"))
                {
                    iconNonVisited = iconCityBlack;
                    iconVisited    = iconCityWhite;
                }
                else if (uname.Contains("COPSE") || uname.Contains("TREE") || uname.Contains("FOREST"))
                {
                    iconNonVisited = iconForestBlack;
                    iconVisited    = iconForestWhite;
                }
                else
                {
                    iconNonVisited = iconGenericBlack;
                    iconVisited    = iconGenericWhite;
                }

                poi.iconNonVisited = iconNonVisited;
                poi.iconVisited    = iconVisited;

                // try to find a suitable radius for this group
                Vector3 poiCenter = Misc.Vector3zero;
                Bounds  bounds    = new Bounds(spawned.transform.position, Misc.Vector3zero);
                for (int r = 0; r < renderersCount; r++)
                {
                    Renderer renderer = renderers[k];
                    if (r == 0)
                    {
                        bounds = new Bounds(renderer.transform.position, renderer.bounds.size);
                    }
                    else
                    {
                        if (poiCenter == Misc.Vector3zero)
                        {
                            poiCenter = renderer.transform.position;
                        }
                        else
                        {
                            poiCenter = (poiCenter + renderer.transform.position) * 0.5f;
                        }
                        bounds.Encapsulate(renderer.bounds);
                    }
                }

                if (terrain != null)
                {
                    float h = terrain.transform.position.y + terrain.terrainData.GetInterpolatedHeight((poiCenter.x - terrain.transform.position.x) / terrain.terrainData.size.x, (poiCenter.z - terrain.transform.position.z) / terrain.terrainData.size.z);
                    if (h > poiCenter.y)
                    {
                        poiCenter.y = h;
                    }
                }
                poi.transform.position = poiCenter;
                poi.radius             = Mathf.Max(bounds.size.x, bounds.size.z) * 1.15f + 5f;

                if (newPOI)
                {
                    Debug.Log(poi.title + " added to compass bar.");
                }
                else
                {
                    Debug.Log(poi.title + " has been refreshed.");
                }
            }
        }