Esempio n. 1
0
    private List <ChassisRule> LoadChassisRules(TextAsset txt)
    {
        List <ChassisRule> chassisRules = new List <ChassisRule>();

        if (txt != null)
        {
            Debug.Log("Loading chassis rules from csv");
            StreamReader reader = new StreamReader(new MemoryStream(txt.bytes));

            while (reader.Peek() != -1)
            {
                ChassisRule rule = new ChassisRule();
                string      s    = reader.ReadLine(); //one entire rule
                string[]    arr  = s.Split(',');      //split into conditions, visual, effects etc
                for (int i = 0; i < arr.Length; i++)
                {
                    //detect function call names
                    if (arr[i].StartsWith("_"))
                    {
                        //split on SPACE to break into a string name in [0] and parameter(s) in [1],[2] etc
                        string[]     ob = arr[i].Split();
                        FunctionCall e  = CreateFunctionCall(ob);

                        if (e != null)
                        {
                            rule.functons.Add(e);
                        }
                    }
                    //detect visuals -- we dont need this here, visuals and rules are totally seperate
                    if (arr[i].StartsWith("\""))
                    {
                        //rule.visual = arr[i];
                    }
                    if (!arr[i].StartsWith("_") && !arr[i].StartsWith("\""))
                    {
                        //split on SPACE to break into a string name in [0] and parameter(s) in [1],[2] etc
                        string[]         ob = arr[i].Split();
                        ChassisCondition cc = CreateChassisCondition(ob);

                        if (cc != null)
                        {
                            rule.conditions.Add(cc);
                        }
                    }
                }
                chassisRules.Add(rule);
            }
        }

        else
        {
            Debug.Log("Error: txt asset is null");
        }

        Debug.Log(chassisRules.Count + " Chassis rules loaded");
        return(chassisRules);
    }
Esempio n. 2
0
    private List <ChassisRule> LoadDefaultChassisVisuals(TextAsset txt)
    {
        List <ChassisRule> chassisRules = new List <ChassisRule>();

        if (txt != null)
        {
            Debug.Log("Loading default chassis visuals from csv");
            StreamReader reader = new StreamReader(new MemoryStream(txt.bytes));

            while (reader.Peek() != -1)
            {
                ChassisRule rule = new ChassisRule();
                string      s    = reader.ReadLine(); //one entire rule
                string[]    arr  = s.Split(',');      //split into conditions, visual, effects etc
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i].StartsWith("\""))
                    {
                        rule.visual = arr[i];
                    }
                    else
                    {
                        string[]         ob = arr[i].Split();
                        ChassisCondition cc = CreateChassisCondition(ob);

                        if (cc != null)
                        {
                            rule.conditions.Add(cc);
                        }
                    }
                }
                chassisRules.Add(rule);
            }
            Debug.Log(chassisRules.Count + " default chassis visuals loaded");
        }

        else
        {
            Debug.Log("Error: txt asset is null");
        }

        return(chassisRules);
    }