// // Update is called once per frame
    // void Update ()
    // {
    //
    // }

    public void Load(string name, ResourceDelegate completeDel)
    {
        if (GameDefines.USE_ASSET_BUNDLE)
        {
            // Parse the relative path
            string url     = string.Empty;
            int    version = -1;
            if (name.IndexOf("file://") == 0)
            {
                // Local download bundle
                url     = name;
                version = -1;
            }
            else
            {
                name    = name.Substring(name.LastIndexOf("/") + 1);
                url     = GameDefines.GetUrlBase() + GetCachePath(name) + name + ".assetbundle";
                version = GetCacheID(name);
            }

            LoadBundle(url, version, completeDel);
        }
        else
        {
            // Use the path relative to Resources
            LoadLocal(name, completeDel);
        }
    }
Beispiel #2
0
    void ParseDownloadStrategy()
    {
        if (GameDefines.IsUseStream())
        {
            AssetBundle  ab     = GetBundle(BUND_DOWNLOAD);
            TextAsset    ta     = ab.mainAsset as TextAsset;
            MemoryStream stream = new MemoryStream(ta.bytes);
            StreamReader sr     = new StreamReader(stream);
            while (!sr.EndOfStream)
            {
                string bundName = sr.ReadLine();
                m_resourceList.Add(bundName);

                /*
                 * int cacheID = GetCacheID(bundName);
                 * string url = GameDefines.GetUrlBase() + GetCachePath(bundName) + bundName + ".assetbundle";
                 * if (Caching.IsVersionCached (url, cacheID)) {
                 *      Debug.Log("----url=" + url + " cached");
                 * } else {
                 *  WwwLoaderManager.CreateLoader(url, cacheID);
                 * }
                 */
            }
        }
    }
Beispiel #3
0
    public static void InitializeWithScene()
    {
        var settingsGo = GameObject.Find("Defines");

        Defines = settingsGo?.GetComponent <GameDefines>();
        //Assert.IsNotNull(Defines);
    }
Beispiel #4
0
 void ParseVersionData()
 {
     if (GameDefines.IsUseStream())
     {
         AssetBundle  ab     = GetBundle(BUND_VERSION);
         TextAsset    ta     = ab.mainAsset as TextAsset;
         MemoryStream stream = new MemoryStream(ta.bytes);
         StreamReader sr     = new StreamReader(stream);
         m_mCacheID.Clear();
         m_mCachePath.Clear();
         while (!sr.EndOfStream)
         {
             string s         = sr.ReadLine();
             char[] spiltChar = new char[1] {
                 '$'
             };
             string[] strings  = s.Split(spiltChar);
             long     verData  = long.Parse(strings[2]);
             long     baseData = long.Parse("201201010000");
             m_mCacheID.Add(strings[0], (int)(verData - baseData));
             string path = strings[2] + "_" + strings[1];
             m_mCachePath.Add(strings[0], path);
         }
     }
 }
    public UnityEngine.Object Load(string name)
    {
        if (GameDefines.USE_ASSET_BUNDLE)
        {
            if (File.Exists(GameDefines.GetUnZipAssetBundlePath() + name + ".assetbundle"))
            {
                if (!mResourceWWWs.ContainsKey(name))
                {
                    AssetBundle baseBundle = AssetBundle.LoadFromFile(GameDefines.GetUnZipAssetBundlePath() + name + ".assetbundle");
                    if (baseBundle == null)
                    {
                        return(null);
                    }

                    mResourceWWWs[name] = baseBundle;
                }

                return(mResourceWWWs[name].mainAsset);

                mResourceWWWs[name].Unload(false);
            }
            else
            {
                return(Resources.Load(name));
            }
        }
        else
        {
            return(Resources.Load(name));
        }
        return(null);
    }
Beispiel #6
0
 public bool CheckBundleExist(string bundleName)
 {
     if (GameDefines.IsUseStream())
     {
         return(m_mBundle.ContainsKey(bundleName));
     }
     else
     {
         return(true);
     }
 }
    public void Restart()
    {
        Debug.Log("[Globals]: Restart begin...");

        GameDefines.WriteConfigFile();
        //GUIVipStore.WritePendingOrderIds();

        ThirdPartyPlatform.CloseSDK();


        Debug.Log("[Globals]: Restart call Release()...");
        Globals.Instance.Release();
        GameObject dontAutoDelObj = GameObject.Find("GlobalScripts");

        if (null != dontAutoDelObj)
        {
            GameObject.Destroy(dontAutoDelObj);
        }

        dontAutoDelObj = GameObject.Find("StaticRes");
        if (null != dontAutoDelObj)
        {
            GameObject.Destroy(dontAutoDelObj);
        }

        dontAutoDelObj = GameObject.Find("UI Root");
        if (null != dontAutoDelObj)
        {
            GameObject.Destroy(dontAutoDelObj);
        }

        dontAutoDelObj = GameObject.Find("CameraControl");
        if (null != dontAutoDelObj)
        {
            GameObject.Destroy(dontAutoDelObj);
        }

        dontAutoDelObj = GameObject.Find("TaskCameraControl");
        if (null != dontAutoDelObj)
        {
            GameObject.Destroy(dontAutoDelObj);
//			GameObject.DestroyImmediate(dontAutoDelObj);
        }

        Debug.Log("[Globals]: Restart call Application.LoadLevel...");
        Application.LoadLevel("SceneStart");

        Debug.Log("[Globals]: Restart End...");
    }
Beispiel #8
0
 void ParseLocalLevel()
 {
     if (GameDefines.IsUseStream())
     {
         AssetBundle  ab     = GetBundle(BUND_LOCAL_LEVEL);
         TextAsset    ta     = ab.mainAsset as TextAsset;
         MemoryStream stream = new MemoryStream(ta.bytes);
         StreamReader sr     = new StreamReader(stream);
         while (!sr.EndOfStream)
         {
             string sLocalLevel = sr.ReadLine();
             m_mLocalLevel.Add(sLocalLevel, sLocalLevel);
         }
     }
 }
Beispiel #9
0
 public void LoadAllAssetBundles()
 {
     foreach (string name in m_resourceList)
     {
         int    cacheID = GetCacheID(name);
         string url     = GameDefines.GetUrlBase() + GetCachePath(name) + name + ".assetbundle";
         if (Caching.IsVersionCached(url, cacheID))
         {
             Debug.Log("----url=" + url + " cached");
         }
         else
         {
             LoadAssetBundle(name, null);
         }
     }
 }
    public void QuitGame()
    {
        GameDefines.WriteConfigFile();
        //GUIVipStore.WritePendingOrderIds();

        // Quit game
        Application.Quit();

        // Test the Process state
        if (!Application.isEditor)
        {
            Process currentProcess = Process.GetCurrentProcess();
            if (currentProcess != null)
            {
                currentProcess.Kill();
            }
        }
    }
Beispiel #11
0
 public Object LoadResource(string bundleName, string res, bool bIgnoreBundle, System.Type type)
 {
     if (GameDefines.IsUseStream())
     {
         Debug.Log("LoadResource:bundle:" + bundleName + "res:" + res);
         AssetBundle ab = GetBundle(bundleName);
         Object      o  = ab.LoadAsset(res, type);
         return(o);
     }
     else
     {
         if (!bIgnoreBundle)
         {
             res = bundleName + "/" + res;
         }
         return(Resources.Load(res));
     }
 }
Beispiel #12
0
    public void ChangeDefinition(GameObject obj)
    {
        GameDefines.Setting_UserDefined = true;
        bool state = obj.GetComponent <UIToggle> ().value;

        SetBallPsition(Definition_Ball, state);
        if (state)
        {
            Globals.Instance.MGUIManager.ShowSimpleCenterTips(9001);
            GameDefines.Setting_ScreenQuality = true;
        }
        else
        {
            Globals.Instance.MGUIManager.ShowSimpleCenterTips(9002);
            GameDefines.Setting_ScreenQuality = false;
        }

        GameDefines.WriteConfigFile();
    }
Beispiel #13
0
    //public static int	Setting_MusicVol		= 100;
    //public static int	Setting_SoundVol		= 100;
    public void ChangeSound(GameObject obj)
    {
        bool state = obj.GetComponent <UIToggle> ().value;

        SetBallPsition(Sound_Ball, state);
        if (state)
        {
            GameDefines.Setting_MusicVol = 100;
            GameDefines.Setting_SoundVol = 100;
            SoundManager.CurrentPlayingMusicAudio.volume = 1;
        }
        else
        {
            GameDefines.Setting_MusicVol = 0;
            GameDefines.Setting_SoundVol = 0;
            SoundManager.CurrentPlayingMusicAudio.volume = 0;
        }
        GameDefines.WriteConfigFile();
    }
Beispiel #14
0
    public void OnReceived(EBEvent e)
    {
        switch (e.type)
        {
        case EBEventType.GameStarted:
            var gse = e as GameStarted;
            stats[GameDefines.Side.Blue].gameIndex = gse.gameIndex;
            stats[GameDefines.Side.Blue].timestamp = gse.timestamp;
            stats[GameDefines.Side.Red].gameIndex  = gse.gameIndex;
            stats[GameDefines.Side.Red].timestamp  = gse.timestamp;
            break;

        case EBEventType.ControllerInited:
            var cie = e as ControllerInited;
            stats[cie.side].controllerType = cie.controllerType;
            break;

        case EBEventType.NewFrame:
            var nfe = e as NewFrame;
            stats[nfe.side].framesTime += nfe.frameTime;
            ++stats[nfe.side].framesCount;
            break;

        case EBEventType.HealthChanged:
            var hce = e as HealthChanged;
            if (!hce.isHeal)
            {
                stats[hce.side].damageTaken += hce.diff;
                stats[GameDefines.OpposingTo(hce.side)].damageGiven += hce.diff;
                if (hce.value <= 0.0f)
                {
                    stats[hce.side].dead = true;
                }
            }
            break;

        case EBEventType.HealthPackCollected:
            var hpce = e as HealthPackCollected;
            stats[hpce.side].healthPackCollected = true;
            break;
        }
    }
    // Use this for initialization
    protected void Start()
    {
        if (!CheckGoogleResource())
        {
            return;
        }

        if (!TapjoyUnity.Tapjoy.IsConnected)
        {
            TapjoyUnity.Tapjoy.Connect();
        }

        UnityEngine.Profiling.Profiler.enabled = false;
        publisher.NotifyMonoStart();
        // read game defined setting
        GameDefines.ReadConfigFile();


        // Unified the login logic, move it to ThirdPartyPlatform.AtlanticLogin
        // FadeInLogo();

        if (!Globals.Instance.Initialize())
        {
            return;
        }

        Debug.Log("/var/mobile/Applications/3D2A01DB-BDCB-40CE-A537-E04FCAD5EBD0/Documents");
        Debug.Log("Application.persistentDataPath is :" + Application.persistentDataPath);

        //PlayTitleMovie();
        ThirdPartyPlatform.InitSDK();

        GameStatusManager.Instance.Initialize();
        GameStatusManager.Instance.SetGameState(GameState.GAME_STATE_INITIAL);

//		AndroidSDKAgent.getMacAddress ();
    }
Beispiel #16
0
    public void FixedUpdate()
    {
        if (!landed)
        {
            if (Mathf.Approximately(startingDistance, 0))
            {
                startingDistance = Vector2.Distance(body.position, location);
                position         = body.position;
                lastPosition     = body.position;
                startingAtan     = Mathf.Atan2(location.y - position.y, location.x - position.x);
                maxHeight        = GameDefines.ProjectileHeight * (startingDistance / GameDefines.RangedDistance(onWall)) + Mathf.Abs(location.y - position.y) / 2f;
            }

            float currentDistance = Vector2.Distance(position, location);

            if (currentDistance <= GameDefines.ProjectileSpeed * GameData.Instance.gameSpeed)
            {
                landed        = true;
                body.position = location;
                float angle = Mathf.Atan2(location.y - lastPosition.y, location.x - lastPosition.x) * Mathf.Rad2Deg;
                body.eulerAngles = new Vector3(0, 0, angle - 90);
                DamageTarget();
            }
            else
            {
                position.x     += GameDefines.ProjectileSpeed * GameData.Instance.gameSpeed * Mathf.Cos(startingAtan);
                position.y     += GameDefines.ProjectileSpeed * GameData.Instance.gameSpeed * Mathf.Sin(startingAtan);
                currentDistance = Vector2.Distance(position, location);
                Vector2 tempPosition = position;
                float   distancePerc = currentDistance / startingDistance;
                tempPosition.y += Mathf.Lerp(maxHeight * (1 - distancePerc), maxHeight * distancePerc, 1 - distancePerc);
                float angle = Mathf.Atan2(tempPosition.y - lastPosition.y, tempPosition.x - lastPosition.x) * Mathf.Rad2Deg;
                body.position    = tempPosition;
                body.eulerAngles = new Vector3(0, 0, angle - 90);
                lastPosition     = tempPosition;
            }
        }
        else if (timer >= maxTimer)
        {
            GameData.Instance.ReturnSpear(this);
        }
        else
        {
            timer += Time.fixedDeltaTime;
        }
    }
Beispiel #17
0
    void OnDrawGizmosSelected()
    {
        if (unit == null)
        {
            return;
        }

        if (unit.enemy != null)
        {
            GameData.Instance.circleIndicator1.position = unit.enemy.unitMB.body.position;
            GameData.Instance.circleIndicator1.GetComponent <SpriteRenderer> ().sortingOrder = unit.enemy.unitMB.spriteRenderer.sortingOrder - 1;
        }

        GameData.Instance.circleIndicator2.localScale = new Vector3(GameDefines.UnitFieldOfView * 2f, GameDefines.UnitFieldOfView * 2f, 1f);
        GameData.Instance.circleIndicator2.position   = unit.position;
        GameData.Instance.circleIndicator2.GetComponent <SpriteRenderer> ().sortingOrder = spriteRenderer.sortingOrder - 2;
        GameData.Instance.circleIndicator3.localScale = unit.unitType == UnitTypes.Archer ? new Vector3(GameDefines.RangedDistance(unit.onWall) * 2f, GameDefines.RangedDistance(unit.onWall) * 2f, 1f) :
                                                        new Vector3(GameDefines.UnitAttackDistance * 2f, GameDefines.UnitAttackDistance * 2f, 1f);
        GameData.Instance.circleIndicator3.position = unit.position;
        GameData.Instance.circleIndicator3.GetComponent <SpriteRenderer> ().sortingOrder = spriteRenderer.sortingOrder - 1;
    }
Beispiel #18
0
    public void FixedUpdate()
    {
        if (unit != null)
        {
            bool lookForANewEnemy = false;
            if (unit.enemy != null && unit.enemy.health <= 0)
            {
                unit.enemy = null;

                if (unit.task == UnitTasks.Attack)
                {
                    lookForANewEnemy = true;
                }

                //if ( unit.prevTask == UnitTasks.MoveAndAttack )
                unit.SetPreviousTask();
            }
            if (unit.enemyBuilding != null && unit.enemyBuilding.health <= 0)
            {
                unit.enemyBuilding = null;

                if (unit.task == UnitTasks.AttackBuilding)
                {
                    lookForANewEnemy = true;
                }

                //if ( unit.prevTask == UnitTasks.MoveAndAttack )
                unit.SetPreviousTask();
            }
            if (unit.health <= 0)
            {
                GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID).DestroyUnit(unit);
                return;
            }
            else if (lookForANewEnemy)
            {
                SearchForEnemies(GameDefines.UnitCheckForEnemiesPassiveTime, true);
            }
        }
        else
        {
            GameData.Instance.ReturnUnitBody(this);
            return;
        }

        moving = false;
        unit.currentMapPosition = MapGenerator.Instance.GetPositionOnMap(unit.position);

        if (MapGenerator.Instance.IsTileBuilding(unit.currentMapPosition.x, unit.currentMapPosition.y, out short tileType) &&
            tileType - (short)TileTypes.Buildings == (short)BuildingTypes.Wall && MapGenerator.Instance.GetKingdom(unit.currentMapPosition.x, unit.currentMapPosition.y) == unit.kingdomID)
        {
            unit.onWall = true;
        }
        else
        {
            unit.onWall = false;
        }

        if (unit.unitType != UnitTypes.Peasant && (unit.task == UnitTasks.AttackBuilding || unit.task == UnitTasks.Attack ||
                                                   unit.task == UnitTasks.MoveAndAttack || (unit.task == UnitTasks.Guard && inPosition) ||
                                                   (unit.task != UnitTasks.Guard && GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID).underAttack)))
        {
            SearchForEnemies(unit.task == UnitTasks.MoveAndAttack ? GameDefines.UnitCheckForEnemiesTime : GameDefines.UnitCheckForEnemiesPassiveTime);
        }

        if (unit.task != UnitTasks.Guard)
        {
            inPosition = false;
        }

        if (unit.task == UnitTasks.GatherResources)
        {
            Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
            Movement(pos);

            if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
            {
                MapGenerator.Instance.RemoveTileFromTileMap(unit.taskLocation.x, unit.taskLocation.y);
                //GameData.Instance.kingdoms.Find ( m => m.id == unit.kingdomID ).peasants.Remove ( unit );
                //GameData.Instance.ReturnUnitBody ( this );
                moving = false;

                if (unit.tileType == TileTypes.Tree || unit.tileType == TileTypes.Stone)
                {
                    if (unit.tileType == TileTypes.Tree)
                    {
                        log.gameObject.SetActive(true);
                    }
                    else
                    {
                        stone.gameObject.SetActive(true);
                    }

                    unit.ReturnToLoiter();
                    unit.task = UnitTasks.ReturnResource;
                    Building castle = GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID).buildings.Find(m => m.buildingType == BuildingTypes.Castle);
                    unit.taskLocation    = castle.position;
                    unit.taskLocation.y -= 1;
                }
                else
                {
                    unit.ReturnToLoiter();
                }
            }
        }
        else if (unit.task == UnitTasks.ReturnResource)
        {
            Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
            Movement(pos);

            if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
            {
                log.gameObject.SetActive(false);
                stone.gameObject.SetActive(false);
                unit.ReturnToLoiter();
                moving = false;
            }
        }
        else if (unit.task == UnitTasks.BuildBuilding)
        {
            Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
            if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
            {
                attackBuildingAnimation  = true;
                attackDirection          = pos;
                unit.building.buildPerc += 1 * GameData.Instance.gameSpeed;
                if (unit.building.buildPerc >= 100)
                {
                    GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID).buildersWorking--;

                    if (unit.building.buildingType == BuildingTypes.House)
                    {
                        GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID).populationCap += GameDefines.PopulationCapIncrease;
                    }

                    MapGenerator.Instance.RemoveTileFromTileMap(unit.taskLocation.x, unit.taskLocation.y);
                    MapGenerator.Instance.AddTile(unit.building.buildingType, unit.taskLocation);
                    unit.building.buildPerc = 100;
                    unit.ReturnToLoiter();
                    //unit.building = null;
                    //GameData.Instance.kingdoms.Find ( m => m.id == unit.kingdomID ).peasants.Remove ( unit );
                    //GameData.Instance.ReturnUnitBody ( this );
                }
            }
            else
            {
                Movement(pos);
            }
        }
        else if (unit.task == UnitTasks.Move)
        {
            Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
            Movement(pos);

            if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
            {
                unit.ReturnToLoiter();
                unit.task = UnitTasks.Stay;
                moving    = false;
            }
        }
        else if (unit.task == UnitTasks.MoveAndAttack)
        {
            Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
            Movement(pos);

            if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
            {
                unit.ReturnToLoiter();
                unit.task = UnitTasks.Stay;
                moving    = false;
            }
        }
        else if (unit.task == UnitTasks.Guard)
        {
            if (Vector2.Distance(unit.position, unit.taskLocationVector) > GameDefines.UnitSpeed)
            {
                Movement(unit.taskLocationVector);
            }
            else
            {
                if (!inPosition)
                {
                    SearchForEnemies(unit.task == UnitTasks.MoveAndAttack ? GameDefines.UnitCheckForEnemiesTime : GameDefines.UnitCheckForEnemiesPassiveTime, true);
                }

                unit.SetPosition(unit.taskLocationVector);
                inPosition = true;
            }
        }
        else if (unit.task == UnitTasks.Attack)
        {
            float distance        = unit.unitType == UnitTypes.Archer ? GameDefines.RangedDistance(unit.onWall) : GameDefines.UnitAttackDistance;
            float distanceToEnemy = Vector2.Distance(unit.position, unit.enemy.position);

            if (distanceToEnemy >= distance)
            {
                Movement(unit.enemy.position);
            }
            else
            {
                if (unit.unitType != UnitTypes.Archer)
                {
                    attackBuildingAnimation = true;
                    attackDirection         = unit.enemy.position;
                }
                else
                {
                    if (attackTimer >= GameDefines.UnitRangedAttackTimer)
                    {
                        attackTimer = 0;
                        Vector2 thisPosition = unit.position;
                        Spear   spear        = GameData.Instance.GetSpear();
                        thisPosition.y     += 0.235f;
                        spear.onWall        = unit.onWall;
                        spear.target        = unit.enemy;
                        spear.body.position = thisPosition;
                        spear.location      = unit.enemy.GetMovementVector(unit.position) + new Vector2(UnityEngine.Random.Range(-GameDefines.ProjectileMaxOffset, GameDefines.ProjectileMaxOffset),
                                                                                                        UnityEngine.Random.Range(-GameDefines.ProjectileMaxOffset, GameDefines.ProjectileMaxOffset));
                        spear.FixedUpdate();
                    }
                    else
                    {
                        attackTimer += Time.fixedDeltaTime * GameData.Instance.gameSpeed;
                    }
                }
            }
        }
        else if (unit.task == UnitTasks.AttackBuilding)
        {
            float   distance        = unit.unitType == UnitTypes.Archer ? GameDefines.RangedDistance(unit.onWall) : GameDefines.UnitAttackDistance + MapGenerator.Instance.halfCellSize.x;
            Vector2 enemyPosition   = unit.enemyBuilding.positionVector;
            float   distanceToEnemy = Vector2.Distance(unit.position, enemyPosition);

            if (distanceToEnemy > distance)
            {
                Movement(enemyPosition);
            }
            else
            {
                if (unit.unitType != UnitTypes.Archer)
                {
                    attackBuildingAnimation = true;
                    attackDirection         = enemyPosition;
                }
                else
                {
                    if (attackTimer >= GameDefines.UnitRangedAttackTimer)
                    {
                        attackTimer = 0;
                        Vector2 thisPosition = unit.position;
                        Spear   spear        = GameData.Instance.GetSpear();
                        thisPosition.y      += 0.235f;
                        spear.onWall         = unit.onWall;
                        spear.targetBuilding = unit.enemyBuilding;
                        spear.body.position  = thisPosition;
                        spear.location       = enemyPosition + new Vector2(UnityEngine.Random.Range(-GameDefines.ProjectileMaxOffset, GameDefines.ProjectileMaxOffset),
                                                                           UnityEngine.Random.Range(-GameDefines.ProjectileMaxOffset, GameDefines.ProjectileMaxOffset));
                        spear.FixedUpdate();
                    }
                    else
                    {
                        attackTimer += Time.fixedDeltaTime * GameData.Instance.gameSpeed;
                    }
                }
            }
        }
        else if (unit.task == UnitTasks.Nothing)
        {
            if (!Mathf.Approximately(loiterTimer, 0) && loiter < loiterTimer)
            {
                loiter += Time.fixedDeltaTime * GameData.Instance.gameSpeed;
            }
            else
            {
                if (unit.taskLocation == Vector2Int.zero)
                {
                    Kingdom kingdom = GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID);
                    unit.taskLocation = new Vector2Int(UnityEngine.Random.Range(kingdom.sX, kingdom.eX + (kingdom.eX < MapGenerator.Instance.mapSize - 2 ? 1 : 0)),
                                                       UnityEngine.Random.Range(kingdom.sY, kingdom.eY + (kingdom.eY < MapGenerator.Instance.mapSize - 2 ? 1 : 0)));
                }

                Vector2 pos = MapGenerator.Instance.GetPositionOnWorld(unit.taskLocation);
                if (Vector2.Distance(unit.position, pos) < MapGenerator.Instance.halfCellSize.magnitude)
                {
                    Kingdom kingdom = GameData.Instance.kingdoms.Find(m => m.id == unit.kingdomID);
                    unit.taskLocation = new Vector2Int(UnityEngine.Random.Range(kingdom.sX, kingdom.eX + (kingdom.eX < MapGenerator.Instance.mapSize - 2 ? 1 : 0)),
                                                       UnityEngine.Random.Range(kingdom.sY, kingdom.eY + (kingdom.eY < MapGenerator.Instance.mapSize - 2 ? 1 : 0)));
                    loiter      = 0;
                    loiterTimer = UnityEngine.Random.Range(GameDefines.UnitLoiterTime, GameDefines.UnitLoiterTimeMax);
                }
                else
                {
                    Movement(pos, GameDefines.UnitHalfSpeed);
                }
            }
        }

        HoppingAnimation();
        if (attackBuildingAnimation)
        {
            BuildingAttackAnimation();
        }
    }
Beispiel #19
0
    IEnumerator DoLoadAssetBundle(string name, LoaderCallback callback)
    {
        if (GameDefines.IsUseStream())
        {
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(name, out ab))
            {
                string url = GameDefines.GetUrlBase() + name + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                //int cacheID = GetCacheID(name);
                int cacheID = GameDefines.AssetBundleVersion;
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    yield return(0);
                }
                if (www.error != null)
                {
                    Debug.Log("Error: " + name + " " + www.error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + name + "" + www.assetBundle.ToString());

                    if (!m_mBundle.ContainsKey(name))
                    {
                        m_mBundle.Add(name, www.assetBundle);
                    }

                    if (callback != null)
                    {
                        ab = www.assetBundle;
                        bool useMainAsset = true;
                        if (useMainAsset)
                        {
                            callback(ab.mainAsset);
                        }
                        else
                        {
                            callback(ab.LoadAsset(name));
                        }
                    }

                    yield break;
                }
            }
            else
            {
                if (callback != null)
                {
                    bool useMainAsset = true;
                    if (useMainAsset)
                    {
                        callback(ab.mainAsset);
                    }
                    else
                    {
                        callback(ab.LoadAsset(name));
                    }
                }
                yield break;
            }
        }
        else
        {
            Object o = Resources.Load(name);
            if (callback != null)
            {
                callback(o);
            }
            yield break;
        }
    }
Beispiel #20
0
    public IEnumerator GetUILoader(string name, System.Action <string> callback)
    {
        if (GameDefines.IsUseStream())
        {
            string      url    = "";
            string      bundle = "GUI_" + name;
            AssetBundle ab     = null;
            m_loadingPub.NotifyLoadingName(bundle);
            m_loadingPub.NotifyPhase(1, 1);
            if (!m_mBundle.TryGetValue(bundle, out ab))
            {
                url = GameDefines.GetUrlBase() + GetCachePath(bundle) + bundle + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                int cacheID = GetCacheID(bundle);
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    m_loadingPub.NotifyProgress(www.progress);
                    yield return(0);
                }
                if (www.error != null)
                {
                    m_loadingPub.NotifyProgress(1.0f);
                    Debug.Log("Error: " + www.error);
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + bundle + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundle, www.assetBundle);
                    ab = www.assetBundle;
                }
            }

            m_loadingPub.NotifyProgress(1.0f);
            if (callback != null)
            {
                callback(name);
            }
        }
        else
        {
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(name, out ab))
            {
                m_mBundle.Add(name, ab);
                yield return(null);
            }
            if (callback != null)
            {
                callback(name);
            }
        }
    }
Beispiel #21
0
    public IEnumerator GetLoader(string bundName, string name, bool useMainAsset, LoaderCallback callback)
    {
        if (GameDefines.IsUseStream())
        {
            string url    = "";
            string bundle = bundName;
            if (useMainAsset)
            {
                bundle += "_" + name;
            }
            AssetBundle ab = null;
            if (!m_mBundle.TryGetValue(bundle, out ab))
            {
                url = GameDefines.GetUrlBase() + GetCachePath(bundle) + bundle + ".assetbundle";
                Debug.Log("url:" + url);

                WWW www;
                int cacheID = GetCacheID(bundle);
                if (cacheID >= 0)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    yield return(0);
                }
                if (www.error != null)
                {
                    Debug.Log("Error: " + www.error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    yield break;
                }
                else
                {
                    Debug.Log("OK: " + bundle + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundle, www.assetBundle);
                    ab = www.assetBundle;
                }
            }
            if (useMainAsset)
            {
                if (callback != null)
                {
                    callback(ab.mainAsset);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(ab.LoadAsset(name));
                }
            }
        }
        else
        {
            string res = bundName + "/" + name;
            Object o   = Resources.Load(res);
            if (callback != null)
            {
                callback(o);
            }
            yield break;
        }
    }
Beispiel #22
0
    IEnumerator DoLoadBundle(bool bUseCache)
    {
        Debug.Log("Start Load Bundle...");
        bool bSuccess = true;

        int c = 1;

        foreach (string bundName in m_preLoadList)
        {
            m_loadingPub.NotifyLoadingName(bundName);
            m_loadingPub.NotifyPhase(c++, m_preLoadList.Length);
            if (GameDefines.IsUseStream())
            {
                string url = GameDefines.GetUrlBase() + GetCachePath(bundName) + bundName + ".assetbundle";
                Debug.Log("url:" + url);
                WWW www = null;


                int cacheID = GetCacheID(bundName);
                if (cacheID >= 0 && bUseCache)
                {
                    www = WWW.LoadFromCacheOrDownload(url, cacheID);
                }
                else
                {
                    www = new WWW(url);
                }

                while (!www.isDone)
                {
                    m_loadingPub.NotifyProgress(www.progress);
                    yield return(0);
                }
                if (www.error != null)
                {
                    m_loadingPub.NotifyProgress(1.0f);
                    Debug.Log("Error: " + bundName + " " + www.error);
                    bSuccess = false;
                    break;
                }
                else
                {
                    Debug.Log("OK: " + bundName + "" + www.assetBundle.ToString());
                    m_mBundle.Add(bundName, www.assetBundle);
                }
            }
            else
            {
                m_loadingPub.NotifyProgress(1.0f);
                Debug.Log("Downloading Local " + bundName.ToLower());
                yield return(new WaitForSeconds(0.05f));
            }
        }

        Debug.Log("work flow end");
        m_preLoadList = null;
        if (bSuccess)
        {
            m_bIsDone = LoadResultEnum.SUCC;
        }
        else
        {
            m_bIsDone = LoadResultEnum.FAIL;
        }

        Debug.Log("Load Result is " + m_bIsDone);
    }
    private void InitPreloadResources()
    {
        // WWWForm form = new WWWForm();
        return;

        if (!GameDefines.IsUseStream())
        {
            _mPreloadLoaded = true;
            return;
        }

        // string url = GameDefines.GetUrlBase() + "201209120957_0/" + name + ".assetbundle";
        string name = BUND_VERSION;

        Load(name, delegate(Object obj, string error)
        {
            if (string.IsNullOrEmpty(error))
            {
                ParseVersionData(obj);

                _mVersionLoaded = true;
                if (_mVersionLoaded && _mStrategyLoaded && _mLocalLevelLoaded)
                {
                    _mPreloadLoaded = true;
                }
            }
            else
            {
                Debug.Log("[PreLoad-Error:] " + name);
            }
        });

        name = BUND_DOWNLOAD;
        Load(name, delegate(Object obj, string error)
        {
            if (string.IsNullOrEmpty(error))
            {
                ParseDownloadStrategy(obj);

                _mStrategyLoaded = true;
                if (_mVersionLoaded && _mStrategyLoaded && _mLocalLevelLoaded)
                {
                    _mPreloadLoaded = true;
                }
            }
            else
            {
                Debug.Log("[PreLoad-Error:] " + name);
            }
        });

        name = BUND_LOCAL_LEVEL;
        Load(name, delegate(Object obj, string error)
        {
            if (string.IsNullOrEmpty(error))
            {
                ParseLocalLevel(obj);

                _mLocalLevelLoaded = true;
                if (_mVersionLoaded && _mStrategyLoaded && _mLocalLevelLoaded)
                {
                    _mPreloadLoaded = true;
                }
            }
            else
            {
                Debug.Log("[PreLoad-Error:] " + name);
            }
        });
    }