示例#1
0
    //-Implementation
    private void Awake()
    {
        _sprite = XUtils.getComponent <SpriteRenderer>(
            gameObject, XUtils.AccessPolicy.ShouldExist
            );

        _collider = XUtils.getComponent <BoxCollider2D>(
            gameObject, XUtils.AccessPolicy.ShouldExist
            );

        XUtils.getComponent <MouseAttachComponent>(
            gameObject, XUtils.AccessPolicy.ShouldBeCreated
            ).onMouseMove += (Vector2 inMousePosition) => {
            updateColor();
        };

        XUtils.getComponent <MouseClickTrackingComponent>(
            gameObject, XUtils.AccessPolicy.ShouldBeCreated
            ).onClick += () => {
            if (!isPossibleToBuild())
            {
                return;
            }

            ConstructionSiteObject theConstructionSite = createConstructionSite();
            getUIInterface().processConstructionStart(theConstructionSite);

            Destroy(gameObject);
        };
    }
示例#2
0
 internal void removeWayElementsUpToEnd(int inBeginIndex)
 {
     _wayElements.removeElementsUpToEnd(inBeginIndex,
                                        (HierarchicalGridWayUIElement inWayElement) =>
     {
         XUtils.getComponent <RectTransform>(
             inWayElement.gameObject, XUtils.AccessPolicy.ShouldExist
             ).SetParent(null);
     });
 }
示例#3
0
    void Awake()
    {
        _carRigidBody = XUtils.getComponent <Rigidbody2D>(
            _car, XUtils.AccessPolicy.ShouldExist
            );

        _camera = XUtils.getComponent <Camera>(
            gameObject, XUtils.AccessPolicy.ShouldExist
            );
    }
示例#4
0
    //-Internal API
    internal void addWayElement(HierarchicalGridWayUIElement inWayElement)
    {
        XUtils.getComponent <LayoutElement>(
            inWayElement, XUtils.AccessPolicy.ShouldBeCreated
            ).flexibleHeight = 1;

        XUtils.getComponent <RectTransform>(
            inWayElement, XUtils.AccessPolicy.ShouldExist
            ).SetParent(_rectTransformForPlacingWayElements, false);

        _wayElements.add(inWayElement);
    }
示例#5
0
    //Methods
    //-API
    public void attach(
        GameObject inUI, WorldObjectAttachPoint inAttachPoint, bool inDestroyUIWithObject = true)
    {
        XUtils.getComponent <RectTransform>(
            inUI, XUtils.AccessPolicy.ShouldExist
            ).SetParent(_worldAttachTransform, false);

        var theNewAttach = new UIAttach_ToWorldObjectAttachPoint(
            inUI.GetComponent <RectTransform>(), inAttachPoint, inDestroyUIWithObject
            );

        _uiAttaches_toWorldObjectAttachPoint.add(theNewAttach);
    }
示例#6
0
    private void refreshShowingElement()
    {
        XUtils.check(_elementShownInGrid);

        _gridRectTransform.DetachChildren();

        foreach (HierarchicalUIElementObject theChildElement in _elementShownInGrid._elements)
        {
            XUtils.getComponent <RectTransform>(
                theChildElement, XUtils.AccessPolicy.ShouldExist
                ).SetParent(_gridRectTransform, false);
        }
    }
示例#7
0
    private void Awake()
    {
        _selectButton.onClick.AddListener(() => {
            select();
        });

        var theTransform = XUtils.getComponent <RectTransform>(
            this, XUtils.AccessPolicy.ShouldExist
            );
        Vector2 theSize = theTransform.sizeDelta;

        theSize.x = 100;
        theTransform.sizeDelta = theSize;
    }
示例#8
0
    //-Car control
    private void Update_CarControl()
    {
        //Car movement update
        if (_isGasIsPressed)
        {
            _carPhysics.applyGas();
        }
        if (_isReversIsPressed)
        {
            _carPhysics.applyRevers();
        }

        if (_isClockwiseRotatePressed)
        {
            _carPhysics.rotateSteeringWheelClockwise();
        }
        if (_isCounterClockwiseRotatePressed)
        {
            _carPhysics.rotateSteeringWheelCounterClockwise();
        }

        //Car shooting update
        if (_isMouseButtonPressed)
        {
            foreach (WeaponLogic theGunLogic in _weaponsLogic)
            {
                theGunLogic.doShoot();
            }
        }

        foreach (WeaponLogic theGunLogic in _weaponsLogic)
        {
            var theTargetComponent =
                XUtils.getComponent <RotateToTargetAngleLogic>(theGunLogic);
            if (!theTargetComponent)
            {
                continue;
            }

            Vector2 theTurretPosition = theGunLogic.transform.position;
            Vector2 theDelta          = XUtils.getMouseWorldPosition() - theTurretPosition;

            theTargetComponent.setTargetAngle(
                Mathf.Atan2(theDelta.y, theDelta.x) * Mathf.Rad2Deg
                );
        }
    }
示例#9
0
    //TODO: Find how to organize Damage API Classes better
    public static void applyDamage(GameObject inGameObject, Damage inDamage)
    {
        XUtils.check(inGameObject);
        var theDamageProxy = XUtils.getComponent <DamageProxy>(
            inGameObject, XUtils.AccessPolicy.JustFind
            );

        if (theDamageProxy)
        {
            theDamageProxy.applyDamage(inDamage);
            return;
        }

        var theDurability = XUtils.getComponent <DurabilityComponent>(
            inGameObject, XUtils.AccessPolicy.JustFind
            );

        if (theDurability)
        {
            theDurability.changeHitPoints(-inDamage.damageAmount);
        }
    }
示例#10
0
    BuildingSelectionUIElementObject createBuildingSelectionUI(
        BuildingScheme inBuildingSceme)
    {
        GameObject theBuildingSelectionUIGameObject =
            Instantiate(_buildingSelectionUIElementPrefab);
        var theBuildingSelectionUI =
            XUtils.getComponent <BuildingSelectionUIElementObject>(
                theBuildingSelectionUIGameObject, XUtils.AccessPolicy.ShouldExist
                );

        theBuildingSelectionUI.init(inBuildingSceme,
                                    (BuildingScheme inBuildingScheme) =>
        {
            BuildingPlanObject theBuildingPlan = XUtils.createObject(
                inBuildingScheme.buildingPlan
                );
            theBuildingPlan.init(_carCity);
            theBuildingPlan.getUIInterface().init(
                _carCity, _constructionSiteUIPrefab
                );
        });

        return(theBuildingSelectionUI);
    }
示例#11
0
 //-Implementation
 private void Awake()
 {
     _camera = XUtils.getComponent <Camera>(
         this, XUtils.AccessPolicy.ShouldExist
         );
 }
示例#12
0
 private void Awake()
 {
     _lineRender = XUtils.getComponent <LineRenderer>(
         this, XUtils.AccessPolicy.ShouldExist
         );
 }
示例#13
0
 public BuildingPlanUIInterface getUIInterface()
 {
     return(XUtils.getComponent <BuildingPlanUIInterface>(
                this, XUtils.AccessPolicy.CreateIfNo
                ));
 }
示例#14
0
 //-Implementation
 private void Awake()
 {
     _durabilityComponent = XUtils.getComponent <DurabilityComponent>(
         this, XUtils.AccessPolicy.ShouldExist
         );
 }