Esempio n. 1
0
 private void Awake()
 {
     Physics.IgnoreLayerCollision(layer, layer, true);
     pathing     = GameObject.Find("A*").GetComponent <AStarManager>();
     gridScript  = GameObject.Find("UGrid").GetComponent <UGrid>();
     myTransform = GetComponent <Transform>();
 }
Esempio n. 2
0
        //bool displayGUI = false;
        //Progress progressObj;

        private void Awake()
        {
            var playerManager = GameObject.Find("Player Manager");

            selection = playerManager.GetComponent <UnitSelection>();
            manager   = playerManager.GetComponent <GUIManager>();
            gui.type  = "Building";
            if (buildingType == BuildingType.ProgressBuilding)
            {
                InvokeRepeating("Progress", 0, progressRate);
            }
            else if (buildingType == BuildingType.CompleteBuilding)
            {
                gameObject.name = name;
                gui.Awake(gameObject);
                for (int x = 0; x < techEffect.Length; x++)
                {
                    Faction.Tech[techEffect[x].index].AddListener(gameObject);
                    if (Faction.Tech[techEffect[x].index].active)
                    {
                        Upgraded(Faction.Tech[techEffect[x].index].name);
                    }
                }
            }
            grid      = GameObject.Find("UGrid").GetComponent <UGrid>();
            healthObj = GetComponent <Health>();
            //progressObj = GetComponent<Progress>();
        }
Esempio n. 3
0
        private GameManager Initialize()
        {
            if (_instance != null)
            {
                return(_instance);
            }
            _instance = this;
            Terrain   = GameObject.Find("BasicTerrain").GetComponent <Terrain>();
            UGrid     = GameObject.Find(UGrid.ScriptName).GetComponent <UGrid>();
            if (UGrid.grids[UGrid.index].points == null)
            {
                // TODO: Issue caused after hot-swap, his obviously resets the grid state generated by buildings
                Log.d("Grid points have reset after a hot-swap problem, re-generating state!");
                UGrid.OnEnable();
            }
            Fog          = GameObject.Find(Fog.ScriptName).GetComponent <Fog>();
            AStarManager = GameObject.Find(AStarManager.ScriptName).GetComponent <AStarManager>();
            var factionList = GameObject.Find("Faction Manager")
                              .GetComponent <FactionManager>()
                              .FactionList;

            Factions = new Faction[factionList.Length];
            ResourceManagerFaction = new ResourceManager[factionList.Length];
            for (var factionIndex = 0; factionIndex < factionList.Length; factionIndex++)
            {
                Factions[factionIndex] = factionList[factionIndex].GetComponent <Faction>();
                ResourceManagerFaction[factionIndex] = Factions[factionIndex].GetComponent <ResourceManager>();
            }
            return(this);
        }
 void OnGUI()
 {
     if(findPoint == null){
         findPoint = new GameObject();
         findPoint.name = "Find Point";
         pointCube = findPoint.AddComponent<DrawCube>();
     }
     if(grid == null){
         grid = GameObject.Find("UGrid").GetComponent<UGrid>();
     }
     index = EditorGUILayout.IntField("Grid : ", index);
     if(index < grid.grids.Length){
         loc = EditorGUILayout.IntField("Index : ", loc);
         if(loc < grid.grids[index].grid.Length){
             GUILayout.Label("X : " + grid.grids[index].grid[loc].loc.x +
                             ", Y : " + grid.grids[index].grid[loc].loc.y +
                             ", Z : " + grid.grids[index].grid[loc].loc.z);
         }
     }
     if(index < grid.grids.Length){
         if(loc < grid.grids[index].grid.Length){
             findPoint.transform.position = grid.grids[index].grid[loc].loc;
             pointCube.index = index;
         }
     }
 }
 int DetermineLoc(Vector3 loc, UGrid gridScript)
 {
     float xLoc = (loc.x-gridScript.grids[gridI].startLoc.x);
     float yLoc = (loc.z-gridScript.grids[gridI].startLoc.z);
     int x = Mathf.RoundToInt(xLoc/gridScript.grids[gridI].nodeDist);
     int y = Mathf.RoundToInt(yLoc/gridScript.grids[gridI].nodeDist);
     int nLoc = x+(y*gridScript.grids[gridI].size);
     return nLoc;
 }
Esempio n. 6
0
        int DetermineLoc(Vector3 loc, UGrid gridScript)
        {
            Grid  grid = gridScript.grids[gridI];
            float xLoc = loc.x - grid.startLoc.x;
            float yLoc = loc.z - grid.startLoc.z;
            int   x    = Mathf.RoundToInt(xLoc / grid.nodeDist);
            int   y    = Mathf.RoundToInt(yLoc / grid.nodeDist);

            return(x + y * grid.size);
        }
Esempio n. 7
0
 public void OpenPoints(UGrid grid, int gridI, int index)
 {
     for (int x = -closeWidth; x <= closeWidth; x++)
     {
         for (int y = -closeLength; y <= closeLength; y++)
         {
             int i = x + y * grid.grids[gridI].size;
             grid.grids[gridI].grid[index + i].state = 0;
         }
     }
 }
Esempio n. 8
0
 public void ClosePoints(UGrid grid, int gridI, int index, bool pathing)
 {
     for (int x = -closeWidth; x <= closeWidth; x++)
     {
         for (int y = -closeLength; y <= closeLength; y++)
         {
             int i = x + y * grid.grids[gridI].size;
             grid.grids[gridI].grid[index + i].state = closePoints[(x + closeWidth) * (closeLength * 2 + 1) + (y + closeLength)];
         }
     }
 }
Esempio n. 9
0
    public void Setup(float ep, float NPE, string strat)
    {
        epsilon  = ep;
        strategy = strat;

        environment = new Environment();
        environment.EnvSet(epsilon, strategy, NPE);

        UEnv  = new GameObject("Environment");
        ugrid = UEnv.AddComponent <UGrid>();
        ugrid.createUGrid(environment.GetNomGrid(), environment.GetAgentRow(), environment.GetAgentCol());
    }
Esempio n. 10
0
 // Use this for initialization
 void OnDrawGizmos()
 {
     if(grid == null){
         grid = GameObject.Find("UGrid").GetComponent<UGrid>();
     }
     else{
         if(index < grid.grids.Length){
             nodeSize = grid.grids[index].nodeDist;
             Gizmos.color = Color.green;
             Gizmos.DrawCube(gameObject.transform.position, new Vector3(nodeSize, nodeSize, nodeSize));
         }
     }
 }
Esempio n. 11
0
 public void Start()
 {
     if (unitSelect == null)
     {
         unitSelect = gameObject.GetComponent <UnitSelection>();
     }
     if (uGrid == null)
     {
         GameObject gridObj = GameObject.Find("UGrid");
         if (gridObj)
         {
             uGrid = gridObj.GetComponent <UGrid>();
         }
     }
 }
Esempio n. 12
0
        public void ClosePoints()
        {
            UGrid uGrid = GameObject.Find("UGrid").GetComponent <UGrid>();
            int   index = DetermineLoc(transform.position, uGrid);
            Grid  grid  = uGrid.grids[gridI];

            grid.points[index].state = 2;
            for (int x = -closeSize; x <= closeSize; x++)
            {
                for (int y = -closeSize; y <= closeSize; y++)
                {
                    int i = x + y * grid.size;
                    grid.points[index + i].state = 2;
                }
            }
        }
Esempio n. 13
0
 // Use this for initialization
 void OnDrawGizmos()
 {
     if (grid == null)
     {
         grid = GameObject.Find("UGrid").GetComponent <UGrid>();
     }
     else
     {
         if (index < grid.grids.Length)
         {
             nodeSize     = grid.grids[index].nodeDist;
             Gizmos.color = Color.green;
             Gizmos.DrawCube(gameObject.transform.position, new Vector3(nodeSize, nodeSize, nodeSize));
         }
     }
 }
Esempio n. 14
0
    void Start()
    {
        pathList   = new UPath[amountOfThreads];
        targetList = new List <Vector3>();
        startList  = new List <Vector3>();
        indexList  = new List <int>();
        returnList = new List <GameObject>();
        apath      = new APath[amountOfThreads];
        UGrid gridScript = GameObject.Find("UGrid").GetComponent <UGrid>();

        for (int x = 0; x < apath.Length; x++)
        {
            apath[x]            = new APath();
            apath[x].gridScript = gridScript;
        }
        startedThreads = new bool[amountOfThreads];
    }
    private void InitUGrid()
    {
        uGrid = new UGrid <UGridBoid>(2, 2, cellSize, cellSize, sets.bounds.width, sets.bounds.height);

        UGridBoid.bounds = sets.bounds;
        UGridBoid.ugrid  = uGrid;
        UGridBoid.sets   = sets;

        for (int i = 0; i < sets.testElements; ++i)
        {
            Vector3Int pos = new Vector3Int(r.Next(sets.bounds.width), 0, r.Next(sets.bounds.height));
            GameObject go  = Instantiate(uGridBoidPrefab, pos, Quaternion.identity);
            go.TryGetComponent(out UGridBoid b);
            b.ID = entityCount;
            uGrid.Insert(b);
            ++entityCount;
        }
    }
Esempio n. 16
0
    public bool CheckPoints(UGrid grid, int gridI, int index)
    {
        bool state = true;

        for (int x = -closeWidth; x <= closeWidth; x++)
        {
            for (int y = -closeLength; y <= closeLength; y++)
            {
                if (closePoints[(x + closeWidth) * closeLength + (y + closeLength)] != 0)
                {
                    if (grid.grids[gridI].grid[index + x + y * grid.grids[gridI].size].state == 2)
                    {
                        state = false;
                    }
                }
            }
        }
        return(state);
    }
Esempio n. 17
0
    // Update is called once per frame
    void OnDrawGizmos()
    {
        if (!grid)
        {
            grid = GameObject.Find("UGrid").GetComponent <UGrid>();
        }

        if (generate)
        {
            for (int x = 0; x < obj.Length; x++)
            {
                GameObject folder = new GameObject();
                folder.name = "Folder";
                for (int z = 0; z < obj[x].amount; z++)
                {
                    int  loc    = 0;
                    bool viable = false;
                    while (viable == false)
                    {
                        loc = Random.Range(0, grid.grids[gridI].grid.Length);
                        Vector3 point = grid.grids[gridI].grid[loc].loc;
                        if (point.x >= obj[x].area.x && point.x <= obj[x].area.width && point.z >= obj[x].area.y && point.z <= obj[x].area.height)
                        {
                            viable = true;
                        }
                        else
                        {
                            viable = false;
                        }
                        if (grid.grids[gridI].grid[loc].state == 2)
                        {
                            viable = false;
                        }
                    }
                    GameObject clone = Instantiate(obj[x].obj, grid.grids[gridI].grid[loc].loc, Quaternion.identity) as GameObject;
                    clone.transform.parent            = folder.transform;
                    clone.name                        = obj[x].obj.name;
                    grid.grids[gridI].grid[loc].state = 2;
                }
            }
            generate = false;
        }
    }
Esempio n. 18
0
 void OnGUI()
 {
     if (_uGrid == null)
     {
         _uGrid = GameObject.Find("UGrid").GetComponent <UGrid>();
     }
     _gridIndex = EditorGUILayout.IntField("Grid : ", _gridIndex);
     if (_gridIndex < _uGrid.grids.Length && _gridIndex >= 0)
     {
         _pointIndex = EditorGUILayout.IntField("Index : ", _pointIndex);
         GridPoint[] points = _uGrid.grids[_gridIndex].points;
         if (_pointIndex < points.Length && _pointIndex >= 0)
         {
             Vector3 pointLoc = points[_pointIndex].loc;
             GUILayout.Label("X : " + pointLoc.x + ", Y : " + pointLoc.y + ", Z : " + pointLoc.z);
             _uGrid.FindPointGridIndex = _gridIndex;
             _uGrid.FindPointLoc       = pointLoc;
             SceneView.RepaintAll();
         }
     }
 }
Esempio n. 19
0
 public void Produce(Group g, int group, UGrid grid, int gridI)
 {
     for (int x = 0; x < canBuildAtOnce; x++)
     {
         if (x < jobsAmount)
         {
             if (jobs[x].Produce())
             {
                 Vector3        loc    = grid.DetermineNearestPoint(buildLoc.transform.position, buildLoc.transform.position, gridI);
                 GameObject     obj    = GameObject.Instantiate(g.unitList[jobs[x].groupIndex].obj, loc, Quaternion.identity) as GameObject;
                 UnitController script = obj.GetComponent <UnitController>();
                 if (script)
                 {
                     script.group = group;
                 }
                 jobs.RemoveAt(x);
                 x--;
                 jobsAmount--;
             }
         }
     }
 }
Esempio n. 20
0
 void ModifyG(int ol, int nl, UGrid starget)
 {
     Grid[] copyArr = new Grid[ol];
     for (int x = 0; x < copyArr.Length; x++)
     {
         copyArr[x] = starget.grids[x];
     }
     starget.grids = new Grid[nl];
     if (nl < ol)
     {
         for (int x = 0; x < copyArr.Length - 1; x++)
         {
             starget.grids[x] = copyArr[x];
         }
     }
     else
     {
         for (int x = 0; x < starget.grids.Length - 1; x++)
         {
             starget.grids[x] = copyArr[x];
         }
         starget.grids[nl - 1] = new Grid();
     }
 }
Esempio n. 21
0
    public void Start()
    {
        gridScript = GameObject.Find("UGrid").GetComponent <UGrid>();
        groupM     = GameObject.Find("Faction Manager").GetComponent <GroupManager>();
        placement  = gameObject.GetComponent <BuildingPlacement>();
        if (placement)
        {
            placement.SetGroup(group);
        }
        GUIManager manager = gameObject.GetComponent <GUIManager>();

        if (manager)
        {
            manager.group = groupM.groupList[group].GetComponent <Group>();
        }
        guiManager = gameObject.GetComponent <GUIManager>();
        GameObject obj = GameObject.Find("MiniMap");

        if (obj)
        {
            map = obj.GetComponent <MiniMap>();
        }
        test = Camera.main.GetComponent <GUILayer>();
    }
Esempio n. 22
0
 public void Produce(Group g, int group, UGrid grid, int gridI)
 {
     for(int x = 0; x < canBuildAtOnce; x++){
         if(x < jobsAmount){
             if(jobs[x].Produce()){
                 Vector3 loc = grid.DetermineNearestPoint(buildLoc.transform.position, buildLoc.transform.position, gridI);
                 GameObject obj = GameObject.Instantiate(g.unitList[jobs[x].groupIndex].obj, loc, Quaternion.identity) as GameObject;
                 UnitController script = obj.GetComponent<UnitController>();
                 if(script)
                     script.group = group;
                 jobs.RemoveAt(x);
                 x--;
                 jobsAmount--;
             }
         }
     }
 }
 public void Start()
 {
     gridScript = GameObject.Find("UGrid").GetComponent<UGrid>();
     groupM = GameObject.Find("Faction Manager").GetComponent<GroupManager>();
     placement = gameObject.GetComponent<BuildingPlacement>();
     if(placement)
         placement.SetGroup(group);
     GUIManager manager = gameObject.GetComponent<GUIManager>();
     if(manager)
         manager.group = groupM.groupList[group].GetComponent<Group>();
     guiManager = gameObject.GetComponent<GUIManager>();
     GameObject obj = GameObject.Find("MiniMap");
     if(obj)
         map = obj.GetComponent<MiniMap>();
     test = Camera.main.GetComponent<GUILayer>();
 }
Esempio n. 24
0
 public void ClosePoints(UGrid grid, int gridI, int index, bool pathing)
 {
     for(int x = -closeWidth; x <= closeWidth; x++){
         for(int y = -closeLength; y <= closeLength; y++){
             int i = x+y*grid.grids[gridI].size;
             grid.grids[gridI].grid[index+i].state = closePoints[(x+closeWidth)*(closeLength*2+1)+(y+closeLength)];
         }
     }
 }
    // Use this for initialization
    void Start()
    {
        selection = GameObject.Find("Player Manager").GetComponent<UnitSelection>();
        manager = GameObject.Find("Player Manager").GetComponent<GUIManager>();
        gui.type = "Building";
        g = GameObject.Find("Player Manager").GetComponent<GUIManager>().group;
        if(buildingType == BuildingType.ProgressBuilding){
            InvokeRepeating("Progress", 0, progressRate);
        }

        else if(buildingType == BuildingType.CompleteBuilding){
            gameObject.name = name;
            gui.Start(gameObject);
            for(int x = 0; x < techEffect.Length; x++){
                g.tech[techEffect[x].index].AddListener(gameObject);
                if(g.tech[techEffect[x].index].active){
                    Upgraded(g.tech[techEffect[x].index].name);
                }
            }
        }
        grid = GameObject.Find("UGrid").GetComponent<UGrid>();
        healthObj = GetComponent<Health>();
        progressObj = GetComponent<Progress>();
    }
Esempio n. 26
0
 public void OpenPoints(UGrid grid, int gridI, int index)
 {
     for(int x = -closeWidth; x <= closeWidth; x++){
         for(int y = -closeLength; y <= closeLength; y++){
             int i = x+y*grid.grids[gridI].size;
             grid.grids[gridI].grid[index+i].state = 0;
         }
     }
 }
 void Start()
 {
     Physics.IgnoreLayerCollision(layer, layer, true);
     pathing = GameObject.Find("A*").GetComponent<AStarManager>();
     gridScript = GameObject.Find("UGrid").GetComponent<UGrid>();
     myTransform = GetComponent<Transform>();
 }
 public void Start()
 {
     if(resourceManager == null){
         resourceManager = gameObject.GetComponent<ResourceManager>();
     }
     if(fog == null){
         GameObject nObj;
         nObj = GameObject.Find("Fog");
         if(nObj)
             fog = nObj.GetComponent<Fog>();
     }
     if(unitSelect == null){
         unitSelect = gameObject.GetComponent<UnitSelection>();
     }
     if(grid == null){
         GameObject nObj;
         nObj = GameObject.Find("UGrid");
         if(nObj)
             grid = nObj.GetComponent<UGrid>();
     }
 }
Esempio n. 29
0
 public bool CheckPoints(UGrid grid, int gridI, int index)
 {
     bool state = true;
     for(int x = -closeWidth; x <= closeWidth; x++){
         for(int y = -closeLength; y <= closeLength; y++){
             if(closePoints[(x+closeWidth)*closeLength+(y+closeLength)] != 0){
                 if(grid.grids[gridI].grid[index+x+y*grid.grids[gridI].size].state == 2){
                     state = false;
                 }
             }
         }
     }
     return state;
 }
Esempio n. 30
0
        public override void OnInspectorGUI()
        {
            UGrid starget = (UGrid)target;

            selected = starget.selectionTexture;
            string[] gridList = new string[starget.grids.Length];
            for (int x = 0; x < gridList.Length; x++)
            {
                gridList[x] = "Grid " + (x + 1);
            }
            int size  = gridList.Length;
            int lsize = size;

            size = EditorGUILayout.IntField("Grid Amount : ", size);
            if (size != lsize)
            {
                ModifyG(lsize, size, starget);
            }
            starget.index = EditorGUILayout.Popup(starget.index, gridList);
            EditorGUILayout.Space();
            if (starget.index >= gridList.Length)
            {
                starget.index = 0;
                return;
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Settings"))
            {
                menuSetting = 0;
            }
            if (menuSetting == 0)
            {
                GUI.DrawTexture(GUILayoutUtility.GetLastRect(), selected);
            }
            if (GUILayout.Button("Display"))
            {
                menuSetting = 1;
            }
            if (menuSetting == 1)
            {
                GUI.DrawTexture(GUILayoutUtility.GetLastRect(), selected);
            }
            EditorGUILayout.EndHorizontal();
            int  i    = starget.index;
            Grid grid = starget.grids[i];

            if (menuSetting == 0)
            {
                grid.size     = EditorGUILayout.IntField("Grid Size : ", grid.size);
                grid.nodeDist = EditorGUILayout.FloatField("Node Size : ", grid.nodeDist);
                EditorGUILayout.Space();
                grid.startLoc         = EditorGUILayout.Vector3Field("Start Loc : ", grid.startLoc);
                grid.octileConnection = EditorGUILayout.Toggle("Octile Connection : ", grid.octileConnection);
                grid.displaceDown     = EditorGUILayout.Toggle("Displace Down : ", grid.displaceDown);
                grid.checkSlope       = EditorGUILayout.Toggle("Check Slope : ", grid.checkSlope);
                if (grid.checkSlope)
                {
                    grid.slopeMax = EditorGUILayout.FloatField("Slope Max : ", grid.slopeMax);
                }
                EditorGUILayout.Space();
                grid.checkLayer    = LayerMaskField("State Check Layers : ", grid.checkLayer, true);
                grid.displaceLayer = LayerMaskField("Displace Layer : ", grid.displaceLayer, true);
            }
            else if (menuSetting == 1)
            {
                grid.displayGrid  = EditorGUILayout.Toggle("Display Cubes : ", grid.displayGrid);
                grid.displayLines = EditorGUILayout.Toggle("Display Lines : ", grid.displayLines);
            }
            if (GUILayout.Button("Generate Grid"))
            {
                starget.GenerateGrid(starget.index);
                // Immediate effect instead of waiting for the camera to move
                SceneView.RepaintAll();
            }
        }