public static Structure AddBuilding(PhantomConstruction Prototype)
    {
        Structure _b = new Structure(Prototype);

        BuildingList.Add(_b);
        return(_b);
    }
Beispiel #2
0
 public Storage(PhantomConstruction PitTemplate)
     : base(1, Vector3.zero, Vector3.zero, "A resources storage for building the " + PitTemplate.MasterObject.name)
 {
     foreach (GameObject _b in PitTemplate.Elements)
     {
         if (_b.transform.childCount == 0)
         {
             if (Map.BrickExists(_b.transform.position) && Map.GetBrick(_b.transform.position).gameObject.activeInHierarchy)
             {
                 AddBrick(Map.GetBrick(_b.transform.position).gameObject);
             }
         }
         else
         {
             foreach (GameObject _subb in Functions.GetAllChildren(_b))
             {
                 if (Map.BrickExists(_subb.transform.position) && Map.GetBrick(_subb.transform.position).gameObject.activeInHierarchy)
                 {
                     AddBrick(Map.GetBrick(_subb.transform.position).gameObject);
                 }
             }
         }
     }
     ZoneController.AllStorages.Add(this);
     StorageSack = new Sack(this.GetTarget(), 1);
 }
Beispiel #3
0
 public Mine(PhantomConstruction PitTemplate)
     : base(4, Vector3.zero, Vector3.zero, "A pit for" + PitTemplate.MasterObject.name)
 {
     foreach (GameObject _b in PitTemplate.Elements)
     {
         if (_b.transform.childCount == 0)
         {
             if (Map.BrickExists(_b.transform.position) && Map.GetBrick(_b.transform.position).gameObject.activeInHierarchy)
             {
                 AddBrick(Map.GetBrick(_b.transform.position).gameObject);
             }
         }
         else
         {
             foreach (GameObject _subb in Functions.GetAllChildren(_b))
             {
                 if (Map.BrickExists(_subb.transform.position) && Map.GetBrick(_subb.transform.position).gameObject.activeInHierarchy)
                 {
                     AddBrick(Map.GetBrick(_subb.transform.position).gameObject);
                 }
             }
         }
     }
     ZoneController.AllMines.Add(this);
 }
    //public Workbench(Vector3 StartPoint, ushort TemplateType, byte Rotation, Structure ParentBuilding)
    //{
    //    //initialization
    //    Master = new GameObject();
    //    //Bricks = new List<GameObject>();
    //    Sack = new Sack(Master);

    //    Type = TemplateType;
    //    WorkbenchTemplate Template = Workbenches.Templates.Find(x => x.Type == Type);
    //    Name = Template.Name;
    //    ID = Workbenches.WorkbenchID;
    //    Master.transform.position = StartPoint;
    //    Master.transform.SetParent(ParentBuilding.MasterObject.transform,true);
    //    Master.name = Template.Name;
    //    Master.tag = "WorkbenchBrick";
    //    foreach (WorkbenchElement _e in Template.Elements)
    //    {
    //        Vector3 _RotatedCoordinates = new Vector3();
    //        _RotatedCoordinates = _e.Coordinates;
    //        for (byte i = 0; i < Rotation; i++)
    //            _RotatedCoordinates = Functions.RightVector(_RotatedCoordinates);
    //        GameObject _CurrentBrick = Links.Bricks.AddBrick(Functions.ObjectToWorldCoordinates(StartPoint + _RotatedCoordinates), _e.ResourceID, true);
    //        //Bricks.Add(_CurrentBrick);
    //        if (_e.BasicBrick) Base = _CurrentBrick;
    //        _CurrentBrick.transform.SetParent(Master.transform, true);
    //        _CurrentBrick.tag = "WorkbenchBrick";
    //    }
    //}
    public Workbench(PhantomConstruction Prototype, Structure ParentBuilding)
    {
        Master = new GameObject();
        Sack   = new Sack(Master);
        Base   = Master;

        Type = Prototype.Type;
        Name = Prototype.TypeName;
        ID   = Workbenches.WorkbenchID;
        Master.transform.position = Prototype.MasterObject.transform.position;
        Master.transform.SetParent(ParentBuilding.MasterObject.transform, true);
        Master.name = Prototype.TypeName;
        Master.tag  = "WorkbenchBrick";
    }
    public void ConstructPhantomBuilding()
    {
        //_PhantomBuildingCoordinates.Clear();
        if (_PhantomBuilding != null)
        {
            _PhantomBuilding.Destroy();
        }
        _BuildingMode = true;
        XmlDocument _BuildingsRepository = new XmlDocument();

        _BuildingsRepository.Load(Settings.BuildingsStoragePath);
        //_PhantomBuilding = new PhantomBuilding(_BuildingsRepository.DocumentElement.ChildNodes[_BuildingSelectionDD.value]);
        _PhantomBuilding = new PhantomConstruction(_BuildingsRepository.DocumentElement.ChildNodes[_BuildingSelectionDD.value]);
    }
Beispiel #6
0
    //Private methods
    private GameObject AddElement(XmlNode ElementDescription)
    {
        GameObject  _Element;
        Vector3     _Coordinates;
        XmlNodeList _CoordinatesDescription;

        switch (ElementDescription.Name)
        {
        case "Workbench":
            //Defenition
            ushort _type             = ushort.Parse(ElementDescription.ChildNodes[1].InnerText);
            PhantomConstruction _phc = new PhantomConstruction(Workbenches.Templates.Find(x => x.Type == _type));
            _CoordinatesDescription = ElementDescription.ChildNodes[0].ChildNodes;
            _Coordinates            = new Vector3(float.Parse(_CoordinatesDescription[0].InnerText), float.Parse(_CoordinatesDescription[1].InnerText) + 0.05f, float.Parse(_CoordinatesDescription[2].InnerText));
            byte _rotation = byte.Parse(ElementDescription.ChildNodes[2].InnerText);

            //Processing
            ChildConstructions.Add(_phc);
            _phc.MasterObject.transform.SetParent(MasterObject.transform);
            _phc.Rotate(_rotation);
            _phc.Show(_Coordinates);
            _Element = _phc.MasterObject;
            break;

        case "Brick":
            //Defenition
            _CoordinatesDescription = ElementDescription.ChildNodes[0].ChildNodes;
            _Coordinates            = new Vector3(float.Parse(_CoordinatesDescription[0].InnerText), float.Parse(_CoordinatesDescription[1].InnerText) + 0.05f, float.Parse(_CoordinatesDescription[2].InnerText));
            ushort _ResID = ushort.Parse(ElementDescription.ChildNodes.Item(1).InnerText);

            //Processing
            _Element = MonoBehaviour.Instantiate(Settings.BrickPrefab, Vector3.zero, Quaternion.identity);
            _Element.transform.SetParent(MasterObject.transform, false);
            _Element.transform.localPosition = _Coordinates;
            _Element.GetComponent <MeshRenderer>().material = Resources.GetResource(_ResID).Material;
            _Element.name  = Resources.GetResource(_ResID).Name;
            _Element.tag   = "Untagged";
            _Element.layer = 10;
            Highlighter.Phantomize(_Element);
            break;

        default:
            Log.Warning(scr, "Unknown element type in phantom constructing: ");
            Functions.ReadXMLNode(ElementDescription, scr);
            _Element = null;
            break;
        }
        return(_Element);
    }
    //Constructor
    public Structure(PhantomConstruction Prototype)
    {
        //Consturction
        //Bricks = new List<GameObject>();
        BWorkbenches = new List <Workbench>();
        //XmlDocument _BuildingXMLDescription = new XmlDocument();
        //XmlNodeList _CoordinatesDescription;
        //Vector3 _Coordinates;
        MasterObject = new GameObject();

        //Defenition
        State    = StructureState.New;
        id       = Structures.BuildingID;
        Version  = 0;
        Rotation = Prototype.Rotation;
        TypeName = Prototype.TypeName;

        //Processing
        MasterObject.name = TypeName + ":" + id.ToString();
        MasterObject.transform.SetParent(Map.GetBrick(Prototype.MasterObject.transform.position).gameObject.transform.parent);
        MasterObject.transform.position = Prototype.MasterObject.transform.position;
    }
Beispiel #8
0
 public void BuildingModeOn(Vector3 _Coordinates)
 {
     //SetParams();
     Links.MainCamera.GetComponent <camera_move>()._CameraCanMove = false;
     _Center = _Coordinates;
     _Normal = _Coordinates - Links.MainCamera.transform.position;
     _RightForCameraDirection = new Vector3(_Normal.z, 0f, -_Normal.x);
     _RightForCameraDirection = Vector3.ClampMagnitude(_RightForCameraDirection, 1);
     Debug.Log("Right to camera direction is " + _RightForCameraDirection);
     _BuildModeOff = false;
     _BasicObject  = new GameObject();
     _BasicObject.transform.position = _Coordinates;
     _WorkbrenchSelectDD.value       = 0;
     _WorkbrenchSelectDD.value       = 1;
     _PhantomWorkbench.Destroy();
     _PhantomWorkbench = null;
     _BuildingElements.Add(Instantiate(Settings.BrickPrefab, _Coordinates, Quaternion.identity));
     Highlighter.Pick(_BuildingElements[0]);
     _BuildingElements[0].transform.SetParent(_BasicObject.transform, true);
     _BuildingElements[0].layer = 9;
     _BuildingElements[0].GetComponent <Renderer>().material = Resources.ResourceLibrary.Find(x => x.Name == _ResourceSelectDD.options[_ResourceSelectDD.value].text).Material;
 }
Beispiel #9
0
 public void SetParams()
 {
     _ResourceSelectDD.options.Clear();
     _WorkbrenchSelectDD.options.Clear();
     if (_SetDefaults)
     {
         _ScrollSpeed    = 3f;
         _RotateSpeed    = 0.1f;
         _AngleLimit     = 75;
         _TransformSpeed = 0.015f;
     }
     foreach (Resource _r in Resources.ResourceLibrary.FindAll(x => x.MayBeUsedInStructures))
     {
         _ResourceSelectDD.options.Add(new Dropdown.OptionData(_r.Name, _r.Sprite));
         _ResourceSelectDD.value = 1;
         _ResourceSelectDD.value = 0;
         Debug.Log("Resource " + _r.Name + " added to select");
     }
     foreach (WorkbenchTemplate _t in Workbenches.Templates)
     {
         _WorkbrenchSelectDD.options.Add(new Dropdown.OptionData(_t.Name));
         _PhantomWorkbench = null;
     }
 }
Beispiel #10
0
    void Update()
    {
        if (!_BuildModeOff)
        {
            //Camera moving rules
            if (Input.mouseScrollDelta.y < 0 && _BasicObject.transform.localScale.x > 0.1f)
            {
                _BasicObject.transform.localScale += Vector3.one * (_ScrollSpeed * Input.mouseScrollDelta.y * Time.deltaTime); // когда крутишь колесиком, надо чуть чуть смещать основной блок к центру. (или отдалять)
                _BasicObject.transform.position   -= Vector3.Normalize(_Center - _BasicObject.transform.position) * (_ScrollSpeed * Input.mouseScrollDelta.y * Time.deltaTime);
            }
            if (Input.mouseScrollDelta.y > 0 && _BasicObject.transform.localScale.x < 25f)
            {
                _BasicObject.transform.localScale += Vector3.one * (_ScrollSpeed * Input.mouseScrollDelta.y * Time.deltaTime);
                _BasicObject.transform.position   -= Vector3.Normalize(_Center - _BasicObject.transform.position) * (_ScrollSpeed * Input.mouseScrollDelta.y * Time.deltaTime);
            }
            if (Input.GetMouseButtonDown(1))
            {
                _PreviousMousePosition = Input.mousePosition;
            }
            if (Input.GetMouseButton(1))
            {
                _HorisontalDeltaPos = (_PreviousMousePosition.x - Input.mousePosition.x);
                _VerticalDeltaPos   = -(_PreviousMousePosition.y - Input.mousePosition.y);
                _BasicObject.transform.RotateAround(_BasicObject.transform.up, _HorisontalDeltaPos * _RotateSpeed / 32); // нужно чтоб фигура вращалась вокруг центра, а не вокруг основного блока. А для этого нужно перемещать основной блок немножко в сторону
                _BasicObject.transform.RotateAround(_RightForCameraDirection, _VerticalDeltaPos * _RotateSpeed / 32);
                _PreviousMousePosition = Input.mousePosition;
            }
            if (Input.GetMouseButtonDown(2))
            {
                _PreviousMousePosition = Input.mousePosition;
            }
            if (Input.GetMouseButton(2))
            {
                _VerticalDeltaPos = _PreviousMousePosition.y - Input.mousePosition.y;
                _BasicObject.transform.Translate(Vector3.up * _VerticalDeltaPos * -1 * _TransformSpeed);
                _HorisontalDeltaPos              = _PreviousMousePosition.x - Input.mousePosition.x;
                _BasicObject.transform.position += _RightForCameraDirection * _HorisontalDeltaPos * -1 * _TransformSpeed;
                _PreviousMousePosition           = Input.mousePosition;
            }

            //User inputs reaction
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (_IsHit)
                {
                    Highlighter.UnHighLight(_Hit.transform.gameObject);
                }
                _IsHit = Physics.Raycast(Links.MainCamera.ScreenPointToRay(Input.mousePosition), out _Hit, 200, _mask);
                if (_IsHit)
                {
                    /*if(_Hit.transform.tag == "Brick")*/ Highlighter.HighLight(_Hit.transform.gameObject);
                    //Debug.Log("Dont touch my " + _Hit.transform.name + "!!!1!11odinodin");
                    if (Input.GetKey("r"))
                    {
                        _Hit.transform.gameObject.GetComponent <Renderer>().material = Resources.ResourceLibrary[_ResourceSelectDD.value].Material;
                    }
                    if (Input.GetMouseButtonDown(0) && _Hit.transform.tag == "Brick")
                    {
                        if (_PhantomWorkbench != null)
                        {
                            Highlighter.UnHighLight(_Hit.transform.gameObject);
                            _IsHit = false;
                            _PhantomWorkbench.UnPhantomize();
                            _BuildingWorkbenches.Add(_PhantomWorkbench);
                            Debug.Log("Create workbench, master local position is:" + _PhantomWorkbench.MasterObject.transform.localPosition);
                            ClearASpaceForWorkbench(_BuildingWorkbenches.Count - 1);
                            _PhantomWorkbench = null;
                        }
                        else
                        {
                            _Normal           = _Hit.normal;
                            _NewBrickPosition = _Hit.transform.position + _Normal * _BasicObject.transform.lossyScale.x;
                            _BuildingElements.Add(Instantiate(Settings.BrickPrefab, _NewBrickPosition, _Hit.transform.rotation));
                            _BuildingElements[_BuildingElements.Count - 1].transform.localScale = _BasicObject.transform.localScale;
                            _BuildingElements[_BuildingElements.Count - 1].layer = 9;
                            _BuildingElements[_BuildingElements.Count - 1].transform.SetParent(_BasicObject.transform, true);
                            _BuildingElements[_BuildingElements.Count - 1].GetComponent <Renderer>().material = Resources.ResourceLibrary.Find(x => x.Name == _ResourceSelectDD.options[_ResourceSelectDD.value].text).Material;
                        }
                    }
                    if (_PhantomWorkbench != null)
                    {
                        _PhantomWorkbench.Hide();
                        _PhantomWorkbench.Show(_Hit.transform.localPosition);
                        if (Input.GetKeyDown("r"))
                        {
                            _PhantomWorkbench.Rotate();
                        }
                    }
                    if (Input.GetKeyUp("d"))
                    {
                        _IsHit = false;
                        switch (_Hit.transform.tag)
                        {
                        case "Brick":
                            _BuildingElements.Remove(_Hit.transform.gameObject);
                            Destroy(_Hit.transform.gameObject);
                            break;

                        case "WorkbenchBrick":
                            _BuildingWorkbenches.RemoveAll(x => x.MasterObject == _Hit.transform.parent.gameObject);
                            Destroy(_Hit.transform.parent.gameObject);
                            break;

                        default:
                            break;
                        }
                        if (_PhantomWorkbench != null)
                        {
                            _PhantomWorkbench.Hide();
                        }
                    }
                }
                else
                if (_PhantomWorkbench != null)
                {
                    _PhantomWorkbench.Hide();
                }
                if (Input.GetMouseButtonDown(1))
                {
                    if (_PhantomWorkbench != null)
                    {
                        _PhantomWorkbench.Destroy();
                        _PhantomWorkbench = null;
                    }
                }
            }
        }
    }
Beispiel #11
0
 public void WorkbenchSelect(int _wbnum)
 {
     Debug.Log(_wbnum);
     _PhantomWorkbench = new PhantomConstruction(Workbenches.Templates[_wbnum]);
     _PhantomWorkbench.MasterObject.transform.SetParent(_BasicObject.transform, false);
 }
 void Update()
 {
     if (!_PopupMode)
     {
         if (_CurrentObject != null)
         {
             Highlighter.UnHighLight(_CurrentObject);
             _CurrentObject = null;
         }
         if (_CurrentUnit != null)
         {
             Highlighter.UnHighLight(_CurrentUnit);
             _CurrentUnit = null;
         }
         if (Input.GetKeyDown("z"))
         {
             Settings.ZoneRod.SetActive(true);
         }
         if (Input.GetKeyUp("z") && _ZoneStartPoint == null)
         {
             Settings.ZoneRod.SetActive(false);
         }
         if (!EventSystem.current.IsPointerOverGameObject())             //Изучить. Непонятно что это, но работает
         {
             _CameraRay = _Camera.ScreenPointToRay(Input.mousePosition); //создаем луч, идущий из камеры через координаты мышки
             _IsHit     = Physics.Raycast(_CameraRay, out _Hit, 1000, mask);
             if (_IsHit)
             {
                 if (_Hit.transform.tag == "Brick")
                 {
                     if ((_BuildingMode) && (_Hit.transform.gameObject != _CurrentObject))
                     {
                         _PhantomBuilding.Hide();
                         _PhantomBuilding.Show(_Hit.transform.position);
                     }
                     _CurrentObject = _Hit.transform.gameObject;
                     Highlighter.HighLight(_CurrentObject);
                     if (Settings.ZoneRod.activeInHierarchy)
                     {
                         Settings.ZoneRod.transform.SetParent(_CurrentObject.transform, false);
                     }
                 }
                 if (_Hit.transform.tag == "Unit")
                 {
                     _CurrentUnit = _Hit.transform.gameObject;
                     Highlighter.HighLight(_CurrentUnit);
                 }
             }
             if (Input.GetMouseButtonDown(0))
             {
                 if (PickedObject != null)
                 {
                     Highlighter.UnPick(PickedObject);
                 }
                 if (_IsHit)
                 {
                     if (_Hit.transform.tag == "Brick" && _BuildingMode)
                     {
                         new ProcessManager.Building(_PhantomBuilding);
                         //Building _b = new Building(_BuildingSelectionDD.value, _PhantomBuilding.Rotation, _PhantomBuilding.MasterObject.transform.position);
                         //_PhantomBuilding.Destroy();
                         //Brick_intreraction_script.AddBuilding(_b);
                         _PhantomBuilding = null;
                         _BuildingMode    = false;
                     }
                     else
                     {
                         if (Settings.ZoneRod.activeInHierarchy) //В режиме выбора зоны
                         {
                             if (_ZoneStartPoint == null)        //Стартовая точка не задана
                             {
                                 _ZoneStartPoint = Instantiate(Settings.ZoneRod);
                                 _ZoneStartPoint.transform.SetParent(_CurrentObject.transform, false);
                             }
                             else //Стартовая точка задана
                             {
                                 //_ZoneEndPoint = Settings.ZoneRod; Пока написана херня для теста
                                 _ZoneEndPoint = Instantiate(Settings.ZoneRod);
                                 _ZoneEndPoint.transform.SetParent(_CurrentObject.transform, false);
                                 Settings.ZoneRod.SetActive(false);
                                 Links.Interface.SwitchToZoneMenu(0);
                             }
                         }
                         PickedObject = _Hit.transform.gameObject;
                         PickedObject.BroadcastMessage("Click");
                         Highlighter.Pick(PickedObject);
                         _Normal = _Hit.normal;
                         Log.Notice(scr + scrm, "Picked Object : " + PickedObject.name);
                     }
                 }
                 else
                 {
                     PickedObject = null;
                     Settings.ZoneRod.SetActive(false);
                     Destroy(_ZoneStartPoint);
                 }
             }
         }
         if (Input.GetKeyDown("a"))
         {
             if (PickedObject != null && PickedObject.tag == "Unit")
             {
                 if (_ActorUnit != null)
                 {
                     Highlighter.UnPick(_ActorUnit);
                 }
                 _ActorUnit   = PickedObject;
                 PickedObject = null;
                 Highlighter.BrightPick(_ActorUnit);
             }
             else
             {
                 if (_ActorUnit != null)
                 {
                     Highlighter.UnPick(_ActorUnit);
                 }
                 _ActorUnit = null;
             }
         }
         if (Input.GetKeyDown("r"))
         {
             if (_PhantomBuilding != null)
             {
                 _PhantomBuilding.Rotate();
             }
         }
         if (Input.GetMouseButton(1) && _ActorUnit != null)
         {
             Log.Notice(scr, "Walking");
             if ((_IsHit) && (_Hit.normal == Vector3.up))
             {
                 //_Normal.x = Mathf.RoundToInt(_Hit.point.x);
                 //_Normal.z = Mathf.RoundToInt(_Hit.point.z);
                 //_Normal.y = _Hit.point.y;
                 Log.Notice(scr, "Waybuilder call");
                 //_ActorUnit.GetComponent<RouteBuilder>().Build(_Normal);
                 _ActorUnit.GetComponent <Unit>().GoTo(_Hit.point);
             }
         }
         if (Input.GetMouseButton(1))//Massive reject
         {
             _BuildingMode = false;
             if (_PhantomBuilding != null)
             {
                 _PhantomBuilding.Destroy();
                 _PhantomBuilding = null;
             }
             CancelZoneCreation();
         }
         if (PickedObject != null && PickedObject.tag == "Unit" && Input.GetKey("l"))
         {
             PickedObject.GetComponent <RouteBuilder>().LogRoute();
         }
         if (Input.GetKey("o"))
         {
             if (!(PickedObject == null || PickedObject.tag == "Unit"))
             {
                 CreateUnit(PickedObject.transform.position);
                 Highlighter.UnPick(PickedObject);
                 PickedObject = null;
             }
             else
             {
                 Log.Notice(scr, "There is no picked cube");
             }
         }
     }
     else // Popup is open
     {
     }
 }