Ejemplo n.º 1
0
    void OnDeletedActor(string[] newContent, BaseRuleElement.ActorData oldActor)
    {
        string[] newNames = new string[newContent.Length]; // there should be only one actor with the old label in the list
        int oldSelected = System.Array.FindIndex(Content, item => item.text == oldActor.label);
        if (oldSelected == -1)
            extended = true;

        int j = 0;
        for (int i = 0; i < Content.Length; i++)
        {
            if (Content[i].text != oldActor.label)
            {
                newNames[j] = Content[i].text;
                j++;
            }
        }

        if (oldSelected >= 0 && oldSelected < Content.Length && Selected > oldSelected)
        {
            string oldName = Content[oldSelected].text;
            Selected = System.Array.FindIndex(newNames, item => item == oldName);
        }

        ChangeContent(newNames);
    }
Ejemplo n.º 2
0
 void OnRenamedActor(string[] newContent, BaseRuleElement.ActorData changedActor, string oldName)
 {
     for (int i = 0; i < Content.Length; i++)
     {
         if (Content[i].text == oldName)
         {
             Content[i].text = changedActor.label;
             break;
         }
     }
 }
Ejemplo n.º 3
0
    void OnAddedActor(string[] newContent, BaseRuleElement.ActorData newActor)
    {
        string[] newNames = new string[Content.Length + 1];

        // copy old names
        int i = 0;
        for (; i < Content.Length; i++)
            newNames[i] = Content[i].text;

        // add new name
        newNames[i++] = newActor.label;

        ChangeContent(newNames);
    }
Ejemplo n.º 4
0
    void DeleteReaction(BaseRuleElement.ReactionData reaction)
    {
        if (eventReactionDict.ContainsKey(reaction.eventId))
            eventReactionDict[reaction.eventId].Remove(reaction.id);
        if (actorReactionDict.ContainsKey(reaction.actorId))
            actorReactionDict[reaction.actorId].Remove(reaction.id);

        reactionData.Remove(reaction);

        Analytics.LogEvent(Analytics.ruleEvent, Analytics.delete_reaction, reaction.label);
    }
Ejemplo n.º 5
0
    BaseRuleElement.Param ShowParameterValue(BaseRuleElement.Param parameter)
    {
        // handle parameter value according to type

        // ACTORS
        if (parameter.type.IsSubclassOf(typeof(Actor)) || parameter.type.IsAssignableFrom(typeof(Actor)))
        {
            // get names
            string[] names = new string[actorData.Count + 1];
            for (int i = 0; i < actorData.Count; i++)
            {
                names[i] = actorData[i].label;
            }
            names[names.Length - 1] = "None"; // add option to have no actor selected

            // show selection grid
            int selected = GUILayout.SelectionGrid((int)parameter.value, names, 2, selectionGridStyle);

            // feed back selected actor
            if (selected == names.Length - 1) // chose "None"
                parameter.value = -1;
            else if (selected < names.Length - 1 && selected >= 0)
                parameter.value = actorData.Find(item => item.label == names[selected]).id;
        }
        // ENUMS
        else if (parameter.type.IsEnum)
        {
            string[] names = Enum.GetNames(parameter.type);
            int selected = GUILayout.SelectionGrid((int)parameter.value, names, 2, selectionGridStyle);
            if (selected < names.Length) // when invisible, this gets some weeeird values
                parameter.value = Enum.Parse(parameter.type, names[selected]);
        }
        // INT
        else if (parameter.value is int)
        {
            string v = GUILayout.TextField(parameter.value.ToString(), GUILayout.Width(100));
            if (v == "")
                parameter.value = 0;
            else
                parameter.value = int.Parse(v);
        }
        // FLOAT
        else if (parameter.value is float)
        {
            string v = GUILayout.TextField(parameter.value.ToString(), GUILayout.Width(100));
            if (v == "")
                parameter.value = 0;
            else
                parameter.value = float.Parse(v);
        }
        // VECTOR3
        else if (parameter.type == typeof(Vector3))
        {
            string show;
            if (vectorParamTemporaries.ContainsKey(parameter.name))
            {
                show = vectorParamTemporaries[parameter.name];
            }
            else
            {
                Vector3 vec = (Vector3)parameter.value;
                show = vec.x + " " + vec.y + " " + vec.z;
                vectorParamTemporaries.Add(parameter.name, show);
            }

            vectorParamTemporaries[parameter.name] = GUILayout.TextField(show);

            if (GUILayout.Button("Set"))
            {
                string[] s = vectorParamTemporaries[parameter.name].Split(' ');
                float parseresult;
                Vector3 vec = (Vector3)parameter.value;
                int i;
                for (i = 0; i < s.Length && i < 3; i++)
                {
                    if (float.TryParse(s[i], out parseresult))
                    {
                        vec[i] = parseresult;
                    }
                }
                // handling any number of spaces in string
                for (; i < 3; i++)
                {
                    vec[i] = 0;
                }
                vectorParamTemporaries.Remove(parameter.name);
                parameter.value = vec;
            }
        }
        // BOOL
        else if (parameter.value is bool)
        {
            parameter.value = GUILayout.Toggle((bool)parameter.value, "");
        }
        // STRING
        else if (parameter.type == typeof(string))
        {
            parameter.value = GUILayout.TextField(parameter.value.ToString(), GUILayout.Width(100));
        }
        // LIST<STRING>
        else if (parameter.type == typeof(List<string>))
        {
            List<string> values = parameter.value as List<string>;
            List<int> delete = new List<int>();
            GUILayout.BeginVertical();
            for (int i = 0; i < values.Count; i++)
            {
                GUILayout.BeginHorizontal();
                values[i] = GUILayout.TextField(values[i]);

                if (GUILayout.Button("Del"))
                {
                    delete.Add(i);
                }

                GUILayout.EndHorizontal();
            }

            if (GUILayout.Button("Add"))
            {
                values.Add("");
            }
            GUILayout.EndVertical();

            for (int i = 0; i < delete.Count; i++)
            {
                values.RemoveAt(delete[i]);
            }

            parameter.value = values;
        }

        return parameter;
    }
Ejemplo n.º 6
0
 public override void ShowGui(BaseRuleElement.RuleData ruleData)
 {
 }
Ejemplo n.º 7
0
    public override void ShowGui(BaseRuleElement.RuleData ruleData)
    {
        // column 1
        GUILayout.BeginVertical();

        // label
        GUILayout.BeginHorizontal();

        GUILayout.Label("Name: ", RuleGUI.ruleLabelStyle);
        string oldName = Label;
        name = Label = RuleGUI.ShowParameter(Label);
        if (oldName != Label)
            RuleGenerator.Gui.Rename(Id, Label);

        GUILayout.EndHorizontal();

        // type
        GUILayout.BeginHorizontal();
        GUILayout.Label("Type: " + GetType(), RuleGUI.smallLabelStyle);
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();

        // column 2
        if (ShowPrefabInGUI)
        {
            RuleGUI.VerticalLine();

            GUILayout.BeginVertical();

            // prefab
            GUILayout.BeginHorizontal();
            GUILayout.Label("Prefab", RuleGUI.ruleLabelStyle);
            int index = prefabDropDown.Draw();
            if (index > -1)
            {
                string temp = prefabDropDown.Content[index].text;
                if (temp != CurrentPrefab)
                {
                    OldPrefab = CurrentPrefab;
                    CurrentPrefab = temp;
                }
                (ruleData as ActorData).prefab = CurrentPrefab;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
    }