Example #1
0
        public void CreateAtPosition(PlanetoidState initState, Vector2 pos)
        {
            var obj   = CreateObject(new object[] { pos }, initState);
            var model = (PlanetoidModel)obj.Model;

            model.Rigidbody.position = pos + GetRandomSpawnLocation();
        }
Example #2
0
        private ObjectFacade CreateObject(object[] extraArgs, PlanetoidState initState = PlanetoidState.DefaultState)
        {
            var t = new ObjectTunables
            {
                InitState = (int)initState,
                ExtraArgs = extraArgs
            };
            //var obj = ObjectFactory.Create(t);
            var obj = _pool.Spawn(t);

            return(obj);
        }
Example #3
0
 public override void TakeHit(CombatStrength attackerWeaponStrength) {
     if (CurrentState == PlanetoidState.Dead) {
         return;
     }
     LogEvent();
     float damage = Data.Strength - attackerWeaponStrength;
     if (damage == Constants.ZeroF) {
         return;
     }
     bool isAlive = ApplyDamage(damage);
     if (!isAlive) {
         CurrentState = PlanetoidState.Dead;
         return;
     }
     OnShowAnimation(EffectID.Hit);
 }
Example #4
0
 private void OnCurrentStateChanging(PlanetoidState newState) {
     PlanetoidState previousState = CurrentState;
     //D.Log("{0}.CurrentState changing from {1} to {2}.", Data.Name, previousState.GetName(), newState.GetName());
     switch (previousState) {
         case PlanetoidState.None:
             IsOperational = true;
             break;
         case PlanetoidState.Idling:
             break;
         case PlanetoidState.Dead:
         default:
             throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(previousState));
     }
 }
        public void InitializeSystem()
        {
            //Clear old data
            if (generateName)
            {
                name = (new Spaceworks.PhenomicNameGenerator()).Generate(4, 8);
            }

            DestorySystem();

            //Make the floating origin if it does not exist
            FloatingOrigin.Make();

            //Create the sun's reference (0,0,0) in the model (view not made)
            this.sun = new KeplerBody(this.SolarMass, null);

            //Create the initial states of all planetoids
            this.planetStates = new PlanetoidState[this.planetoids.Length];
            for (int i = 0; i < this.planetoids.Length; i++)
            {
                try {
                    //Init references
                    Planetoid      planet   = this.planetoids[i];
                    GameObject     planetGO = new GameObject(string.IsNullOrEmpty(planet.planetData.name) ? this.name + " - " + i : planet.planetData.name);
                    PlanetoidState state    = new PlanetoidState();
                    this.planetStates[i] = state;

                    //Init orbit model
                    state.orbit      = new KeplerOrbit(this.sun, planet.orbit);
                    state.body       = new KeplerBody(planet.mass, state.orbit);
                    state.gameobject = planetGO;

                    //Configure components
                    FloatingTransform transform = planetGO.AddComponent <FloatingTransform>();
                    transform.worldPosition = new WorldPosition(state.orbit.GetCurrentPosition());
                    state.transform         = transform;

                    CubemapMeshGenerator meshService = planetGO.AddComponent <CubemapMeshGenerator>();
                    meshService.range     = planet.mountains;
                    meshService.useSkirts = true;
                    meshService.heights   = planet.heights;
                    meshService.Init();

                    CubemapTextureService textureService = planetGO.AddComponent <CubemapTextureService>();
                    textureService.top = planet.baseMaterial;
                    textureService.top.SetTexture("_MainTex", planet.textures.top);

                    textureService.bottom = planet.baseMaterial;
                    textureService.bottom.SetTexture("_MainTex", planet.textures.bottom);

                    textureService.left = planet.baseMaterial;
                    textureService.left.SetTexture("_MainTex", planet.textures.left);

                    textureService.right = planet.baseMaterial;
                    textureService.right.SetTexture("_MainTex", planet.textures.right);

                    textureService.front = planet.baseMaterial;
                    textureService.front.SetTexture("_MainTex", planet.textures.front);

                    textureService.back = planet.baseMaterial;
                    textureService.back.SetTexture("_MainTex", planet.textures.back);

                    PlanetConfig pcc = new PlanetConfig(planet.planetData);
                    pcc.generationService = meshService;
                    pcc.textureService    = textureService;

                    Planet p = new Planet(pcc);
                    p.RenderOn(planetGO);
                    if (Camera.main)
                    {
                        p.ForceUpdateLODs(Camera.main.transform.position);
                    }

                    state.planet = p;
                }
                catch (Exception e) {
                    Debug.Log("Failed to fully instanciate planetoid: " + i + " because");
                    Debug.Log(e.Message);
                    Debug.Log(e.StackTrace);
                }
            }
        }
 public IObjectState Create(PlanetoidState state, object[] extraArgs = null)
 {
     return(Create((int)state, extraArgs));
 }