Beispiel #1
0
 static void InitUnits()
 {
     UpgradePool.Init();
     AbilityPool.Init();
     UnitPool.Init();
     AbilityPool.PoolInit();
 }
Beispiel #2
0
    void UnitPoolCreate(Transform parent, UnitType type, Data.UnitContainer container)
    {
        m_unitPools[type] = new Dictionary <int, UnitPool>();

        for (int i = 0; i < container.GetUnitCount(type); i++)
        {
            CUnitData unitData = container.GetUnitData(type, i);
            if (unitData != null)
            {
                UnitPool pool = new UnitPool();
                pool.unitData      = unitData;
                pool.nBufferAmount = type != UnitType.Boss ? m_unitAmount:1;
                pool.pooledList    = new Stack <GameObject>();

                for (int j = 0; j < pool.nBufferAmount; j++)
                {
                    if (unitData.UnitPrefab == null)
                    {
                        break;
                    }
                    GameObject poolObj = Instantiate(unitData.UnitPrefab);
                    poolObj.name             = unitData.UnitPrefab.name;
                    poolObj.transform.parent = parent;
                    poolObj.SetActive(false);
                    pool.pooledList.Push(poolObj);
                }

                m_unitPools[type].Add(i, pool);
            }
        }
    }
Beispiel #3
0
    public GameObject GetUnit(UnitType type, int nIdx)
    {
        UnitPool unitPool = m_unitPools[type][nIdx];

        if (unitPool == null)
        {
            return(null);
        }

        if (unitPool.pooledList.Count < 1)
        {
            if (m_canBeGrow)
            {
                GameObject newUnit = Instantiate(unitPool.unitData.UnitPrefab);
                newUnit.name = unitPool.unitData.UnitPrefab.name;
                return(newUnit);
            }
            else
            {
                return(null);
            }
        }

        GameObject outPut = unitPool.pooledList.Pop();

        outPut.transform.parent = null;
        //outPut.SetActive(true);

        return(outPut);
    }
Beispiel #4
0
 public UnitInfo(UnitPool unitPool, int unitCode, int lv)
 {
     this.unitPool = unitPool;
     this.unitCode = unitCode;
     this.lv       = lv;
     this.hp       = MaxHp;
     this.sp       = MaxSp;
     this.exp      = 0;
 }
Beispiel #5
0
 private void LoadContent_UnitSprites(ContentManager Content)
 {
     //generate a dictionary of unit types to their sprite.
     // makes drawing each unit's sprite a lot easier
     foreach (Type unitType in UnitPool.GetUnitPool())
     {
         string directory = (string)unitType.GetField("SpriteReference").GetRawConstantValue();
         unitSprites[unitType] = Content.Load <Texture2D>(directory);
     }
 }
Beispiel #6
0
    //Init
    void Start()
    {
        grid     = FindObjectOfType <Grid>();
        camera   = FindObjectOfType <Camera>();
        gameMan  = FindObjectOfType <GameManager>();
        unitPool = FindObjectOfType <UnitPool>();

        selectedUnit = null;
        mouseUpCheck = 0;
    }
Beispiel #7
0
 void Start()
 {
     m_UnitPool            = GetComponent <UnitPool>();
     m_Spawner             = GetComponent <UnitSpawnerManager>();
     m_CanvasRectTransform = m_Canvas.gameObject.GetComponent <RectTransform>();
     m_SelectableSymbols.gameObject.SetActive(false);
     m_UpgradeMenuOpen = false;
     m_UpradesGroup.SetActive(false);
     m_SelectMenuActive = false;
 }
 public override void onPopUp(object[] args)
 {
     base.onPopUp(args);
     this._playerId = (int)args[1];
     this._isCheck = (bool)args[2];
     this._curUnitPool = BattleGlobal.Core.getPlayer(this._playerId).unitPool;
     this._curIndex = 0;
     this.updateView();
     this.addListener();
 }
Beispiel #9
0
    private void Awake()
    {
        character = GetComponent <Character>();
        myHealth  = GetComponent <Health>();

        animator    = GetComponent <Animator>();
        audioSource = GetComponent <AudioSource>();

        theEnemyPool = EnemyPool.Instance;
        theUnitPool  = UnitPool.Instance;
    }
        public static Unit ClickHandler(Player _player, double mouseX, double mouseY, string areaPos, Unit container, List <Unit> units)
        {
            Unit unit = null;

            if (areaPos == "")
            {
                return(unit);
            }

            string[] areaCoord = areaPos.Split('|');
            if (areaCoord.Count() != 4)
            {
                return(unit);
            }

            float top    = 0;
            float right  = 0;
            float bottom = 0;
            float left   = 0;

            float.TryParse(areaCoord[0], out top);
            float.TryParse(areaCoord[1], out right);
            float.TryParse(areaCoord[2], out bottom);
            float.TryParse(areaCoord[3], out left);

            Vector2 newpos    = new Vector2((float)mouseX - left, (float)mouseY - top);
            Vector2 newintpos = new Vector2((float)Math.Round((newpos.X / 1000) * paxgame.Buildareasize.Y, MidpointRounding.AwayFromZero) / 2, (float)Math.Round((newpos.Y / 400) * paxgame.Buildareasize.X, MidpointRounding.AwayFromZero) / 2);

            unit = units.SingleOrDefault(x => x.PlacePos == newintpos && x.Status != UnitStatuses.Available);

            if (container != null && container.Status == UnitStatuses.Available && unit == null)
            {
                unit          = UnitPool.GetCopy(container.Name);
                unit.PlacePos = newintpos;
                return(unit);
            }
            else if (unit != null)
            {
                return(unit);
            }
            else if (container != null && container.Status != UnitStatuses.Available && unit == null)
            {
                container.PlacePos = newintpos;
                UnitService.NewUnitPos(_player, container);
                return(null);
            }
            else
            {
                return(null);
            }
        }
    } // void Initialize

    protected bool clearGLOBAL(bool isSkipLoadedData = false)
    {
        try
        {
            //@ Release & Clear Triangle, DrawMesh, Object Dyn
            UnitPool unitpool_ = UnitPool.GetInstance;
            unitpool_.TruncateAll();

            m_intervalUnitWalking.DestructIntervalsAll();
            m_processInput.DestructInput();

            if (false == isSkipLoadedData)
            {
                m_stageMap.Release();
            }

            m_baseTowerCollector.DestructBaseAll();
            m_baseCoreCollector.DestructBaseAll();
            m_baseCoresubCollector.DestructBaseAll();
            m_baseStartCollector.DestructBaseAll();
            m_baseBlockCollector.DestructBaseAll();

            m_toolmoduleNavimesh.ReleaseNaviMeshTool();

            if (null != m_meshNavigation_global)
            {
                m_meshNavigation_global.DestructNaviMesh();
                m_meshNavigation_global = null;
            }

            GC.Collect();

            return(true);
        }
        catch (Exception e)
        {
            Debug.Log(e);
            return(false);
        }
    } // protected void clearGLOBAL()
Beispiel #12
0
    public void PooledObject(GameObject unitObj, CUnitData data, UnitType type, int nIdx)
    {
        UnitPool pool = m_unitPools[type][nIdx];

        if (pool == null)
        {
            Destroy(unitObj);
            return;
        }

        if (pool.pooledList.Count >= pool.nBufferAmount)
        {
            if (!m_canBeGrow)
            {
                Destroy(unitObj);
                return;
            }
        }

        unitObj.SetActive(false);
        unitObj.transform.parent = m_unitParent.transform;
        pool.pooledList.Push(unitObj);
    }
    //protected void FlyAttackMove(float deltaTime)
    //{
    //    if (MoveCore == 0)      //  타겟으로 이동
    //    {
    //        //transform.root.Translate(targetDirection);
    //        positionUnit = transform.root.position + targetDirection * deltaTime;
    //        if (Vector3.Distance(transform.root.position, targetPostion) <= 0.1f)
    //            MoveCore = 1;

    //    }
    //    else if (MoveCore == 1)     //  타겟주위에서 비행
    //    {
    //        if (bezierElapsedTime == 0.0f)
    //        {
    //            bezierPoint[0] = targetPostion;
    //            Quaternion q = Quaternion.Euler(0, 90, 0);
    //            bezierPoint[1] = targetPostion + bezierDirection * bezierTurningRadius + q * bezierDirection * bezierTurningRadius * bezierRotationDir;
    //            bezierPoint[2] = targetPostion + bezierDirection * bezierTurningRadius - q * bezierDirection * bezierTurningRadius * bezierRotationDir;
    //        }
    //        bezierElapsedTime += deltaTime;
    //        positionUnit = CMATH.Bezier(bezierPoint[0], bezierPoint[1], bezierPoint[2], bezierPoint[0],
    //            (bezierElapsedTime / bezierTimePerTurning > 1.0f ? 1.0f : bezierElapsedTime / bezierTimePerTurning));
    //        if (bezierElapsedTime >= bezierTimePerTurning)
    //        {
    //            bezierElapsedTime = 0.0f;
    //            bezierDirection = -bezierDirection;
    //            if (bezierRotationDir == 1)
    //                bezierRotationDir = -1;
    //            else
    //                bezierRotationDir = 1;

    //        }
    //    }
    //}

    protected void FlyAttackMove(float deltaTime)
    {
        if (aroundUnits.Count > 0)
        {
            UnitPool unitPool = UnitPool.GetInstance;
            UnitBase unit = null;
            int count = 0;

            //if (m_UnitTemplate.m_AttackTerm <= m_AttackTime)
            {
                foreach (int unitID in aroundUnits)
                {
                    unit = unitPool[unitID];
                    if (unit != null && !unit.IsUnitDie())
                    {
                        adjustAttackPosition += transform.position - unit.transform.position;
                        count++;
                    }
                }
            }

            if (count != 0)
            {
                adjustAttackPosition = Vector3.Normalize(adjustAttackPosition) * deltaTime * speedmove;
                positionUnit += adjustAttackPosition;
            }
        }
        else
        {
            if (isCollisionArtMap)
            {
                adjustAttackPosition = Vector3.Normalize(adjustAttackPosition) * deltaTime * speedmove;
                positionUnit += adjustAttackPosition;
            }
        }
    }
 public void init()
 {
     this._unitPool = new UnitPool();
     this._unitPool.init();
 }
Beispiel #15
0
 public void init()
 {
     this._unitPool = new UnitPool();
     this._unitPool.init();
     this.curHp = BattleConsts.DEFAULT_HP;
     this.curBPoint = BattleConsts.DEFAULT_BPOINT;
 }
    } // void calculatePosCollision(Vector3 v3DirForceCollide, float fTimeDelta, Vector3 v3PosObject, CNaviMesh meshNavi)

    bool Update_Collision_sameforce(float fTimeDelta, CNaviMesh meshNavi, ref SortedDictionary<int, float> listCollider)
    {
        //@1.Forced setting, Cell wasn't prepared go to way to goal.
        if (false == _bProcessWalking_Static)
        {
            return false;
        }
        //@2.No landing mesh.
        if (null == meshNavi)
        {
            return false;
        }

        UnitPool unitpool = UnitPool.GetInstance;

        //@ 1 more colliders 
        if (listCollider.Count > 0)
        {
            //@ If unit is null, Delete unit from collideList.
            List<UnitWalking> listCollideCollect = new List<UnitWalking>();
            ICollection<int> collectionID = listCollider.Keys;
            List<int> listcollideremove = new List<int>();

            foreach (int idunit in collectionID)
            {
                UnitWalking unitWalking = unitpool[idunit] as UnitWalking;
                if (null == unitWalking)
                {
                    listcollideremove.Add(idunit);
                }
                else
                {
                    if (true == unitWalking.IsUnitDie())
                    {
                        listcollideremove.Add(idunit);
                    }
                    else
                    {
                        float fdistInterEstimate = (unitWalking.m_fRadius_aabb * unitWalking.m_fRadius_aabb + m_fRadius_aabb * m_fRadius_aabb);
                        float fdistInterCurr = (positionUnit - unitWalking.positionUnit).sqrMagnitude;

                        if (fdistInterEstimate > fdistInterCurr)
                        {
                            listCollideCollect.Add(unitWalking);
                        }
                    }
                }
            } // foreach (int idunit in collectionID)

            //@ for safety elimination
            foreach (int idunitremove in listcollideremove)
            {
                listCollider.Remove(idunitremove);
            }

            if (listCollideCollect.Count == 0)
            {
                return false;
            }

            Vector3 v3DirForceCollide = Vector3.zero;
            Vector3 v3PosCurrent = positionUnit, v3PosOther, v3DistanceOther;

            int iCntActualCollide = 0;
            foreach (UnitWalking colliderUnitWalking in listCollideCollect)
            {
                v3PosOther = colliderUnitWalking.positionUnit;
                v3DistanceOther = (positionUnit - v3PosOther).normalized;

                if (colliderUnitWalking.IsUnitAttack())
                {
                    v3DistanceOther = v3DistanceOther.normalized * spdcollision_unit;
                }

                v3DirForceCollide = v3DirForceCollide + v3DistanceOther;
                iCntActualCollide++;
            }

            v3DirForceCollide = v3DirForceCollide.normalized;

            if (Vector3.zero != v3DirForceCollide)
            {
                calculatePosCollision(v3DirForceCollide, fTimeDelta, v3PosCurrent, meshNavi);
            }
        } // if (listCollider.Count > 0)

        return true;
    } // void Update_Collision_sameforce()
 // Use this for initialization
 void Awake()
 {
     _instance = this;
     PreparePools();
 }