Пример #1
0
    public static void Target(Property property)
    {
        var    target       = (Target)property.value;
        string targetString = target.ToString();

        Color baseColor = GUI.color;

        if (target.entityRef.entity != null)
        {
            EntityReferencePropertyManager.Next(target.entityRef.entity);
            GUI.color    = baseColor * EntityReferencePropertyManager.GetColor();
            targetString = EntityReferencePropertyManager.GetName();
        }

        GUILayout.BeginHorizontal();
        AlignedLabel(property);
        if (GUILayout.Button(targetString, GUI.skin.textField))
        {
            TargetGUI targetGUI = GUIManager.guiGameObject.AddComponent <TargetGUI>();
            targetGUI.title      = property.name;
            targetGUI.voxelArray = VoxelArrayEditor.instance;
            targetGUI.handler    = (Target newTarget) =>
            {
                property.value = newTarget;
            };
        }
        GUILayout.EndHorizontal();

        GUI.color = baseColor;
    }
Пример #2
0
    public static void Filter(Property property)
    {
        var    filter       = (ActivatedSensor.Filter)property.value;
        string filterString = filter.ToString();

        Color baseColor = GUI.color;

        ActivatedSensor.EntityFilter entityFilter = filter as ActivatedSensor.EntityFilter;
        if (entityFilter != null)
        {
            Entity e = entityFilter.entityRef.entity;
            if (e != null)
            {
                EntityReferencePropertyManager.Next(e);
                GUI.color    = baseColor * EntityReferencePropertyManager.GetColor();
                filterString = EntityReferencePropertyManager.GetName();
            }
        }

        GUILayout.BeginHorizontal();
        AlignedLabel(property);
        if (GUILayout.Button(filterString, GUI.skin.textField))
        {
            FilterGUI filterGUI = GUIManager.guiGameObject.AddComponent <FilterGUI>();
            filterGUI.title      = property.name + " by...";
            filterGUI.voxelArray = VoxelArrayEditor.instance;
            filterGUI.handler    = (ActivatedSensor.Filter newFilter) =>
            {
                property.value = newFilter;
            };
        }
        GUILayout.EndHorizontal();

        GUI.color = baseColor;
    }
Пример #3
0
 public static void BehaviorTarget(Property property)
 {
     var value = (EntityBehavior.BehaviorTargetProperty)(property.value);
     Entity behaviorTarget = value.targetEntity.entity;
     string text;
     if (value.targetEntityIsActivator)
     {
         text = "Activators";
     }
     else if (behaviorTarget != null)
     {
         // only temporarily, so the name won't be "Target":
         EntityReferencePropertyManager.SetBehaviorTarget(null);
         EntityReferencePropertyManager.Next(behaviorTarget);
         text = EntityReferencePropertyManager.GetName();
         EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget); // put it back
     }
     else
     {
         return;
     }
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     GUILayout.Label(GUIIconSet.instance.target, alignedLabelStyle.Value, GUILayout.ExpandWidth(false));
     if (GUILayout.Button("<i>" + text + "</i>", GUILayout.ExpandWidth(false)))
     {
         BehaviorTargetPicker(GUIPanel.guiGameObject, VoxelArrayEditor.instance,
             EntityReferencePropertyManager.CurrentEntity(), newValue =>
             {
                 property.value = newValue;
             });
     }
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
 }
Пример #4
0
    public static void _EntityReferenceCustom(Property property, bool allowNull, string nullName)
    {
        var    reference   = (EntityReference)property.value;
        string valueString = nullName;

        Color baseColor = GUI.color;

        if (reference.entity != null)
        {
            EntityReferencePropertyManager.Next(reference.entity);
            GUI.color   = baseColor * EntityReferencePropertyManager.GetColor();
            valueString = EntityReferencePropertyManager.GetName();
        }

        GUILayout.BeginHorizontal();
        AlignedLabel(property);
        if (GUILayout.Button(valueString, GUI.skin.textField))
        {
            EntityPickerGUI picker = GUIManager.guiGameObject.AddComponent <EntityPickerGUI>();
            picker.voxelArray    = VoxelArrayEditor.instance;
            picker.allowNone     = false;
            picker.allowMultiple = false;
            picker.allowNull     = allowNull;
            picker.nullName      = nullName;
            picker.handler       = (ICollection <Entity> entities) =>
            {
                foreach (Entity entity in entities)
                {
                    property.value = new EntityReference(entity);
                    return;
                }
                property.value = null;
            };
        }
        GUILayout.EndHorizontal();

        GUI.color = baseColor;
    }
Пример #5
0
    private void InputsGUI(Property property)
    {
        Input[] inputs = (Input[])property.value;

        GUILayout.Label("Inputs:");
        if (GUILayout.Button("Add Input"))
        {
            EntityPickerGUI picker = GUIPanel.guiGameObject.AddComponent <EntityPickerGUI>();
            picker.voxelArray = VoxelArrayEditor.instance;
            picker.handler    = (ICollection <Entity> entities) =>
            {
                Input[] newInputs = new Input[inputs.Length + entities.Count];
                Array.Copy(inputs, newInputs, inputs.Length);
                int i = 0;
                foreach (Entity entity in entities)
                {
                    newInputs[inputs.Length + i] = new Input(entity);
                    i++;
                }
                property.value = newInputs;
            };
        }

        bool  copyArray     = false;
        int   inputToDelete = -1;
        Color baseColor     = GUI.color;

        for (int i = 0; i < inputs.Length; i++)
        {
            Entity e = inputs[i].entityRef.entity;
            if (e == null)
            {
                inputToDelete = i;
            }
            EntityReferencePropertyManager.Next(e);
            GUI.color = baseColor * EntityReferencePropertyManager.GetColor();
            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.BeginHorizontal();
            GUILayout.Label(EntityReferencePropertyManager.GetName() + " ");
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("X"))
            {
                inputToDelete = i;
            }
            GUILayout.EndHorizontal();

            int negativeNum    = inputs[i].negative ? 1 : 0;
            int newNegativeNum = GUILayout.SelectionGrid(negativeNum,
                                                         new string[] { "Positive", "Negative" }, 2, GUI.skin.GetStyle("button_tab"));
            if (negativeNum != newNegativeNum)
            {
                inputs[i].negative = newNegativeNum == 1;
                copyArray          = true;
            }
            GUILayout.EndVertical();
        }
        GUI.color = baseColor;
        if (inputToDelete != -1)
        {
            Input[] newInputs = new Input[inputs.Length - 1];
            Array.Copy(inputs, newInputs, inputToDelete);
            Array.Copy(inputs, inputToDelete + 1, newInputs, inputToDelete, newInputs.Length - inputToDelete);
            property.value = newInputs;
        }
        else if (copyArray)
        {
            Input[] newInputs = new Input[inputs.Length];
            Array.Copy(inputs, newInputs, inputs.Length);
            property.value = newInputs; // mark unsaved changes flag
        }
    }