Esempio n. 1
0
    public static void Initialize()
    {
        _cachedCommander = PlayerManager.MainController.Commander;
        GridBuilder.Initialize();

        OrganizerStructures = LSUtility.CreateEmpty().transform;
        OrganizerStructures.transform.parent = PlayerManager.MainController.Commander.GetComponentInChildren <RTSAgents>().transform;
        OrganizerStructures.gameObject.name  = "OrganizerStructures";

        WallPositioningHelper.Initialize();

        UserInputHelper.OnSingleLeftTapDown  += HandleSingleLeftClick;
        UserInputHelper.OnSingleRightTapDown += HandleSingleRightClick;
    }
Esempio n. 2
0
    public static void FindStructureLocation()
    {
        Vector3 newLocation = RTSInterfacing.GetWorldPos3(Input.mousePosition);

        if (RTSInterfacing.HitPointIsGround(Input.mousePosition) && lastLocation != newLocation)
        {
            lastLocation = newLocation;

            tempStructure.transform.position = Positioning.GetSnappedPosition(newLocation);

            if (_constructingWall)
            {
                WallPositioningHelper.Visualize();
            }
        }
    }
Esempio n. 3
0
    public static void Reset()
    {
        _findingPlacement = false;
        if (_constructingWall)
        {
            _constructingWall = false;
            WallPositioningHelper.Reset();
        }

        //temp structure no longer required
        Object.Destroy(tempObject);
        tempStructure     = null;
        tempStructureBody = null;
        cachedAgent       = null;
        // remove temporary structure from grid
        GridBuilder.Reset();
    }
Esempio n. 4
0
    public static void CreateStructure(string buildingName, RTSAgent constructingAgent, Rect playingArea)
    {
        Vector2d buildPoint       = new Vector2d(constructingAgent.transform.position.x, constructingAgent.transform.position.z + 10);
        RTSAgent buildingTemplate = GameResourceManager.GetAgentTemplate(buildingName);

        if (buildingTemplate.MyAgentType == AgentType.Building && buildingTemplate.GetComponent <Structure>())
        {
            // check that the Player has the resources available before allowing them to create a new structure
            if (!_cachedCommander.CachedResourceManager.CheckResources(buildingTemplate))
            {
                Debug.Log("Not enough resources!");
            }
            else
            {
                tempObject = Object.Instantiate(buildingTemplate.gameObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                if (tempObject)
                {
                    _findingPlacement = true;
                    SetTransparentMaterial(tempObject, GameResourceManager.AllowedMaterial);
                    tempObject.gameObject.name = buildingName;

                    tempStructure = tempObject.GetComponent <Structure>();
                    if (tempStructure.StructureType == StructureType.Wall)
                    {
                        // walls require a little help since they are click and drag
                        _constructingWall       = true;
                        tempStructure.IsOverlay = true;
                        WallPositioningHelper.Setup();
                    }

                    tempStructureBody = tempObject.GetComponent <UnityLSBody>().InternalBody;

                    // structure size is 2 times the size of halfwidth & halfheight
                    tempStructure.BuildSizeLow  = (tempStructureBody.HalfWidth.CeilToInt() * 2);
                    tempStructure.BuildSizeHigh = (tempStructureBody.HalfLength.CeilToInt() * 2);

                    cachedAgent = constructingAgent;

                    tempStructure.gameObject.transform.position = Positioning.GetSnappedPosition(buildPoint.ToVector3());
                }
            }
        }
    }
Esempio n. 5
0
 private static void HandleSingleLeftClick()
 {
     if (IsFindingBuildingLocation())
     {
         if (_constructingWall)
         {
             WallPositioningHelper.OnLeftClick();
         }
         else
         {
             // only constructing 1 object, place it in the agents construct queue
             if (tempStructure.ValidPlacement)
             {
                 SetConstructionQueue(tempObject);
                 SendConstructCommand();
             }
             else
             {
                 Debug.Log("Invalid end placement!");
             }
         }
     }
 }