コード例 #1
0
    static void BuildVariables()
    {
        if (SceneManager.GetActiveScene().name == "GameGlue")
        {
            string core   = "Assets/0_Game/GameVariables/CoreLoop";
            string system = "Assets/0_Game/GameVariables/System";

            string[] val = AssetDatabase.FindAssets("l:GameVariable", new[] { core, system });

            GameVarDictionary varDict = GameObject.FindObjectOfType <GameVarDictionary>();

            varDict.refVariables = new System.Collections.Generic.List <GameVariable>();
            EditorUtility.DisplayProgressBar("Building Indexes", "wait", 0.3f);

            foreach (string guid2 in val)
            {
                string       path = AssetDatabase.GUIDToAssetPath(guid2);
                GameVariable var  = AssetDatabase.LoadAssetAtPath <GameVariable>(path);
                varDict.refVariables.Add(var);
            }
            EditorUtility.ClearProgressBar();

            EditorUtility.SetDirty(varDict);
            Undo.RecordObject(varDict, "Added game variables");

            UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
        }
        else
        {
            Debug.LogWarning("In Wrong Scene");
        }
    }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CollisionService" /> class.
        /// </summary>
        /// <param name="entityService">The entity service.</param>
        /// <param name="mapService">The map service.</param>
        /// <param name="renderService">The render service.</param>
        /// <param name="varService">The variable service.</param>
        public CollisionService(IEntityService entityService, IMapService mapService, IRenderService renderService, IVariableService varService)
        {
            if (entityService == null)
            {
                throw new ArgumentNullException(nameof(entityService));
            }

            if (mapService == null)
            {
                throw new ArgumentNullException(nameof(mapService));
            }

            if (renderService == null)
            {
                throw new ArgumentNullException(nameof(renderService));
            }

            if (varService == null)
            {
                throw new ArgumentNullException(nameof(varService));
            }

            _entityService = entityService;
            _mapService    = mapService;
            _renderService = renderService;
            _varService    = varService;

            _quadPool    = new QuadtreePool();
            _entListPool = new ObjectPool <List <GameEntity> >(() => new List <GameEntity>(10));

            _varShowTracelines = _varService.GetVar <bool>("r_showtracelines");
        }
コード例 #3
0
ファイル: GameScript.cs プロジェクト: lblanch/ekojam2019
    Tuple <bool, string> CheckConsequences(GameVariable var)
    {
        string returnStr = "";

        //check max value
        if (var.value > var.maxValue)
        {
            if (var.maxConsequence.isGameOver)
            {
                //GAME OVER
                returnStr = "GAME OVER -> " + var.name + " value: " + var.value + " max value: " + var.maxValue;
                return(new Tuple <bool, string> (true, returnStr));
            }
            else
            {
                returnStr += var.maxConsequence.ExecuteConsequenceActions();
            }
        }
        //check min value
        if (var.value < var.minValue)
        {
            if (var.minConsequence.isGameOver)
            {
                //GAME OVER
                returnStr = "GAME OVER -> " + var.name + " value: " + var.value + " min value: " + var.minValue;
                return(new Tuple <bool, string>(true, returnStr));
            }
            else
            {
                returnStr += var.minConsequence.ExecuteConsequenceActions();
            }
        }

        return(new Tuple <bool, string>(false, returnStr));
    }
コード例 #4
0
            public override void OnOpen()
            {
                if (assignmentType.enumValueIndex == 0)                 // Constant value, we have all we need, just create the editor
                {
                    _editor = UnityEditor.Editor.CreateEditor(constantValue.objectReferenceValue);
                }
                else if (assignmentType.enumValueIndex == 1)                 // Global. Pretty easy, just get the global variable object and cast it to GameVariable<T>
                {
                    _gameVariable = globalVariable.objectReferenceValue as GameVariable <T>;

                    if (_gameVariable != null)
                    {
                        _editor = UnityEditor.Editor.CreateEditor(_gameVariable);
                    }
                    else
                    {
                        _runtimeSet = globalVariable.objectReferenceValue as RuntimeSet <T>;

                        if (_runtimeSet != null)
                        {
                            _editor = UnityEditor.Editor.CreateEditor(_runtimeSet);
                        }
                        else
                        {
                            _noReference = true;
                        }
                    }
                }
                else if (assignmentType.enumValueIndex == 2)                 // instanced
                {
                    var variable = instancedVariable.objectReferenceValue as InstancedVariable <T>;

                    if (variable != null)
                    {
                        var token = (idTokenHolder.objectReferenceValue as IDTokenHolder)?.IDToken;
                        _gameVariable = variable.GetVariable(token);
                        _editor       = UnityEditor.Editor.CreateEditor(_gameVariable);
                    }
                    else
                    {
                        var list = instancedVariable.objectReferenceValue as InstancedList <T>;

                        if (list != null)
                        {
                            var token = (idTokenHolder.objectReferenceValue as IDTokenHolder)?.IDToken;
                            _runtimeSet = list.GetList(token);
                            _editor     = UnityEditor.Editor.CreateEditor(_runtimeSet);
                        }
                        else
                        {
                            _noReference = true;
                        }
                    }
                }

                base.OnOpen();
            }
コード例 #5
0
 /// <summary>
 /// Create "year" as a variable. Called by JsonImport after importing other variables
 /// </summary>
 public void AddYearVariable()
 {
     yearVar = GetComponent<VariablesManager>().AddCustomVar("Year");
     yearVar.description = "The current in-game year";
     yearVar.value = 0;
     yearVar.maxAmount = maxYear;
     timeScale = startTimeScale;
     yearText.text = "0";
 }
コード例 #6
0
ファイル: Level.cs プロジェクト: kallotec/Bonsai
        public override void Load(IContentLoader loader)
        {
            _loader = loader;

            var defaultFont = loader.Load <SpriteFont>(ContentPaths.FONT_UI_GENERAL);

            varShowLootTip = new GameVariable <bool>();
            varShowLootTip.Load(loader);
            GameObjects.Add(varShowLootTip);

            // Player
            player = new Player(eventBus, varShowLootTip);
            player.Load(loader);
            GameObjects.Add(player);

            // Bot
            bot = new Bot(eventBus, Camera);
            bot.Load(loader);
            GameObjects.Add(bot);

            // Message manager
            textPopupManager = new TextPopupManager(ContentPaths.FONT_UI_GENERAL, StackingMethod.Parallel);
            textPopupManager.Load(loader);
            GameObjects.Add(textPopupManager);

            // Physics
            phys = new MapPhysics(chunkMap, physSettings);
            GameObjects.Add(chunkMap);

            // Camera
            GameObjects.Add(Camera);

            // Services
            setupKeyListeners();

            // Event listeners
            eventBusSubscriptionIds.AddRange(new[] {
                eventBus.Subscribe(Events.PlayerPickedUpCoin, (p) => Debug.WriteLine("picked up coin!")),
                eventBus.Subscribe(Events.PlayerDied, (p) => playerDied()),
                eventBus.Subscribe(Events.CreateProjectile, (p) => playerCreatedProjectile(p as Projectile)),
            });

            // Game variables
            var tipLootBoxOpen = "Press <E> to open loot box";

            txtDisplayTipLootBoxOpen = new TextElement <string>(tipLootBoxOpen, defaultFont, new TextElementSettings())
            {
                Position           = new Vector2(10, 10),
                IsAttachedToCamera = true,
                IsHidden           = true,
            };
            txtDisplayTipLootBoxOpen.Load(loader);
            GameObjects.Add(txtDisplayTipLootBoxOpen);

            // Map
            loadMap();
        }
コード例 #7
0
 /// <summary>
 /// Create "year" as a variable. Called by JsonImport after importing other variables
 /// </summary>
 public void AddYearVariable()
 {
     yearVar             = GetComponent <VariablesManager>().AddCustomVar("Year");
     yearVar.description = "The current in-game year";
     yearVar.value       = 0;
     yearVar.maxAmount   = maxYear;
     timeScale           = startTimeScale;
     yearText.text       = "0";
 }
コード例 #8
0
        public ActionResult Game(string exlamation, string adverb, string noun, string adjective)
        {
            GameVariable newGame = new GameVariable();

            newGame.SetExlamation(exlamation);
            newGame.SetAdverb(adverb);
            newGame.SetNoun(noun);
            newGame.SetAdjective(adjective);
            return(View(newGame));
        }
コード例 #9
0
    /// <summary>
    /// Create a new slider as child of sliderLayout, which should stack them vertically
    /// </summary>
    void AddSlider(GameVariable gameVar)
    {
        GameObject newSlider = Instantiate(sliderPrefab);

        newSlider.transform.SetParent(sliderLayout.transform);
        VariableSlider sliderManager = newSlider.GetComponent <VariableSlider>();

        sliderManager.Setup(gameVar);
        sliders[gameVar.name] = sliderManager;
    }
コード例 #10
0
ファイル: Level.cs プロジェクト: kallotec/Bonsai
        public override void Load(IContentLoader loader)
        {
            _loader = loader;

            // Player
            player = new Player(eventBus, Camera);
            player.Load(loader);
            GameObjects.Add(player);

            // Game variables
            Jumps = new GameVariable <int>();
            Jumps.Load(loader);
            GameObjects.Add(Jumps);
            CoinsCount = new GameVariable <int>();
            CoinsCount.Load(loader);
            GameObjects.Add(CoinsCount);

            // Message manager
            textPopupManager = new TextPopupManager(ContentPaths.FONT_UI_GENERAL, StackingMethod.Parallel);
            textPopupManager.Load(loader);
            GameObjects.Add(textPopupManager);

            // HUD
            hud = new HUD(this);
            hud.ScreenBounds = base.Game.GraphicsDevice.Viewport.Bounds;
            hud.DrawOrder    = DrawOrderPosition.HUD;
            hud.Load(loader);
            GameObjects.Add(hud);

            // Physics
            phys = new MapPhysics(chunkMap, physSettings);
            GameObjects.Add(chunkMap);

            // Camera
            GameObjects.Add(Camera);

            // Services
            setupKeyListeners();

            // Event listeners
            eventBusSubscriptionIds.AddRange(new[] {
                eventBus.Subscribe(Events.PlayerPickedUpCoin, (p) => CoinsCount.Value += 1),
                eventBus.Subscribe(Events.PlayerJumped, (p) => Jumps.Value            += 1),
                eventBus.Subscribe(Events.PlayerEnteredDoor, (p) => playerTouchedDoor()),
                eventBus.Subscribe(Events.PlayerDied, (p) => playerDied()),
                eventBus.Subscribe(Events.CreateProjectile, (p) => playerCreatedProjectile(p as Projectile)),
            });

            // Load first map
            loadMap(ContentPaths.PATH_MAP_1);

            startGameTimer = new MillisecCounter(1500);
            Camera.SetFocus(playerExit, immediateFocus: true);
            isPlayerFocused = false;
        }
コード例 #11
0
    /// <summary>
    /// Create a blank new variable.
    /// For special variables like the current year that are not read from variables.txt
    /// Cannot be the first variable!
    /// </summary>
    public GameVariable AddCustomVar(string name, bool addSlider = false)
    {
        GameVariable newVar = new GameVariable();

        newVar.varManager     = this; // so the variable can modify sliders etc
        newVar.name           = name;
        gameVars[newVar.name] = newVar;
        if (addSlider)
        {
            AddSlider(newVar);
        }
        return(newVar);
    }
コード例 #12
0
    public void SetState(GameVariable variable, int state)
    {
        int value;

        if (dictionaryInstance.runtimeVars.TryGetValue(variable.name, out value))
        {
            dictionaryInstance.runtimeVars[variable.name] = state;
        }
        else
        {
            Debug.LogWarning($"Game Variable Missing {variable.name}");
        }
    }
コード例 #13
0
    public int GetState(GameVariable variable)
    {
        int value;

        if (dictionaryInstance.runtimeVars.TryGetValue(variable.name, out value))
        {
            return(value);
        }
        else
        {
            Debug.LogWarning($"Game Variable Missing {variable.name}");
        }
        return(-1);
    }
コード例 #14
0
        /// <summary>
        /// Gets a game variable.
        /// </summary>
        /// <typeparam name="TValue">The type of the variable value.</typeparam>
        /// <param name="name">The name of the variable.</param>
        /// <returns>
        /// An instance of <see cref="GameVariable" />, or null if no variable was found, or the value was the wrong type.
        /// </returns>
        public GameVariable <TValue> GetVar <TValue>(string name)
        {
            lock (_lock)
            {
                GameVariable retval;
                if (!_variables.TryGetValue(name, out retval))
                {
                    retval = new GameVariable <TValue>(name);
                    _variables.Add(name, retval);
                }

                return(retval as GameVariable <TValue>);
            }
        }
コード例 #15
0
        public Player(EventBus eventBus, GameVariable <bool> varCanOpenBox)
        {
            this.eventBus   = eventBus;
            this.canOpenBox = varCanOpenBox;

            DrawOrder = DrawOrderPosition.Foreground;

            // Physical properties
            Props.TopSpeed     = 150f;
            Props.PhysicalRect = new Rectangle(0, 0, 15, 20);
            Props.Weight       = 1f;
            Props.HasGravity   = true;

            fireListener = new KeyPressListener(Keys.Space, () => fireProjectile(), 0100);
        }
コード例 #16
0
        public TextElement(GameVariable <T> variable, SpriteFont font, TextElementSettings settings)
        {
            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            this.font     = font;
            this.Settings = settings;
            this.variable = variable;

            updateText(variable.Value);
        }
コード例 #17
0
 private void ModifyConditionVariableValue(List <int> IDList, List <int> valueList, int actionID, List <int> pathIDList)
 {
     for (int i = 0; i < IDList.Count; i++)
     {
         int          index        = IDList[i];
         int          value        = valueList[i];
         GameVariable gameVariable = GameDataCache.Instance.gameVariableSet.GetGameVariableByID(index);
         if ((GameVariableType)gameVariable.type == GameVariableType.ConditonVariable)
         {
             for (int j = 0; j < pathIDList.Count; j++)
             {
                 int pathID = pathIDList[j];
                 if (gameVariableDict.ContainsKey(index))
                 {
                     Dictionary <int, Dictionary <int, int> > savedData = gameVariableDict[index];
                     if (savedData.ContainsKey(pathID))
                     {
                         Dictionary <int, int> savedPathData = savedData[pathID];
                         if (savedPathData.ContainsKey(actionID))
                         {
                             savedPathData[actionID] = value;
                         }
                         else
                         {
                             savedPathData.Add(actionID, value);
                         }
                     }
                     else
                     {
                         Dictionary <int, int> savedPathData = new Dictionary <int, int>();
                         savedPathData.Add(actionID, value);
                         savedData.Add(pathID, savedPathData);
                     }
                 }
                 else
                 {
                     Dictionary <int, Dictionary <int, int> > savedData = new Dictionary <int, Dictionary <int, int> >();
                     Dictionary <int, int> savedPathData = new Dictionary <int, int>();
                     savedPathData.Add(actionID, value);
                     savedData.Add(pathID, savedPathData);
                     gameVariableDict.Add(index, savedData);
                 }
             }
         }
     }
 }
コード例 #18
0
    public int GetLoveVariableValue(int id)
    {
        int res = 0;

        if (gameVariableDict.ContainsKey(id))
        {
            // Dictionary<int,Dictionary<int, int>> savedData = gameVariableDict[id];
            GameVariable gameVariable = GameDataCache.Instance.gameVariableSet.GetGameVariableByID(id);
            Dictionary <int, Dictionary <int, int> > savedData = gameVariableDict[id];
            Dictionary <int, int> savedPathData = savedData[0];
            foreach (var VARIABLE in savedPathData)
            {
                res += VARIABLE.Value;
            }
        }

        return(res);
    }
コード例 #19
0
    /// <summary>
    /// Add a new player controlled variable and create a slider for it
    /// </summary>
    /// <param name="jsonString">
    /// Should have properties: "name", "description", "default", "hasSlider"
    /// </param>
    public void AddVariable(string jsonString, int variableNum, int numVariables)
    {
        // if this is the first variable, initialise the arrays
        if (gameVars == null)
        {
            gameVars = new Dictionary <string, GameVariable>(numVariables);
            sliders  = new Dictionary <string, VariableSlider>(numVariables);
        }

        GameVariable newVar = JsonUtility.FromJson <GameVariable>(jsonString);

        newVar.varManager     = this; // so the variable can modify sliders etc
        gameVars[newVar.name] = newVar;

        if (newVar.hasSlider)
        {
            AddSlider(newVar);
        }
    }
コード例 #20
0
 public void ResetText()
 {
     if (this.GroupID == -1 || this.VariableID == -1)
     {
         SetInitialText("");
     }
     else
     {
         if (this.GroupID > Editor.ProjectSettings.Variables.Count)
         {
             SetInitialText("");
         }
         else if (this.VariableID > Editor.ProjectSettings.Variables[this.GroupID - 1].Variables.Count)
         {
             SetInitialText("");
         }
         else
         {
             GameVariable var = Editor.ProjectSettings.Variables[this.GroupID - 1].Variables[this.VariableID - 1];
             SetInitialText($"{Utilities.Digits(this.VariableID, 3)}: {var.Name}");
         }
     }
 }
コード例 #21
0
        public void Load(IContentLoader loader)
        {
            // Fonts
            fontGeneral = loader.Load <SpriteFont>(ContentPaths.FONT_UI_GENERAL);

            //key listeners
            setupKeyListeners();

            // Variables
            fps = new GameVariable <int>();

            // [Fields]
            // FPS variable
            fields.Add(new TextElement <int>(
                           variable: this.fps,
                           font: fontGeneral,
                           settings: new TextElementSettings()
            {
                Label       = "FPS: ",
                DisplayMode = TextDisplayMode.LabelAndValue
            }
                           )
            {
                Position = new Vector2(10, 10)
            });

            // Jumps variable
            fields.Add(new TextElement <int>(
                           variable: level.Jumps,
                           font: fontGeneral,
                           settings: new TextElementSettings()
            {
                Label               = "Jumps: ",
                DisplayMode         = TextDisplayMode.LabelAndValue,
                HorizontalAlignment = TextHorizontalAlignment.Center,
                ForegroundColor     = Color.Green,
            }
                           )
            {
                Position = new Vector2(ScreenBounds.Width / 2, screenMargin),
            });

            // Coins variable
            fields.Add(new TextElement <int>(
                           variable: level.CoinsCount,
                           font: fontGeneral,
                           settings: new TextElementSettings
            {
                Label               = "Coins: ",
                DisplayMode         = TextDisplayMode.LabelAndValue,
                HorizontalAlignment = TextHorizontalAlignment.Right,
                ForegroundColor     = Color.Yellow,
            }
                           )
            {
                Position = new Vector2(ScreenBounds.Width - screenMargin, screenMargin),
            });

            foreach (var field in fields)
            {
                field.Load(loader);
            }
        }
コード例 #22
0
        public bool Parse()
        {
            if (!File.Exists(FileName))
            {
                return(false);
            }

            bool         Parse        = false;
            bool         ParseComment = false;
            string       Comment      = "";
            GameVariable GameVar      = null;

            foreach (String Line in File.ReadAllLines(FileName, Encoding.GetEncoding("Windows-1251")))
            {
                if (Line == "**************************************************************************************")
                {
                    Parse = !Parse;
                }
                if (Line == "**********")
                {
                    ParseComment = !ParseComment;
                    if (!ParseComment) // end of variable
                    {
                        if (GameVar != null)
                        {
                            GameVar.Description = Comment;
                            Variables.Add(GameVar);
                        }
                        Comment = "";
                    }
                    else
                    {
                        continue;
                    }
                }

                if (!Parse || Line.Length < 3)
                {
                    continue;
                }

                if (ParseComment)
                {
                    Comment += Line + Environment.NewLine;
                }

                if (Line[0] == '$')
                {
                    GameVar = new GameVariable();
                    String[] Params = Line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    GameVar.Id         = Int32.Parse(Params[1]);
                    GameVar.Type       = (GameVariableType)Int32.Parse(Params[2]);
                    GameVar.Name       = Params[3];
                    GameVar.StartValue = Int32.Parse(Params[4]);
                    GameVar.MinValue   = Int32.Parse(Params[5]);
                    GameVar.MaxValue   = Int32.Parse(Params[6]);

                    if (Params.Length > 7)
                    {
                        int Flags = Int32.Parse(Params[7]);
                        GameVar.Quest   = ((Flags & 1) == 1);
                        GameVar.Random  = ((Flags & 2) == 2);
                        GameVar.NoLimit = ((Flags & 4) == 4);
                    }
                }
            }

            return(true);
        }
コード例 #23
0
ファイル: Module.cs プロジェクト: MysteriousMilk/OrionEngine
 public void RegisterVariable(GameVariable variable)
 {
     _variables.Add(variable);
 }
コード例 #24
0
 public void AddToGroup(GameVariable var)
 {
     variables.Add(var);
 }
コード例 #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Renderer" /> class.
        /// </summary>
        /// <param name="gameEngine">The game engine.</param>
        /// <param name="form">The form.</param>
        /// <param name="width">The primary width of the view in pixels.</param>
        /// <param name="height">The primary height of the view in pixels.</param>
        public Renderer(IGameEngine gameEngine, GameForm form, int width, int height)
        {
            if (gameEngine == null)
            {
                throw new ArgumentNullException(nameof(gameEngine));
            }

            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            _form   = form;
            _resize = false;
            _scale  = 1.0f;
            _width  = width;
            _height = height;

            _dwFactory = new SharpDX.DirectWrite.Factory();
            InitFonts();

            // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            _device     = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
            _d3dContext = _device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            using (var dxgiDevice2 = _device.QueryInterface <SharpDX.DXGI.Device2>())
            {
                _d2dFactory = new SharpDX.Direct2D1.Factory2(SharpDX.Direct2D1.FactoryType.SingleThreaded);

                // Get the default Direct2D device and create a context.
                using (var d2dDevice = new SharpDX.Direct2D1.Device1(_d2dFactory, dxgiDevice2))
                {
                    _d2dContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);
                }
            }

            CreateSizeDependentResources();

            _d2dContext.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;
            _d2dContext.AntialiasMode     = AntialiasMode.Aliased;
            _d2dContext.UnitMode          = UnitMode.Pixels;

            _hudYellow     = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 0.0f, 1.0f));
            _hudWhite      = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 1.0f, 1.0f));
            _hudTextFormat = new TextFormat(_dwFactory, "Sonic Genesis/Mega Drive Font", _fontCollection, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 14);

            // init game stuff
            _game = gameEngine;

            _texResMan    = new TextureResourceManager(gameEngine, _d2dContext);
            _spriteResMan = new SpriteResourceManager(gameEngine, _d2dContext);

            // get the services
            _mapService       = _game.GetService <IMapService>();
            _varService       = _game.GetService <IVariableService>();
            _entityService    = _game.GetService <IEntityService>();
            _renderService    = _game.GetService <IRenderService>();
            _collisionService = _game.GetService <ICollisionService>();

            _varShowCollisionMaps  = _varService.GetVar <bool>("r_showcollisionmaps");
            _varShowTileFrames     = _varService.GetVar <bool>("r_showtileframes");
            _varShowEntityOrigins  = _varService.GetVar <bool>("r_showentityorigins");
            _varShowTraceLines     = _varService.GetVar <bool>("r_showtracelines");
            _varShowCollisionBoxes = _varService.GetVar <bool>("r_showcollisionboxes");

            _rc = new RenderContext();

            _spriteRenderList = new List <Animatable>(25);
        }
コード例 #26
0
ファイル: VariableParser.cs プロジェクト: MisterDr/FOCommon
        public bool Parse()
        {
            if (!File.Exists(FileName))
                return false;

            bool Parse=false;
            bool ParseComment = false;
            string Comment="";
            GameVariable GameVar = null;

            foreach (String Line in File.ReadAllLines(FileName, Encoding.GetEncoding("Windows-1251")))
            {
                if (Line == "**************************************************************************************")
                    Parse = !Parse;
                if (Line == "**********")
                {
                    ParseComment = !ParseComment;
                    if (!ParseComment) // end of variable
                    {
                        if (GameVar != null)
                        {
                            GameVar.Description = Comment;
                            Variables.Add(GameVar);
                        }
                        Comment = "";
                    }
                    else
                        continue;
                }

                if (!Parse || Line.Length < 3)
                    continue;

                if (ParseComment)
                {
                    Comment += Line + Environment.NewLine;
                }

                if (Line[0] == '$')
                {
                    GameVar = new GameVariable();
                    String[] Params = Line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    GameVar.Id = Int32.Parse(Params[1]);
                    GameVar.Type = (GameVariableType)Int32.Parse(Params[2]);
                    GameVar.Name = Params[3];
                    GameVar.StartValue = Int32.Parse(Params[4]);
                    GameVar.MinValue = Int32.Parse(Params[5]);
                    GameVar.MaxValue = Int32.Parse(Params[6]);

                    if (Params.Length > 7)
                    {
                        int Flags = Int32.Parse(Params[7]);
                        GameVar.Quest = ((Flags & 1) == 1);
                        GameVar.Random = ((Flags & 2) == 2);
                        GameVar.NoLimit = ((Flags & 4) == 4);
                    }
                }
            }

            return true;
        }
コード例 #27
0
	public void Setup (GameVariable thisGameVar) {
        gameVar = thisGameVar;
        slider = GetComponentInChildren<CircularSlider>();
        titleText.text = gameVar.name;
	}
コード例 #28
0
 public void Setup(GameVariable thisGameVar)
 {
     gameVar        = thisGameVar;
     slider         = GetComponentInChildren <CircularSlider>();
     titleText.text = gameVar.name;
 }
コード例 #29
0
ファイル: GameScript.cs プロジェクト: lblanch/ekojam2019
    void LoadData()
    {
        GameVariable     auxVar;
        GamePercentGroup auxGroup;
        Action           auxAction;

        VariablesHelper.baseVariables.Clear();
        VariablesHelper.groupVariables.Clear();
        VariablesHelper.actions.Clear();
        VariablesHelper.actionsAppearences.Clear();

        //Indexes for variables
        //CO2 -> 0
        //population -> 1
        //food -> 2
        //happiness -> 3

        auxVar = new GameVariable("CO2", "kilotons", 2000, 0, 500000, -500000);
        auxVar.maxConsequence.isGameOver = true;
        auxVar.minConsequence.isGameOver = false;
        VariablesHelper.baseVariables.Add(auxVar);
        CO2Index = 0;

        auxVar = new GameVariable("Population", "persons", 500, 0.1f, 4000, 0);
        //eat food
        auxVar.AddAction(2, -0.5f);
        auxVar.maxConsequence.isGameOver = false;
        auxAction = new Action("People too cramped, unhappy!");
        auxAction.AddVariableAction(3, -20);
        auxVar.maxConsequence.AddConsequenceActions(auxAction);
        auxVar.minConsequence.isGameOver = true;
        VariablesHelper.baseVariables.Add(auxVar);

        auxVar = new GameVariable("Food", "kg", 5000, 0, 6000, 2000);
        auxVar.maxConsequence.isGameOver = false;
        auxAction = new Action("People unhappy we are trowing away food!");
        auxAction.AddVariableAction(3, -20);
        auxVar.maxConsequence.AddConsequenceActions(auxAction);
        auxVar.minConsequence.isGameOver = false;
        auxAction = new Action("People migrate out of country because of starvation!");
        auxAction.AddVariableAction(1, -20);
        auxVar.minConsequence.AddConsequenceActions(auxAction);
        auxAction = new Action("People unhappy because of starvation!");
        auxAction.AddVariableAction(3, -20);
        auxVar.minConsequence.AddConsequenceActions(auxAction);
        VariablesHelper.baseVariables.Add(auxVar);

        auxVar = new GameVariable("Happiness", "%", 60, 0, 100, 0);
        auxVar.minConsequence.isGameOver = true;
        auxVar.maxConsequence.isGameOver = false;
        VariablesHelper.baseVariables.Add(auxVar);

        auxGroup = new GamePercentGroup();
        auxVar   = new GameVariable("City Land", "m2", 10, 40, 100, 0);
        auxVar.minConsequence.isGameOver = true;
        auxVar.maxConsequence.isGameOver = true;
        auxGroup.AddToGroup(auxVar);
        auxVar = new GameVariable("Farming Land", "m2", 30, 60, 100, 0);
        auxVar.minConsequence.isGameOver = true;
        auxVar.maxConsequence.isGameOver = true;
        auxVar.AddAction(2, 1.0f);
        auxGroup.AddToGroup(auxVar);
        auxVar = new GameVariable("Forest", "m2", 40, -2000, 100, 0);
        auxVar.minConsequence.isGameOver = true;
        auxVar.maxConsequence.isGameOver = true;
        auxGroup.AddToGroup(auxVar);
        auxVar = new GameVariable("Sea", "m2", 20, 0, 100, 0);
        auxVar.minConsequence.isGameOver = true;
        auxVar.maxConsequence.isGameOver = true;
        auxGroup.AddToGroup(auxVar);
        VariablesHelper.groupVariables.Add(auxGroup);

        //add actions to action vector
        auxAction = new Action("Increase city land");
        auxAction.AddGroupAction(0, 2, 0, 20);
        auxAction.AddVariableAction(1, 10);
        VariablesHelper.actions.Add(auxAction);
        VariablesHelper.actionsAppearences.Add(0);

        auxAction = new Action("Add farming land");
        auxAction.AddGroupAction(0, 2, 1, 10);
        VariablesHelper.actions.Add(auxAction);
        VariablesHelper.actionsAppearences.Add(0);

        auxAction = new Action("Turn farming land to forest");
        auxAction.AddGroupAction(0, 1, 2, 30);
        VariablesHelper.actions.Add(auxAction);
        VariablesHelper.actionsAppearences.Add(0);

        auxAction = new Action("Increase farming and city land");
        auxAction.AddGroupAction(0, 2, 1, 40);
        auxAction.AddGroupAction(0, 2, 0, 20);
        VariablesHelper.actions.Add(auxAction);
        VariablesHelper.actionsAppearences.Add(0);

        auxAction = new Action("Organize big party on your city");
        auxAction.AddVariableAction(0, 400);
        auxAction.AddVariableAction(3, 20);
        VariablesHelper.actions.Add(auxAction);
        VariablesHelper.actionsAppearences.Add(0);

        //add CO2 cycle Action for all variables
        foreach (GameVariable var in VariablesHelper.baseVariables)
        {
            var.AddAction(CO2Index, var.CalculateCO2());
        }
        foreach (GamePercentGroup var in VariablesHelper.groupVariables)
        {
            foreach (GameVariable varVar in var.variables)
            {
                varVar.AddAction(CO2Index, varVar.CalculateCO2());
            }
        }
    }
コード例 #30
0
    public int GetConditionVariableValue(int id)
    {
        int res = 0;

        if (gameVariableDict.ContainsKey(id))
        {
            // Dictionary<int,Dictionary<int, int>> savedData = gameVariableDict[id];
            GameVariable gameVariable = GameDataCache.Instance.gameVariableSet.GetGameVariableByID(id);


            List <string>      pathStrList = gameVariable.path;
            List <List <int> > pathList    = new List <List <int> >();
            for (int i = 0; i < pathStrList.Count; i++)
            {
                string[]   pathStr = pathStrList[i].Split(',');
                List <int> path    = new List <int>();
                for (int j = 0; j < pathStr.Length; j++)
                {
                    path.Add(int.Parse(pathStr[j]));
                }

                pathList.Add(path);
            }


            for (int i = historyActionList.Count - 1; i >= 0; i--)
            {
                int actionID = historyActionList[i];


                List <List <int> > containedPathList = CalulatePath(pathList, actionID);

                if (containedPathList.Count == 0)
                {
                    continue;
                }
                else if (containedPathList.Count == 1)
                {
                    int pathID = pathList.FindIndex(a => a == containedPathList[0]);
                    res = CalculatePathValue(containedPathList[0], pathID, id, actionID);
                    LogManager.Log("Variable id: " + id + " value: " + res);
                    return(res);
                }
                else if (containedPathList.Count > 1)
                {
                    List <List <int> > completePathList = new List <List <int> >();
                    for (int j = 0; j < containedPathList.Count; j++)
                    {
                        int actionIndex = containedPathList[j].FindIndex(a => a == actionID);
                        int k           = actionIndex;
                        if (actionIndex >= 1)
                        {
                            for (k = actionIndex - 1; k >= 0; k--)
                            {
                                int tempActionID = containedPathList[j][k];
                                if (!historyActionList.Contains(tempActionID))
                                {
                                    break;
                                }
                            }
                        }

                        if (k <= 0)
                        {
                            completePathList.Add(containedPathList[j]);
                        }
                    }

                    if (completePathList.Count == 0)
                    {
                        LogManager.LogError("no path !!!");
                    }
                    else if (completePathList.Count == 1)
                    {
                        LogManager.Log("Variable id: " + id + " value: " + res);
                        int pathID = pathList.FindIndex(a => a == containedPathList[0]);
                        res = CalculatePathValue(completePathList[0], pathID, id, actionID);
                        return(res);
                    }
                    else
                    {
                        List <List <int> > containedPrePathList = completePathList;

                        while (containedPrePathList.Count != 1)
                        {
                            i--;
                            if (i < 0)
                            {
                                break;
                                //LogManager.LogError("Data Error! no avaliable data");
                                //return res;
                            }

                            int preActionID = historyActionList[i];
                            if (preActionID < actionID)
                            {
                                containedPrePathList = CalulatePath(containedPrePathList, preActionID);
                            }
                        }

                        if (containedPrePathList.Count > 1)
                        {
                            int optionIndex = optionStatusDict[actionID] - 1;
                            OptionActionData optionActionData =
                                GameDataCache.Instance.optionActionDataSet.GetOptionActionDataByID(actionID);
                            int        optionID   = optionActionData.options[optionIndex];
                            OptionData optionData = GameDataCache.Instance.optionDataSet.GetOptionDataByID(optionID);
                            for (int j = 0; j < containedPrePathList.Count; j++)
                            {
                                int pathID = pathList.FindIndex(a => a == containedPrePathList[j]);

                                if (optionData.pathIDList.Contains(pathID))
                                {
                                    res = CalculatePathValue(containedPrePathList[j], pathID, id, actionID);
                                    LogManager.Log("Variable id: " + id + " value: " + res);
                                    return(res);
                                }
                            }
                        }
                        else if (containedPrePathList.Count == 1)
                        {
                            int pathID = pathList.FindIndex(a => a == containedPrePathList[0]);
                            res = CalculatePathValue(containedPrePathList[0], pathID, id, actionID);
                            LogManager.Log("Variable id: " + id + " value: " + res);
                            return(res);
                        }
                    }
                }
            }
        }

        return(res);
    }
コード例 #31
0
ファイル: EditorHelper.cs プロジェクト: hughrogers/RPGQuest
    public static GameVariable GameVariableSettings(GameVariable var)
    {
        if(GUILayout.Button("Add variable", GUILayout.Width(mWidth)))
        {
            var.AddVariable();
        }
        for(int i=0; i<var.variableKey.Length; i++)
        {
            EditorGUILayout.BeginHorizontal();
            if(GUILayout.Button("Remove", GUILayout.Width(mWidth*0.3f)))
            {
                var.RemoveVariable(i);
                break;
            }
            var.remove[i] = EditorGUILayout.Toggle("Remove", var.remove[i], GUILayout.Width(mWidth));
            var.variableKey[i] = EditorGUILayout.TextField("Key", var.variableKey[i], GUILayout.Width(mWidth));
            if(!var.remove[i])
            {
                var.variableValue[i] = EditorGUILayout.TextField("Value", var.variableValue[i], GUILayout.Width(mWidth));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.Separator();

        if(GUILayout.Button("Add number variable", GUILayout.Width(mWidth)))
        {
            var.AddNumberVariable();
        }
        for(int i=0; i<var.numberVarKey.Length; i++)
        {
            EditorGUILayout.BeginHorizontal();
            if(GUILayout.Button("Remove", GUILayout.Width(mWidth*0.3f)))
            {
                var.RemoveNumberVariable(i);
                break;
            }
            var.removeNumber[i] = EditorGUILayout.Toggle("Remove", var.removeNumber[i], GUILayout.Width(mWidth));
            var.numberVarKey[i] = EditorGUILayout.TextField("Key", var.numberVarKey[i], GUILayout.Width(mWidth));
            if(!var.removeNumber[i])
            {
                var.changeType[i] = (SimpleOperator)EditorGUILayout.EnumPopup(
                        var.changeType[i], GUILayout.Width(EditorHelper.mWidth*0.5f));
                var.numberVarValue[i] = EditorGUILayout.FloatField(var.numberVarValue[i], GUILayout.Width(mWidth*0.5f));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
        }
        return var;
    }