Example #1
0
 protected override void OnPreload(GUnit unit, List <IObservable <Unit> > taskList)
 {
     taskList.Add(AssetProcess.Load <GameObject>("Prefabs/UI/PreloadItem").Do(asset =>
     {
         asset.Prespawn(10);
     }).AsUnitObservable());
 }
Example #2
0
    protected override void StartGame()
    {
        // spawn / despwn 接口只能用 asset资源(不能是实例化出来的资源)调用,为了统一管理资源!
        AssetProcess.Load <GameObject>("Prefabs/Actor/Plane1").Subscribe(asset =>
        {
            asset.Spawn();
        });

        AssetProcess.Load <GameObject>("Prefabs/Actor/Cube1").Subscribe(asset =>
        {
            var cubeList = new List <GameObject>();
            for (var i = 0; i < 15; i++)
            {
                var cubeAsset  = asset.Spawn();
                cubeAsset.name = "cube_" + i;
                cubeAsset.transform.position = new Vector3(URandom.Range(0, 10),
                                                           URandom.Range(0, 10), URandom.Range(0, 10));
                cubeList.Add(cubeAsset);
            }

            for (var i = 10; i < 15; i++)
            {
                cubeList[i].Despawn();
            }

            var cubeArray = cubeList.ToArray();
            AssetProcess.ClearUnusedAsset();
            Observable.Timer(TimeSpan.FromSeconds(2)).Subscribe(_ =>
            {
                Log.I("Cube list fter clear unused asset!");
                foreach (var cube in cubeArray)
                {
                    Log.I("cube {0}", cube);
                }

                AssetProcess.ClearByAssetPrefix("Prefabs/Actor");
                Observable.Timer(TimeSpan.FromSeconds(2)).Subscribe(time =>
                {
                    Log.I("Cube list fter clear asset by prefix {0}!", "Prefabs/Actor");
                    foreach (var cube in cubeArray)
                    {
                        Log.I("cube {0}", cube);
                    }
                });
            });
        });
    }
Example #3
0
    protected override void StartGame()
    {
        var moduleMgr = WorldManager.Instance.Module;
        var gameCore  = WorldManager.Instance.Unit.GetUnit(Constant.GAME_CORE_UNIT_NAME);

        gameCore.UpdateRequiredModuleGroup(moduleMgr.TagToModuleGroupType(Constant.SYNC_MODULE_GROUP_NAME));
        var syncServerData = gameCore.AddData <ObjectSyncServerData>();

        gameCore.UpdateMeetModuleList();

        var factory = WorldManager.Instance.Factory;

        var slowDownTrapObject = GameObject.Find("Ground/SlowDownTrap");

        factory.CreateSlowDownTrap(slowDownTrapObject);

        AssetProcess.Load <GameObject>("Prefabs/Cube").Subscribe(asset =>
        {
            factory.CreatePlayer(asset);
            syncServerData.enable.Value = true;
        });
    }
Example #4
0
    protected override void StartGame()
    {
        // spawn / despwn 接口只能用 asset资源(不能是实例化出来的资源)调用,为了统一管理资源!
        AssetProcess.Load <GameObject>("Prefabs/Actor/Plane1").Subscribe(asset =>
        {
            asset.Spawn();
        });

        AssetProcess.Load <GameObject>("Prefabs/Actor/Cube1").Subscribe(asset =>
        {
            var cubeList = new Queue <GameObject>();
            for (var i = 0; i < 10; i++)
            {
                var cubeAsset  = asset.Spawn();
                cubeAsset.name = "cube_" + i;
                cubeAsset.transform.position = new Vector3(URandom.Range(0, 10),
                                                           URandom.Range(0, 10), URandom.Range(0, 10));
                cubeList.Enqueue(cubeAsset);

                Log.I("spawned " + cubeAsset.name);
            }

            Observable.Interval(TimeSpan.FromSeconds(3)).Subscribe(_ =>
            {
                if (cubeList.Count <= 6)
                {
                    var random = URandom.Range(0, 10 - cubeList.Count);
                    for (var i = 0; i < random; i++)
                    {
                        var cubeAsset = asset.Spawn();
                        cubeAsset.transform.position = new Vector3(URandom.Range(0, 10),
                                                                   URandom.Range(0, 10), URandom.Range(0, 10));
                        cubeList.Enqueue(cubeAsset);

                        Log.I("spawned " + cubeAsset.name);
                    }
                }
                else
                {
                    var random = URandom.Range(0, 5);
                    for (var i = 0; i < random; i++)
                    {
                        var cubeAsset = cubeList.Dequeue();
                        Log.I("despawned " + cubeAsset.name);
                        cubeAsset.Despawn();
                    }
                }
            });
        }).AddTo(disposables);

        AssetProcess.Load <GameObject>("Prefabs/Actor/Sphere1").Subscribe(asset =>
        {
            var sphereList = new Queue <GameObject>();
            for (var i = 0; i < 8; i++)
            {
                var sphereAsset  = asset.Spawn();
                sphereAsset.name = "sphere_" + i;
                sphereAsset.transform.position = new Vector3(URandom.Range(0, 10),
                                                             URandom.Range(0, 10), URandom.Range(0, 10));
                sphereList.Enqueue(sphereAsset);

                Log.I("spawned " + sphereAsset.name);
            }

            Observable.Interval(TimeSpan.FromSeconds(5)).Subscribe(_ =>
            {
                if (sphereList.Count <= 4)
                {
                    var random = URandom.Range(0, 8 - sphereList.Count);
                    for (var i = 0; i < random; i++)
                    {
                        var sphereAsset = asset.Spawn();
                        sphereAsset.transform.position = new Vector3(URandom.Range(0, 10),
                                                                     URandom.Range(0, 10), URandom.Range(0, 10));
                        sphereList.Enqueue(sphereAsset);

                        Log.I("spawned " + sphereAsset.name);
                    }
                }
                else
                {
                    var random = URandom.Range(0, 5);
                    for (var i = 0; i < random; i++)
                    {
                        var sphereAsset = sphereList.Dequeue();
                        Log.I("despawned " + sphereAsset.name);
                        sphereAsset.Despawn();
                    }
                }
            });
        }).AddTo(disposables);
    }