Exemple #1
0
        private void AddRule(RuleData rd)
        {
            //update data
            SaveLoadManager.Instance.AddNewRule(rd);

            AddRuleUI(rd);
        }
        public void UpdateAllUI(RuleData rd)
        {
            if (rd != null)
            {
                OnThisColorChange(0);
                OnIfColorChange(0);
                OnThenColorChange(0);
                OnMinNeighborsChange(0);
                OnMaxNeighborsChange(0);
            }


            //because we can "create rules" by changing rulesets, we need to ensure they line up
            //with the tutorial. They should simply be transparent or not, no need to change raycast targets.
            if (SaveLoadManager.Instance.ShouldShowTutorial)
            {
                //for each child of this root obj
                Transform[] ts = transform.GetComponentsInChildren <Transform>();
                foreach (Transform childT in ts)
                {
                    TutorialManager.Instance.ChangeAlphaOnCompatibleComponents(childT.gameObject,
                                                                               TutorialManager.Instance.ShouldShowRules ? 1f : TutorialManager.MIN_ALPHA);
                }
            }
        }
Exemple #3
0
        private void AddRuleUI(RuleData rd, bool b_locked = false)
        {
            //create new rule UI
            RuleBehavior rb = Instantiate(m_RuleBehaviorPrefab);

            rb.transform.SetParent(m_RulesetParent);
            rb.txtRuleX.text = String.Format(RuleBehavior.c_RuleXString, (rb.transform.GetSiblingIndex() + 1).ToString());
            rb.SetLocked(b_locked);

            //Initialize all ui elements in from ruledata
            rb.UpdateAllUI(rd);
        }
Exemple #4
0
        public void AddNewRule(RuleData rd)
        {
            //convert from json to object
            RulesetList rsets = JsonUtility.FromJson <RulesetList>(
                PlayerPrefs.GetString(c_RulesetsKey)
                );

            rsets.list[CurrentRulesetIndex].list.Add(rd);

            //save
            PlayerPrefs.SetString(c_RulesetsKey,
                                  //convert from object to json
                                  JsonUtility.ToJson(rsets)
                                  );

            PlayerPrefs.Save();
        }
Exemple #5
0
        //TODO: Evaluate can be generic, object param cast to RuleData ?
        internal virtual void Evaluate(RuleData rule)
        {
            //cache m_Cells only on the first evaluation since we wrote the cache
            if (m_CellsCache == null)
            {
                //m_CellsCache = m_Cells;
                m_CellsCache = new int[m_Area];
                for (int i = 0; i < m_Area; i++)
                {
                    m_CellsCache[i] = m_Cells[i];
                }
            }
            //for each cell
            for (int i = 0; i < m_Area; i++)
            {
                int iColor = m_Cells[i];

                //if concerning cells of color: (0=all)
                if (rule.m_ThisColor == 0 ||
                    rule.m_ThisColor == iColor)
                {
                    int[] neighbors = GetNeighbors(i);

                    //find all neighbors matching ifcolor
                    int relevantNeighborCount = 0;
                    for (int j = 0; j < neighbors.Length; j++)
                    {
                        if (neighbors[j] == rule.m_IfColor)
                        {
                            relevantNeighborCount++;
                        }
                    }

                    //if between <MIN (inclusive)> and <MAX (inclusive)> neighbors are <COLOR>
                    if ((rule.m_MinNumNeighbors <= relevantNeighborCount &&
                         rule.m_MaxNumNeighbors >= relevantNeighborCount) ||
                        rule.m_IfColor == 0) //evaluate to true if if color is ANY
                    {
                        //Then this cell will change to <COLOR>
                        m_CellsCache[i] = rule.m_ThenColor;
                    }
                }
                //if no change in color is determined, remain unchanged into the next state
            }
        }