예제 #1
0
 // Use this for initialization
 public override void UpdateView()
 {
     base.UpdateView();
     (GetComponent <Collider>() as BoxCollider).size = new Vector3(roomInfo.size * Cell.defaultCellWidth, Cell.defaultCellHeight, 0f);
     DoorBuilder.PlaceDoors(this);
     roomView.SetSprite(roomInfo.spriteName);
     roomMenu.transform.localPosition = new Vector3(roomInfo.size * 0.5f * defaultCellWidth - 0.08f, defaultCellHeight * 0.5f - 0.08f, 0f);
     selection.dimensions             = new Vector2(roomInfo.size * Cell.defaultCellWidth * 100f, Cell.defaultCellHeight * 100f);
     if (roomInfo is StorageRoomInfo)
     {
         if (!GetComponent <Storage>())
         {
             var storage = gameObject.AddComponent <Storage>();
             storage.Init(roomInfo as StorageRoomInfo);
             StorageManager.AddStorage(storage);
         }
     }
     else if (roomInfo is FactoryRoomInfo)
     {
         if (!GetComponent <Factory>())
         {
             var factory = gameObject.AddComponent <Factory>();
             factory.Init(roomInfo as FactoryRoomInfo);
         }
     }
 }
예제 #2
0
 void Start()
 {
     sm.AddStorage(gameObject);
     type = "Storage";
 }
        private T CreateGrain <T>(IGrainIdentity identity) where T : Grain
        {
            if (_isGrainCreated)
            {
                throw new Exception(
                          "A grain has already been created in this silo. Only 1 grain per test silo should every be created. Add grain probes for supporting grains.");
            }

            _isGrainCreated = true;

            Grain grain;

            var grainContext = new TestGrainActivationContext()
            {
                ActivationServices = _serviceProvider,
                GrainIdentity      = identity,
                GrainType          = typeof(T)
            };

            //Check to see if the grain is stateful
            if (typeof(T).IsSubclassOfRawGeneric(typeof(Grain <>)))
            {
                var grainGenericArgs = typeof(T).BaseType?.GenericTypeArguments;

                if (grainGenericArgs == null || grainGenericArgs.Length == 0)
                {
                    throw new Exception($"Unable to get grain state type info for {typeof(T)}");
                }

                //Get the state type
                var stateType = grainGenericArgs[0];

                var storage = _storageManager.AddStorage <T>(identity);

                //Create a new stateful grain
                grain = _grainCreator.CreateGrainInstance(grainContext, stateType, storage);

                if (grain == null)
                {
                    throw new Exception($"Unable to instantiate stateful grain {typeof(T)} properly");
                }

                var stateProperty = GetProperty(typeof(T), "State");

                var state = stateProperty?.GetValue(grain);

                _grainStateManager.AddState(grain, state);
            }
            else
            {
                //Create a stateless grain
                grain = _grainCreator.CreateGrainInstance(grainContext) as T;

                if (grain == null)
                {
                    throw new Exception($"Unable to instantiate grain {typeof(T)} properly");
                }
            }

            //Emulate the grain's lifecycle
            grain.OnActivateAsync().Wait(1000);

            return(grain as T);
        }