示例#1
0
    void ApplyAction(string entityIdToApply, object value, ActionType actionType, bool isUndo)
    {
        switch (actionType)
        {
        case ActionType.MOVE:
            Vector3 convertedPosition = (Vector3)value;
            builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity.gameObject.transform.position = convertedPosition;
            break;

        case ActionType.ROTATE:
            Vector3 convertedAngles = (Vector3)value;
            builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity.gameObject.transform.eulerAngles = convertedAngles;
            break;

        case ActionType.SCALE:
            Vector3            convertedScale = (Vector3)value;
            DecentralandEntity entityToApply  = builderInWorldEntityHandler.GetEntity(entityIdToApply).rootEntity;
            Transform          parent         = entityToApply.gameObject.transform.parent;

            entityToApply.gameObject.transform.localScale = new Vector3(convertedScale.x / parent.localScale.x, convertedScale.y / parent.localScale.y, convertedScale.z / parent.localScale.z);
            break;

        case ActionType.CREATE:
            string entityString = (string)value;
            if (isUndo)
            {
                builderInWorldEntityHandler.DeleteEntity(entityString);
            }
            else
            {
                builderInWorldEntityHandler.CreateEntityFromJSON(entityString);
            }

            break;

        case ActionType.DELETE:
            string deletedEntityString = (string)value;

            if (isUndo)
            {
                builderInWorldEntityHandler.CreateEntityFromJSON(deletedEntityString);
            }
            else
            {
                builderInWorldEntityHandler.DeleteEntity(deletedEntityString);
            }

            break;

        case ActionType.CHANGE_FLOOR:
            string sceneObjectToApply = (string)value;

            SceneObject floorObject = JsonConvert.DeserializeObject <SceneObject>(sceneObjectToApply);
            builderInWorldEntityHandler.DeleteFloorEntities();
            builderInWorldController.CreateFloor(floorObject);
            break;
        }
    }