Exemplo n.º 1
0
        public void Run()
        {
            if (isExecuting)
            {
                return;
            }

            if (tgs == null)
            {
                tgs = TerrainGridSystem.instance;
                if (tgs == null)
                {
                    return;
                }
            }
            if (tgs.cells == null)
            {
                return;
            }
            if (Prepare())
            {
                if (duration == 0)
                {
                    Execute();
                }
                else
                {
                    StartCoroutine(ExecuteWithDuration());
                }
            }
        }
Exemplo n.º 2
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.white;

            tgs.OnCellHighlight += (int cellIndex, ref bool cancelHighlight) => {
                cancelHighlight = true;
                tgs.CellFadeOut(cellIndex, Color.yellow, 2f);
            };
            tgs.OnCellClick += (int cellIndex, int buttonIndex) => MergeCell(cellIndex);

            // Compute sprite scale
            //float tileSize = Vector3.Distance(tgs.CellGetVertexPosition(0, 0), tgs.CellGetVertexPosition(0, 3));
            //float spriteSize = Vector3.Distance(sprite.bounds.max, sprite.bounds.min);
            //float scale = tileSize / spriteSize;
            //for (int k=0;k<100;k++) {
            //    GameObject o = Instantiate<GameObject>(sprite.gameObject);
            //    o.transform.position = tgs.CellGetPosition(Random.Range(0, tgs.cellCount));
            //    o.transform.localScale = new Vector3(scale, scale, 1f);
            //}

            for (int k = 0; k < tgs.cellCount; k++)
            {
                tgs.CellSetColor(k, Color.yellow);
            }
        }
Exemplo n.º 3
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // setup GUI styles
            labelStyle                         = new GUIStyle();
            labelStyle.alignment               = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor        = Color.black;
            labelStyleShadow                   = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor  = Color.black;
            buttonStyle                        = new GUIStyle(labelStyle);
            buttonStyle.alignment              = TextAnchor.MiddleCenter;
            buttonStyle.normal.background      = Texture2D.whiteTexture;
            buttonStyle.normal.textColor       = Color.black;
            sliderStyle                        = new GUIStyle();
            sliderStyle.normal.background      = Texture2D.whiteTexture;
            sliderStyle.fixedHeight            = 4.0f;
            sliderThumbStyle                   = new GUIStyle();
            sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb");
            sliderThumbStyle.overflow          = new RectOffset(0, 0, 8, 0);
            sliderThumbStyle.fixedWidth        = 20.0f;
            sliderThumbStyle.fixedHeight       = 12.0f;
            StartCoroutine(MoveGrid());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Call this method to force a configuration load.
        /// </summary>
        public void LoadConfiguration()
        {
            if (config == null)
            {
                return;
            }

            TerrainGridSystem tgs = GetTGS();

            if (tgs == null)
            {
                return;
            }
            tgs.textures = textures;
            int[] territories = null;
            if (!string.IsNullOrEmpty(filterTerritories))
            {
                string[]   ss = filterTerritories.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
                List <int> tt = new List <int> ();
                for (int k = 0; k < ss.Length; k++)
                {
                    int v = 0;
                    if (int.TryParse(ss [k], out v))
                    {
                        tt.Add(v);
                    }
                }
                territories = tt.ToArray();
            }
            tgs.CellSetConfigurationData(config, territories);
        }
Exemplo n.º 5
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // setup GUI styles
            labelStyle                         = new GUIStyle();
            labelStyle.alignment               = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor        = Color.black;
            labelStyleShadow                   = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor  = Color.black;
            buttonStyle                        = new GUIStyle(labelStyle);
            buttonStyle.alignment              = TextAnchor.MiddleCenter;
            buttonStyle.normal.background      = Texture2D.whiteTexture;
            buttonStyle.normal.textColor       = Color.black;
            sliderStyle                        = new GUIStyle();
            sliderStyle.normal.background      = Texture2D.whiteTexture;
            sliderStyle.fixedHeight            = 4.0f;
            sliderThumbStyle                   = new GUIStyle();
            sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb");
            sliderThumbStyle.overflow          = new RectOffset(0, 0, 8, 0);
            sliderThumbStyle.fixedWidth        = 20.0f;
            sliderThumbStyle.fixedHeight       = 12.0f;

            ball       = Resources.Load <GameObject>("Ball");
            ballParent = new GameObject("BallParent");
            ballParent.transform.position = tgs.terrainCenter + Vector3.up * 200.0f;

            ResetTerrain();
        }
Exemplo n.º 6
0
        //Animations
        //sleep
        //wake up
        //eat
        //walk
        //Idle
        //Interact with animal

        //could add memory banks for other animals and fruit types


        // Use this for initialization
        void Start()
        {
            //grabs Sun ref
            sun       = GameObject.FindGameObjectWithTag("Sun");
            sunScript = sun.GetComponent <Sun>();

            tgs       = TerrainGridSystem.instance;
            state     = State.MOVESELECT;
            bigStates = BigStates.PICKGOAL;

            //Assign Stats
            hungerModifier += Random.Range(0, .3f);
            //socialModifier += Random.Range(0, .3f);
            sleepModifier += Random.Range(0, .3f);

            nestObject = GameObject.FindGameObjectsWithTag("Nest"); // add naming convention of + ___ specie name

            //Zero Meters
            hunger = 0;
            social = 0;
            sleep  = 0;

            _player = GameObject.FindGameObjectWithTag("Player");
            //chanceToAwaken = 10;
        }
Exemplo n.º 7
0
        void Start()
        {
            // Load marker prefabs
            GameObject yellowSpherePrefab = Resources.Load <GameObject>("YellowSphere");
            GameObject redSpherePrefab    = Resources.Load <GameObject>("RedSphere");

            // Get a reference to Terrain Grid System's API
            tgs = TerrainGridSystem.instance;

            // Iterate each cell and draws a sphere on the center of the cell as well as on the vertices
            for (int k = 0; k < tgs.cells.Count; k++)
            {
                // Add a yellow circle on the center of the cell
                Vector3    worldSpaceCenter = tgs.CellGetPosition(k);
                GameObject yellowSphere     = Instantiate(yellowSpherePrefab);
                yellowSphere.transform.position = worldSpaceCenter + Vector3.up * 0.1f;

                // For each vertex of the cell, add a red circle
                int vertexCount = tgs.CellGetVertexCount(k);
                for (int p = 0; p < vertexCount; p++)
                {
                    Vector3    worldSpacePosition = tgs.CellGetVertexPosition(k, p);
                    GameObject redSphere          = Instantiate(redSpherePrefab);
                    redSphere.transform.position = worldSpacePosition + Vector3.up * 0.1f;                     // note: "up" is -z (grid is x,y) - displaced to avoid z-fighting
                }
            }
        }
Exemplo n.º 8
0
        void Start()
        {
            TerrainGridSystem tgs = TerrainGridSystem.instance;
            int       rows        = tgs.rowCount;
            int       columns     = tgs.columnCount;
            Texture2D tex         = new Texture2D(columns, rows);

            tex.filterMode = FilterMode.Point;
            Color[] colors = new Color[columns * rows];
            for (int k = 0; k < colors.Length; k++)
            {
                float c = Random.value * 0.5f + 0.5f;
                colors[k] = new Color(c, c, 1f);
            }
            tex.SetPixels(colors);
            tex.Apply();

            // Create a quad
            GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);

            quad.GetComponent <Renderer>().material.mainTexture = tex;

            // Adjust size to match grid also considering any cell scale
            Bounds bounds = tgs.bounds;

            quad.transform.position   = bounds.center;
            quad.transform.localScale = new Vector3(bounds.size.x, bounds.size.y, 1f);
        }
Exemplo n.º 9
0
        void Start()
        {
            // Get a reference to TGS system's API
            tgs = TerrainGridSystem.instance;

            // Read texture colors
            Color32[] colors = textureForCells.GetPixels32();

            // Iterate cells and picks the corresponding color in the texture
            int cellCount = tgs.cells.Count;

            for (int k = 0; k < cellCount; k++)
            {
                Vector2 cellCenter = tgs.cells [k].center;

                // Convert the center to texture coordinates
                // The center is in the range of -0.5..0.5, so we add 0.5 and multiply by the texture width in pixels to get the X texture coordinate
                int px = (int)((cellCenter.x + 0.5f) * textureForCells.width);
                // Same for Y
                int py = (int)((cellCenter.y + 0.5f) * textureForCells.height);

                // Now get the color
                Color32 color = colors [py * textureForCells.width + px];

                // And assign it to the cell
                tgs.CellToggleRegionSurface(k, true, color);
            }
        }
Exemplo n.º 10
0
        void Start()
        {
            // Create a TGS instance from scratch

            // Step 1: instantiate TGS prefab and position it in world space
            GameObject tgsGO = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/TerrainGridSystem"));

            tgsGO.transform.position = new Vector3(0, 0, 500);

            // Step 2: get a reference to the TGS main script (this is the API)
            tgs = tgsGO.GetComponent <TerrainGridSystem>();

            // Step 3: customize TGS look & feel (check the documentation for the complete property list)
            tgs.gridTopology = GRID_TOPOLOGY.Hexagonal;
            tgs.rowCount     = 48;
            tgs.columnCount  = 64;

            tgs.cellBorderColor = Color.yellow;                                   // color of cells
            tgs.GetComponent <MeshRenderer>().sharedMaterial.color = Color.black; // color of grid background

            tgs.showTerritories = true;                                           // territories are optional
            tgs.numTerritories  = 8;
            tgs.territoryDisputedFrontierColor = Color.red;
            tgs.highlightMode = HIGHLIGHT_MODE.Territories;

            // Step 4: configure some event trigger
            tgs.OnCellClick += OnCellClickHandler;
        }
Exemplo n.º 11
0
 void Start()
 {
     if (tgs == null)
     {
         tgs = TerrainGridSystem.instance;
     }
     selectionSquareImage.gameObject.SetActive(false);
 }
Exemplo n.º 12
0
 void Start()
 {
     // Get a reference to Terrain Grid System's API
     tgs        = TerrainGridSystem.instance;
     currentRow = 0;
     currentCol = 0;
     StartCoroutine(HighlightCell());
 }
Exemplo n.º 13
0
        // Use this for initialization
        void Start()
        {
            Debug.Log("Select the sphere in the hierarchy and watch script values.");
            Debug.Log("Or click the sphere gameobject to print them to console.");

            tgs        = TerrainGridSystem.instance;
            location.x = tgs.columnCount / 2;
            location.y = tgs.rowCount / 2;
        }
Exemplo n.º 14
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI styles
            labelStyle = new GUIStyle ();
            labelStyle.alignment = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;
        }
Exemplo n.º 15
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;
        }
Exemplo n.º 16
0
        public void Clear()
        {
            TerrainGridSystem tgs = GetTGS();

            if (tgs != null)
            {
                tgs.ClearAll();
            }
        }
Exemplo n.º 17
0
 public void Init <T> (TerrainGridSystem tgs) where T : Component
 {
     this.tgs = tgs;
     hits     = new RaycastHit[20];
     if (GetComponent <T> () == null)
     {
         gameObject.AddComponent <T> ();
     }
 }
Exemplo n.º 18
0
        public void SetupTriggers(TerrainGridSystem tgs)
        {
            TerrainTrigger trigger = terrain.gameObject.GetComponent <TerrainTrigger> ();

            if (trigger == null)
            {
                trigger = terrain.gameObject.AddComponent <TerrainTrigger> ();
            }
            trigger.Init <TerrainCollider> (tgs);
        }
Exemplo n.º 19
0
        TerrainGridSystem GetTGS()
        {
            TerrainGridSystem tgs = GetComponent <TerrainGridSystem> ();

            if (tgs == null)
            {
                Debug.Log("Terrain Grid System not found in this game object!");
                return(null);
            }
            return(tgs);
        }
 void Start()
 {
     if (GetComponent<TerrainCollider> () == null) {
         gameObject.AddComponent<TerrainCollider> ();
     }
     ths = transform.GetComponentInChildren<TerrainGridSystem>();
     if (ths==null) {
         Debug.LogError("Missing Terrain Highlight System reference in Terrain Trigger script.");
         DestroyImmediate (this);
     }
 }
Exemplo n.º 21
0
        // Use this for initialization
        void Start()
        {
            tgs = TerrainGridSystem.instance;
            Color blockedColor = new Color(0.2f, 0.2f, 0.2f, 1f);

            for (int k = 0; k < 1500; k++)
            {
                int cellIndex = Random.Range(0, tgs.cellCount);
                tgs.CellToggleRegionSurface(cellIndex, true, blockedColor);
                tgs.CellSetCanCross(cellIndex, false);
            }
        }
 void Start()
 {
     if (GetComponent <TerrainCollider> () == null)
     {
         gameObject.AddComponent <TerrainCollider> ();
     }
     ths = transform.GetComponentInChildren <TerrainGridSystem>();
     if (ths == null)
     {
         Debug.LogError("Missing Terrain Highlight System reference in Terrain Trigger script.");
         DestroyImmediate(this);
     }
 }
Exemplo n.º 23
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.black;

            character = GameObject.Find("Character").GetComponent <Rigidbody>();
        }
Exemplo n.º 24
0
        void Start()
        {
            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;

            // hide all cells
            tgs = TerrainGridSystem.instance;
            tgs.cells.ForEach((cell) => cell.visible = true);
            tgs.Redraw();

            // listen to events
            tgs.OnCellClick += (cellIndex, buttonIndex) => toggleCellVisible(cellIndex);
        }
Exemplo n.º 25
0
 public void SetupTriggers(TerrainGridSystem tgs)
 {
     for (int k = 0; k < rr.Length; k++)
     {
         if (rr[k].renderer == null)
         {
             continue;
         }
         if (rr[k].renderer.GetComponent <TerrainTrigger>() == null)
         {
             TerrainTrigger trigger = rr[k].renderer.gameObject.AddComponent <TerrainTrigger>();
             trigger.Init <MeshCollider>(tgs);
         }
     }
 }
Exemplo n.º 26
0
        public static void FadeOut(TerrainGridSystem tgs, GameObject surface, Region region, Color color, float duration)
        {
            SurfaceFader fader = surface.GetComponent <SurfaceFader>();

            if (fader != null)
            {
                DestroyImmediate(fader);
            }
            fader           = surface.AddComponent <SurfaceFader>();
            fader.tgs       = tgs;
            fader.startTime = Time.time;
            fader.duration  = duration + 0.0001f;
            fader.color     = color;
            fader.region    = region;
        }
Exemplo n.º 27
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.white;

            tgs.OnCellHighlight += (int cellIndex, ref bool cancelHighlight) => {
                cancelHighlight = true;
                tgs.CellFadeOut(cellIndex, Color.yellow, 2f);
            };
            tgs.OnCellClick += (int cellIndex, int buttonIndex) => MergeCell(cellIndex);
        }
Exemplo n.º 28
0
        TerrainGridSystem GetTGS()
        {
            TerrainGridSystem tgs = GetComponent <TerrainGridSystem> ();

            if (tgs == null)
            {
                tgs = TerrainGridSystem.instance;
            }
            if (tgs == null)
            {
                Debug.Log("Terrain Grid System not found!");
                return(null);
            }
            return(tgs);
        }
Exemplo n.º 29
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;

            // Events
            // OnCellMouseDown occurs when user presses the mouse button on a cell
            tgs.OnCellMouseDown += OnCellMouseDown;
            // OnCellMouseUp occurs when user releases the mouse button on a cell even after a drag
            // OnCellClick occurs when user presses and releases the mouse button as in a normal click
            tgs.OnCellClick += OnCellClick;
        }
Exemplo n.º 30
0
        void Start()
        {
            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;

            // Get a reference to Terrain Grid System's API
            tgs = TerrainGridSystem.instance;

            // listen to events
            tgs.OnCellClick += (cellIndex, buttonIndex) => textureCell(cellIndex);

            // assign a canvas texture
            tgs.canvasTexture = Resources.Load <Texture2D>("Textures/worldMap");
        }
Exemplo n.º 31
0
        /// <summary>
        /// Call this method to force a configuration load.
        /// </summary>
        public void LoadConfiguration()
        {
            if (config == null)
            {
                return;
            }

            TerrainGridSystem tgs = GetComponent <TerrainGridSystem>();

            if (tgs == null)
            {
                Debug.Log("Terrain Grid System not found in this game object!");
                return;
            }
            tgs.textures = textures;
            tgs.CellSetConfigurationData(config);
        }
Exemplo n.º 32
0
        void Start()
        {
            // setup GUI styles
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor = Color.black;

            // Get a reference to Terrain Grid System's API
            tgs = TerrainGridSystem.instance;

            // Set colors for frontiers
            tgs.territoryDisputedFrontierColor = Color.yellow;
            tgs.TerritorySetFrontierColor(0, Color.red);
            tgs.TerritorySetFrontierColor(1, Color.blue);

            // listen to events
            tgs.OnCellClick += (cellIndex, buttonIndex) => changeCellOwner(cellIndex);
        }
        void OnEnable()
        {
            _blackTexture = MakeTex (4, 4, new Color (0.18f, 0.18f, 0.18f));
            _blackTexture.hideFlags = HideFlags.DontSave;
            _headerTexture = Resources.Load<Texture2D> ("EditorHeader");
            blackStyle = new GUIStyle ();
            blackStyle.normal.background = _blackTexture;

            selectionModeOptions = new string[] { "None", "Territories", "Cells" };
            overlayModeOptions = new string[] { "Overlay", "Ground" };
            topologyOptions = new string[] { "Irregular", "Box", "Rectangular", "Hexagonal" };

            // Load UI icons
            Texture2D[] icons = new Texture2D[5];
            icons [(int)RESHAPE_MODE.NONE] = Resources.Load<Texture2D> ("IconLock");
            icons [(int)RESHAPE_MODE.ADD] = Resources.Load<Texture2D> ("IconPen");
            icons [(int)RESHAPE_MODE.MOVE] = Resources.Load<Texture2D> ("IconMove");
            icons [(int)RESHAPE_MODE.ERASE] = Resources.Load<Texture2D> ("IconEraser");
            icons [(int)RESHAPE_MODE.MERGE] = Resources.Load<Texture2D> ("IconMerge");

            reshapeToolbarIcons = new GUIContent[5];
            reshapeToolbarIcons [(int)RESHAPE_MODE.NONE] = new GUIContent ("", icons [(int)RESHAPE_MODE.NONE], "");
            reshapeToolbarIcons [(int)RESHAPE_MODE.ADD] = new GUIContent ("Add", icons [(int)RESHAPE_MODE.ADD], "Add a new cell to the grid");
            reshapeToolbarIcons [(int)RESHAPE_MODE.MOVE] = new GUIContent ("Move", icons [(int)RESHAPE_MODE.MOVE], "Move a border point");
            reshapeToolbarIcons [(int)RESHAPE_MODE.ERASE] = new GUIContent ("Erase", icons [(int)RESHAPE_MODE.ERASE], "Remove a cell");
            reshapeToolbarIcons [(int)RESHAPE_MODE.MERGE] = new GUIContent ("Merge", icons [(int)RESHAPE_MODE.MERGE], "Merge two cells");
            reshapeExplanation = new string[5];
            reshapeExplanation [(int)RESHAPE_MODE.ADD] = "CLICK on the grid to add a new cell ";
            reshapeExplanation [(int)RESHAPE_MODE.MOVE] = "DRAG a border point on the grid";
            reshapeExplanation [(int)RESHAPE_MODE.ERASE] = "CLICK on any cell to delete it.";
            reshapeExplanation [(int)RESHAPE_MODE.MERGE] = "CLICK on two or more cells in sequence to merge them.";

            tgs = (TerrainGridSystem)target;
            if (tgs.territories == null) {
                tgs.Init ();
            }
            HideEditorMesh();
        }
 // Use this for initialization
 void Start()
 {
     tgs = TerrainGridSystem.instance;
 }
Exemplo n.º 35
0
        void Start()
        {
            tgs = TerrainGridSystem.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init (800, 500);

            // setup GUI styles
            labelStyle = new GUIStyle ();
            labelStyle.alignment = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.black;
            labelStyleShadow = new GUIStyle (labelStyle);
            labelStyleShadow.normal.textColor = Color.black;
            buttonStyle = new GUIStyle (labelStyle);
            buttonStyle.alignment = TextAnchor.MiddleCenter;
            buttonStyle.normal.background = Texture2D.whiteTexture;
            buttonStyle.normal.textColor = Color.black;
            sliderStyle = new GUIStyle ();
            sliderStyle.normal.background = Texture2D.whiteTexture;
            sliderStyle.fixedHeight = 4.0f;
            sliderThumbStyle = new GUIStyle ();
            sliderThumbStyle.normal.background = Resources.Load<Texture2D> ("thumb");
            sliderThumbStyle.overflow = new RectOffset (0, 0, 8, 0);
            sliderThumbStyle.fixedWidth = 20.0f;
            sliderThumbStyle.fixedHeight = 12.0f;

            ball = Resources.Load<GameObject>("Ball");
            ballParent = new GameObject("BallParent");
            ballParent.transform.position = tgs.terrainCenter + Vector3.up * 200.0f;

            ResetTerrain();
        }