Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     rb                    = this.GetComponent <Rigidbody2D>();
     _animator             = this.GetComponent <Animator>();
     _shadow               = ob.GetComponent <FogOfWarUnit>();
     ob.transform.position = this.transform.position;
 }
        //initialize the faction entity
        protected virtual void Init(GameManager gameMgr, int fID, bool free)
        {
            base.Init(gameMgr);

            //get the components that are attached to the faction entity:
            TaskLauncherComp  = GetComponent <TaskLauncher>();
            APCComp           = GetComponent <APC>();
            MultipleAttackMgr = GetComponent <MultipleAttackManager>();
            EntityHealthComp  = GetComponent <FactionEntityHealth>();

            //initialize these components
            //task launcher must be initialized separately on units and buildings
            if (APCComp)
            {
                APCComp.Init(gameMgr, this);
            }
            EntityHealthComp.Init(gameMgr, this);

#if RTSENGINE_FOW
            FoWUnit = GetComponent <FogOfWarUnit>();
#endif

            selection.FactionEntity = this; //assign as the selection's source faction entity

            //initial settings for the double click
            clickedOnce      = false;
            doubleClickTimer = 0.0f;

            this.free = free;

            if (this.free == false)                                            //if the entity belongs to a faction
            {
                factionID  = fID;                                              //set the faction ID.
                FactionMgr = gameMgr.GetFaction(factionID).FactionMgr;         //get the faction manager
                UpdateFactionColors(gameMgr.GetFaction(factionID).GetColor()); //update the faction colors on the unit

                gameMgr.ResourceMgr.UpdateResource(factionID, initResources);  //add the initialization resources to the entity's faction.
            }
            else
            {
                factionID = -1;
            }
        }
Ejemplo n.º 3
0
 private void Awake()
 {
     parent       = GetComponent <ParentObject>();
     fogOfWarUnit = GetComponent <FogOfWarUnit>();
 }
Ejemplo n.º 4
0
    void Update()
    {
        // select unit
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            RaycastHit hit;
            if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out hit))//, unitLayer))
            {
                FogOfWarUnit unit = hit.collider.GetComponent <FogOfWarUnit>();
                if (unit != null)
                {
                    int index = _units.FindIndex(((u) => u.unit == unit));
                    if (index != -1)
                    {
                        _units.Add(_units[index]);
                        _units.RemoveAt(index);
                    }
                    else
                    {
                        _units.Add(new FOWUnit(unit));
                    }
                }
            }
        }

        // move unit
        if (_units.Count > 0 && (Input.GetKeyDown(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.Mouse2)))
        {
            RaycastHit[] hits = Physics.RaycastAll(_camera.ScreenPointToRay(Input.mousePosition));
            if (hits.Length > 0)
            {
                Vector3 p = hits[hits.Length - 1].point;
                p.y = 1.0f;
                _units[_units.Count - 1].destination = p;
            }
        }

        // update units
        float moveamount = unitMoveSpeed * Time.deltaTime;

        for (int i = 0; i < _units.Count; ++i)
        {
            FOWUnit u         = _units[i];
            Vector3 direction = u.destination - u.position;
            direction.y = 0.0f;
            if (direction.sqrMagnitude < moveamount * moveamount)
            {
                u.position = new Vector3(u.destination.x, u.position.y, u.destination.z);
            }
            else
            {
                u.position         += direction.normalized * moveamount;
                u.transform.forward = direction;
            }
        }

        // update highlight
        if (_units.Count > 0)
        {
            highlight.position = new Vector3(_units[_units.Count - 1].position.x, 0.1f, _units[_units.Count - 1].position.z);
            highlight.gameObject.SetActive(true);
        }

        // update camera
        _cameraTransform.position += new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * (Time.deltaTime * cameraSpeed);

        // update camera zooming
        float zoomchange = Input.GetAxis("Mouse ScrollWheel");

        _cameraTransform.position = new Vector3(_cameraTransform.position.x, Mathf.Clamp(_cameraTransform.position.y - zoomchange * 10, 25, 50), _cameraTransform.position.z);
    }
Ejemplo n.º 5
0
 public FOWUnit(FogOfWarUnit u)
 {
     unit        = u;
     transform   = unit.transform;
     destination = unit.transform.position;
 }