Beispiel #1
0
    public void SmartItemComponent()
    {
        SmartItemComponent.Model model = new SmartItemComponent.Model();

        string testFloatKey = "TestFloat";
        float  testFloat    = 20f;

        string intKey  = "Speed";
        int    testInt = 10;

        string stringKey  = "TextExample";
        string testString = "unit test example";

        string onClickKey = "OnClick";


        Dictionary <object, object> onClickDict = new Dictionary <object, object>();

        onClickDict.Add(testFloatKey, testFloat);

        model.values = new Dictionary <object, object>();
        model.values.Add(intKey, testInt);
        model.values.Add(testFloatKey, testFloat);
        model.values.Add(stringKey, testString);
        model.values.Add(onClickKey, onClickDict);

        string jsonModel = JsonUtility.ToJson(model);

        string entityId = "1";

        TestHelpers.CreateSceneEntity(scene, entityId);
        SmartItemComponent smartItemComponent = null;

        //Note (Adrian): This shouldn't work this way, we should have a function to create the component from Model directly
        scene.EntityComponentCreateOrUpdateFromUnity(entityId, CLASS_ID_COMPONENT.SMART_ITEM, jsonModel);

        if (scene.entities[entityId].TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out BaseComponent baseComponent))
        {
            //Note (Adrian): We can't wait to set the component 1 frame in production, so we set it like production
            smartItemComponent = ((SmartItemComponent)baseComponent);
            smartItemComponent.UpdateFromModel(model);
        }
        else
        {
            Assert.Fail("Smart Compoenent not found");
        }

        Assert.AreEqual(testInt, smartItemComponent.GetValues()[intKey]);
        Assert.AreEqual(testFloat, smartItemComponent.GetValues()[testFloatKey]);
        Assert.AreEqual(testString, smartItemComponent.GetValues()[stringKey]);

        Dictionary <object, object> onClickDictFromComponent = (Dictionary <object, object>)smartItemComponent.GetValues()[onClickKey];

        Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]);
    }
Beispiel #2
0
    public void SmartItemComponent()
    {
        SmartItemComponent.Model model = new SmartItemComponent.Model();

        string testFloatKey = "TestFloat";
        float  testFloat    = 20f;

        string intKey  = "Speed";
        int    testInt = 10;

        string stringKey  = "TextExample";
        string testString = "unit test example";

        string onClickKey = "OnClick";


        Dictionary <object, object> onClickDict = new Dictionary <object, object>();

        onClickDict.Add(testFloatKey, testFloat);

        model.values = new Dictionary <object, object>();
        model.values.Add(intKey, testInt);
        model.values.Add(testFloatKey, testFloat);
        model.values.Add(stringKey, testString);
        model.values.Add(onClickKey, onClickDict);

        SmartItemComponent smartItemComponent = null;

        scene.EntityComponentCreateOrUpdateWithModel(ENTITY_ID, CLASS_ID_COMPONENT.SMART_ITEM, model);

        if (scene.entities[ENTITY_ID].TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseComponent))
        {
            //Note (Adrian): We can't wait to set the component 1 frame in production, so we set it like production
            smartItemComponent = ((SmartItemComponent)baseComponent);
            smartItemComponent.UpdateFromModel(model);
        }
        else
        {
            Assert.Fail("Smart Component not found");
        }

        Assert.AreEqual(testInt, smartItemComponent.GetValues()[intKey]);
        Assert.AreEqual(testFloat, smartItemComponent.GetValues()[testFloatKey]);
        Assert.AreEqual(testString, smartItemComponent.GetValues()[stringKey]);

        Dictionary <object, object> onClickDictFromComponent = (Dictionary <object, object>)smartItemComponent.GetValues()[onClickKey];

        Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]);
    }
    public void UpdateSmartItemComponent(DCLBuilderInWorldEntity entity, ParcelScene scene)
    {
        SmartItemComponent smartItemComponent = entity.rootEntity.TryGetComponent <SmartItemComponent>();

        if (smartItemComponent == null)
        {
            return;
        }


        entitySingleComponentPayload.entityId    = entity.rootEntity.entityId;
        entitySingleComponentPayload.componentId = (int)CLASS_ID_COMPONENT.SMART_ITEM;

        entitySingleComponentPayload.data = smartItemComponent.GetValues();

        ChangeEntityComponent(entitySingleComponentPayload, scene);
    }
    void GenerateParametersFromIndex(int index)
    {
        string label = actionDropDown.options[index].text;

        SmartItemAction selectedAction = null;

        foreach (SmartItemAction action in selectedEntity.GetSmartItemActions())
        {
            if (action.label == label)
            {
                selectedAction = action;
                break;
            }
        }

        smartItemListView.SetEntityList(entityList);
        smartItemListView.SetSmartItemParameters(selectedAction.parameters, selectedComponent.GetValues());
    }