Exemple #1
0
 void Start()
 {
     typePicker = gameObject.AddComponent <TypePickerGUI>();
     typePicker.categoryNames = GameScripts.behaviorTabNames;
     UpdateBehaviorList();
     typePicker.handler = (PropertiesObjectType type) =>
     {
         PropertiesObjectType behaviorTypeWithTarget = new PropertiesObjectType(
             type, () =>
         {
             EntityBehavior behavior = (EntityBehavior)type.Create();
             if (targetEntityIsActivator)
             {
                 behavior.targetEntityIsActivator = true;
             }
             else if (targetEntity != null)
             {
                 behavior.targetEntity = new EntityReference(targetEntity);
             }
             return(behavior);
         });
         handler(behaviorTypeWithTarget);
         Destroy(this);
     };
     typePicker.enabled = false;
 }
Exemple #2
0
 public PropertiesObjectType(PropertiesObjectType baseType, PropertiesObjectConstructor newConstructor)
 {
     this.fullName        = baseType.fullName;
     this.description     = baseType.description;
     this.longDescription = baseType.longDescription;
     this.iconName        = baseType.iconName;
     this.type            = baseType.type;
     constructor          = newConstructor;
 }
Exemple #3
0
    public virtual ICollection <Property> Properties()
    {
        return(new Property[]
        {
            new Property("tar", "Target",
                         () => new BehaviorTargetProperty(targetEntity, targetEntityIsActivator),
                         v => {
                var prop = (BehaviorTargetProperty)v;

                // selfEntity will be null if multiple entities are selected
                Entity selfEntity = EntityReferencePropertyManager.CurrentEntity();

                var oldTargetEntity = targetEntity.entity;
                var newTargetEntity = prop.targetEntity.entity;
                if (oldTargetEntity == null && !targetEntityIsActivator)
                {
                    oldTargetEntity = selfEntity;
                }
                if (newTargetEntity == null && !prop.targetEntityIsActivator)
                {
                    newTargetEntity = selfEntity;
                }

                if (oldTargetEntity != null)
                {
                    // replace all property values referencing the old target with the new target
                    // the new target could be null
                    foreach (Property _selfProp in this.Properties())
                    {
                        var selfProp = _selfProp;
                        selfProp.value = PropertiesObjectType.PropertyValueReplaceEntity(
                            selfProp.value, oldTargetEntity, newTargetEntity);
                    }
                }

                targetEntity = prop.targetEntity;
                targetEntityIsActivator = prop.targetEntityIsActivator;
            },
                         PropertyGUIs.BehaviorTarget),
            new Property("con", "Condition",
                         () => condition,
                         v => condition = (Condition)v,
                         (Property property) => {
                if (targetEntityIsActivator)
                {
                    PropertyGUIs.ActivatorBehaviorCondition(property);
                }
                else
                {
                    PropertyGUIs.BehaviorCondition(property);
                }
            })
        });
    }
Exemple #4
0
    public List <string> BuildWorld(Transform cameraPivot, VoxelArray voxelArray, bool editor)
    {
        var warnings = ReadWorldFile.Read(Resources.Load <TextAsset>("default"),
                                          cameraPivot, voxelArray, editor);

        foreach (var obj in voxelArray.IterateObjects())
        {
            if (obj is PlayerObject)
            {
                var behavior = new SunVoxSongBehavior();
                PropertiesObjectType.SetProperty(behavior, "dat", data);
                obj.behaviors.Add(behavior);
                break;
            }
        }
        return(warnings);
    }
Exemple #5
0
    public override void WindowGUI()
    {
        if (categoryNames.Length > 1)
        {
            int tab = GUILayout.SelectionGrid(selectedCategory, categoryNames,
                                              categoryNames.Length, GUIStyleSet.instance.buttonTab);
            if (tab != selectedCategory)
            {
                selectedCategory = tab;
                scroll           = Vector2.zero;
                scrollVelocity   = Vector2.zero;
            }
        }

        var categoryItems = categories[selectedCategory];

        scroll = GUILayout.BeginScrollView(scroll);
        for (int i = 0; i < categoryItems.Length; i++)
        {
            PropertiesObjectType item = categoryItems[i];
            GUIUtils.BeginButtonHorizontal(item.fullName);
            GUILayout.Label(item.icon, GUILayout.ExpandWidth(false));
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label(item.fullName, GUIStyleSet.instance.labelTitle);
            if (item.longDescription != "" &&
                GUILayout.Button(GUIIconSet.instance.helpCircle, helpIconStyle.Value, GUILayout.ExpandWidth(false)))
            {
                var typeInfo = gameObject.AddComponent <TypeInfoGUI>();
                typeInfo.type = item;
            }
            GUILayout.EndHorizontal();
            GUILayout.Label("<i>" + item.description + "</i>", descriptionStyle.Value);
            GUILayout.EndVertical();
            if (GUIUtils.EndButtonHorizontal(item.fullName))
            {
                handler(item);
                Destroy(this);
            }
        }
        GUILayout.EndScrollView();
    }
Exemple #6
0
    public virtual Entity Clone()
    {
        var newEntity = (Entity)(ObjectType().Create());

        PropertiesObjectType.CopyProperties(this, newEntity, this, newEntity);
        if (sensor != null)
        {
            newEntity.sensor = (Sensor)(sensor.ObjectType().Create());
            PropertiesObjectType.CopyProperties(sensor, newEntity.sensor, this, newEntity);
        }
        else
        {
            newEntity.sensor = null; // in case the Object Type had a default sensor
        }
        newEntity.behaviors.Clear(); // in case the Object Type had default behaviors
        foreach (var behavior in behaviors)
        {
            var newBehavior = (EntityBehavior)(behavior.ObjectType().Create());
            PropertiesObjectType.CopyProperties(behavior, newBehavior, this, newEntity);
            newEntity.behaviors.Add(newBehavior);
        }
        return(newEntity);
    }
Exemple #7
0
    // merge properties of objects
    public StoredPropertiesObject(PropertiesObject[] objects)
    {
        properties = new List <Property>();
        if (objects.Length == 0)
        {
            return;
        }
        if (objects[0] != null)
        {
            type = objects[0].ObjectType();
        }
        // check that all objects have the same type. if they don't, fail
        foreach (PropertiesObject obj in objects)
        {
            PropertiesObjectType objType = null;
            if (obj != null)
            {
                objType = obj.ObjectType();
            }
            if (objType != type)
            {
                type = DIFFERENT_OBJECT_TYPE;
                return;
            }
        }
        if (type == null)
        {
            return; // null objects, no properties
        }
        // first index: object
        // second index: property
        List <List <Property> > objectPropertiesSets = new List <List <Property> >();

        foreach (PropertiesObject obj in objects)
        {
            objectPropertiesSets.Add(new List <Property>(obj.Properties()));
        }

        int numObjects    = objectPropertiesSets.Count;
        int numProperties = objectPropertiesSets[0].Count;

        for (int propertyI = 0; propertyI < numProperties; propertyI++)
        {
            int      _propertyI    = propertyI; // for use in lambda functions -- won't change
            Property firstProperty = objectPropertiesSets[0][propertyI];

            GetProperty getter = () =>
            {
                object value = objectPropertiesSets[0][_propertyI].getter();
                for (int objectI = 0; objectI < numObjects; objectI++)
                {
                    if (!(objectPropertiesSets[objectI][_propertyI].getter().Equals(value)))
                    {
                        return(NOT_EQUAL_VALUE);
                    }
                }
                return(value);
            };

            SetProperty setter = value =>
            {
                for (int objectI = 0; objectI < numObjects; objectI++)
                {
                    objectPropertiesSets[objectI][_propertyI].setter(value);
                }
            };

            PropertyGUI gui = property =>
            {
                if (property.getter() == (object)NOT_EQUAL_VALUE)
                {
                    GUILayout.BeginHorizontal();
                    PropertyGUIs.AlignedLabel(property);
                    if (GUILayout.Button("different"))
                    {
                        // set all properties to one value
                        property.setter(firstProperty.getter());
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    firstProperty.gui(property);
                }
            };

            properties.Add(new Property(
                               firstProperty.id, firstProperty.name, getter, setter, gui, firstProperty.explicitType));
        }
    }
Exemple #8
0
 public StoredPropertiesObject(PropertiesObject store)
 {
     type       = store.ObjectType();
     properties = store.Properties();
 }
        }                             // deserialization

        public EntityTypeFilter(PropertiesObjectType type)
        {
            entityType = type;
        }